Orbiter 2022
Combinatorial Objects
graph_theory_domain.cpp
Go to the documentation of this file.
1/*
2 * graph_theory_domain.cpp
3 *
4 * Created on: Apr 21, 2019
5 * Author: betten
6 */
7
8#include "foundations.h"
9
10using namespace std;
11
12namespace orbiter {
13namespace layer1_foundations {
14namespace graph_theory {
15
16
18
19}
20
22
23}
24
26 std::string &fname_graph,
28 int f_labels,
29 int verbose_level)
30{
31 int f_v = (verbose_level >= 1);
32 std::string fname_draw;
34
35 if (f_v) {
36 cout << "graph_theory_domain::colored_graph_draw" << endl;
37 }
38
39 CG.load(fname_graph, verbose_level - 1);
40
41 fname_draw.assign(CG.fname_base);
42 fname_draw.append("_graph");
43
44 if (f_v) {
45 cout << "graph_theory_domain::colored_graph_draw before CG.draw_partitioned" << endl;
46 }
48 fname_draw,
49 Draw_options,
50 //fname_draw, xmax_in, ymax_in, xmax_out, ymax_out,
51 //FALSE /* f_labels */, scale, line_width,
52 f_labels,
53 verbose_level);
54 if (f_v) {
55 cout << "graph_theory_domain::colored_graph_draw after CG.draw_partitioned" << endl;
56 }
57 if (f_v) {
58 cout << "graph_theory_domain::colored_graph_draw done" << endl;
59 }
60}
61
63 clique_finder_control *Control,
64 std::string &fname,
65 int f_output_solution_raw,
66 int f_output_fname, std::string &output_fname,
67 int verbose_level)
68{
69 int f_v = (verbose_level >= 1);
71 std::string fname_sol;
72 std::string fname_success;
73
74 if (f_v) {
75 cout << "colored_graph_all_cliques" << endl;
76 }
77 CG.load(fname, verbose_level - 1);
78 if (f_output_fname) {
79 fname_sol.assign(output_fname);
80 fname_success.assign(output_fname);
81 fname_success.append(".success");
82 }
83 else {
84 fname_sol.assign(CG.fname_base);
85 fname_sol.append("_sol.txt");
86 fname_success.assign(CG.fname_base);
87 fname_success.append("_sol.success");
88 }
89
90 //CG.print();
91
92 {
93 ofstream fp(fname_sol.c_str());
94
95 if (f_v) {
96 cout << "colored_graph_all_cliques "
97 "before CG.all_rainbow_cliques" << endl;
98 }
99 CG.all_rainbow_cliques(Control,
100 fp,
101 verbose_level - 1);
102 if (f_v) {
103 cout << "colored_graph_all_cliques "
104 "after CG.all_rainbow_cliques" << endl;
105 }
106 fp << -1 << " " << Control->nb_sol << " " << Control->nb_search_steps << " "
107 << Control->nb_decision_steps << " " << Control->dt << endl;
108 }
109 {
110 ofstream fp(fname_success);
111 fp << "success" << endl;
112 }
113 if (f_v) {
114 cout << "colored_graph_all_cliques done" << endl;
115 }
116}
117
119 clique_finder_control *Control,
120 long int *list_of_cases, int nb_cases,
121 std::string &fname_template, std::string &fname_sol,
122 std::string &fname_stats,
123 int f_split, int split_r, int split_m,
124 int f_prefix, std::string &prefix,
125 int verbose_level)
126{
127 int f_v = (verbose_level >= 1);
128 int i, c;
129 int Search_steps = 0, Decision_steps = 0, Nb_sol = 0, Dt = 0;
130 std::string fname;
131 char fname_tmp[2000];
132
133 if (f_v) {
134 cout << "colored_graph_all_cliques_list_of_cases" << endl;
135 }
136 {
137 ofstream fp(fname_sol.c_str());
138 ofstream fp_stats(fname_stats.c_str());
139
140 fp_stats << "i,Case,Nb_sol,Nb_vertices,search_steps,"
141 "decision_steps,dt" << endl;
142 for (i = 0; i < nb_cases; i++) {
143
144 if (f_split && ((i % split_m) == split_r)) {
145 continue;
146 }
147 colored_graph *CG;
148
150
151 c = list_of_cases[i];
152 if (f_v) {
153 cout << "colored_graph_all_cliques_list_of_cases case " << i
154 << " / " << nb_cases << " which is " << c << endl;
155 }
156 snprintf(fname_tmp, 2000, fname_template.c_str(), c);
157 if (f_prefix) {
158 fname.assign(prefix);
159 fname.append(fname_tmp);
160 }
161 else {
162 fname.assign(fname_tmp);
163 }
164 CG->load(fname, verbose_level - 2);
165
166 //CG->print();
167
168 fp << "# start case " << c << endl;
169
170 string dummy;
171
172 CG->all_rainbow_cliques(Control,
173 fp,
174 verbose_level - 1);
175
176 fp << "# end case " << c << " " << Control->nb_sol << " " << Control->nb_search_steps
177 << " " << Control->nb_decision_steps << " " << Control->dt << endl;
178 fp_stats << i << "," << c << "," << Control->nb_sol << "," << CG->nb_points
179 << "," << Control->nb_search_steps << "," << Control->nb_decision_steps << "," << Control->dt
180 << endl;
181 Search_steps += Control->nb_search_steps;
182 Decision_steps += Control->nb_decision_steps;
183 Nb_sol += Control->nb_sol;
184 Dt += Control->dt;
185
186 FREE_OBJECT(CG);
187 }
188 fp << -1 << " " << Nb_sol << " " << Search_steps << " "
189 << Decision_steps << " " << Dt << endl;
190 fp_stats << "END" << endl;
191 }
192 if (f_v) {
193 cout << "colored_graph_all_cliques_list_of_cases "
194 "done Nb_sol=" << Nb_sol << endl;
195 }
196}
197
198
200 int n, int *Adj, int verbose_level)
201{
202 std::string fname;
203 int f_v = (verbose_level >= 1);
205
206 if (f_v) {
207 cout << "save_as_colored_graph_easy" << endl;
208 }
209 fname.assign(fname_base);
210 fname.append(".colored_graph");
211
212 colored_graph *CG;
213
215 CG->init_adjacency_no_colors(n, Adj, fname_base, fname_base, 0 /*verbose_level*/);
216
217 CG->save(fname, verbose_level);
218
219 FREE_OBJECT(CG);
220
221 if (f_v) {
222 cout << "save_as_colored_graph_easy Written file " << fname
223 << " of size " << Fio.file_size(fname) << endl;
224 }
225}
226
228 int nb_vertices, int nb_colors, int nb_colors_per_vertex,
229 long int *points, int *point_color,
230 long int *data, int data_sz,
232 int verbose_level)
233{
234 int f_v = (verbose_level >= 1);
235 int i, j, a, b;
236
237 if (f_v) {
238 cout << "save_colored_graph" << endl;
239 cout << "save_colored_graph fname=" << fname << endl;
240 cout << "save_colored_graph nb_vertices=" << nb_vertices << endl;
241 cout << "save_colored_graph nb_colors=" << nb_colors << endl;
242 cout << "save_colored_graph nb_colors_per_vertex="
243 << nb_colors_per_vertex << endl;
244 //cout << "save_colored_graph bitvector_length=" << bitvector_length << endl;
245 }
246
247 {
248 ofstream fp(fname, ios::binary);
249
250 a = -1; // marker for new file format
251 b = 1; // file format version number
252
253 fp.write((char*) &a, sizeof(int));
254 fp.write((char*) &b, sizeof(int));
255 fp.write((char*) &nb_vertices, sizeof(int));
256 fp.write((char*) &nb_colors, sizeof(int));
257 fp.write((char*) &nb_colors_per_vertex, sizeof(int));
258 fp.write((char*) &data_sz, sizeof(int));
259 if (FALSE) {
260 cout << "save_colored_graph before writing data" << endl;
261 }
262 for (i = 0; i < data_sz; i++) {
263 fp.write((char*) &data[i], sizeof(long int));
264 }
265 for (i = 0; i < nb_vertices; i++) {
266 if (FALSE) {
267 cout << "save_colored_graph before writing vertex " << i << " / " << nb_vertices << endl;
268 }
269 if (points) {
270 fp.write((char*) &points[i], sizeof(long int));
271 }
272 else {
273 a = 0;
274 fp.write((char*) &a, sizeof(int));
275 }
276 for (j = 0; j < nb_colors_per_vertex; j++) {
277 fp.write((char*) &point_color[i * nb_colors_per_vertex + j], sizeof(int));
278 }
279 }
280 if (FALSE) {
281 cout << "save_colored_graph before writing bitvec" << endl;
282 }
283 //Bitvec->save(fp);
284 fp.write((char*) Bitvec->get_data(), Bitvec->get_allocated_length());
285 if (FALSE) {
286 cout << "save_colored_graph after writing bitvec" << endl;
287 }
288 }
289
290 if (f_v) {
291 cout << "save_colored_graph done" << endl;
292 }
293}
294
296 int &nb_vertices, int &nb_colors, int &nb_colors_per_vertex,
297 long int *&vertex_labels, int *&vertex_colors, long int *&user_data,
298 int &user_data_size,
300 int verbose_level)
301{
302 int f_v = (verbose_level >= 1);
303 long int L;
304 int i, j, a, b;
306
307 if (f_v) {
308 cout << "graph_theory_domain::load_colored_graph" << endl;
309 }
310
311 if (Fio.file_size(fname) <= 0) {
312 cout << "graph_theory_domain::load_colored_graph the file " << fname << " does not exist or is empty" << endl;
313 exit(1);
314 }
315
316 {
317 ifstream fp(fname, ios::binary);
319
320 fp.read((char *) &a, sizeof(int));
321 if (a == -1) {
322
323
324 if (f_v) {
325 cout << "graph_theory_domain::load_colored_graph detected new file format" << endl;
326 }
327
328 // new file format
329 // the new format allows for multiple colors per vertex
330 // (must be constant across all vertices)
331 // The nb_colors_per_vertex tells how many colors each vertex has.
332 // So, vertex_colors[] is now a two-dimensional array:
333 // vertex_colors[nb_vertices * nb_colors_per_vertex]
334 // Also, vertex_labels[] is now long int.
335
336 // read the version number:
337
338 fp.read((char *) &b, sizeof(int));
339 if (f_v) {
340 cout << "graph_theory_domain::load_colored_graph version=" << b << endl;
341 }
342
343 fp.read((char *) &nb_vertices, sizeof(int));
344 fp.read((char *) &nb_colors, sizeof(int));
345 fp.read((char *) &nb_colors_per_vertex, sizeof(int));
346 if (f_v) {
347 cout << "graph_theory_domain::load_colored_graph nb_vertices=" << nb_vertices
348 << " nb_colors=" << nb_colors
349 << " nb_colors_per_vertex=" << nb_colors_per_vertex
350 << endl;
351 }
352
353
354 L = ((long int) nb_vertices * (long int) (nb_vertices - 1)) >> 1;
355
356#if 0
357 bitvector_length = (L + 7) >> 3;
358 if (f_v) {
359 cout << "graph_theory_domain::load_colored_graph bitvector_length="
360 << bitvector_length << endl;
361 }
362#endif
363
364 fp.read((char *) &user_data_size, sizeof(int));
365 if (f_v) {
366 cout << "graph_theory_domain::load_colored_graph user_data_size="
367 << user_data_size << endl;
368 }
369 user_data = NEW_lint(user_data_size);
370
371 for (i = 0; i < user_data_size; i++) {
372 fp.read((char *) &user_data[i], sizeof(long int));
373 }
374
375 vertex_labels = NEW_lint(nb_vertices);
376 vertex_colors = NEW_int(nb_vertices * nb_colors_per_vertex);
377
378 for (i = 0; i < nb_vertices; i++) {
379 fp.read((char *) &vertex_labels[i], sizeof(long int));
380 for (j = 0; j < nb_colors_per_vertex; j++) {
381 fp.read((char *) &vertex_colors[i * nb_colors_per_vertex + j], sizeof(int));
382 if (vertex_colors[i * nb_colors_per_vertex + j] >= nb_colors) {
383 cout << "graph_theory_domain::load_colored_graph" << endl;
384 cout << "vertex_colors[i * nb_colors_per_vertex + j] >= nb_colors" << endl;
385 cout << "vertex_colors[i * nb_colors_per_vertex + j]=" << vertex_colors[i * nb_colors_per_vertex + j] << endl;
386 cout << "i=" << i << endl;
387 cout << "j=" << j << endl;
388 cout << "nb_colors=" << nb_colors << endl;
389 exit(1);
390 }
391 }
392 Sorting.int_vec_heapsort(vertex_colors + i * nb_colors_per_vertex, nb_colors_per_vertex);
393 for (j = 1; j < nb_colors_per_vertex; j++) {
394 if (vertex_colors[i * nb_colors_per_vertex + j - 1] == vertex_colors[i * nb_colors_per_vertex + j]) {
395 cout << "graph_theory_domain::load_colored_graph repeated color for vertex " << i << " : " << endl;
396 Int_vec_print(cout, vertex_colors + i * nb_colors_per_vertex, nb_colors_per_vertex);
397 cout << endl;
398 exit(1);
399 }
400 }
401 }
402 }
403 else {
404
405 if (f_v) {
406 cout << "graph_theory_domain::load_colored_graph detected old file format in file " << fname << endl;
407 }
408 // old file format is still supported:
409
410 //cout << "graph_theory_domain::load_colored_graph old file format no longer supported" << endl;
411 //exit(1);
412 cout << "graph_theory_domain::load_colored_graph old file format detected, using compatibility mode" << endl;
413 nb_vertices = a;
414 fp.read((char *) &nb_colors, sizeof(int));
415 nb_colors_per_vertex = 1;
416 if (f_v) {
417 cout << "graph_theory_domain::load_colored_graph nb_vertices=" << nb_vertices
418 << " nb_colors=" << nb_colors
419 << " nb_colors_per_vertex=" << nb_colors_per_vertex
420 << endl;
421 }
422
423
424 L = ((long int) nb_vertices * (long int) (nb_vertices - 1)) >> 1;
425
426#if 0
427 bitvector_length = (L + 7) >> 3;
428 if (f_v) {
429 cout << "graph_theory_domain::load_colored_graph bitvector_length="
430 << bitvector_length << endl;
431 }
432#endif
433
434 fp.read((char *) &user_data_size, sizeof(int));
435 if (f_v) {
436 cout << "graph_theory_domain::load_colored_graph user_data_size="
437 << user_data_size << endl;
438 }
439 user_data = NEW_lint(user_data_size);
440
441 for (i = 0; i < user_data_size; i++) {
442 fp.read((char *) &a, sizeof(int));
443 user_data[i] = a;
444 }
445
446 vertex_labels = NEW_lint(nb_vertices);
447 vertex_colors = NEW_int(nb_vertices * nb_colors_per_vertex);
448
449 for (i = 0; i < nb_vertices; i++) {
450 fp.read((char *) &a, sizeof(int));
451 vertex_labels[i] = a;
452 for (j = 0; j < nb_colors_per_vertex; j++) {
453 fp.read((char *) &vertex_colors[i * nb_colors_per_vertex + j], sizeof(int));
454 if (vertex_colors[i * nb_colors_per_vertex + j] >= nb_colors) {
455 cout << "graph_theory_domain::load_colored_graph" << endl;
456 cout << "vertex_colors[i * nb_colors_per_vertex + j] >= nb_colors" << endl;
457 cout << "vertex_colors[i * nb_colors_per_vertex + j]=" << vertex_colors[i * nb_colors_per_vertex + j] << endl;
458 cout << "i=" << i << endl;
459 cout << "j=" << j << endl;
460 cout << "nb_colors=" << nb_colors << endl;
461 exit(1);
462 }
463 }
464 }
465 }
466
467 if (f_v) {
468 cout << "graph_theory_domain::load_colored_graph before allocating bitvector_adjacency" << endl;
469 }
471 Bitvec->allocate(L);
472 //bitvector_adjacency = NEW_uchar(bitvector_length);
473 fp.read((char *) Bitvec->get_data(), Bitvec->get_allocated_length());
474 }
475
476
477 if (f_v) {
478 cout << "graph_theory_domain::load_colored_graph done" << endl;
479 }
480}
481
482
484 int *&Pijk, int *&colors, int &nb_colors, int verbose_level)
485// color_graph[n * n]
486// added Dec 22, 2010.
487 {
488 int f_v = (verbose_level >= 1);
489 int f_vv = (verbose_level >= 2);
490 int N;
491 int *M1;
492 int k, i, j;
493 int ret = FALSE;
494
495 if (f_v) {
496 cout << "is_association_scheme" << endl;
497 }
498 N = (n * (n - 1)) / 2;
499 M1 = NEW_int(N);
500 k = 0;
501 for (i = 0; i < n; i++) {
502 for (j = i + 1; j < n; j++) {
503 M1[k++] = color_graph[i * n + j];
504 }
505 }
506 if (k != N) {
507 cout << "N=" << N << endl;
508 cout << "k=" << k << endl;
509 exit(1);
510 }
511
513
514 Cl.init(M1, N, FALSE, 0);
515 nb_colors = Cl.nb_types + 1;
516 colors = NEW_int(nb_colors);
517 colors[0] = color_graph[0];
518 for (i = 0; i < Cl.nb_types; i++) {
519 colors[i + 1] = Cl.data_sorted[Cl.type_first[i]];
520 }
521
522 if (f_vv) {
523 cout << "colors (the 0-th color is the diagonal color): ";
524 Int_vec_print(cout, colors, nb_colors);
525 cout << endl;
526 }
527
528 int C = nb_colors;
529 int *M = color_graph;
530 int pijk, pijk1, u, v, w, u0 = 0, v0 = 0;
531
532 Pijk = NEW_int(C * C * C);
533 Int_vec_zero(Pijk, C * C * C);
534 for (k = 0; k < C; k++) {
535 for (i = 0; i < C; i++) {
536 for (j = 0; j < C; j++) {
537 pijk = -1;
538 for (u = 0; u < n; u++) {
539 for (v = 0; v < n; v++) {
540 //if (v == u) continue;
541 if (M[u * n + v] != colors[k])
542 continue;
543 // now: edge (u,v) is colored k
544 pijk1 = 0;
545 for (w = 0; w < n; w++) {
546 //if (w == u)continue;
547 //if (w == v)continue;
548 if (M[u * n + w] != colors[i])
549 continue;
550 if (M[v * n + w] != colors[j])
551 continue;
552 //cout << "i=" << i << " j=" << j << " k=" << k
553 //<< " u=" << u << " v=" << v << " w=" << w
554 //<< " increasing pijk" << endl;
555 pijk1++;
556 } // next w
557 //cout << "i=" << i << " j=" << j << " k=" << k
558 //<< " u=" << u << " v=" << v
559 //<< " pijk1=" << pijk1 << endl;
560 if (pijk == -1) {
561 pijk = pijk1;
562 u0 = u;
563 v0 = v;
564 //cout << "u=" << u << " v=" << v
565 //<< " p_{" << i << "," << j << ","
566 //<< k << "}="
567 //<< Pijk[i * C * C + j * C + k] << endl;
568 }
569 else {
570 if (pijk1 != pijk) {
571 //FREE_int(Pijk);
572 //FREE_int(colors);
573
574 cout << "not an association scheme" << endl;
575 cout << "k=" << k << endl;
576 cout << "i=" << i << endl;
577 cout << "j=" << j << endl;
578 cout << "u0=" << u0 << endl;
579 cout << "v0=" << v0 << endl;
580 cout << "pijk=" << pijk << endl;
581 cout << "u=" << u << endl;
582 cout << "v=" << v << endl;
583 cout << "pijk1=" << pijk1 << endl;
584 //exit(1);
585
586 goto done;
587 }
588 }
589 } // next v
590 } // next u
591 Pijk[i * C * C + j * C + k] = pijk;
592 } // next j
593 } // next i
594 } // next k
595
596 ret = TRUE;
597
598 if (f_v) {
599 cout << "it is an association scheme" << endl;
600
601 if (f_v) {
602 print_Pijk(Pijk, C);
603 }
604
605 if (C == 3 && colors[1] == 0 && colors[2] == 1) {
606 int k, lambda, mu;
607
608 k = Pijk[2 * C * C + 2 * C + 0]; // p220;
609 lambda = Pijk[2 * C * C + 2 * C + 2]; // p222;
610 mu = Pijk[2 * C * C + 2 * C + 1]; // p221;
611 cout << "it is an SRG(" << n << "," << k << "," << lambda << ","
612 << mu << ")" << endl;
613 }
614
615 }
616
617 done:
618 FREE_int(M1);
619 return ret;
620}
621
622void graph_theory_domain::print_Pijk(int *Pijk, int nb_colors) {
623 int i, j, k;
624 int C = nb_colors;
625
626 for (k = 0; k < C; k++) {
627 int *Mtx;
628
629 Mtx = NEW_int(C * C);
630 for (i = 0; i < C; i++) {
631 for (j = 0; j < C; j++) {
632 Mtx[i * C + j] = Pijk[i * C * C + j * C + k];
633 }
634 }
635 cout << "P^{(" << k << ")}=(p_{i,j," << k << "})_{i,j}:" << endl;
636 Int_vec_print_integer_matrix_width(cout, Mtx, C, C, C, 3);
637 FREE_int(Mtx);
638 }
639}
640
642 int *Adj,
643 int N, int *first, int *len, int nb_parts, int *&R,
644 int verbose_level)
645{
646 int f_v = (verbose_level >= 1);
647 int I, J, i, j, f1, l1, f2, l2, r0 = 0, r;
648
649 if (f_v) {
650 cout << "compute_decomposition_of_graph_wrt_partition" << endl;
651 cout << "The partition is:" << endl;
652 cout << "first = ";
653 Int_vec_print(cout, first, nb_parts);
654 cout << endl;
655 cout << "len = ";
656 Int_vec_print(cout, len, nb_parts);
657 cout << endl;
658 }
659 R = NEW_int(nb_parts * nb_parts);
660 Int_vec_zero(R, nb_parts * nb_parts);
661 for (I = 0; I < nb_parts; I++) {
662 f1 = first[I];
663 l1 = len[I];
664 for (J = 0; J < nb_parts; J++) {
665 f2 = first[J];
666 l2 = len[J];
667 for (i = 0; i < l1; i++) {
668 r = 0;
669 for (j = 0; j < l2; j++) {
670 if (Adj[(f1 + i) * N + f2 + j]) {
671 r++;
672 }
673 }
674 if (i == 0) {
675 r0 = r;
676 }
677 else {
678 if (r0 != r) {
679 cout << "compute_decomposition_of_graph_"
680 "wrt_partition not tactical" << endl;
681 cout << "I=" << I << endl;
682 cout << "J=" << J << endl;
683 cout << "r0=" << r0 << endl;
684 cout << "r=" << r << endl;
685 exit(1);
686 }
687 }
688 }
689 R[I * nb_parts + J] = r0;
690 }
691 }
692 if (f_v) {
693 cout << "compute_decomposition_of_graph_wrt_partition done" << endl;
694 }
695}
696
698 std::string &fname_base,
700 int f_dots,
701 int f_partition, int nb_row_parts, int *row_part_first,
702 int nb_col_parts, int *col_part_first, int f_row_grid, int f_col_grid,
703 int f_bitmatrix, data_structures::bitmatrix *Bitmatrix,
704 int *M, int m, int n,
705 int f_has_labels, int *labels,
706 int verbose_level)
707{
708 int f_v = (verbose_level >= 1);
709
710 if (f_v) {
711 cout << "graph_theory_domain::draw_bitmatrix" << endl;
712 }
713 {
715
716 G.init(fname_base, Draw_options, verbose_level - 1);
717
718 G.draw_bitmatrix2(f_dots, f_partition, nb_row_parts, row_part_first,
719 nb_col_parts, col_part_first, f_row_grid, f_col_grid,
720 f_bitmatrix, Bitmatrix, M, m, n, //xmax_in, ymax_in,
721 f_has_labels, labels);
722
723 G.finish(cout, TRUE);
724 }
725 if (f_v) {
726 cout << "graph_theory_domain::draw_bitmatrix done" << endl;
727 }
728}
729
730
731void graph_theory_domain::list_parameters_of_SRG(int v_max, int verbose_level)
732{
733 int f_v = (verbose_level >= 1);
734
735 if (f_v) {
736 cout << "graph_theory_domain::list_parameters_of_SRG" << endl;
737 }
738
739 int v, v2, k, lambda, mu, cnt = 0;
740 int top, top2, bottom, b, tb;
741 int i, f, g, r, s;
743
744 for (v = 2; v <= v_max; v++) {
745 v2 = v >> 1;
746 for (k = 1; k <= v2; k++) {
747 for (lambda = 0; lambda <= k; lambda++) {
748 for (mu = 1; mu <= k; mu++) {
749 if (k * (k - lambda - 1) != mu * (v - k - 1)) {
750 continue;
751 }
752 top = (v - 1) * (mu - lambda) - 2 * k;
753 top2 = top * top;
754 bottom = (mu - lambda) * (mu - lambda) + 4 * (k - mu);
755 cnt++;
756 cout << "cnt=" << cnt << " v=" << v << " k=" << k
757 << " lambda=" << lambda << " mu=" << mu
758 << " top=" << top << " bottom=" << bottom << endl;
759 if (top2 % bottom) {
760 cout << "is ruled out by integrality condition" << endl;
761 continue;
762 }
763
764 int nb;
765 int *primes, *exponents;
766 nb = NT.factor_int(bottom, primes, exponents);
767 for (i = 0; i < nb; i++) {
768 if (ODD(exponents[i])) {
769 break;
770 }
771 }
772 if (i < nb) {
773 cout << "bottom is not a square" << endl;
774 continue;
775 }
776 for (i = 0; i < nb; i++) {
777 exponents[i] >>= 1;
778 }
779 b = 1;
780 for (i = 0; i < nb; i++) {
781 b *= NT.i_power_j(primes[i], exponents[i]);
782 }
783 cout << "b=" << b << endl;
784 tb = top / b;
785 cout << "tb=" << tb << endl;
786 if (ODD(v - 1 + tb)) {
787 cout << "is ruled out by integrality condition (2)" << endl;
788 continue;
789 }
790 if (ODD(v - 1 - tb)) {
791 cout << "is ruled out by integrality condition (3)" << endl;
792 continue;
793 }
794 f = (v - 1 + tb) >> 1;
795 g = (v - 1 - tb) >> 1;
796 if (ODD(lambda - mu + b)) {
797 cout << "r is not integral, skip" << endl;
798 continue;
799 }
800 if (ODD(lambda - mu - b)) {
801 cout << "r is not integral, skip" << endl;
802 continue;
803 }
804 r = (lambda - mu + b) >> 1;
805 s = (lambda - mu - b) >> 1;
806 cout << "f=" << f << " g=" << g << " r=" << r << " s=" << s << endl;
807
808 int L1, R1, L2, R2;
809
810 L1 = (r + 1) * (k + r + 2 * r * s);
811 R1 = (k + r) * (s + 1) * (s + 1);
812 L2 = (s + 1) * (k + s + 2 * r * s);
813 R2 = (k + s) * (r + 1) * (r + 1);
814
815 if (L1 > R1) {
816 cout << "is ruled out by Krein condition (1)" << endl;
817 continue;
818 }
819 if (L2 > R2) {
820 cout << "is ruled out by Krein condition (2)" << endl;
821 continue;
822 }
823 }
824 }
825 }
826 }
827
828 if (f_v) {
829 cout << "graph_theory_domain::list_parameters_of_SRG done" << endl;
830 }
831}
832
834 int n, int verbose_level)
835{
836 int f_v = (verbose_level >= 1);
837
838 if (f_v) {
839 cout << "graph_theory_domain::make_cycle_graph" << endl;
840 }
841 int i, j;
842
843 N = n;
844
845
846 Adj = NEW_int(N * N);
847 Int_vec_zero(Adj, N * N);
848
849 for (i = 0; i < N; i++) {
850 j = (i + 1) % N;
851 Adj[i * N + j] = 1;
852 Adj[j * N + i] = 1;
853 }
854
855 if (f_v) {
856 cout << "graph_theory_domain::make_cycle_graph done" << endl;
857 }
858
859}
860
861
862
863
865 int n, int q, int verbose_level)
866{
867 int f_v = (verbose_level >= 1);
868
869 if (f_v) {
870 cout << "graph_theory_domain::make_Hamming_graph" << endl;
871 }
875 int *v1;
876 int *v2;
877 int *v3;
878 int i, j, d;
879
880 N = NT.i_power_j(q, n);
881
882
883 Adj = NEW_int(N * N);
884 Int_vec_zero(Adj, N * N);
885
886 v1 = NEW_int(n);
887 v2 = NEW_int(n);
888 v3 = NEW_int(n);
889
890 for (i = 0; i < N; i++) {
891 GG.AG_element_unrank(q, v1, 1, n, i);
892 for (j = i + 1; j < N; j++) {
893 GG.AG_element_unrank(q, v2, 1, n, j);
894
895 d = Coding.Hamming_distance(v1, v2, n);
896 if (d == 1) {
897 Adj[i * N + j] = 1;
898 Adj[j * N + i] = 1;
899 }
900 }
901 }
902
903 FREE_int(v1);
904 FREE_int(v2);
905 FREE_int(v3);
906
907 if (f_v) {
908 cout << "graph_theory_domain::make_Hamming_graph done" << endl;
909 }
910
911}
912
913
915 int n, int k, int s, int verbose_level)
916{
917 int f_v = (verbose_level >= 1);
918
919 if (f_v) {
920 cout << "graph_theory_domain::make_Johnson_graph" << endl;
921 }
924 int *set1;
925 int *set2;
926 int *set3;
927 int i, j, sz;
928
929 N = Combi.int_n_choose_k(n, k);
930
931
932 Adj = NEW_int(N * N);
933 Int_vec_zero(Adj, N * N);
934
935 set1 = NEW_int(k);
936 set2 = NEW_int(k);
937 set3 = NEW_int(k);
938
939 for (i = 0; i < N; i++) {
940 Combi.unrank_k_subset(i, set1, n, k);
941 for (j = i + 1; j < N; j++) {
942 Combi.unrank_k_subset(j, set2, n, k);
943
944 Sorting.int_vec_intersect_sorted_vectors(set1, k, set2, k, set3, sz);
945 if (sz == s) {
946 Adj[i * N + j] = 1;
947 Adj[j * N + i] = 1;
948 }
949 }
950 }
951
952 FREE_int(set1);
953 FREE_int(set2);
954 FREE_int(set3);
955
956 if (f_v) {
957 cout << "graph_theory_domain::make_Johnson_graph done" << endl;
958 }
959
960}
961
963 int q, int verbose_level)
964{
965 int f_v = (verbose_level >= 1);
966
967 if (f_v) {
968 cout << "graph_theory_domain::make_Paley_graph" << endl;
969 }
970
971 if (EVEN(q)) {
972 cout << "graph_theory_domain::make_Paley_graph q must be odd" << endl;
973 exit(1);
974 }
975 if (!DOUBLYEVEN(q - 1)) {
976 cout << "graph_theory_domain::make_Paley_graph q must be congruent to 1 modulo 4" << endl;
977 }
978
980 int *f_is_square;
981 int i, j, a;
982
984 F->finite_field_init(q, FALSE /* f_without_tables */, verbose_level);
985
986 f_is_square = NEW_int(q);
987 Int_vec_zero(f_is_square, q);
988
989 for (i = 0; i < q; i++) {
990 j = F->mult(i, i);
991 f_is_square[j] = TRUE;
992 }
993
994 Adj = NEW_int(q * q);
995 Int_vec_zero(Adj, q * q);
996
997 for (i = 0; i < q; i++) {
998 for (j = i + 1; j < q; j++) {
999 a = F->add(i, F->negate(j));
1000 if (f_is_square[a]) {
1001 Adj[i * q + j] = 1;
1002 Adj[j * q + i] = 1;
1003 }
1004 }
1005 }
1006 N = q;
1007
1008 FREE_OBJECT(F);
1009 FREE_int(f_is_square);
1010
1011 if (f_v) {
1012 cout << "graph_theory_domain::make_Paley_graph done" << endl;
1013 }
1014}
1015
1017 int q, int verbose_level)
1018{
1019 int f_v = (verbose_level >= 1);
1020
1021 if (f_v) {
1022 cout << "graph_theory_domain::make_Schlaefli_graph" << endl;
1023 }
1024
1027 int n = 4;
1028 int k = 2;
1029
1030
1032 F->finite_field_init(q, FALSE /* f_without_tables */, verbose_level);
1033
1035 Gr->init(n, k, F, verbose_level);
1036
1037 Gr->create_Schlaefli_graph(Adj, N, verbose_level);
1038
1039 FREE_OBJECT(Gr);
1040 FREE_OBJECT(F);
1041
1042 if (f_v) {
1043 cout << "graph_theory_domain::make_Schlaefli_graph done" << endl;
1044 }
1045}
1046
1048 int q, int index, int verbose_level)
1049{
1050 int f_v = (verbose_level >= 1);
1051
1052 if (f_v) {
1053 cout << "graph_theory_domain::make_Winnie_Li_graph" << endl;
1054 }
1055
1057 int i, j, h, u, p, k, co_index, q1, relative_norm;
1058 int *N1;
1060
1061
1063 F->finite_field_init(q, FALSE /* f_without_tables */, verbose_level - 1);
1064 p = F->p;
1065
1066#if 0
1067 if (!f_index) {
1068 index = F->e;
1069 }
1070#endif
1071
1072 co_index = F->e / index;
1073
1074 if (co_index * index != F->e) {
1075 cout << "graph_theory_domain::make_Winnie_Li_graph "
1076 "the index has to divide the field degree" << endl;
1077 exit(1);
1078 }
1079 q1 = NT.i_power_j(p, co_index);
1080
1081 k = (q - 1) / (q1 - 1);
1082
1083 if (f_v) {
1084 cout << "q=" << q << endl;
1085 cout << "index=" << index << endl;
1086 cout << "co_index=" << co_index << endl;
1087 cout << "q1=" << q1 << endl;
1088 cout << "k=" << k << endl;
1089 }
1090
1091 relative_norm = 0;
1092 j = 1;
1093 for (i = 0; i < index; i++) {
1094 relative_norm += j;
1095 j *= q1;
1096 }
1097 if (f_v) {
1098 cout << "graph_theory_domain::make_Winnie_Li_graph "
1099 "relative_norm=" << relative_norm << endl;
1100 }
1101
1102 N1 = NEW_int(k);
1103 j = 0;
1104 for (i = 0; i < q; i++) {
1105 if (F->power(i, relative_norm) == 1) {
1106 N1[j++] = i;
1107 }
1108 }
1109 if (j != k) {
1110 cout << "graph_theory_domain::make_Winnie_Li_graph "
1111 "j != k" << endl;
1112 exit(1);
1113 }
1114 if (f_v) {
1115 cout << "graph_theory_domain::make_Winnie_Li_graph "
1116 "found " << k << " norm-one elements:" << endl;
1117 Int_vec_print(cout, N1, k);
1118 cout << endl;
1119 }
1120
1121 Adj = NEW_int(q * q);
1122 for (i = 0; i < q; i++) {
1123 for (h = 0; h < k; h++) {
1124 j = N1[h];
1125 u = F->add(i, j);
1126 Adj[i * q + u] = 1;
1127 Adj[u * q + i] = 1;
1128 }
1129 }
1130
1131 N = q;
1132
1133
1134 FREE_int(N1);
1135 FREE_OBJECT(F);
1136
1137
1138 if (f_v) {
1139 cout << "graph_theory_domain::make_Winnie_Li_graph done" << endl;
1140 }
1141}
1142
1144 int n, int k, int q, int r, int verbose_level)
1145{
1146 int f_v = (verbose_level >= 1);
1147
1148 if (f_v) {
1149 cout << "graph_theory_domain::make_Grassmann_graph" << endl;
1150 }
1151
1152
1155 int i, j, rr;
1156 int *M1; // [k * n]
1157 int *M2; // [k * n]
1158 int *M; // [2 * k * n]
1160
1162 F->finite_field_init(q, FALSE /* f_without_tables */, verbose_level);
1163
1164
1166 Gr->init(n, k, F, verbose_level);
1167
1168 N = Combi.generalized_binomial(n, k, q);
1169
1170 M1 = NEW_int(k * n);
1171 M2 = NEW_int(k * n);
1172 M = NEW_int(2 * k * n);
1173
1174 Adj = NEW_int(N * N);
1175 Int_vec_zero(Adj, N * N);
1176
1177 for (i = 0; i < N; i++) {
1178
1179 Gr->unrank_lint_here(M1, i, 0 /* verbose_level */);
1180
1181 for (j = i + 1; j < N; j++) {
1182
1183 Gr->unrank_lint_here(M2, j, 0 /* verbose_level */);
1184
1185 Int_vec_copy(M1, M, k * n);
1186 Int_vec_copy(M2, M + k * n, k * n);
1187
1188 rr = F->Linear_algebra->rank_of_rectangular_matrix(M, 2 * k, n, 0 /* verbose_level */);
1189 if (rr == r) {
1190 Adj[i * N + j] = 1;
1191 Adj[j * N + i] = 1;
1192 }
1193 }
1194 }
1195
1196
1197
1198 FREE_int(M1);
1199 FREE_int(M2);
1200 FREE_int(M);
1201 FREE_OBJECT(Gr);
1202 FREE_OBJECT(F);
1203
1204 if (f_v) {
1205 cout << "graph_theory_domain::make_Grassmann_graph done" << endl;
1206 }
1207}
1208
1209
1211 int epsilon, int d, int q, int verbose_level)
1212{
1213 int f_v = (verbose_level >= 1);
1214
1215 if (f_v) {
1216 cout << "graph_theory_domain::make_orthogonal_collinearity_graph" << endl;
1217 }
1218
1220 int i, j;
1221 int n, a, nb_e, nb_inc;
1222 int c1 = 0, c2 = 0, c3 = 0;
1223 int *v, *v2;
1224 int *Gram; // Gram matrix
1226
1227
1228 n = d - 1; // projective dimension
1229
1230 v = NEW_int(d);
1231 v2 = NEW_int(d);
1232 Gram = NEW_int(d * d);
1233
1234 if (f_v) {
1235 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1236 "epsilon=" << epsilon << " n=" << n << " q=" << q << endl;
1237 }
1238
1239 N = Gg.nb_pts_Qepsilon(epsilon, n, q);
1240
1241 if (f_v) {
1242 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1243 "number of points = " << N << endl;
1244 }
1245
1247
1248 F->finite_field_init(q, FALSE /* f_without_tables */, verbose_level - 1);
1249 F->print();
1250
1251 if (epsilon == 0) {
1252 c1 = 1;
1253 }
1254 else if (epsilon == -1) {
1255 F->Linear_algebra->choose_anisotropic_form(c1, c2, c3, verbose_level - 2);
1256 //cout << "incma.cpp: epsilon == -1, need irreducible polynomial" << endl;
1257 //exit(1);
1258 }
1259 F->Linear_algebra->Gram_matrix(epsilon, n, c1, c2, c3, Gram, verbose_level - 1);
1260 if (f_v) {
1261 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1262 "Gram matrix" << endl;
1263 Int_vec_print_integer_matrix_width(cout, Gram, d, d, d, 2);
1264 }
1265
1266#if 0
1267 if (f_list_points) {
1268 for (i = 0; i < N; i++) {
1269 F->Q_epsilon_unrank(v, 1, epsilon, n, c1, c2, c3, i, 0 /* verbose_level */);
1270 cout << i << " : ";
1271 int_vec_print(cout, v, n + 1);
1272 j = F->Q_epsilon_rank(v, 1, epsilon, n, c1, c2, c3, 0 /* verbose_level */);
1273 cout << " : " << j << endl;
1274
1275 }
1276 }
1277#endif
1278
1279
1280 if (f_v) {
1281 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1282 "allocating adjacency matrix" << endl;
1283 }
1284 Adj = NEW_int(N * N);
1285 if (f_v) {
1286 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1287 "allocating adjacency matrix was successful" << endl;
1288 }
1289 nb_e = 0;
1290 nb_inc = 0;
1291 for (i = 0; i < N; i++) {
1292 F->Orthogonal_indexing->Q_epsilon_unrank(v, 1, epsilon, n, c1, c2, c3, i, 0 /* verbose_level */);
1293 for (j = i + 1; j < N; j++) {
1294 F->Orthogonal_indexing->Q_epsilon_unrank(v2, 1, epsilon, n, c1, c2, c3, j, 0 /* verbose_level */);
1295 a = F->Linear_algebra->evaluate_bilinear_form(v, v2, n + 1, Gram);
1296 if (a == 0) {
1297 nb_e++;
1298 Adj[i * N + j] = 1;
1299 Adj[j * N + i] = 1;
1300 }
1301 else {
1302 Adj[i * N + j] = 0;
1303 Adj[j * N + i] = 0;
1304 nb_inc++;
1305 }
1306 }
1307 Adj[i * N + i] = 0;
1308 }
1309 if (f_v) {
1310 cout << "graph_theory_domain::make_orthogonal_collinearity_graph "
1311 "The adjacency matrix of the collinearity graph has been computed" << endl;
1312 }
1313
1314
1315 FREE_int(v);
1316 FREE_int(v2);
1317 FREE_int(Gram);
1318 FREE_OBJECT(F);
1319
1320 if (f_v) {
1321 cout << "graph_theory_domain::make_orthogonal_collinearity_graph done" << endl;
1322 }
1323}
1324
1326 int n, int verbose_level)
1327{
1328 int f_v = (verbose_level >= 1);
1329
1330 if (f_v) {
1331 cout << "graph_theory_domain::make_non_attacking_queens_graph" << endl;
1332 }
1333 int i1, j1, n1;
1334 int i2, j2, n2;
1335
1336 N = n * n;
1337
1338
1339 Adj = NEW_int(N * N);
1340 Int_vec_zero(Adj, N * N);
1341
1342
1343 for (n1 = 0; n1 < N; n1++) {
1344 i1 = n1 / n;
1345 j1 = n1 % n;
1346 for (n2 = n1 + 1; n2 < N; n2++) {
1347 i2 = n2 / n;
1348 j2 = n2 % n;
1349 if (i2 == i1) {
1350 continue;
1351 }
1352 if (j2 == j1) {
1353 continue;
1354 }
1355 if (j2 - j1 == i2 - i1) {
1356 continue;
1357 }
1358 if (j2 - j1 == i1 - i2) {
1359 continue;
1360 }
1361 Adj[n1 * N + n2] = 1;
1362 Adj[n2 * N + n1] = 1;
1363 }
1364 }
1365
1366 if (f_v) {
1367 cout << "graph_theory_domain::make_non_attacking_queens_graph done" << endl;
1368 }
1369
1370}
1371
1373 std::string &fname, int verbose_level)
1374{
1375 int f_v = (verbose_level >= 1);
1376
1377 if (f_v) {
1378 cout << "graph_theory_domain::make_disjoint_sets_graph" << endl;
1379 }
1380
1382 long int *M;
1383 int m, n;
1384
1385 Fio.lint_matrix_read_csv(fname, M, m, n, verbose_level);
1386
1387
1388 int i, j;
1390
1391 N = m;
1392
1393 if (f_v) {
1394 cout << "graph_theory_domain::make_disjoint_sets_graph N=" << N << endl;
1395 }
1396
1397 Adj = NEW_int(N * N);
1398 Int_vec_zero(Adj, N * N);
1399
1400
1401 for (i = 0; i < N; i++) {
1402 for (j = i + 1; j < N; j++) {
1403
1404 if (Sorting.test_if_sets_are_disjoint(M + i * n, n, M + j * n, n)) {
1405 Adj[i * N + j] = 1;
1406 Adj[j * N + i] = 1;
1407 }
1408 }
1409 }
1410
1411 if (f_v) {
1412 cout << "graph_theory_domain::make_disjoint_sets_graph done" << endl;
1413 }
1414
1415}
1416
1417
1418
1419
1421 int *Table, int nb_sets, int set_size,
1422 std::string &prefix_for_graph,
1424 int verbose_level)
1425{
1426 int f_v = (verbose_level >= 1);
1427 long int i, j, k, cnt, N2, N2_100;
1428
1429 if (f_v) {
1430 cout << "graph_theory_domain::compute_adjacency_matrix" << endl;
1431 }
1432
1433 N2 = (nb_sets * (nb_sets - 1)) >> 1;
1434 if (f_v) {
1435 cout << "graph_theory_domain::compute_adjacency_matrix N2=" << N2 << endl;
1436 }
1437 N2_100 = (N2 / 100) + 1;
1438
1440
1441 B->allocate(N2);
1442
1443 if (f_v) {
1444 cout << "graph_theory_domain::compute_adjacency_matrix "
1445 "after allocating adjacency bitvector" << endl;
1446 cout << "computing adjacency matrix:" << endl;
1447 }
1448 k = 0;
1449 cnt = 0;
1450 for (i = 0; i < nb_sets; i++) {
1451 for (j = i + 1; j < nb_sets; j++) {
1452
1453 int *p, *q;
1454 int u, v;
1455
1456 p = Table + i * set_size;
1457 q = Table + j * set_size;
1458 u = v = 0;
1459 while (u + v < 2 * set_size) {
1460 if (p[u] == q[v]) {
1461 break;
1462 }
1463 if (u == set_size) {
1464 v++;
1465 }
1466 else if (v == set_size) {
1467 u++;
1468 }
1469 else if (p[u] < q[v]) {
1470 u++;
1471 }
1472 else {
1473 v++;
1474 }
1475 }
1476 if (u + v < 2 * set_size) {
1477 B->m_i(k, 0);
1478
1479 }
1480 else {
1481 B->m_i(k, 1);
1482 cnt++;
1483 }
1484
1485 k++;
1486 if ((k % N2_100) == 0) {
1487 cout << "i=" << i << " j=" << j << " " << k / N2_100 << "% done, k=" << k << endl;
1488 }
1489#if 0
1490 if ((k & ((1 << 21) - 1)) == 0) {
1491 cout << "i=" << i << " j=" << j << " k=" << k
1492 << " / " << N2 << endl;
1493 }
1494#endif
1495 }
1496 }
1497
1498
1499 if (f_v) {
1500 cout << "graph_theory_domain::compute_adjacency_matrix making a graph" << endl;
1501 }
1502
1503 {
1504 colored_graph *CG;
1505 std::string fname;
1507
1509 int *color;
1510
1511 color = NEW_int(nb_sets);
1512 Int_vec_zero(color, nb_sets);
1513
1514 CG->init(nb_sets, 1 /* nb_colors */, 1 /* nb_colors_per_vertex */,
1515 color, B,
1516 FALSE,
1517 prefix_for_graph, prefix_for_graph,
1518 verbose_level);
1519
1520 fname.assign(prefix_for_graph);
1521 fname.append("_disjointness.colored_graph");
1522
1523 CG->save(fname, verbose_level);
1524
1525 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
1526
1527 FREE_int(color);
1528 FREE_OBJECT(CG);
1529 }
1530
1531
1532 if (f_v) {
1533 cout << "graph_theory_domain::compute_adjacency_matrix done" << endl;
1534 }
1535}
1536
1538 int *M, int m, int n,
1539 int *&Adj, int verbose_level)
1540// assumes that the rows are sorted
1541{
1542 int f_v = (verbose_level >= 1);
1543 int i, j, a;
1545
1546 if (f_v) {
1547 cout << "graph_theory_domain::make_graph_of_disjoint_sets_from_rows_of_matrix" << endl;
1548 }
1549 Adj = NEW_int(m * m);
1550 for (i = 0; i < m * m; i++) {
1551 Adj[i] = 0;
1552 }
1553
1554 for (i = 0; i < m; i++) {
1555 for (j = i + 1; j < m; j++) {
1557 M + i * n, M + j * n, n, n)) {
1558 a = 1;
1559 }
1560 else {
1561 a = 0;
1562 }
1563 Adj[i * m + j] = a;
1564 Adj[j * m + i] = a;
1565 }
1566 }
1567 if (f_v) {
1568 cout << "graph_theory_domain::make_graph_of_disjoint_sets_from_rows_of_matrix done" << endl;
1569 }
1570}
1571
1573 int nb_pts, int clique_sz, int *&Sol, long int &nb_sol,
1574 int verbose_level)
1575{
1576 int f_v = (verbose_level >= 1);
1577
1578 if (f_v) {
1579 cout << "graph_theory_domain::all_cliques_of_given_size" << endl;
1580 }
1581
1582 int *adj_list_coded;
1583 int n2;
1584 int i, j, h;
1585 clique_finder *C;
1586 std::string label;
1587 int f_maxdepth = FALSE;
1588 int maxdepth = 0;
1589
1590
1591 label.assign("all_cliques_of_given_size");
1592
1593 n2 = (nb_pts * (nb_pts - 1)) >> 1;
1594 adj_list_coded = NEW_int(n2);
1595 h = 0;
1596 cout << "graph_theory_domain::all_cliques_of_given_size: "
1597 "computing adj_list_coded" << endl;
1598 for (i = 0; i < nb_pts; i++) {
1599 for (j = i + 1; j < nb_pts; j++) {
1600 adj_list_coded[h++] = Adj[i * nb_pts + j];
1601 }
1602 }
1603
1604 clique_finder_control *Control;
1605
1607 Control->target_size = clique_sz;
1608 Control->f_maxdepth = f_maxdepth;
1609 Control->maxdepth = maxdepth;
1610 Control->f_store_solutions = TRUE;
1611
1613
1614 if (f_v) {
1615 cout << "graph_theory_domain::all_cliques_of_given_size: "
1616 "before C->init" << endl;
1617 }
1618 C->init(Control,
1619 label, nb_pts,
1620 TRUE, adj_list_coded,
1621 FALSE, NULL,
1622 verbose_level);
1623
1624 C->backtrack_search(0 /* depth */, 0 /* verbose_level */);
1625
1626 if (f_v) {
1627 cout << "graph_theory_domain::all_cliques_of_given_size "
1628 "done with search, "
1629 "we found " << C->solutions.size() << " solutions" << endl;
1630 }
1631
1632 int sz;
1633 if (f_v) {
1634 cout << "graph_theory_domain::all_cliques_of_given_size "
1635 "before C->get_solutions" << endl;
1636 }
1637 C->get_solutions(Sol, nb_sol, sz, verbose_level);
1638 if (f_v) {
1639 cout << "graph_theory_domain::all_cliques_of_given_size "
1640 "after C->get_solutions" << endl;
1641 }
1642 if (sz != clique_sz) {
1643 cout << "graph_theory_domain::all_cliques_of_given_size "
1644 "sz != clique_sz" << endl;
1645 exit(1);
1646 }
1647 FREE_OBJECT(C);
1648 FREE_OBJECT(Control);
1649 FREE_int(adj_list_coded);
1650 if (f_v) {
1651 cout << "graph_theory_domain::all_cliques_of_given_size done" << endl;
1652 }
1653}
1654
1655
1656
1657
1658
1659}}}
1660
matrices over GF(2) stored as bitvectors
compact storage of 0/1-data as bitvectors
a collection of functions related to sorted vectors
int test_if_sets_are_disjoint(long int *set1, int sz1, long int *set2, int sz2)
Definition: sorting.cpp:519
int test_if_sets_are_disjoint_assuming_sorted(int *set1, int *set2, int sz1, int sz2)
Definition: sorting.cpp:2790
void int_vec_intersect_sorted_vectors(int *v1, int len1, int *v2, int len2, int *v3, int &len3)
Definition: sorting.cpp:771
a statistical analysis of data consisting of single integers
void init(int *data, int data_length, int f_second, int verbose_level)
Definition: tally.cpp:72
orthogonal_geometry::orthogonal_indexing * Orthogonal_indexing
void finite_field_init(int q, int f_without_tables, int verbose_level)
various functions related to geometries
Definition: geometry.h:721
void AG_element_unrank(int q, int *v, int stride, int len, long int a)
long int nb_pts_Qepsilon(int epsilon, int k, int q)
to rank and unrank subspaces of a fixed dimension in F_q^n
Definition: geometry.h:892
void create_Schlaefli_graph(int *&Adj, int &sz, int verbose_level)
Definition: grassmann.cpp:1214
void unrank_lint_here(int *Mtx, long int rk, int verbose_level)
Definition: grassmann.cpp:269
void init(int n, int k, field_theory::finite_field *F, int verbose_level)
Definition: grassmann.cpp:70
parameters that control the clique finding process
Definition: graph_theory.h:32
finds all cliques of a certain size in a graph
Definition: graph_theory.h:115
void init(clique_finder_control *Control, std::string &label, int n, int f_has_adj_list, int *adj_list_coded, int f_has_bitvector, data_structures::bitvector *Bitvec_adjacency, int verbose_level)
void get_solutions(int *&Sol, long int &nb_solutions, int &clique_sz, int verbose_level)
void save(std::string &fname, int verbose_level)
void draw_partitioned(std::string &fname, graphics::layered_graph_draw_options *Draw_options, int f_labels, int verbose_level)
void init(int nb_points, int nb_colors, int nb_colors_per_vertex, int *colors, data_structures::bitvector *Bitvec, int f_ownership_of_bitvec, std::string &label, std::string &label_tex, int verbose_level)
void init_adjacency_no_colors(int nb_points, int *Adj, std::string &label, std::string &label_tex, int verbose_level)
void load(std::string &fname, int verbose_level)
void all_rainbow_cliques(clique_finder_control *Control, std::ostream &fp, int verbose_level)
void make_graph_of_disjoint_sets_from_rows_of_matrix(int *M, int m, int n, int *&Adj, int verbose_level)
void colored_graph_all_cliques_list_of_cases(clique_finder_control *Control, long int *list_of_cases, int nb_cases, std::string &fname_template, std::string &fname_sol, std::string &fname_stats, int f_split, int split_r, int split_m, int f_prefix, std::string &prefix, int verbose_level)
void all_cliques_of_given_size(int *Adj, int nb_pts, int clique_sz, int *&Sol, long int &nb_sol, int verbose_level)
void load_colored_graph(std::string &fname, int &nb_vertices, int &nb_colors, int &nb_colors_per_vertex, long int *&vertex_labels, int *&vertex_colors, long int *&user_data, int &user_data_size, data_structures::bitvector *&Bitvec, int verbose_level)
void compute_decomposition_of_graph_wrt_partition(int *Adj, int N, int *first, int *len, int nb_parts, int *&R, int verbose_level)
void make_Paley_graph(int *&Adj, int &N, int q, int verbose_level)
void save_colored_graph(std::string &fname, int nb_vertices, int nb_colors, int nb_colors_per_vertex, long int *points, int *point_color, long int *data, int data_sz, data_structures::bitvector *Bitvec, int verbose_level)
void colored_graph_all_cliques(clique_finder_control *Control, std::string &fname, int f_output_solution_raw, int f_output_fname, std::string &output_fname, int verbose_level)
void compute_adjacency_matrix(int *Table, int nb_sets, int set_size, std::string &prefix_for_graph, data_structures::bitvector *&B, int verbose_level)
void make_Winnie_Li_graph(int *&Adj, int &N, int q, int index, int verbose_level)
void make_orthogonal_collinearity_graph(int *&Adj, int &N, int epsilon, int d, int q, int verbose_level)
void make_Hamming_graph(int *&Adj, int &N, int n, int q, int verbose_level)
void make_disjoint_sets_graph(int *&Adj, int &N, std::string &fname, int verbose_level)
void make_Grassmann_graph(int *&Adj, int &N, int n, int k, int q, int r, int verbose_level)
void save_as_colored_graph_easy(std::string &fname_base, int n, int *Adj, int verbose_level)
void make_cycle_graph(int *&Adj, int &N, int n, int verbose_level)
void colored_graph_draw(std::string &fname, graphics::layered_graph_draw_options *Draw_options, int f_labels, int verbose_level)
int is_association_scheme(int *color_graph, int n, int *&Pijk, int *&colors, int &nb_colors, int verbose_level)
void make_Schlaefli_graph(int *&Adj, int &N, int q, int verbose_level)
void make_non_attacking_queens_graph(int *&Adj, int &N, int n, int verbose_level)
void make_Johnson_graph(int *&Adj, int &N, int n, int k, int s, int verbose_level)
void draw_bitmatrix(std::string &fname_base, graphics::layered_graph_draw_options *Draw_options, int f_dots, int f_partition, int nb_row_parts, int *row_part_first, int nb_col_parts, int *col_part_first, int f_row_grid, int f_col_grid, int f_bitmatrix, data_structures::bitmatrix *Bitmatrix, int *M, int m, int n, int f_has_labels, int *labels, int verbose_level)
options for drawing an object of type layered_graph
Definition: graphics.h:457
a general 2D graphical output interface (metapost, tikz, postscript)
Definition: graphics.h:545
void init(std::string &file_name, layered_graph_draw_options *Draw_options, int verbose_level)
Definition: mp_graphics.cpp:71
void draw_bitmatrix2(int f_dots, int f_partition, int nb_row_parts, int *row_part_first, int nb_col_parts, int *col_part_first, int f_row_grid, int f_col_grid, int f_bitmatrix, data_structures::bitmatrix *Bitmatrix, int *M, int m, int n, int f_has_labels, int *labels)
void finish(std::ostream &ost, int verbose_level)
int evaluate_bilinear_form(int n, int *v1, int *v2, int *Gram)
void choose_anisotropic_form(int &c1, int &c2, int &c3, int verbose_level)
int rank_of_rectangular_matrix(int *A, int m, int n, int verbose_level)
void Gram_matrix(int epsilon, int k, int form_c1, int form_c2, int form_c3, int *&Gram, int verbose_level)
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
void Q_epsilon_unrank(int *v, int stride, int epsilon, int k, int c1, int c2, int c3, long int a, int verbose_level)
#define FREE_int(p)
Definition: foundations.h:640
#define Int_vec_zero(A, B)
Definition: foundations.h:713
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define Int_vec_print_integer_matrix_width(A, B, C, D, E, F)
Definition: foundations.h:691
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define EVEN(x)
Definition: foundations.h:221
#define ODD(x)
Definition: foundations.h:222
#define Int_vec_copy(A, B, C)
Definition: foundations.h:693
#define DOUBLYEVEN(x)
Definition: foundations.h:223
#define NEW_lint(n)
Definition: foundations.h:628
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects