Orbiter 2022
Combinatorial Objects
packings_global.cpp
Go to the documentation of this file.
1/*
2 * packings_global.cpp
3 *
4 * Created on: Oct 18, 2021
5 * Author: betten
6 */
7
8
9
10
11#include "orbiter.h"
12
13using namespace std;
14
15namespace orbiter {
16namespace layer5_applications {
17namespace packings {
18
19
21{
22}
23
24
26{
27}
28
29
30
32 std::string *fnames, int nb_files,
33 std::string &file_of_spreads,
35 int verbose_level)
36{
37#if 0
38 int f_v = (verbose_level >= 1);
39 file_io Fio;
40
41 if (f_v) {
42 cout << "packings_global::merge_packings" << endl;
43 }
44
45 CB = NEW_OBJECT(classify_bitvectors);
46
47
48 // for use if INPUT_TYPE_FILE_OF_PACKINGS_THROUGH_SPREAD_TABLE
49 long int *Spread_table;
50 int nb_spreads;
51 int spread_size;
52
53 if (f_v) {
54 cout << "packings_global::merge_packings "
55 "Reading spread table from file "
56 << file_of_spreads << endl;
57 }
58 Fio.lint_matrix_read_csv(file_of_spreads,
59 Spread_table, nb_spreads, spread_size,
60 0 /* verbose_level */);
61 if (f_v) {
62 cout << "Reading spread table from file "
63 << file_of_spreads << " done" << endl;
64 cout << "The spread table contains " << nb_spreads
65 << " spreads" << endl;
66 }
67
68 int f, g, N, table_length, nb_reject = 0;
69
70 N = 0;
71
72 if (f_v) {
73 cout << "packings_global::merge_packings "
74 "counting the overall number of input packings" << endl;
75 }
76
77 for (f = 0; f < nb_files; f++) {
78
79 if (f_v) {
80 cout << "packings_global::merge_packings file "
81 << f << " / " << nb_files << " : " << fnames[f] << endl;
82 }
83
84 spreadsheet *S;
85
86 S = NEW_OBJECT(spreadsheet);
87
88 S->read_spreadsheet(fnames[f], 0 /*verbose_level*/);
89
90 table_length = S->nb_rows - 1;
91 N += table_length;
92
93
94
95 FREE_OBJECT(S);
96
97 }
98
99 if (f_v) {
100 cout << "packings_global::merge_packings file "
101 << "we have " << N << " packings in "
102 << nb_files << " files" << endl;
103 }
104
105 for (f = 0; f < nb_files; f++) {
106
107 if (f_v) {
108 cout << "packings_global::merge_packings file "
109 << f << " / " << nb_files << " : " << fnames[f] << endl;
110 }
111
112 spreadsheet *S;
113
114 S = NEW_OBJECT(spreadsheet);
115
116 S->read_spreadsheet(fnames[f], 0 /*verbose_level*/);
117 if (FALSE /*f_v3*/) {
118 S->print_table(cout, FALSE);
119 }
120
121 int ago_idx, original_file_idx, input_idx_idx, input_set_idx;
122 int nb_rows_idx, nb_cols_idx, canonical_form_idx;
123
124 ago_idx = S->find_by_column("ago");
125 original_file_idx = S->find_by_column("original_file");
126 input_idx_idx = S->find_by_column("input_idx");
127 input_set_idx = S->find_by_column("input_set");
128 nb_rows_idx = S->find_by_column("nb_rows");
129 nb_cols_idx = S->find_by_column("nb_cols");
130 canonical_form_idx = S->find_by_column("canonical_form");
131
132 table_length = S->nb_rows - 1;
133
134 //rep,ago,original_file,input_idx,input_set,nb_rows,nb_cols,canonical_form
135
136
137 for (g = 0; g < table_length; g++) {
138
139 int ago;
140 char *text;
141 long int *the_set_in;
142 int set_size_in;
143 long int *canonical_labeling;
144 int canonical_labeling_sz;
145 int nb_rows, nb_cols;
146 object_in_projective_space *OiP;
147
148
149 ago = S->get_int(g + 1, ago_idx);
150 nb_rows = S->get_int(g + 1, nb_rows_idx);
151 nb_cols = S->get_int(g + 1, nb_cols_idx);
152
153 text = S->get_string(g + 1, input_set_idx);
154 Orbiter->Lint_vec.scan(text, the_set_in, set_size_in);
155
156
157 if (f_v) {
158 cout << "File " << f << " / " << nb_files
159 << ", input set " << g << " / "
160 << table_length << endl;
161 //int_vec_print(cout, the_set_in, set_size_in);
162 //cout << endl;
163 }
164
165 if (FALSE) {
166 cout << "canonical_form_idx=" << canonical_form_idx << endl;
167 }
168 text = S->get_string(g + 1, canonical_form_idx);
169 if (FALSE) {
170 cout << "text=" << text << endl;
171 }
172 Orbitr->Lint_vec.scan(text, canonical_labeling, canonical_labeling_sz);
173 if (FALSE) {
174 cout << "File " << f << " / " << nb_files
175 << ", input set " << g << " / "
176 << table_length << " canonical_labeling = ";
177 Orbiter->Lint_vec.print(cout, canonical_labeling, canonical_labeling_sz);
178 cout << endl;
179 }
180
181 if (canonical_labeling_sz != nb_rows + nb_cols) {
182 cout << "packings_global::merge_packings "
183 "canonical_labeling_sz != nb_rows + nb_cols" << endl;
184 exit(1);
185 }
186
187 OiP = NEW_OBJECT(object_in_projective_space);
188
189 if (FALSE) {
190 cout << "packings_global::merge_packings "
191 "before init_packing_from_spread_table" << endl;
192 }
193 OiP->init_packing_from_spread_table(P, the_set_in,
194 Spread_table, nb_spreads, spread_size,
195 0 /*verbose_level*/);
196 if (FALSE) {
197 cout << "packings_global::merge_packings "
198 "after init_packing_from_spread_table" << endl;
199 }
200 OiP->f_has_known_ago = TRUE;
201 OiP->known_ago = ago;
202
203 int *Incma_in;
204 int *Incma_out;
205 int nb_rows1, nb_cols1;
206 int *partition;
207 uchar *canonical_form;
208 int canonical_form_len;
209
210
211 if (FALSE) {
212 cout << "packings_global::merge_packings "
213 "before encode_incma" << endl;
214 }
215 OiP->encode_incma(Incma_in, nb_rows1, nb_cols1,
216 partition, 0 /*verbose_level - 1*/);
217 if (FALSE) {
218 cout << "packings_global::merge_packings "
219 "after encode_incma" << endl;
220 }
221 if (nb_rows1 != nb_rows) {
222 cout << "packings_global::merge_packings "
223 "nb_rows1 != nb_rows" << endl;
224 exit(1);
225 }
226 if (nb_cols1 != nb_cols) {
227 cout << "packings_global::merge_packings "
228 "nb_cols1 != nb_cols" << endl;
229 exit(1);
230 }
231
232 OiP->input_fname = S->get_string(g + 1, original_file_idx);
233 OiP->input_idx = S->get_int(g + 1, input_idx_idx);
234
235 text = S->get_string(g + 1, input_set_idx);
236
237 OiP->set_as_string.assign(text);
238
239 int i, j, ii, jj, a;
240 int L = nb_rows * nb_cols;
241
242 Incma_out = NEW_int(L);
243 for (i = 0; i < nb_rows; i++) {
244 ii = canonical_labeling[i];
245 for (j = 0; j < nb_cols; j++) {
246 jj = canonical_labeling[nb_rows + j] - nb_rows;
247 //cout << "i=" << i << " j=" << j << " ii=" << ii
248 //<< " jj=" << jj << endl;
249 Incma_out[i * nb_cols + j] = Incma_in[ii * nb_cols + jj];
250 }
251 }
252 if (FALSE) {
253 cout << "packings_global::merge_packings "
254 "before bitvector_allocate_and_coded_length" << endl;
255 }
256 canonical_form = bitvector_allocate_and_coded_length(
257 L, canonical_form_len);
258 for (i = 0; i < nb_rows; i++) {
259 for (j = 0; j < nb_cols; j++) {
260 if (Incma_out[i * nb_cols + j]) {
261 a = i * nb_cols + j;
262 bitvector_set_bit(canonical_form, a);
263 }
264 }
265 }
266
267 if (CB->n == 0) {
268 if (f_v) {
269 cout << "packings_global::merge_packings "
270 "before CB->init" << endl;
271 }
272 CB->init(N, canonical_form_len, verbose_level);
273 }
274 if (f_v) {
275 cout << "packings_global::merge_packings "
276 "before CB->add" << endl;
277 }
278 int idx;
279 int f_found;
280
281 CB->search_and_add_if_new(canonical_form, OiP, f_found, idx, 0 /*verbose_level*/);
282 if (f_found) {
283 nb_reject++;
284 }
285 if (f_v) {
286 cout << "packings_global::merge_packings "
287 "CB->add returns f_found = " << f_found
288 << " nb iso = " << CB->nb_types
289 << " nb_reject=" << nb_reject << endl;
290 }
291
292
293 //int idx;
294
295 object_in_projective_space_with_action *OiPA;
296
297 OiPA = NEW_OBJECT(object_in_projective_space_with_action);
298
299 OiPA->init(OiP, ago, nb_rows, nb_cols,
300 canonical_labeling, 0 /*verbose_level*/);
301 idx = CB->type_of[CB->n - 1];
302 CB->Type_extra_data[idx] = OiPA;
303
304
305 FREE_lint(the_set_in);
306 //FREE_int(canonical_labeling);
307 FREE_int(Incma_in);
308 FREE_int(Incma_out);
309 FREE_int(partition);
310 //FREE_uchar(canonical_form);
311
312 } // next g
313
314
315
316 } // next f
317
318 if (f_v) {
319 cout << "packings_global::merge_packings done, "
320 "we found " << CB->nb_types << " isomorphism types "
321 "of packings" << endl;
322 }
323
324
325 //FREE_OBJECT(CB);
326 FREE_lint(Spread_table);
327
328 if (f_v) {
329 cout << "packings_global::merge_packings done" << endl;
330 }
331#endif
332}
333
335 std::string &fname,
336 std::string &file_of_spreads_original,
337 geometry::spread_tables *Spread_tables,
338 int f_self_polar,
339 int f_ago, int select_ago,
341 int verbose_level)
342{
343#if 0
344 int f_v = (verbose_level >= 1);
345
346
347 int nb_accept = 0;
348 file_io Fio;
349
350 if (f_v) {
351 cout << "packings_global::select_packings" << endl;
352 }
353
354 CB = NEW_OBJECT(classify_bitvectors);
355
356
357
358 long int *Spread_table;
359 int nb_spreads;
360 int spread_size;
361 int packing_size;
362 int a, b;
363
364 if (f_v) {
365 cout << "packings_global::select_packings "
366 "Reading spread table from file "
367 << file_of_spreads_original << endl;
368 }
369 Fio.lint_matrix_read_csv(file_of_spreads_original,
370 Spread_table, nb_spreads, spread_size,
371 0 /* verbose_level */);
372 if (nb_spreads != Spread_tables->nb_spreads) {
373 cout << "packings_global::select_packings "
374 "nb_spreads != Spread_tables->nb_spreads" << endl;
375 exit(1);
376 }
377 if (spread_size != Spread_tables->spread_size) {
378 cout << "packings_global::select_packings "
379 "spread_size != Spread_tables->spread_size" << endl;
380 exit(1);
381 }
382 if (f_v) {
383 cout << "Reading spread table from file "
384 << file_of_spreads_original << " done" << endl;
385 cout << "The spread table contains " << nb_spreads
386 << " spreads" << endl;
387 }
388
389
390
391 if (f_v) {
392 cout << "Reading file_isomorphism_type_of_spreads "
393 "computing s2l and l2s" << endl;
394 }
395
396 int *s2l, *l2s;
397 int i, idx;
398 long int *set;
399 long int extra_data[1];
400 sorting Sorting;
401
402 extra_data[0] = spread_size;
403
404 set = NEW_lint(spread_size);
405 s2l = NEW_int(nb_spreads);
406 l2s = NEW_int(nb_spreads);
407 for (i = 0; i < nb_spreads; i++) {
408 Orbiter->Lint_vec.copy(Spread_tables->spread_table +
409 i * spread_size, set, spread_size);
410 Sorting.lint_vec_heapsort(set, spread_size);
411 if (!Sorting.search_general(Spread_tables->spread_table,
412 nb_spreads, (void *) set, idx,
413 table_of_sets_compare_func,
414 extra_data, 0 /*verbose_level*/)) {
415 cout << "packings_global::select_packings "
416 "cannot find spread " << i << " = ";
417 Orbiter->Lint_vec.print(cout, set, spread_size);
418 cout << endl;
419 exit(1);
420 }
421 s2l[i] = idx;
422 l2s[idx] = i;
423 }
424 if (f_v) {
425 cout << "Reading file_isomorphism_type_of_spreads "
426 "computing s2l and l2s done" << endl;
427 }
428
429 int g, table_length, nb_reject = 0;
430
431
432 if (f_v) {
433 cout << "packings_global::select_packings file "
434 << fname << endl;
435 }
436
437 spreadsheet *S;
438
439 S = NEW_OBJECT(spreadsheet);
440
441 S->read_spreadsheet(fname, 0 /*verbose_level*/);
442 if (FALSE /*f_v3*/) {
443 S->print_table(cout, FALSE);
444 }
445
446 int ago_idx, original_file_idx, input_idx_idx, input_set_idx;
447 int nb_rows_idx, nb_cols_idx, canonical_form_idx;
448
449 ago_idx = S->find_by_column("ago");
450 original_file_idx = S->find_by_column("original_file");
451 input_idx_idx = S->find_by_column("input_idx");
452 input_set_idx = S->find_by_column("input_set");
453 nb_rows_idx = S->find_by_column("nb_rows");
454 nb_cols_idx = S->find_by_column("nb_cols");
455 canonical_form_idx = S->find_by_column("canonical_form");
456
457 table_length = S->nb_rows - 1;
458
459 //rep,ago,original_file,input_idx,
460 //input_set,nb_rows,nb_cols,canonical_form
461 int f_first = TRUE;
462
463
464 for (g = 0; g < table_length; g++) {
465
466 int ago;
467 char *text;
468 long int *the_set_in;
469 int set_size_in;
470 long int *canonical_labeling;
471 int canonical_labeling_sz;
472 int nb_rows, nb_cols;
473 object_in_projective_space *OiP;
474 int f_accept = FALSE;
475 int *set1;
476 int *set2;
477
478 ago = S->get_int(g + 1, ago_idx);
479 nb_rows = S->get_int(g + 1, nb_rows_idx);
480 nb_cols = S->get_int(g + 1, nb_cols_idx);
481
482 text = S->get_string(g + 1, input_set_idx);
483 Orbiter->Lint_vec.scan(text, the_set_in, set_size_in);
484
485 packing_size = set_size_in;
486
487 if (f_v && (g % 1000) == 0) {
488 cout << "File " << fname
489 << ", input set " << g << " / "
490 << table_length << endl;
491 //int_vec_print(cout, the_set_in, set_size_in);
492 //cout << endl;
493 }
494
495
496 if (f_self_polar) {
497 set1 = NEW_int(packing_size);
498 set2 = NEW_int(packing_size);
499
500 // test if self-polar:
501 for (i = 0; i < packing_size; i++) {
502 a = the_set_in[i];
503 b = s2l[a];
504 set1[i] = b;
505 }
506 Sorting.int_vec_heapsort(set1, packing_size);
507 for (i = 0; i < packing_size; i++) {
508 a = set1[i];
509 b = Spread_tables->dual_spread_idx[a];
510 set2[i] = b;
511 }
512 Sorting.int_vec_heapsort(set2, packing_size);
513
514#if 0
515 cout << "set1: ";
516 int_vec_print(cout, set1, packing_size);
517 cout << endl;
518 cout << "set2: ";
519 int_vec_print(cout, set2, packing_size);
520 cout << endl;
521#endif
522 if (int_vec_compare(set1, set2, packing_size) == 0) {
523 cout << "The packing is self-polar" << endl;
524 f_accept = TRUE;
525 }
526 else {
527 f_accept = FALSE;
528 }
529 FREE_int(set1);
530 FREE_int(set2);
531 }
532 if (f_ago) {
533 if (ago == select_ago) {
534 f_accept = TRUE;
535 }
536 else {
537 f_accept = FALSE;
538 }
539 }
540
541
542
543 if (f_accept) {
544
545 nb_accept++;
546
547
548 if (FALSE) {
549 cout << "canonical_form_idx=" << canonical_form_idx << endl;
550 }
551 text = S->get_string(g + 1, canonical_form_idx);
552 if (FALSE) {
553 cout << "text=" << text << endl;
554 }
555 Orbiter->Lint_vec.scan(text, canonical_labeling, canonical_labeling_sz);
556 if (FALSE) {
557 cout << "File " << fname
558 << ", input set " << g << " / "
559 << table_length << " canonical_labeling = ";
560 Orbiter->Lint_vec.print(cout, canonical_labeling, canonical_labeling_sz);
561 cout << endl;
562 }
563
564 if (canonical_labeling_sz != nb_rows + nb_cols) {
565 cout << "packings_global::select_packings "
566 "canonical_labeling_sz != nb_rows + nb_cols" << endl;
567 exit(1);
568 }
569
570 OiP = NEW_OBJECT(object_in_projective_space);
571
572 if (FALSE) {
573 cout << "packings_global::select_packings "
574 "before init_packing_from_spread_table" << endl;
575 }
576 OiP->init_packing_from_spread_table(P, the_set_in,
577 Spread_table, nb_spreads, spread_size,
578 0 /*verbose_level*/);
579 if (FALSE) {
580 cout << "packings_global::merge_packings "
581 "after init_packing_from_spread_table" << endl;
582 }
583 OiP->f_has_known_ago = TRUE;
584 OiP->known_ago = ago;
585
586 int *Incma_in;
587 int *Incma_out;
588 int nb_rows1, nb_cols1;
589 int *partition;
590 uchar *canonical_form;
591 int canonical_form_len;
592
593
594 if (FALSE) {
595 cout << "packings_global::select_packings "
596 "before encode_incma" << endl;
597 }
598 OiP->encode_incma(Incma_in, nb_rows1, nb_cols1,
599 partition, 0 /*verbose_level - 1*/);
600 if (FALSE) {
601 cout << "packings_global::select_packings "
602 "after encode_incma" << endl;
603 }
604 if (nb_rows1 != nb_rows) {
605 cout << "packings_global::select_packings "
606 "nb_rows1 != nb_rows" << endl;
607 exit(1);
608 }
609 if (nb_cols1 != nb_cols) {
610 cout << "packings_global::select_packings "
611 "nb_cols1 != nb_cols" << endl;
612 exit(1);
613 }
614
615 OiP->input_fname = S->get_string(g + 1, original_file_idx);
616 OiP->input_idx = S->get_int(g + 1, input_idx_idx);
617
618 text = S->get_string(g + 1, input_set_idx);
619
620 OiP->set_as_string.assign(text);
621
622 int i, j, ii, jj, a;
623 int L = nb_rows * nb_cols;
624
625 Incma_out = NEW_int(L);
626 for (i = 0; i < nb_rows; i++) {
627 ii = canonical_labeling[i];
628 for (j = 0; j < nb_cols; j++) {
629 jj = canonical_labeling[nb_rows + j] - nb_rows;
630 //cout << "i=" << i << " j=" << j << " ii=" << ii
631 //<< " jj=" << jj << endl;
632 Incma_out[i * nb_cols + j] = Incma_in[ii * nb_cols + jj];
633 }
634 }
635 if (FALSE) {
636 cout << "packings_global::select_packings "
637 "before bitvector_allocate_and_coded_length" << endl;
638 }
639 canonical_form = bitvector_allocate_and_coded_length(
640 L, canonical_form_len);
641 for (i = 0; i < nb_rows; i++) {
642 for (j = 0; j < nb_cols; j++) {
643 if (Incma_out[i * nb_cols + j]) {
644 a = i * nb_cols + j;
645 bitvector_set_bit(canonical_form, a);
646 }
647 }
648 }
649
650 if (f_first) {
651 if (f_v) {
652 cout << "packings_global::select_packings "
653 "before CB->init" << endl;
654 }
655 CB->init(table_length, canonical_form_len, verbose_level);
656 f_first = FALSE;
657 }
658
659
660 if (f_v) {
661 cout << "packings_global::select_packings "
662 "before CB->add" << endl;
663 }
664
665 int idx;
666 int f_found;
667
668 CB->search_and_add_if_new(canonical_form, OiP, f_found, idx, 0 /*verbose_level*/);
669 if (f_found) {
670 cout << "reject" << endl;
671 nb_reject++;
672 }
673 if (f_v) {
674 cout << "packings_global::select_packings "
675 "CB->add returns f_found = " << f_found
676 << " nb iso = " << CB->nb_types
677 << " nb_reject=" << nb_reject
678 << " nb_accept=" << nb_accept
679 << " CB->n=" << CB->n
680 << " CB->nb_types=" << CB->nb_types
681 << endl;
682 }
683
684
685 //int idx;
686
687 object_in_projective_space_with_action *OiPA;
688
689 OiPA = NEW_OBJECT(object_in_projective_space_with_action);
690
691 OiPA->init(OiP, ago, nb_rows, nb_cols,
692 canonical_labeling, 0 /*verbose_level*/);
693 idx = CB->type_of[CB->n - 1];
694 CB->Type_extra_data[idx] = OiPA;
695
696 FREE_int(Incma_in);
697 FREE_int(Incma_out);
698 FREE_int(partition);
699 //FREE_int(canonical_labeling);
700 //FREE_uchar(canonical_form);
701 } // if (f_accept)
702
703
704
705 FREE_lint(the_set_in);
706
707 } // next g
708
709
710
711
712 if (f_v) {
713 cout << "packings_global::select_packings done, "
714 "we found " << CB->nb_types << " isomorphism types "
715 "of packings. nb_accept = " << nb_accept
716 << " CB->n = " << CB->n
717 << " CB->nb_types = " << CB->nb_types
718 << endl;
719 }
720
721
722 //FREE_OBJECT(CB);
723 FREE_lint(Spread_table);
724
725 if (f_v) {
726 cout << "packings_global::select_packings done" << endl;
727 }
728#endif
729}
730
731
732
734 std::string &fname,
735 std::string &file_of_spreads_original,
736 int f_split, int split_r, int split_m,
737 geometry::spread_tables *Spread_tables,
739 int verbose_level)
740{
741 int f_v = (verbose_level >= 1);
742
743 if (f_v) {
744 cout << "packings_global::select_packings_self_dual" << endl;
745 }
746
747
748#if 0
749 int nb_accept = 0;
750 file_io Fio;
751
752 CB = NEW_OBJECT(classify_bitvectors);
753
754
755
756 long int *Spread_table_original;
757 int nb_spreads;
758 int spread_size;
759 int packing_size;
760 int a, b;
761
762 if (f_v) {
763 cout << "packings_global::select_packings_self_dual "
764 "Reading spread table from file "
765 << file_of_spreads_original << endl;
766 }
767 Fio.lint_matrix_read_csv(file_of_spreads_original,
768 Spread_table_original, nb_spreads, spread_size,
769 0 /* verbose_level */);
770 if (nb_spreads != Spread_tables->nb_spreads) {
771 cout << "packings_global::select_packings_self_dual "
772 "nb_spreads != Spread_tables->nb_spreads" << endl;
773 exit(1);
774 }
775 if (spread_size != Spread_tables->spread_size) {
776 cout << "packings_global::select_packings_self_dual "
777 "spread_size != Spread_tables->spread_size" << endl;
778 exit(1);
779 }
780 if (f_v) {
781 cout << "Reading spread table from file "
782 << file_of_spreads_original << " done" << endl;
783 cout << "The spread table contains " << nb_spreads
784 << " spreads" << endl;
785 }
786
787
788
789 if (f_v) {
790 cout << "Reading file_isomorphism_type_of_spreads "
791 "computing s2l and l2s" << endl;
792 }
793
794 int *s2l, *l2s;
795 int i, idx;
796 long int *set;
797 long int extra_data[1];
798 sorting Sorting;
799
800 extra_data[0] = spread_size;
801
802 set = NEW_lint(spread_size);
803 s2l = NEW_int(nb_spreads);
804 l2s = NEW_int(nb_spreads);
805 for (i = 0; i < nb_spreads; i++) {
806 Orbiter->Lint_vec.copy(Spread_table_original +
807 i * spread_size, set, spread_size);
808 Sorting.lint_vec_heapsort(set, spread_size);
809 if (!Sorting.search_general(Spread_tables->spread_table,
810 nb_spreads, (int *) set, idx,
811 table_of_sets_compare_func,
812 extra_data, 0 /*verbose_level*/)) {
813 cout << "packings_global::select_packings_self_dual "
814 "cannot find spread " << i << " = ";
815 Orbiter->Lint_vec.print(cout, set, spread_size);
816 cout << endl;
817 exit(1);
818 }
819 s2l[i] = idx;
820 l2s[idx] = i;
821 }
822 if (f_v) {
823 cout << "Reading file_isomorphism_type_of_spreads "
824 "computing s2l and l2s done" << endl;
825 }
826
827 int g, table_length, nb_reject = 0;
828
829
830 if (f_v) {
831 cout << "packings_global::select_packings_self_dual "
832 "file " << fname << endl;
833 }
834
835 spreadsheet *S;
836
837 S = NEW_OBJECT(spreadsheet);
838
839 S->read_spreadsheet(fname, 0 /*verbose_level*/);
840 if (FALSE /*f_v3*/) {
841 S->print_table(cout, FALSE);
842 }
843
844 if (f_v) {
845 cout << "packings_global::select_packings_self_dual "
846 "read file " << fname << endl;
847 }
848
849
850 int ago_idx, original_file_idx, input_idx_idx, input_set_idx;
851 int nb_rows_idx, nb_cols_idx, canonical_form_idx;
852
853 if (f_v) {
854 cout << "packings_global::select_packings_self_dual "
855 "finding column indices" << endl;
856 }
857
858 ago_idx = S->find_by_column("ago");
859 original_file_idx = S->find_by_column("original_file");
860 input_idx_idx = S->find_by_column("input_idx");
861 input_set_idx = S->find_by_column("input_set");
862 nb_rows_idx = S->find_by_column("nb_rows");
863 nb_cols_idx = S->find_by_column("nb_cols");
864 canonical_form_idx = S->find_by_column("canonical_form");
865
866 table_length = S->nb_rows - 1;
867
868 //rep,ago,original_file,input_idx,
869 //input_set,nb_rows,nb_cols,canonical_form
870 int f_first = TRUE;
871
872
873 if (f_v) {
874 cout << "packings_global::select_packings_self_dual "
875 "first pass, table_length=" << table_length << endl;
876 }
877
878 // first pass: build up the database:
879
880 for (g = 0; g < table_length; g++) {
881
882 int ago;
883 char *text;
884 long int *the_set_in;
885 int set_size_in;
886 long int *canonical_labeling;
887 int canonical_labeling_sz;
888 int nb_rows, nb_cols;
889 object_in_projective_space *OiP;
890 int f_accept;
891
892 ago = S->get_int(g + 1, ago_idx);
893 nb_rows = S->get_int(g + 1, nb_rows_idx);
894 nb_cols = S->get_int(g + 1, nb_cols_idx);
895
896 text = S->get_string(g + 1, input_set_idx);
897 Orbiter->Lint_vec.scan(text, the_set_in, set_size_in);
898
899 packing_size = set_size_in;
900
901 if (f_v && (g % 1000) == 0) {
902 cout << "File " << fname
903 << ", input set " << g << " / "
904 << table_length << endl;
905 //int_vec_print(cout, the_set_in, set_size_in);
906 //cout << endl;
907 }
908
909
910 f_accept = TRUE;
911
912
913
914 if (f_accept) {
915
916 nb_accept++;
917
918
919 if (FALSE) {
920 cout << "canonical_form_idx=" << canonical_form_idx << endl;
921 }
922 text = S->get_string(g + 1, canonical_form_idx);
923 if (FALSE) {
924 cout << "text=" << text << endl;
925 }
926 Orbiter->Lint_vec.scan(text, canonical_labeling, canonical_labeling_sz);
927 if (FALSE) {
928 cout << "File " << fname
929 << ", input set " << g << " / "
930 << table_length << " canonical_labeling = ";
931 Orbiter->Lint_vec.print(cout,
932 canonical_labeling, canonical_labeling_sz);
933 cout << endl;
934 }
935
936 if (canonical_labeling_sz != nb_rows + nb_cols) {
937 cout << "packings_global::select_packings_self_dual "
938 "canonical_labeling_sz != nb_rows + nb_cols" << endl;
939 exit(1);
940 }
941
942 OiP = NEW_OBJECT(object_in_projective_space);
943
944 if (FALSE) {
945 cout << "packings_global::select_packings_self_dual "
946 "before init_packing_from_spread_table" << endl;
947 }
948 OiP->init_packing_from_spread_table(P, the_set_in,
949 Spread_table_original, nb_spreads, spread_size,
950 0 /*verbose_level*/);
951 if (FALSE) {
952 cout << "packings_global::select_packings_self_dual "
953 "after init_packing_from_spread_table" << endl;
954 }
955 OiP->f_has_known_ago = TRUE;
956 OiP->known_ago = ago;
957
958 int *Incma_in;
959 int *Incma_out;
960 int nb_rows1, nb_cols1;
961 int *partition;
962 uchar *canonical_form;
963 int canonical_form_len;
964
965
966 if (FALSE) {
967 cout << "packings_global::select_packings_self_dual "
968 "before encode_incma" << endl;
969 }
970 OiP->encode_incma(Incma_in, nb_rows1, nb_cols1,
971 partition, 0 /*verbose_level - 1*/);
972 if (FALSE) {
973 cout << "packings_global::select_packings_self_dual "
974 "after encode_incma" << endl;
975 }
976 if (nb_rows1 != nb_rows) {
977 cout << "packings_global::select_packings_self_dual "
978 "nb_rows1 != nb_rows" << endl;
979 exit(1);
980 }
981 if (nb_cols1 != nb_cols) {
982 cout << "packings_global::select_packings_self_dual "
983 "nb_cols1 != nb_cols" << endl;
984 exit(1);
985 }
986
987 OiP->input_fname = S->get_string(g + 1, original_file_idx);
988 OiP->input_idx = S->get_int(g + 1, input_idx_idx);
989
990 text = S->get_string(g + 1, input_set_idx);
991
992 OiP->set_as_string.assign(text);
993
994 int i, j, ii, jj, a;
995 int L = nb_rows * nb_cols;
996
997 Incma_out = NEW_int(L);
998 for (i = 0; i < nb_rows; i++) {
999 ii = canonical_labeling[i];
1000 for (j = 0; j < nb_cols; j++) {
1001 jj = canonical_labeling[nb_rows + j] - nb_rows;
1002 //cout << "i=" << i << " j=" << j << " ii=" << ii
1003 //<< " jj=" << jj << endl;
1004 Incma_out[i * nb_cols + j] = Incma_in[ii * nb_cols + jj];
1005 }
1006 }
1007 if (FALSE) {
1008 cout << "packings_global::select_packings_self_dual "
1009 "before bitvector_allocate_and_coded_length" << endl;
1010 }
1011 canonical_form = bitvector_allocate_and_coded_length(
1012 L, canonical_form_len);
1013 for (i = 0; i < nb_rows; i++) {
1014 for (j = 0; j < nb_cols; j++) {
1015 if (Incma_out[i * nb_cols + j]) {
1016 a = i * nb_cols + j;
1017 bitvector_set_bit(canonical_form, a);
1018 }
1019 }
1020 }
1021
1022 if (f_first) {
1023 if (f_v) {
1024 cout << "packings_global::select_packings_self_dual "
1025 "before CB->init" << endl;
1026 }
1027 CB->init(table_length, canonical_form_len, verbose_level);
1028 f_first = FALSE;
1029 }
1030
1031
1032 if (FALSE) {
1033 cout << "packings_global::select_packings_self_dual "
1034 "before CB->add" << endl;
1035 }
1036
1037 int idx;
1038 int f_found;
1039
1040 CB->search_and_add_if_new(canonical_form, OiP, f_found, idx, 0 /*verbose_level*/);
1041 if (f_found) {
1042 cout << "reject" << endl;
1043 nb_reject++;
1044 }
1045 if (FALSE) {
1046 cout << "packings_global::select_packings_self_dual "
1047 "CB->add f_found = " << f_found
1048 << " nb iso = " << CB->nb_types
1049 << " nb_reject=" << nb_reject
1050 << " nb_accept=" << nb_accept
1051 << " CB->n=" << CB->n
1052 << " CB->nb_types=" << CB->nb_types
1053 << endl;
1054 }
1055
1056
1057 //int idx;
1058
1059 object_in_projective_space_with_action *OiPA;
1060
1061 OiPA = NEW_OBJECT(object_in_projective_space_with_action);
1062
1063 OiPA->init(OiP, ago, nb_rows, nb_cols,
1064 canonical_labeling, 0 /*verbose_level*/);
1065 idx = CB->type_of[CB->n - 1];
1066 CB->Type_extra_data[idx] = OiPA;
1067
1068 FREE_int(Incma_in);
1069 FREE_int(Incma_out);
1070 FREE_int(partition);
1071 //FREE_int(canonical_labeling);
1072 //FREE_uchar(canonical_form);
1073 } // if (f_accept)
1074
1075
1076
1077 FREE_lint(the_set_in);
1078
1079 } // next g
1080
1081
1082
1083
1084 if (f_v) {
1085 cout << "packings_global::select_packings_self_dual done, "
1086 "we found " << CB->nb_types << " isomorphism types "
1087 "of packings. nb_accept = " << nb_accept
1088 << " CB->n = " << CB->n
1089 << " CB->nb_types = " << CB->nb_types
1090 << endl;
1091 }
1092
1093
1094 // second pass:
1095
1096 int nb_self_dual = 0;
1097 int g1 = 0;
1098 int *self_dual_cases;
1099 int nb_self_dual_cases = 0;
1100
1101
1102 self_dual_cases = NEW_int(table_length);
1103
1104
1105 if (f_v) {
1106 cout << "packings_global::select_packings_self_dual "
1107 "second pass, table_length="
1108 << table_length << endl;
1109 }
1110
1111
1112 for (g = 0; g < table_length; g++) {
1113
1114 int ago;
1115 char *text;
1116 int *the_set_in;
1117 int set_size_in;
1118 int *canonical_labeling1;
1119 int *canonical_labeling2;
1120 //int canonical_labeling_sz;
1121 int nb_rows, nb_cols;
1122 object_in_projective_space *OiP1;
1123 object_in_projective_space *OiP2;
1124 long int *set1;
1125 long int *set2;
1126
1127 ago = S->get_int(g + 1, ago_idx);
1128 nb_rows = S->get_int(g + 1, nb_rows_idx);
1129 nb_cols = S->get_int(g + 1, nb_cols_idx);
1130
1131 text = S->get_string(g + 1, input_set_idx);
1132 Orbiter->Int_vec.scan(text, the_set_in, set_size_in);
1133
1134 packing_size = set_size_in;
1135
1136
1137 if (f_split) {
1138 if ((g % split_m) != split_r) {
1139 continue;
1140 }
1141 }
1142 g1++;
1143 if (f_v && (g1 % 100) == 0) {
1144 cout << "File " << fname
1145 << ", case " << g1 << " input set " << g << " / "
1146 << table_length
1147 << " nb_self_dual=" << nb_self_dual << endl;
1148 //int_vec_print(cout, the_set_in, set_size_in);
1149 //cout << endl;
1150 }
1151
1152
1153 set1 = NEW_lint(packing_size);
1154 set2 = NEW_lint(packing_size);
1155
1156 for (i = 0; i < packing_size; i++) {
1157 a = the_set_in[i];
1158 b = s2l[a];
1159 set1[i] = b;
1160 }
1161 Sorting.lint_vec_heapsort(set1, packing_size);
1162 for (i = 0; i < packing_size; i++) {
1163 a = set1[i];
1164 b = Spread_tables->dual_spread_idx[a];
1165 set2[i] = l2s[b];
1166 }
1167 for (i = 0; i < packing_size; i++) {
1168 a = set1[i];
1169 b = l2s[a];
1170 set1[i] = b;
1171 }
1172 Sorting.lint_vec_heapsort(set1, packing_size);
1173 Sorting.lint_vec_heapsort(set2, packing_size);
1174
1175#if 0
1176 cout << "set1: ";
1177 int_vec_print(cout, set1, packing_size);
1178 cout << endl;
1179 cout << "set2: ";
1180 int_vec_print(cout, set2, packing_size);
1181 cout << endl;
1182#endif
1183
1184
1185
1186
1187 OiP1 = NEW_OBJECT(object_in_projective_space);
1188 OiP2 = NEW_OBJECT(object_in_projective_space);
1189
1190 if (FALSE) {
1191 cout << "packings_global::select_packings_self_dual "
1192 "before init_packing_from_spread_table" << endl;
1193 }
1194 OiP1->init_packing_from_spread_table(P, set1,
1195 Spread_table_original, nb_spreads, spread_size,
1196 0 /*verbose_level*/);
1197 OiP2->init_packing_from_spread_table(P, set2,
1198 Spread_table_original, nb_spreads, spread_size,
1199 0 /*verbose_level*/);
1200 if (FALSE) {
1201 cout << "packings_global::select_packings_self_dual "
1202 "after init_packing_from_spread_table" << endl;
1203 }
1204 OiP1->f_has_known_ago = TRUE;
1205 OiP1->known_ago = ago;
1206
1207
1208
1209 uchar *canonical_form1;
1210 uchar *canonical_form2;
1211 int canonical_form_len;
1212
1213
1214
1215 int *Incma_in1;
1216 int *Incma_out1;
1217 int *Incma_in2;
1218 int *Incma_out2;
1219 int nb_rows1, nb_cols1;
1220 int *partition;
1221 //uchar *canonical_form1;
1222 //uchar *canonical_form2;
1223 //int canonical_form_len;
1224
1225
1226 if (FALSE) {
1227 cout << "packings_global::select_packings_self_dual "
1228 "before encode_incma" << endl;
1229 }
1230 OiP1->encode_incma(Incma_in1, nb_rows1, nb_cols1,
1231 partition, 0 /*verbose_level - 1*/);
1232 OiP2->encode_incma(Incma_in2, nb_rows1, nb_cols1,
1233 partition, 0 /*verbose_level - 1*/);
1234 if (FALSE) {
1235 cout << "packings_global::select_packings_self_dual "
1236 "after encode_incma" << endl;
1237 }
1238 if (nb_rows1 != nb_rows) {
1239 cout << "packings_global::select_packings_self_dual "
1240 "nb_rows1 != nb_rows" << endl;
1241 exit(1);
1242 }
1243 if (nb_cols1 != nb_cols) {
1244 cout << "packings_global::select_packings_self_dual "
1245 "nb_cols1 != nb_cols" << endl;
1246 exit(1);
1247 }
1248
1249
1250 if (FALSE) {
1251 cout << "packings_global::select_packings_self_dual "
1252 "before PA->set_stabilizer_of_object" << endl;
1253 }
1254
1255
1256 canonical_labeling1 = NEW_int(nb_rows * nb_cols);
1257 canonical_labeling2 = NEW_int(nb_rows * nb_cols);
1258
1259 canonical_labeling(
1260 OiP1,
1261 canonical_labeling1,
1262 0 /*verbose_level - 2*/);
1263 canonical_labeling(
1264 OiP2,
1265 canonical_labeling2,
1266 0 /*verbose_level - 2*/);
1267
1268
1269 OiP1->input_fname = S->get_string(g + 1, original_file_idx);
1270 OiP1->input_idx = S->get_int(g + 1, input_idx_idx);
1271 OiP2->input_fname = S->get_string(g + 1, original_file_idx);
1272 OiP2->input_idx = S->get_int(g + 1, input_idx_idx);
1273
1274 text = S->get_string(g + 1, input_set_idx);
1275
1276 OiP1->set_as_string.assign(text);
1277
1278 OiP2->set_as_string.assign(text);
1279
1280 int i, j, ii, jj, a, ret;
1281 int L = nb_rows * nb_cols;
1282
1283 Incma_out1 = NEW_int(L);
1284 Incma_out2 = NEW_int(L);
1285 for (i = 0; i < nb_rows; i++) {
1286 ii = canonical_labeling1[i];
1287 for (j = 0; j < nb_cols; j++) {
1288 jj = canonical_labeling1[nb_rows + j] - nb_rows;
1289 //cout << "i=" << i << " j=" << j << " ii=" << ii
1290 //<< " jj=" << jj << endl;
1291 Incma_out1[i * nb_cols + j] = Incma_in1[ii * nb_cols + jj];
1292 }
1293 }
1294 for (i = 0; i < nb_rows; i++) {
1295 ii = canonical_labeling2[i];
1296 for (j = 0; j < nb_cols; j++) {
1297 jj = canonical_labeling2[nb_rows + j] - nb_rows;
1298 //cout << "i=" << i << " j=" << j << " ii=" << ii
1299 //<< " jj=" << jj << endl;
1300 Incma_out2[i * nb_cols + j] = Incma_in2[ii * nb_cols + jj];
1301 }
1302 }
1303 if (FALSE) {
1304 cout << "packings_global::select_packings_self_dual "
1305 "before bitvector_allocate_and_coded_length" << endl;
1306 }
1307 canonical_form1 = bitvector_allocate_and_coded_length(
1308 L, canonical_form_len);
1309 for (i = 0; i < nb_rows; i++) {
1310 for (j = 0; j < nb_cols; j++) {
1311 if (Incma_out1[i * nb_cols + j]) {
1312 a = i * nb_cols + j;
1313 bitvector_set_bit(canonical_form1, a);
1314 }
1315 }
1316 }
1317 canonical_form2 = bitvector_allocate_and_coded_length(
1318 L, canonical_form_len);
1319 for (i = 0; i < nb_rows; i++) {
1320 for (j = 0; j < nb_cols; j++) {
1321 if (Incma_out2[i * nb_cols + j]) {
1322 a = i * nb_cols + j;
1323 bitvector_set_bit(canonical_form2, a);
1324 }
1325 }
1326 }
1327
1328
1329 if (FALSE) {
1330 cout << "packings_global::select_packings_self_dual "
1331 "before CB->search" << endl;
1332 }
1333
1334 int idx1, idx2;
1335
1336 ret = CB->search(canonical_form1, idx1, 0 /*verbose_level*/);
1337
1338 if (ret == FALSE) {
1339 cout << "cannot find the dual packing, "
1340 "something is wrong" << endl;
1341 ret = CB->search(canonical_form1, idx1, 5 /* verbose_level*/);
1342#if 0
1343 cout << "CB:" << endl;
1344 CB->print_table();
1345 cout << "canonical form1: ";
1346 for (int j = 0; j < canonical_form_len; j++) {
1347 cout << (int) canonical_form1[j];
1348 if (j < canonical_form_len - 1) {
1349 cout << ", ";
1350 }
1351 }
1352 cout << endl;
1353#endif
1354 exit(1);
1355 }
1356 if (FALSE) {
1357 cout << "packings_global::select_packings_self_dual "
1358 "CB->search returns idx1=" << idx1 << endl;
1359 }
1360 ret = CB->search(canonical_form2, idx2, 0 /*verbose_level*/);
1361
1362 if (ret == FALSE) {
1363 cout << "cannot find the dual packing, "
1364 "something is wrong" << endl;
1365 ret = CB->search(canonical_form2, idx2, 5 /* verbose_level*/);
1366#if 0
1367 cout << "CB:" << endl;
1368 CB->print_table();
1369 cout << "canonical form2: ";
1370 for (int j = 0; j < canonical_form_len; j++) {
1371 cout << (int) canonical_form2[j];
1372 if (j < canonical_form_len - 1) {
1373 cout << ", ";
1374 }
1375 }
1376#endif
1377 exit(1);
1378 }
1379 if (FALSE) {
1380 cout << "packings_global::select_packings_self_dual "
1381 "CB->search returns idx2=" << idx2 << endl;
1382 }
1383
1384 FREE_int(Incma_in1);
1385 FREE_int(Incma_out1);
1386 FREE_int(Incma_in2);
1387 FREE_int(Incma_out2);
1388 FREE_int(partition);
1389 FREE_int(canonical_labeling1);
1390 FREE_int(canonical_labeling2);
1391 FREE_uchar(canonical_form1);
1392 FREE_uchar(canonical_form2);
1393
1394 FREE_lint(set1);
1395 FREE_lint(set2);
1396
1397 if (idx1 == idx2) {
1398 cout << "self-dual" << endl;
1399 nb_self_dual++;
1400 self_dual_cases[nb_self_dual_cases++] = g;
1401 }
1402
1403 FREE_int(the_set_in);
1404
1405 } // next g
1406
1407 string fname_base;
1408 string fname_self_dual;
1409 char str[1000];
1410 string_tools String;
1411
1412 fname_base.assign(fname);
1413 String.chop_off_extension(fname_base);
1414 fname_self_dual.assign(fname);
1415 String.chop_off_extension(fname_self_dual);
1416 if (f_split) {
1417 sprintf(str, "_self_dual_r%d_m%d.csv", split_r, split_m);
1418 }
1419 else {
1420 sprintf(str, "_self_dual.csv");
1421 }
1422 fname_self_dual.append(str);
1423 cout << "saving self_dual_cases to file " << fname_self_dual << endl;
1424 Fio.int_vec_write_csv(self_dual_cases, nb_self_dual_cases,
1425 fname_self_dual, "self_dual_idx");
1426 cout << "written file " << fname_self_dual
1427 << " of size " << Fio.file_size(fname_self_dual) << endl;
1428
1429
1430
1431 //FREE_OBJECT(CB);
1432 FREE_lint(Spread_table_original);
1433
1434 if (f_v) {
1435 cout << "packings_global::select_packings_self_dual "
1436 "done, nb_self_dual = " << nb_self_dual << endl;
1437 }
1438#endif
1439
1440}
1441
1442
1443
1444}}}
1445
1446
classification of 0/1 matrices using canonical forms
void search_and_add_if_new(uchar *data, void *extra_data, int &f_found, int &idx, int verbose_level)
void scan(std::string &s, int *&v, int &len)
Definition: int_vec.cpp:608
void scan(std::string &s, long int *&v, int &len)
Definition: lint_vec.cpp:359
void copy(long int *from, long int *to, long int len)
Definition: lint_vec.cpp:80
void print(std::ostream &ost, long int *v, int len)
Definition: lint_vec.cpp:246
tables with line-spreads in PG(3,q)
Definition: geometry.h:2335
void merge_packings(std::string *fnames, int nb_files, std::string &file_of_spreads, data_structures::classify_bitvectors *&CB, int verbose_level)
void select_packings(std::string &fname, std::string &file_of_spreads_original, geometry::spread_tables *Spread_tables, int f_self_polar, int f_ago, int select_ago, data_structures::classify_bitvectors *&CB, int verbose_level)
void select_packings_self_dual(std::string &fname, std::string &file_of_spreads_original, int f_split, int split_r, int split_m, geometry::spread_tables *Spread_tables, data_structures::classify_bitvectors *&CB, int verbose_level)
#define FREE_uchar(p)
Definition: foundations.h:647
#define FREE_int(p)
Definition: foundations.h:640
unsigned char uchar
Definition: foundations.h:204
#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 TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects