The bliss C++ API 0.77 (Debian 0.77-3)
digraph.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 <bliss/abstractgraph.hh>
23
24namespace bliss {
25
31class Digraph : public AbstractGraph
32{
33public:
42 typedef enum {
46 shs_f = 0,
66
67protected:
68 class Vertex {
69 public:
70 Vertex();
71 ~Vertex();
72 void add_edge_to(const unsigned int dest_vertex);
73 void add_edge_from(const unsigned int source_vertex);
74 void remove_duplicate_edges(std::vector<bool>& tmp);
75 void sort_edges();
76 unsigned int color;
77 std::vector<unsigned int> edges_out;
78 std::vector<unsigned int> edges_in;
79 unsigned int nof_edges_in() const {return edges_in.size(); }
80 unsigned int nof_edges_out() const {return edges_out.size(); }
81 };
82 std::vector<Vertex> vertices;
83 void remove_duplicate_edges();
84
90 static unsigned int vertex_color_invariant(const Digraph* const g,
91 const unsigned int v);
98 static unsigned int indegree_invariant(const Digraph* const g,
99 const unsigned int v);
106 static unsigned int outdegree_invariant(const Digraph* const g,
107 const unsigned int v);
113 static unsigned int selfloop_invariant(const Digraph* const g,
114 const unsigned int v);
115
120 bool refine_according_to_invariant(unsigned int (*inv)(const Digraph* const g,
121 const unsigned int v));
122
123 /*
124 * Routines needed when refining the partition p into equitable
125 */
126 bool split_neighbourhood_of_unit_cell(Partition::Cell* const);
127 bool split_neighbourhood_of_cell(Partition::Cell* const);
128
129
133 bool is_equitable() const;
134
135 /* Splitting heuristics, documented in more detail in the cc-file. */
137 Partition::Cell* find_next_cell_to_be_splitted(Partition::Cell *cell);
138 Partition::Cell* sh_first();
139 Partition::Cell* sh_first_smallest();
140 Partition::Cell* sh_first_largest();
141 Partition::Cell* sh_first_max_neighbours();
142 Partition::Cell* sh_first_smallest_max_neighbours();
143 Partition::Cell* sh_first_largest_max_neighbours();
144
145 /* A data structure used in many functions.
146 * Allocated only once to reduce allocation overhead,
147 * may be used only in one function at a time.
148 */
149 std::vector<Partition::Cell*> _neighbour_cells;
150
151 void make_initial_equitable_partition();
152
153 void initialize_certificate();
154
155 void sort_edges();
156
157 bool nucr_find_first_component(const unsigned int level);
158 bool nucr_find_first_component(const unsigned int level,
159 std::vector<unsigned int>& component,
160 unsigned int& component_elements,
161 Partition::Cell*& sh_return);
162
163public:
167 Digraph(const unsigned int N = 0);
168
172 ~Digraph();
173
187 static Digraph* read_dimacs(FILE* const fp, FILE* const errstr = stderr);
188
192 void write_dimacs(FILE* const fp);
193
194
198 void write_dot(FILE * const fp);
199
203 void write_dot(const char * const file_name);
204
205
206
210 virtual unsigned int get_hash();
211
215 unsigned int get_nof_vertices() const {return vertices.size(); }
216
220 unsigned int add_vertex(const unsigned int color = 0);
221
228 void add_edge(const unsigned int source, const unsigned int target);
229
233 unsigned int get_color(const unsigned int vertex) const;
234
238 void change_color(const unsigned int vertex, const unsigned int color);
239
243 Digraph* copy() const;
244
251 int cmp(Digraph& other);
252
263
267 Digraph* permute(const unsigned int* const perm) const;
268
272 Digraph* permute(const std::vector<unsigned int>& perm) const;
273
277 bool is_automorphism(unsigned int* const perm) const;
278
282 bool is_automorphism(const std::vector<unsigned int>& perm) const;
283};
284
285} // namespace bliss
An abstract base class for different types of graphs.
Definition: abstractgraph.hh:48
The class for directed, vertex colored graphs.
Definition: digraph.hh:32
int cmp(Digraph &other)
Definition: digraph.cc:176
void write_dot(FILE *const fp)
Definition: digraph.cc:304
static Digraph * read_dimacs(FILE *const fp, FILE *const errstr=stderr)
Definition: digraph.cc:397
void add_edge(const unsigned int source, const unsigned int target)
Definition: digraph.cc:126
SplittingHeuristic
Definition: digraph.hh:42
@ shs_fl
Definition: digraph.hh:52
@ shs_fm
Definition: digraph.hh:56
@ shs_fs
Definition: digraph.hh:49
@ shs_flm
Definition: digraph.hh:64
@ shs_f
Definition: digraph.hh:46
@ shs_fsm
Definition: digraph.hh:60
void set_splitting_heuristic(SplittingHeuristic shs)
Definition: digraph.hh:262
virtual unsigned int get_hash()
Definition: digraph.cc:356
Digraph(const unsigned int N=0)
Definition: digraph.cc:102
unsigned int add_vertex(const unsigned int color=0)
Definition: digraph.cc:116
unsigned int get_nof_vertices() const
Definition: digraph.hh:215
Digraph * copy() const
Definition: digraph.cc:151
void change_color(const unsigned int vertex, const unsigned int color)
Definition: digraph.cc:143
Digraph * permute(const unsigned int *const perm) const
Definition: digraph.cc:262
void write_dimacs(FILE *const fp)
Definition: digraph.cc:558
unsigned int get_color(const unsigned int vertex) const
Definition: digraph.cc:136
~Digraph()
Definition: digraph.cc:109
bool is_automorphism(unsigned int *const perm) const
Definition: digraph.cc:1694
Definition: abstractgraph.cc:35