11typedef std::chrono::high_resolution_clock
Clock;
20 bool entered_file =
false;
21 bool permute_graph =
false;
22 bool permute_graph_have_seed =
false;
23 int permute_graph_given_seed = 0;
26 bool true_random =
false;
27 bool true_random_seed =
false;
31 bool write_grp_sz =
false;
32 bool write_benchmark_lines =
false;
33 bool write_auto_stdout =
false;
34 bool write_auto_file =
false;
35 std::string write_auto_file_name;
37 for (
int i = 1; i < argc; ++i) {
38 std::string arg = std::string(argv[i]);
39 std::transform(arg.begin(), arg.end(), arg.begin(), ::toupper);
40 std::replace(arg.begin(), arg.end(),
'-',
'_');
42 if (arg ==
"__HELP" || arg ==
"_H") {
43 std::cout <<
"Usage: dejavu [file] [options]" << std::endl;
44 std::cout <<
"Computes the automorphism group of undirected graph described in FILE." << std::endl;
45 std::cout <<
"FILE is expected to be in DIMACS format." << std::endl;
46 std::cout <<
"Options:" << std::endl;
47 std::cout <<
" " << std::left << std::setw(20) <<
48 "--err [n]" << std::setw(16) <<
49 "Sets the error to be bounded by 1/2^N, assuming uniform random numbers" << std::endl;
50 std::cout <<
" " << std::left << std::setw(20) <<
51 "--silent" << std::setw(16) <<
52 "Does not print progress of the solver" << std::endl;
53 std::cout <<
" " << std::left << std::setw(20) <<
54 "--gens" << std::setw(16) <<
55 "Prints found generators line-by-line to console" << std::endl;
56 std::cout <<
" " << std::left << std::setw(20) <<
57 "--gens-file [f]" << std::setw(16) <<
58 "Writes found generators line-by-line to file F" << std::endl;
59 std::cout <<
" " << std::left << std::setw(20) <<
60 "--grp-sz" << std::setw(16) <<
61 "Prints group size to console (even if --silent)" << std::endl;
62 std::cout <<
" " << std::left << std::setw(20) <<
63 "--pseudo-random" << std::setw(16) <<
64 "Uses pseudo random numbers (default)" << std::endl;
65 std::cout <<
" " << std::left << std::setw(20) <<
66 "--true-random" << std::setw(16) <<
67 "Uses random device of OS" << std::endl;
68 std::cout <<
" " << std::left << std::setw(20) <<
69 "--true-random-seed" << std::setw(16) <<
70 "Seeds pseudo random with random device of OS" << std::endl;
71 std::cout <<
" " << std::left << std::setw(20) <<
72 "--permute" << std::setw(16) <<
73 "Randomly permutes the given graph" << std::endl;
74 std::cout <<
" " << std::left << std::setw(20) <<
75 "--permute-seed [n]" << std::setw(16) <<
76 "Seed for the previous option with N" << std::endl;
78 }
else if (arg ==
"__VERSION" || arg ==
"_V") {
82 }
else if (arg ==
"__FILE") {
88 std::cerr <<
"--file option requires one argument." << std::endl;
91 }
else if (arg ==
"__ERR") {
94 error_bound = atoi(argv[i]);
96 std::cerr <<
"--err option requires one argument." << std::endl;
99 }
else if (arg ==
"__GRP_SZ") {
101 }
else if (arg ==
"__BENCHMARK_LINES") {
102 write_benchmark_lines =
true;
103 }
else if (arg ==
"__GENS") {
104 write_auto_stdout =
true;
105 }
else if (arg ==
"__GENS_FILE") {
108 write_auto_file =
true;
109 write_auto_file_name = argv[i];
111 std::cerr <<
"--write-gens-file option requires one argument." << std::endl;
114 }
else if (arg ==
"__TRUE_RANDOM") {
115 if(true_random_seed) {
116 std::cerr <<
"--true-random and --true-random-seed can not be activated at the same time:" <<
117 "--true-random-seed seeds a pseudo random number generator with a random number" << std::endl;
121 }
else if (arg ==
"__PSEUDO_RANDOM") {
123 }
else if (arg ==
"__TRUE_RANDOM_SEED") {
125 std::cerr <<
"--true-random and --true-random-seed can not be activated at the same time:" <<
126 "--true-random-seed seeds a pseudo random number generator with a random number" << std::endl;
129 true_random_seed =
true;
130 }
else if (arg ==
"__PERMUTE") {
131 permute_graph =
true;
132 }
else if (arg ==
"__PERMUTE_SEED") {
135 permute_graph_have_seed =
true;
136 permute_graph_given_seed = atoi(argv[i]);
138 std::cerr <<
"--permute_seed option requires one argument." << std::endl;
141 }
else if (arg ==
"__SILENT") {
143 }
else if (argv[i][0] !=
'-') {
148 std::cerr <<
"Extraneous file '" << argv[i] <<
"'. Only 1 file required." << std::endl;
152 std::cerr <<
"Invalid commandline option '" << argv[i] <<
"'." << std::endl;
158 std::cerr <<
"no file was specified, usage: dejavu [file] [options], use --help for options" << std::endl;
162 if(!file_exists(filename)) {
163 std::cerr <<
"File '" << filename <<
"' does not exist." << std::endl;
169 if(print) std::cout <<
"------------------------------------------------------------------" << std::endl;
172 if(print) std::cout <<
"parsing '" << filename <<
"'" << std::endl;
173 int* colmap =
nullptr;
175 int permute_seed = 0;
177 permute_seed = permute_graph_given_seed;
178 if(!permute_graph_have_seed) {
179 std::random_device r;
180 permute_seed =
static_cast<int>(r());
182 if(print) std::cout << (true_random?
"true_random=true, ":
"") << (true_random_seed?
"true_random_seed=true":
"");
183 if(print) std::cout <<
"permutation_seed=" << permute_seed <<
", ";
185 parse_dimacs(filename, &g, &colmap, !print, permute_seed);
186 if(print) std::cout <<
", n=" << g.
v_size <<
", " <<
"m=" << g.
e_size/2 << std::endl << std::endl;
191 std::ofstream output_file;
198 if(write_auto_file) {
199 output_file.open(write_auto_file_name);
206 auto test_hook_func =
dejavu_hook(dejavu::test_hook);
213 if(hooks.
size() == 0) hook = &empty_hook_func;
217 if (colmap ==
nullptr) colmap = (
int *) calloc(g.
v_size,
sizeof(
int));
220 Clock::time_point timer = Clock::now();
229 long dejavu_solve_time = (std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now() - timer).count());
232 if (print) std::cout <<
"------------------------------------------------------------------" << std::endl;
233 if (print || write_benchmark_lines)
234 std::cout << std::setprecision(4) <<
"symmetries=" << grp_sz
238 if(print || write_benchmark_lines) std::cout <<
"solve_time=" <<
239 static_cast<double>(dejavu_solve_time) / 1000000.0 <<
"ms" << std::endl;
240 if(!print && write_grp_sz) std::cout << grp_sz << std::endl;
246int main(
int argc,
char *argv[]) {
Calls several other hooks.
void add_hook(dejavu_hook *hook)
dej_nodiscard size_t size() const
dejavu_hook * get_hook() override
dejavu_hook * get_hook() override
Color refinement and related algorithms.
Internal graph data structure.
void copy_graph(sgraph *g)
dej_nodiscard big_number get_automorphism_group_size() const
dej_nodiscard bool get_deterministic_termination() const
int get_error_bound() const
void set_true_random(bool use_true_random=true)
void set_print(bool print=true)
void automorphisms(static_graph *g, dejavu_hook *hook=nullptr)
void set_error_bound(int error_bound=10)
int main(int argc, char *argv[])
std::chrono::high_resolution_clock Clock
dejavu::ir::refinement test_r
dejavu::sgraph dej_test_graph
int commandline_mode(int argc, char **argv)
void empty_hook(int, const int *, int, const int *)
#define DEJAVU_VERSION_MAJOR
#define DEJAVU_VERSION_IS_PREVIEW
#define DEJAVU_VERSION_MINOR
std::function< void(int, const int *, int, const int *)> dejavu_hook