Orbiter 2022
Combinatorial Objects
graph_theoretic_activity.cpp
Go to the documentation of this file.
1/*
2 * graph_theoretic_activity.cpp
3 *
4 * Created on: Mar 23, 2021
5 * Author: betten
6 */
7
8
9
10
11#include "orbiter.h"
12
13using namespace std;
14
15namespace orbiter {
16namespace layer5_applications {
17namespace apps_graph_theory {
18
19
21{
22 Descr = NULL;
23 CG = NULL;
24}
25
27{
28}
29
30
33 int verbose_level)
34{
35 int f_v = (verbose_level >= 1);
36
37 if (f_v) {
38 cout << "graph_theoretic_activity::init" << endl;
39 }
40
43
44 if (f_v) {
45 cout << "graph_theoretic_activity::init, label = " << graph_theoretic_activity::CG->label << endl;
46 }
47
48
49 if (f_v) {
50 cout << "graph_theoretic_activity::init done" << endl;
51 }
52}
53
55{
56 int f_v = (verbose_level >= 1);
57
58 if (f_v) {
59 cout << "graph_theoretic_activity::perform_activity, CG->label=" << CG->label << endl;
60 }
62
63 if (Descr->f_find_cliques) {
64 if (f_v) {
65 cout << "graph_theoretic_activity::perform_activity f_find_cliques" << endl;
66 }
67
68 if (f_v) {
69 cout << "graph_theoretic_activity::perform_activity before CG->all_cliques" << endl;
70 }
73 CG->label, verbose_level);
74 if (f_v) {
75 cout << "graph_theoretic_activity::perform_activity after CG->all_cliques" << endl;
76 }
77
78
79
80
81 if (f_v) {
82 cout << "graph_theoretic_activity::perform_activity Gr->label=" << CG->label << " nb_sol = " << Descr->Clique_finder_control->nb_sol << endl;
83 }
84
85 }
86 else if (Descr->f_export_magma) {
87 if (f_v) {
88 cout << "graph_theoretic_activity::perform_activity f_export_magma" << endl;
89 }
90
91 string fname_magma;
92 string fname_text;
93
94 fname_magma.assign(CG->label);
95
96 fname_text.assign(CG->label);
97
98
99 ST.replace_extension_with(fname_magma, ".magma");
100 ST.replace_extension_with(fname_text, ".txt");
101
102 if (f_v) {
103 cout << "exporting to magma as " << fname_magma << endl;
104 }
105
106
107 CG->export_to_magma(fname_magma, verbose_level);
108
109 CG->export_to_text(fname_text, verbose_level);
110
111 if (f_v) {
112 cout << "export_magma done" << endl;
113 }
114 }
115 else if (Descr->f_export_maple) {
116 if (f_v) {
117 cout << "graph_theoretic_activity::perform_activity f_export_maple" << endl;
118 }
119
120
121 string fname_maple;
122
123 fname_maple.assign(CG->label);
124
125
126 ST.replace_extension_with(fname_maple, ".maple");
127
128 if (f_v) {
129 cout << "exporting to maple as " << fname_maple << endl;
130 }
131
132
133 CG->export_to_maple(fname_maple, verbose_level);
134
135 if (f_v) {
136 cout << "export_maple done" << endl;
137 }
138
139 }
140 else if (Descr->f_export_csv) {
141 if (f_v) {
142 cout << "graph_theoretic_activity::perform_activity f_export_csv" << endl;
143 }
144
145
146 string fname_csv;
147
148 fname_csv.assign(CG->label);
149
150
151 ST.replace_extension_with(fname_csv, ".csv");
152
153 cout << "exporting to csv as " << fname_csv << endl;
154
155
156 CG->export_to_csv(fname_csv, verbose_level);
157
158 }
159
160 else if (Descr->f_export_graphviz) {
161 if (f_v) {
162 cout << "graph_theoretic_activity::perform_activity f_export_graphviz" << endl;
163 }
164
165
166 string fname_csv;
167
168 fname_csv.assign(CG->label);
169
170
171 ST.replace_extension_with(fname_csv, ".gv");
172
173 cout << "exporting to gv as " << fname_csv << endl;
174
175
176 CG->export_to_graphviz(fname_csv, verbose_level);
177
178 }
179
180 else if (Descr->f_print) {
181 if (f_v) {
182 cout << "graph_theoretic_activity::perform_activity f_print" << endl;
183 }
184 CG->print();
185
186 }
187 else if (Descr->f_sort_by_colors) {
188 if (f_v) {
189 cout << "graph_theoretic_activity::perform_activity f_sort_by_colors" << endl;
190 }
192 string fname2;
193
194 fname2.assign(CG->label);
195 //strcpy(fname2, fname_graph);
196 ST.replace_extension_with(fname2, "_sorted.bin");
197 CG2 = CG->sort_by_color_classes(verbose_level);
198 CG2->save(fname2, verbose_level);
199 FREE_OBJECT(CG2);
200
201 }
202
203 else if (Descr->f_split) {
204 cout << "splitting by file " << Descr->split_by_file << endl;
206 long int *Split;
207 int m, n;
208 int a, c;
210
211
212 Fio.lint_matrix_read_csv(Descr->split_by_file, Split, m, n, verbose_level - 2);
213 cout << "We found " << m << " cases for splitting" << endl;
214 for (c = 0; c < m; c++) {
215
216 cout << "splitting case " << c << " / " << m << ":" << endl;
217 a = Split[2 * c + 0];
218
220 data_structures::fancy_set *color_subset;
221 data_structures::fancy_set *vertex_subset;
222
223 Subgraph = CG->compute_neighborhood_subgraph(a,
224 vertex_subset, color_subset,
225 verbose_level);
226
227 string fname_out;
228
229 fname_out.assign(Descr->split_input_fname);
230 ST.chop_off_extension(fname_out);
231
232 char str[1000];
233 sprintf(str, "_case_%03d.bin", c);
234 fname_out.append(str);
235
236
237 Subgraph->save(fname_out, verbose_level - 2);
238 }
239 }
240
241 else if (Descr->f_split_by_starters) {
242 cout << "splitting by file " << Descr->split_by_starters_fname_reps
243 << " column " << Descr->split_by_starters_col_label << endl;
246 //string_tools ST;
247 int c;
248
249
252 Reps, verbose_level);
253
254
255 cout << "We found " << Reps->nb_sets << " cases for splitting" << endl;
256
257 for (c = 0; c < Reps->nb_sets; c++) {
258
259 cout << "splitting case " << c << " / " << Reps->nb_sets << ":" << endl;
260
262 data_structures::fancy_set *color_subset;
263 data_structures::fancy_set *vertex_subset;
264
265
267 Reps->Sets[c], Reps->Set_size[c],
268 vertex_subset, color_subset,
269 verbose_level);
270
271 string fname_out;
272
273 fname_out.assign(CG->label);
274 //ST.chop_off_extension(fname_out);
275
276 char str[1000];
277 sprintf(str, "_case_%03d.bin", c);
278 fname_out.append(str);
279
280
281 Subgraph->save(fname_out, verbose_level - 2);
282 }
283 }
284 else if (Descr->f_split_by_clique) {
285 cout << "splitting by clique " << Descr->split_by_clique_label
286 << " clique " << Descr->split_by_clique_set << endl;
287
288 long int *set;
289 int sz;
290
292
294 data_structures::fancy_set *color_subset;
295 data_structures::fancy_set *vertex_subset;
296
297
299 set, sz,
300 vertex_subset, color_subset,
301 verbose_level);
302
303
304
305 string fname_base, fname_out, fname_subset;
306
307 fname_base.assign(CG->label);
308
309 fname_base.append("_");
310 fname_base.append(Descr->split_by_clique_label);
311
312 fname_out.assign(fname_base);
313 fname_out.append(".graph");
314
315
316 Subgraph->save(fname_out, verbose_level - 2);
317
318 fname_subset.assign(fname_base);
319 fname_subset.append("_subset.txt");
320
321 vertex_subset->save(fname_subset, verbose_level);
322
323 FREE_OBJECT(Subgraph);
324
325 }
326
327 else if (Descr->f_save) {
328
330 string fname;
331
332 fname.assign(CG->label);
333 fname.append(".colored_graph");
334
335 cout << "before save fname_graph=" << fname << endl;
336 CG->save(fname, verbose_level);
337 cout << "after save" << endl;
338
339
340#if 0
341 if (f_v) {
342 cout << "We will write to the file " << fname << endl;
343 }
344 Fio.write_set_to_file(fname, COC->Pts, COC->nb_pts, verbose_level);
345 if (f_v) {
346 cout << "Written file " << fname << " of size "
347 << Fio.file_size(fname) << endl;
348 }
349#endif
350
351 }
352
353 else if (Descr->f_automorphism_group) {
354
355 if (f_v) {
356 cout << "graph_theoretic_activity::perform_activity f_automorphism_group" << endl;
357 }
358
360 string fname;
361
362 fname.assign(CG->label);
363 fname.append(".colored_graph");
364
365
367 actions::action *Aut;
368
369 if (f_v) {
370 cout << "graph_theoretic_activity::perform_activity before Nauty.create_automorphism_group_of_colored_graph_object" << endl;
371 }
372 Aut = Nauty.create_automorphism_group_of_colored_graph_object(CG, verbose_level);
373 if (f_v) {
374 cout << "graph_theoretic_activity::perform_activity after Nauty.create_automorphism_group_of_colored_graph_object" << endl;
375 }
376
377 string fname_report;
378
379 fname_report.assign(CG->label);
380 fname_report.append("_report.tex");
381
382
383 {
384 char title[1000];
385 char author[1000];
386
387 snprintf(title, 1000, "Automorphism group of %s", CG->label_tex.c_str());
388 //strcpy(author, "");
389 author[0] = 0;
390
391
392 {
393 ofstream ost(fname_report);
395
396 L.head(ost,
397 FALSE /* f_book*/,
398 TRUE /* f_title */,
399 title, author,
400 FALSE /* f_toc */,
401 FALSE /* f_landscape */,
402 TRUE /* f_12pt */,
403 TRUE /* f_enlarged_page */,
404 TRUE /* f_pagenumbers */,
405 NULL /* extra_praeamble */);
406
407
409
410 Aut->Strong_gens->group_order(go);
411
412 ost << "\\noindent The automorphism group of $" << CG->label_tex << "$ "
413 "has order " << go << " and is generated by:\\\\" << endl;
415
416
417 if (f_v) {
418 cout << "graph_theoretic_activity::perform_activity after report" << endl;
419 }
420
421
422 L.foot(ost);
423
424 }
426
427 cout << "written file " << fname_report << " of size "
428 << Fio.file_size(fname_report) << endl;
429 }
430
431 string fname_group;
432
433 fname_group.assign(CG->label);
434 fname_group.append("_group.makefile");
435
436 if (f_v) {
437 cout << "graph_theoretic_activity::perform_activity before Aut->export_to_orbiter_as_bsgs label = " << CG->label << endl;
438 }
439 Aut->degree--;
440 if (f_v) {
441 cout << "graph_theoretic_activity::perform_activity before Aut->export_to_orbiter_as_bsgs degree = " << Aut->degree << endl;
442 }
443 Aut->export_to_orbiter_as_bsgs(fname_group, CG->label, CG->label_tex, Aut->Strong_gens, verbose_level);
444 if (f_v) {
445 cout << "graph_theoretic_activity::perform_activity after Aut->export_to_orbiter_as_bsgs" << endl;
446 }
447 //file_io Fio;
448
449 cout << "written file " << fname_group << " of size "
450 << Fio.file_size(fname_group) << endl;
451
452 }
453 else if (Descr->f_properties) {
454
455 if (f_v) {
456 cout << "graph_theoretic_activity::perform_activity f_properties" << endl;
457 }
458
459 CG->properties(verbose_level);
460 }
461 else if (Descr->f_eigenvalues) {
462
463 if (f_v) {
464 cout << "graph_theoretic_activity::perform_activity f_properties" << endl;
465 }
466
467 double *E;
468 double *L;
469 int i;
470
471 CG->eigenvalues(E, verbose_level - 2);
472 CG->Laplace_eigenvalues(L, verbose_level - 2);
473
474 cout << "The eigenvalues are:" << endl;
475 for (i = 0; i < CG->nb_points; i++) {
476 cout << i << " : " << E[i] << endl;
477 }
478
479 double energy = 0;
480 for (i = 0; i < CG->nb_points; i++) {
481 energy += ABS(E[i]);
482 }
483 cout << "The energy is " << energy << endl;
484
485 cout << "The Laplace eigenvalues are:" << endl;
486 for (i = 0; i < CG->nb_points; i++) {
487 cout << i << " : " << L[i] << endl;
488 }
489
490
491 {
492 string fname;
493 char title[1000];
494 char author[1000];
495
496 snprintf(title, 1000, "Eigenvalues of %s", CG->label_tex.c_str());
497 //strcpy(author, "");
498 author[0] = 0;
499
500 fname.assign(CG->label);
501 fname.append("_eigenvalues.tex");
502
503 {
504 ofstream ost(fname);
506
507 Li.head(ost,
508 FALSE /* f_book*/,
509 TRUE /* f_title */,
510 title, author,
511 FALSE /* f_toc */,
512 FALSE /* f_landscape */,
513 TRUE /* f_12pt */,
514 TRUE /* f_enlarged_page */,
515 TRUE /* f_pagenumbers */,
516 NULL /* extra_praeamble */);
517
518
519 if (f_v) {
520 cout << "graph_theoretic_activity::perform_activity before report" << endl;
521 }
522 //report(ost, verbose_level);
523
524 ost << "$$" << endl;
525 ost << "\\begin{array}{|r|r|r|}" << endl;
526 ost << "\\hline" << endl;
527 ost << " i & \\lambda_i & \\theta_i \\\\" << endl;
528 ost << "\\hline" << endl;
529 ost << "\\hline" << endl;
530 for (i = 0; i < CG->nb_points; i++) {
531 ost << i;
532 ost << " & ";
533 ost << E[CG->nb_points - 1 - i];
534 ost << " & ";
535 ost << L[CG->nb_points - 1 - i];
536 ost << "\\\\" << endl;
537 ost << "\\hline" << endl;
538 }
539 ost << "\\end{array}" << endl;
540 ost << "$$" << endl;
541
542 ost << "The energy is " << energy << "\\\\" << endl;
543 ost << "Eigenvalues: $\\lambda_i$\\\\" << endl;
544 ost << "Laplace eigenvalues: $\\theta_i$\\\\" << endl;
545
546 if (f_v) {
547 cout << "graph_theoretic_activity::perform_activity after report" << endl;
548 }
549
550
551 Li.foot(ost);
552
553 }
555
556 cout << "graph_theoretic_activity::perform_activity written file " << fname << " of size "
557 << Fio.file_size(fname) << endl;
558 }
559
560
561
562 delete [] E;
563
564 }
565 else if (Descr->f_draw) {
566
567 if (f_v) {
568 cout << "graph_theoretic_activity::perform_activity f_draw" << endl;
569 }
570
571 string fname;
572
573 fname.assign(CG->label);
574 fname.append("_draw.mp");
575
577 fname,
578 orbiter_kernel_system::Orbiter->draw_options,
579 verbose_level);
580 }
581
582
583
584
585 if (f_v) {
586 cout << "graph_theoretic_activity::perform_activity done" << endl;
587 }
588}
589
590}}}
591
592
593
void save(std::string &fname, int verbose_level)
Definition: fancy_set.cpp:306
functions related to strings and character arrays
void replace_extension_with(char *p, const char *new_ext)
void export_to_maple(std::string &fname, int verbose_level)
colored_graph * sort_by_color_classes(int verbose_level)
void export_to_csv(std::string &fname, int verbose_level)
void Laplace_eigenvalues(double *&E, int verbose_level)
void save(std::string &fname, int verbose_level)
void export_to_magma(std::string &fname, int verbose_level)
void export_to_text(std::string &fname, int verbose_level)
void all_cliques(clique_finder_control *Control, std::string &graph_label, int verbose_level)
colored_graph * compute_neighborhood_subgraph(int pt, data_structures::fancy_set *&vertex_subset, data_structures::fancy_set *&color_subset, int verbose_level)
void draw_on_circle(std::string &fname, graphics::layered_graph_draw_options *Draw_options, int verbose_level)
colored_graph * compute_neighborhood_subgraph_based_on_subset(long int *subset, int subset_sz, data_structures::fancy_set *&vertex_subset, data_structures::fancy_set *&color_subset, int verbose_level)
void export_to_graphviz(std::string &fname, int verbose_level)
void read_column_and_parse(std::string &fname, std::string &col_label, data_structures::set_of_sets *&SoS, int verbose_level)
Definition: file_io.cpp:1633
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
void write_set_to_file(std::string &fname, long int *the_set, int set_size, int verbose_level)
Definition: file_io.cpp:2434
void head(std::ostream &ost, int f_book, int f_title, const char *title, const char *author, int f_toc, int f_landscape, int f_12pt, int f_enlarged_page, int f_pagenumbers, const char *extras_for_preamble)
a class to represent arbitrary precision integers
Definition: ring_theory.h:366
a permutation group in a fixed action.
Definition: actions.h:99
groups::strong_generators * Strong_gens
Definition: actions.h:130
void export_to_orbiter_as_bsgs(std::string &fname, std::string &label, std::string &label_tex, groups::strong_generators *SG, int verbose_level)
Definition: action_io.cpp:1077
Interface to the graph canonization software Nauty.
Definition: actions.h:1154
action * create_automorphism_group_of_colored_graph_object(graph_theory::colored_graph *CG, int verbose_level)
void group_order(ring_theory::longinteger_object &go)
void init(graph_theoretic_activity_description *Descr, graph_theory::colored_graph *CG, int verbose_level)
#define Lint_vec_scan(A, B, C)
Definition: foundations.h:717
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define ABS(x)
Definition: foundations.h:220
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects