The bliss C++ API
graph.hh
1 #pragma once
2 
3 /*
4  Copyright (c) 2003-2021 Tommi Junttila
5  Released under the GNU Lesser General Public License version 3.
6 
7  This file is part of bliss.
8 
9  bliss is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, version 3 of the License.
12 
13  bliss is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with bliss. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "abstractgraph.hh"
23 
24 namespace bliss {
25 
31 class Graph : public AbstractGraph
32 {
33 public:
42  typedef enum {
46  shs_f = 0,
66 
67 protected:
68  class Vertex {
69  public:
70  Vertex();
71  ~Vertex();
72  void add_edge(const unsigned int other_vertex);
73  void remove_duplicate_edges(std::vector<bool>& tmp);
74  void sort_edges();
75 
76  unsigned int color;
77  std::vector<unsigned int> edges;
78  unsigned int nof_edges() const {return edges.size(); }
79  };
80  std::vector<Vertex> vertices;
81  void sort_edges();
82  void remove_duplicate_edges();
83 
89  static unsigned int vertex_color_invariant(const Graph* const g,
90  const unsigned int v);
91 
98  static unsigned int degree_invariant(const Graph* const g,
99  const unsigned int v);
100 
106  static unsigned int selfloop_invariant(const Graph* const g,
107  const unsigned int v);
108 
109 
110  bool refine_according_to_invariant(unsigned int (*inv)(const Graph* const g,
111  const unsigned int v));
112 
113  /*
114  * Routines needed when refining the partition p into equitable
115  */
116  bool split_neighbourhood_of_unit_cell(Partition::Cell * const);
117  bool split_neighbourhood_of_cell(Partition::Cell * const);
118 
122  bool is_equitable() const;
123 
124  /* Splitting heuristics, documented in more detail in graph.cc */
125  SplittingHeuristic sh;
126  Partition::Cell* find_next_cell_to_be_splitted(Partition::Cell *cell);
127  Partition::Cell* sh_first();
128  Partition::Cell* sh_first_smallest();
129  Partition::Cell* sh_first_largest();
130  Partition::Cell* sh_first_max_neighbours();
131  Partition::Cell* sh_first_smallest_max_neighbours();
132  Partition::Cell* sh_first_largest_max_neighbours();
133 
134 
135  /* A data structure used in many functions.
136  * Allocated only once to reduce allocation overhead,
137  * may be used only in one function at a time.
138  */
139  std::vector<Partition::Cell*> _neighbour_cells;
140 
141  void make_initial_equitable_partition();
142 
143  void initialize_certificate();
144 
145 
146 
147  bool nucr_find_first_component(const unsigned int level);
148  bool nucr_find_first_component(const unsigned int level,
149  std::vector<unsigned int>& component,
150  unsigned int& component_elements,
151  Partition::Cell*& sh_return);
152 
153 
154 
155 
156 public:
160  Graph(const unsigned int N = 0);
161 
165  ~Graph();
166 
181  static Graph* read_dimacs(FILE* const fp, FILE* const errstr = stderr);
182 
188  void write_dimacs(FILE* const fp);
189 
193  void write_dot(FILE* const fp);
194 
198  void write_dot(const char* const file_name);
199 
200 
201 
205  virtual unsigned int get_hash();
206 
210  unsigned int get_nof_vertices() const {return vertices.size(); }
211 
215  Graph* permute(const unsigned int* const perm) const;
219  Graph* permute(const std::vector<unsigned int>& perm) const;
220 
224  bool is_automorphism(unsigned int* const perm) const;
225 
229  bool is_automorphism(const std::vector<unsigned int>& perm) const;
230 
234  unsigned int add_vertex(const unsigned int color = 0);
235 
242  void add_edge(const unsigned int v1, const unsigned int v2);
243 
247  unsigned int get_color(const unsigned int vertex) const;
248 
252  void change_color(const unsigned int vertex, const unsigned int color);
253 
257  Graph* copy() const;
258 
265  int cmp(Graph& other);
266 
276  void set_splitting_heuristic(const SplittingHeuristic shs) {sh = shs; }
277 
278 
279 };
280 
281 } // namespace bliss
void write_dimacs(FILE *const fp)
Definition: graph.cc:327
int cmp(Graph &other)
Definition: graph.cc:377
unsigned int get_nof_vertices() const
Definition: graph.hh:210
Definition: abstractgraph.cc:35
Definition: graph.hh:64
static Graph * read_dimacs(FILE *const fp, FILE *const errstr=stderr)
Definition: graph.cc:165
bool is_automorphism(unsigned int *const perm) const
Definition: graph.cc:1387
unsigned int get_color(const unsigned int vertex) const
Definition: graph.cc:126
void write_dot(FILE *const fp)
Definition: graph.cc:498
Definition: graph.hh:56
void add_edge(const unsigned int v1, const unsigned int v2)
Definition: graph.cc:115
SplittingHeuristic
Definition: graph.hh:42
Definition: graph.hh:60
Definition: graph.hh:52
Graph * copy() const
Definition: graph.cc:141
void change_color(const unsigned int vertex, const unsigned int color)
Definition: graph.cc:132
Definition: graph.hh:49
Data structure for holding information about a cell in a Partition.
Definition: partition.hh:50
The class for undirected, vertex colored graphs.
Definition: graph.hh:31
~Graph()
Definition: graph.cc:98
virtual unsigned int get_hash()
Definition: graph.cc:539
An abstract base class for different types of graphs.
Definition: abstractgraph.hh:47
Definition: graph.hh:46
Graph(const unsigned int N=0)
Definition: graph.cc:91
unsigned int add_vertex(const unsigned int color=0)
Definition: graph.cc:105
Graph * permute(const unsigned int *const perm) const
Definition: graph.cc:450
void set_splitting_heuristic(const SplittingHeuristic shs)
Definition: graph.hh:276