The bliss C++ API 0.77 (Debian 0.77-3)
abstractgraph.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
27namespace bliss {
28 class AbstractGraph;
29}
30
31#include <cstdio>
32#include <functional>
33#include <vector>
34#include <bliss/stats.hh>
35#include <bliss/kqueue.hh>
36#include <bliss/heap.hh>
37#include <bliss/orbit.hh>
38#include <bliss/partition.hh>
39#include <bliss/uintseqhash.hh>
40
41namespace bliss {
42
43
48{
49 friend class Partition;
50
51public:
53 virtual ~AbstractGraph();
54
59 void set_verbose_level(const unsigned int level);
60
65 void set_verbose_file(FILE * const fp);
66
70 virtual unsigned int add_vertex(const unsigned int color = 0) = 0;
71
78 virtual void add_edge(const unsigned int source, const unsigned int target) = 0;
79
83 virtual unsigned int get_color(const unsigned int vertex) const = 0;
84
88 virtual void change_color(const unsigned int vertex, const unsigned int color) = 0;
89
90
96 void set_failure_recording(const bool active) {
97 assert(not in_search);
98 opt_use_failure_recording = active;
99 }
100
110 void set_component_recursion(const bool active) {
111 assert(not in_search);
112 opt_use_comprec = active;
113 }
114
115
116
120 virtual unsigned int get_nof_vertices() const = 0;
121
128 virtual AbstractGraph* permute(const unsigned int* const perm) const = 0;
129
136 virtual AbstractGraph* permute(const std::vector<unsigned int>& perm) const = 0;
137
142 virtual bool is_automorphism(unsigned int* const perm) const = 0;
143
148 virtual bool is_automorphism(const std::vector<unsigned int>& perm) const = 0;
149
174 void find_automorphisms(Stats& stats,
175 const std::function<void(unsigned int n, const unsigned int* aut)>& report = nullptr,
176 const std::function<bool()>& terminate = nullptr);
177
203 const unsigned int* canonical_form(Stats& stats,
204 const std::function<void(unsigned int n, const unsigned int* aut)>& report = nullptr,
205 const std::function<bool()>& terminate = nullptr);
206
216 virtual void write_dimacs(FILE * const fp) = 0;
217
222 virtual void write_dot(FILE * const fp) = 0;
223
229 virtual void write_dot(const char * const file_name) = 0;
230
235 virtual unsigned int get_hash() = 0;
236
247 void set_long_prune_activity(const bool active) {
248 assert(not in_search);
249 opt_use_long_prune = active;
250 }
251
252
253
254protected:
257 unsigned int verbose_level;
258
261 FILE *verbstr;
262
265 Partition p;
266
271 bool in_search;
272
276 bool opt_use_failure_recording;
277
278 /* The "tree-specific" invariant value for the point when current path
279 * got different from the first path */
280 unsigned int failure_recording_fp_deviation;
281
285 bool opt_use_comprec;
286
287
288 unsigned int refine_current_path_certificate_index;
289 bool refine_compare_certificate;
290 bool refine_equal_to_first;
291 unsigned int refine_first_path_subcertificate_end;
292 int refine_cmp_to_best;
293 unsigned int refine_best_path_subcertificate_end;
294
295 static const unsigned int CERT_SPLIT = 0; //UINT_MAX;
296 static const unsigned int CERT_EDGE = 1; //UINT_MAX-1;
301 void cert_add(const unsigned int v1,
302 const unsigned int v2,
303 const unsigned int v3);
304
310 void cert_add_redundant(const unsigned int x,
311 const unsigned int y,
312 const unsigned int z);
313
317 bool opt_use_long_prune;
322 static const unsigned int long_prune_options_max_mem = 50;
327 static const unsigned int long_prune_options_max_stored_auts = 100;
328
329 unsigned int long_prune_max_stored_autss;
330 std::vector<std::vector<bool> *> long_prune_fixed;
331 std::vector<std::vector<bool> *> long_prune_mcrs;
332 std::vector<bool> long_prune_temp;
333 unsigned int long_prune_begin;
334 unsigned int long_prune_end;
338 void long_prune_init();
342 void long_prune_deallocate();
343 void long_prune_add_automorphism(const unsigned int *aut);
344 std::vector<bool>& long_prune_get_fixed(const unsigned int index);
345 std::vector<bool>& long_prune_allocget_fixed(const unsigned int index);
346 std::vector<bool>& long_prune_get_mcrs(const unsigned int index);
347 std::vector<bool>& long_prune_allocget_mcrs(const unsigned int index);
352 void long_prune_swap(const unsigned int i, const unsigned int j);
353
354 /*
355 * Data structures and routines for refining the partition p into equitable
356 */
357 Heap neighbour_heap;
358 virtual bool split_neighbourhood_of_unit_cell(Partition::Cell * const) = 0;
359 virtual bool split_neighbourhood_of_cell(Partition::Cell * const) = 0;
360 void refine_to_equitable();
361 void refine_to_equitable(Partition::Cell * const unit_cell);
362 void refine_to_equitable(Partition::Cell * const unit_cell1,
363 Partition::Cell * const unit_cell2);
364
365
371 bool do_refine_to_equitable();
372
373 unsigned int eqref_max_certificate_index;
377 bool compute_eqref_hash;
378 UintSeqHash eqref_hash;
379
380
385 virtual bool is_equitable() const = 0;
386
387 unsigned int *first_path_labeling;
388 unsigned int *first_path_labeling_inv;
389 Orbit first_path_orbits;
390 unsigned int *first_path_automorphism;
391
392 unsigned int *best_path_labeling;
393 unsigned int *best_path_labeling_inv;
394 Orbit best_path_orbits;
395 unsigned int *best_path_automorphism;
396
397 void update_labeling(unsigned int * const lab);
398 void update_labeling_and_its_inverse(unsigned int * const lab,
399 unsigned int * const lab_inv);
400 void update_orbit_information(Orbit &o, const unsigned int *perm);
401
402 void reset_permutation(unsigned int *perm);
403
404 std::vector<unsigned int> certificate_current_path;
405 std::vector<unsigned int> certificate_first_path;
406 std::vector<unsigned int> certificate_best_path;
407
408 unsigned int certificate_index;
409 virtual void initialize_certificate() = 0;
410
411 /* Remove duplicates from seq.
412 * If m is the largest element in seq, them m < tmp.size() must hold.
413 * All entries in tmp must be false when called.
414 * Under that condition, all entries in tmp are false on exit as well.
415 */
416 static void remove_duplicates(std::vector<unsigned int>& seq, std::vector<bool>& tmp);
417
418 virtual void remove_duplicate_edges() = 0;
419 virtual void make_initial_equitable_partition() = 0;
420 virtual Partition::Cell* find_next_cell_to_be_splitted(Partition::Cell *cell) = 0;
421
422
427 typedef struct {
428 unsigned int splitting_element;
429 unsigned int certificate_index;
430 unsigned int subcertificate_length;
431 UintSeqHash eqref_hash;
432 } PathInfo;
433
434 void search(const bool canonical, Stats &stats,
435 const std::function<void(unsigned int n, const unsigned int* aut)>& report_function = nullptr,
436 const std::function<bool()>& terminate = nullptr);
437
438
439 /*
440 *
441 * Nonuniform component recursion (NUCR)
442 *
443 */
444
445 /* The currently traversed component */
446 unsigned int cr_level;
447
451 class CR_CEP {
452 public:
454 unsigned int creation_level;
457 unsigned int discrete_cell_limit;
459 unsigned int next_cr_level;
461 unsigned int next_cep_index;
462 bool first_checked;
463 bool best_checked;
464 };
468 std::vector<CR_CEP> cr_cep_stack;
469
481 virtual bool nucr_find_first_component(const unsigned int level) = 0;
482 virtual bool nucr_find_first_component(const unsigned int level,
483 std::vector<unsigned int>& component,
484 unsigned int& component_elements,
485 Partition::Cell*& sh_return) = 0;
490 std::vector<unsigned int> cr_component;
494 unsigned int cr_component_elements;
495
496
497
498
499
500
501};
502
503} // namespace bliss
An abstract base class for different types of graphs.
Definition: abstractgraph.hh:48
void set_long_prune_activity(const bool active)
Definition: abstractgraph.hh:247
void set_verbose_level(const unsigned int level)
Definition: abstractgraph.cc:89
virtual void write_dot(const char *const file_name)=0
virtual bool is_automorphism(const std::vector< unsigned int > &perm) const =0
virtual AbstractGraph * permute(const unsigned int *const perm) const =0
virtual bool is_automorphism(unsigned int *const perm) const =0
virtual unsigned int get_hash()=0
virtual unsigned int add_vertex(const unsigned int color=0)=0
virtual void add_edge(const unsigned int source, const unsigned int target)=0
virtual unsigned int get_nof_vertices() const =0
virtual AbstractGraph * permute(const std::vector< unsigned int > &perm) const =0
virtual void change_color(const unsigned int vertex, const unsigned int color)=0
virtual void write_dot(FILE *const fp)=0
virtual unsigned int get_color(const unsigned int vertex) const =0
const unsigned int * canonical_form(Stats &stats, const std::function< void(unsigned int n, const unsigned int *aut)> &report=nullptr, const std::function< bool()> &terminate=nullptr)
Definition: abstractgraph.cc:1757
void set_verbose_file(FILE *const fp)
Definition: abstractgraph.cc:95
void set_component_recursion(const bool active)
Definition: abstractgraph.hh:110
void find_automorphisms(Stats &stats, const std::function< void(unsigned int n, const unsigned int *aut)> &report=nullptr, const std::function< bool()> &terminate=nullptr)
Definition: abstractgraph.cc:1745
virtual void write_dimacs(FILE *const fp)=0
void set_failure_recording(const bool active)
Definition: abstractgraph.hh:96
A min-heap of unsigned integers.
Definition: heap.hh:32
A class for representing orbit information.
Definition: orbit.hh:37
Data structure for holding information about a cell in a Partition.
Definition: partition.hh:51
A class for refinable, backtrackable ordered partitions.
Definition: partition.hh:45
Statistics returned by the bliss search algorithm.
Definition: stats.hh:32
A updatable hash for sequences of unsigned ints.
Definition: uintseqhash.hh:28
Definition: abstractgraph.cc:35