Orbiter 2022
Combinatorial Objects
tdo_refinement.cpp
Go to the documentation of this file.
1/*
2 * tdo_refinement.cpp
3 *
4 * Created on: Oct 28, 2019
5 * Author: betten
6 */
7
8
9
10#include "foundations.h"
11
12
13using namespace std;
14
15
16namespace orbiter {
17namespace layer1_foundations {
18namespace combinatorics {
19
20
21static void print_distribution(std::ostream &ost,
22 int *types, int nb_types, int type_len,
23 int *distributions, int nb_distributions);
24static int compare_func_int_vec(void *a, void *b, void *data);
25static int compare_func_int_vec_inverse(void *a, void *b, void *data);
26static void distribution_reverse_sorting(int f_increasing,
27 int *types, int nb_types, int type_len,
28 int *distributions, int nb_distributions);
29
30
32{
33 Descr = NULL;
34
35 t0 = 0;
36 cnt = 0;
37 //p_buf = NULL;
38
39
40 //geo_parameter GP;
41
42 //geo_parameter GP2;
43
44
45 f_doit = FALSE;
46 nb_written = 0;
48 nb_tactical = 0;
50
51}
52
54{
55}
56
57void tdo_refinement::init(tdo_refinement_description *Descr, int verbose_level)
58{
59 int f_v = (verbose_level >= 1);
61
62 if (f_v) {
63 cout << "tdo_refinement::init" << endl;
64 }
65
66 t0 = Os.os_ticks();
67
69
70 GP2.part_nb_alloc = 10000;
71 GP2.entries_nb_alloc = 1000000;
74
75 if (f_v) {
76 cout << "tdo_refinement::init done" << endl;
77 }
78}
79
80
81void tdo_refinement::main_loop(int verbose_level)
82{
83 int f_v = (verbose_level >= 1);
84 int f_vv = (verbose_level >= 2);
85 //int f_vvv = (verbose_level >= 3);
86
87 if (f_v) {
88 cout << "tdo_refinement::main_loop" << endl;
89 }
90
91 if (!Descr->f_input_file) {
92 cout << "please use option -input_file <fanme>" << endl;
93 exit(1);
94 }
95
96 if (f_v) {
97 cout << "tdo_refinement::main_loop "
98 "opening file " << Descr->fname_in << " for reading" << endl;
99 }
100 ifstream f(Descr->fname_in);
101 char str[1000];
103
104 fname.assign(Descr->fname_in);
105 //strcpy(str, Descr->fname_in);
106 //get_extension_if_present(str, ext);
107 //chop_off_extension_if_present(str, ext);
109
110
111 fname_out.assign(fname);
112 //sprintf(fname_out, "%s", str);
113 if (Descr->f_range) {
114 sprintf(str, "_r%d_%d", Descr->range_first, Descr->range_len);
115 fname_out.append(str);
116 }
117 if (Descr->f_select) {
118 fname_out.append("_S");
120 }
121 fname_out.append("r.tdo");
122 //sprintf(fname_out + strlen(fname_out), "r.tdo");
123 {
124
125 if (f_v) {
126 cout << "tdo_parameter_calculation::main_loop "
127 "opening file " << fname_out << " for writing" << endl;
128 }
129 ofstream g(fname_out);
130
131 for (cnt = 0; ; cnt++) {
132
133 if (f_v) {
134 cout << "tdo_parameter_calculation::main_loop "
135 "cnt=" << cnt << endl;
136 }
137
138 if (f.eof()) {
139 cout << "eof reached" << endl;
140 break;
141 }
142
143 #if 0
144 if (cnt && (cnt % 1000) == 0) {
145 cout << cnt << endl;
146 registry_dump();
147 }
148 #endif
149
150 if (!GP.input_mode_stack(f, 0 /*verbose_level - 1*/)) {
151 //cout << "GP.input_mode_stack returns FALSE" << endl;
152 break;
153 }
154
155 if (f) {
156 cout << "tdo_refinement::main_loop "
157 "cnt=" << cnt << " read input TDO" << endl;
158 }
159
160 f_doit = TRUE;
161 if (Descr->f_range) {
162 if (cnt + 1 < Descr->range_first || cnt + 1 >= Descr->range_first + Descr->range_len) {
163 f_doit = FALSE;
164 }
165 }
166 if (Descr->f_select) {
167 if (strcmp(GP.label.c_str(), Descr->select_label.c_str())) {
168 continue;
169 }
170 }
171 if (f_doit) {
172 if (f_v) {
173 cout << "tdo_refinement::main_loop "
174 "read decomposition " << cnt << endl;
175 }
176 if (f_vv) {
178 }
179 if (FALSE) {
180 cout << "after print_schemes" << endl;
181 }
182 do_it(g, verbose_level - 1);
183 }
184
185
186 } // next cnt
187
188
189
190 g << -1 << " " << nb_written << " TDOs, with " << nb_written_tactical << " being tactical" << endl;
191 cout << "tdo_refinement::main_loop " << nb_written
192 << " TDOs, with " << nb_written_tactical << " being tactical" << endl;
193 }
194 if (f_v) {
195 cout << "tdo_refinement::main_loop done" << endl;
196 }
197}
198
199void tdo_refinement::do_it(ofstream &g, int verbose_level)
200{
201 int f_v = (verbose_level >= 1);
202 int f_vv = (verbose_level >= 2);
203 int f_vvv = (verbose_level >= 3);
204
207
208 if (f_v) {
209 cout << "tdo_refinement::do_it "
210 "read TDO " << cnt << " " << GP.label << endl;
211 }
212
213 GP.init_tdo_scheme(G, verbose_level - 1);
214 if (f_vv) {
215 cout << "tdo_refinement::do_it "
216 "after init_tdo_scheme" << endl;
217 GP.print_schemes(G);
218 }
219
220
221 if (f_vvv) {
222 cout << "tdo_refinement::do_it "
223 "calling init_partition_stack" << endl;
224 }
225 G.init_partition_stack(verbose_level - 4);
226 if (f_vvv) {
227 cout << "tdo_refinement::do_it "
228 "row_level=" << GP.row_level << endl;
229 cout << "tdo_parameter_calculation::do_it "
230 "col_level=" << GP.col_level << endl;
231 }
232
233 if (GP.col_level > GP.row_level) {
234 if (f_vvv) {
235 cout << "tdo_refinement::do_it "
236 "calling do_row_refinement" << endl;
237 }
238 do_row_refinement(g, G, P, verbose_level);
239 if (f_vvv) {
240 cout << "tdo_refinement::do_it "
241 "after do_row_refinement" << endl;
242 }
243 }
244 else if (GP.col_level < GP.row_level) {
245 if (f_vvv) {
246 cout << "tdo_refinement::do_it "
247 "calling do_col_refinement" << endl;
248 }
249 do_col_refinement(g, G, P, verbose_level);
250 if (f_vvv) {
251 cout << "tdo_refinement::do_it "
252 "after do_col_refinement" << endl;
253 }
254 }
255 else {
257#if 0
258 tdo_write(g, GP.label, GP.part, GP.nb_parts, GP.entries, GP.nb_entries,
261#endif
262 if (f_vv) {
263 cout << "tdo_refinement::do_it "
264 << GP.label << " written" << endl;
265 }
266 nb_written++;
268 }
269
270 if (f_v) {
271 cout << "tdo_refinement::do_it done" << endl;
272 }
273
274}
275
277 ofstream &g, tdo_scheme_synthetic &G,
279 int verbose_level)
280{
281 int f_v = (verbose_level >= 1);
282 //int f_vv = (verbose_level >= 2);
283 //int f_vvv = (verbose_level >= 3);
284
285 if (f_v) {
286 cout << "tdo_refinement::do_row_refinement "
287 "col_level > row_level" << endl;
288 }
289 int *point_types, nb_point_types, point_type_len;
290 int *distributions, nb_distributions;
291 int f_success;
292
293 if (Descr->f_lambda3) {
294 if (f_v) {
295 cout << "tdo_refinement::do_row_refinement "
296 "before G.td3_refine_rows" << endl;
297 }
298 f_success = G.td3_refine_rows(verbose_level - 1, Descr->f_once,
300 point_types, nb_point_types, point_type_len,
301 distributions, nb_distributions);
302 if (f_v) {
303 cout << "tdo_refinement::do_row_refinement "
304 "after G.td3_refine_rows" << endl;
305 }
306 }
307 else {
308 if (f_v) {
309 cout << "tdo_refinement::do_row_refinement "
310 "before G.refine_rows" << endl;
311 }
312 f_success = G.refine_rows(verbose_level - 1,
314 point_types, nb_point_types, point_type_len,
315 distributions, nb_distributions,
321 if (f_v) {
322 cout << "tdo_refinement::do_row_refinement "
323 "after G.refine_rows" << endl;
324 }
325 }
326
327 if (f_success) {
329 distribution_reverse_sorting(Descr->f_reverse_inverse,
330 point_types, nb_point_types, point_type_len,
331 distributions, nb_distributions);
332 }
333 if (verbose_level >= 5) {
334 print_distribution(cout,
335 point_types, nb_point_types, point_type_len,
336 distributions, nb_distributions);
337 }
338
339 if (f_v) {
340 cout << "tdo_refinement::do_row_refinement "
341 "before do_all_row_refinements" << endl;
342 }
344 point_types, nb_point_types, point_type_len,
345 distributions, nb_distributions, nb_tactical,
346 verbose_level - 2);
347 if (f_v) {
348 cout << "tdo_refinement::do_row_refinement "
349 "after do_all_row_refinements, found "
350 << nb_distributions << " refinements" << endl;
351 }
352
353 nb_written += nb_distributions;
355 FREE_int(point_types);
356 FREE_int(distributions);
357 }
358 else {
359 if (f_v) {
360 cout << "tdo_refinement::do_row_refinement "
361 "Case " << GP.label << ", found " << 0
362 << " row refinements, out of which "
363 << 0 << " are tactical" << endl;
364 }
365 }
366 if (f_v) {
367 cout << "tdo_refinement::do_row_refinement done" << endl;
368 }
369}
370
372 ofstream &g, tdo_scheme_synthetic &G,
373 data_structures::partitionstack &P, int verbose_level)
374{
375 int f_v = (verbose_level >= 1);
376 //int f_vv = (verbose_level >= 2);
377 //int f_vvv = (verbose_level >= 3);
378
379 int *line_types, nb_line_types, line_type_len;
380 int *distributions, nb_distributions;
381 int f_success;
382
383 if (f_v) {
384 cout << "tdo_refinement::do_col_refinement "
385 "col_level < row_level" << endl;
386 }
387 if (Descr->f_lambda3) {
388 if (f_v) {
389 cout << "tdo_refinement::do_col_refinement "
390 "before G.td3_refine_columns" << endl;
391 }
392
393 f_success = G.td3_refine_columns(verbose_level - 1,
394 Descr->f_once,
397 line_types, nb_line_types, line_type_len,
398 distributions, nb_distributions);
399
400 if (f_v) {
401 cout << "tdo_refinement::do_col_refinement "
402 "after G.td3_refine_columns" << endl;
403 }
404 }
405 else {
406 if (f_v) {
407 cout << "tdo_refinement::do_col_refinement "
408 "before G.refine_columns" << endl;
409 }
410 f_success = G.refine_columns(verbose_level - 1,
411 Descr->f_once, P,
412 line_types, nb_line_types, line_type_len,
413 distributions, nb_distributions,
419 if (f_v) {
420 cout << "tdo_refinement::do_col_refinement "
421 "after G.refine_columns" << endl;
422 }
423 }
424 if (f_success) {
426 if (f_v) {
427 cout << "tdo_refinement::do_col_refinement "
428 "before G.distribution_reverse_sorting" << endl;
429 }
430 distribution_reverse_sorting(Descr->f_reverse_inverse,
431 line_types, nb_line_types, line_type_len,
432 distributions, nb_distributions);
433 if (f_v) {
434 cout << "tdo_refinement::do_col_refinement "
435 "after G.distribution_reverse_sorting" << endl;
436 }
437 }
438 if (verbose_level >= 5) {
439 print_distribution(cout,
440 line_types, nb_line_types, line_type_len,
441 distributions, nb_distributions);
442 }
443
444 if (f_v) {
445 cout << "tdo_refinement::do_col_refinement "
446 "before do_all_column_refinements" << endl;
447 }
449 line_types, nb_line_types, line_type_len,
450 distributions, nb_distributions, nb_tactical,
451 verbose_level - 1);
452 if (f_v) {
453 cout << "tdo_refinement::do_col_refinement "
454 "after do_all_column_refinements" << endl;
455 }
456 nb_written += nb_distributions;
458 FREE_int(line_types);
459 FREE_int(distributions);
460 }
461 else {
462 if (f_v) {
463 cout << "tdo_refinement::do_col_refinement "
464 "Case " << GP.label << ", found " << 0
465 << " col refinements, out of which "
466 << 0 << " are tactical" << endl;
467 }
468 }
469 if (f_v) {
470 cout << "tdo_refinement::do_col_refinement done" << endl;
471 }
472}
473
475 std::string &label_in, ofstream &g, tdo_scheme_synthetic &G,
476 int *point_types, int nb_point_types, int point_type_len,
477 int *distributions, int nb_distributions, int &nb_tactical,
478 int verbose_level)
479{
480 int f_v = (verbose_level >= 1);
481 int i, t;
482
483 if (f_v) {
484 cout << "tdo_refinement::do_all_row_refinements" << endl;
485 }
486 nb_tactical = 0;
487 for (i = 0; i < GP.nb_parts; i++) {
488 GP2.part[i] = GP.part[i];
489 }
490 for (i = 0; i < 4 * GP.nb_entries; i++) {
491 GP2.entries[i] = GP.entries[i];
492 }
493
494 for (t = 0; t < nb_distributions; t++) {
495
496 if (do_row_refinement(t, label_in, g, G, point_types, nb_point_types,
497 point_type_len, distributions, nb_distributions,
498 verbose_level - 5)) {
499 nb_tactical++;
500 }
501
502 }
503 if (f_v) {
504 cout << "Case " << label_in << ", found " << nb_distributions
505 << " row refinements, out of which "
506 << nb_tactical << " are tactical" << endl;
507 }
508 if (f_v) {
509 cout << "tdo_refinement::do_all_row_refinements done" << endl;
510 }
511
512}
513
515 std::string &label_in, ofstream &g, tdo_scheme_synthetic &G,
516 int *line_types, int nb_line_types, int line_type_len,
517 int *distributions, int nb_distributions, int &nb_tactical,
518 int verbose_level)
519{
520 int f_v = (verbose_level >= 1);
521 int i, t;
522
523
524 if (f_v) {
525 cout << "tdo_refinement::do_all_column_refinements" << endl;
526 }
527 nb_tactical = 0;
528 for (i = 0; i < GP.nb_parts; i++) {
529 GP2.part[i] = GP.part[i];
530 }
531 for (i = 0; i < 4 * GP.nb_entries; i++) {
532 GP2.entries[i] = GP.entries[i];
533 }
534
535 for (t = 0; t < nb_distributions; t++) {
536
537 //cout << "tdo_refinement::do_all_column_refinements t=" << t << endl;
538 if (do_column_refinement(t, label_in, g, G, line_types, nb_line_types,
539 line_type_len, distributions, nb_distributions,
540 verbose_level - 5)) {
541 nb_tactical++;
542 }
543
544 }
545 if (f_v) {
546 cout << "Case " << label_in << ", found " << nb_distributions
547 << " column refinements, out of which "
548 << nb_tactical << " are tactical" << endl;
549 }
550 if (f_v) {
551 cout << "tdo_refinement::do_all_column_refinements done" << endl;
552 }
553}
554
555
557 int t, std::string &label_in, ofstream &g, tdo_scheme_synthetic &G,
558 int *point_types, int nb_point_types, int point_type_len,
559 int *distributions, int nb_distributions,
560 int verbose_level)
561// returns TRUE or FALSE depending on whether the
562// refinement gave a tactical decomposition
563{
564 int r, i, j, h, a, l, R, c1, c2, S, s, idx, new_nb_parts, new_nb_entries;
565 int *type_index;
566 //char label_out[1000];
567 int f_v = (verbose_level >= 1);
568 int f_vv = (verbose_level >= 6);
569 int f_vvv = (verbose_level >= 7);
570 int f_tactical;
571
572 if (f_v) {
573 cout << "tdo_refinement::do_row_refinement t=" << t << endl;
574 }
575
576 type_index = NEW_int(nb_point_types);
577 for (i = 0; i < nb_point_types; i++) {
578 type_index[i] = -1;
579 }
580
581 new_nb_parts = GP.nb_parts;
582 if (G.row_level >= 2) {
584 }
585 else {
586 R = 1;
587 }
588 i = 0;
589 h = 0;
590 S = 0;
591 for (r = 0; r < R; r++) {
592 if (G.row_level >= 2) {
593 l = G.row_classes_len[ROW_SCHEME][r];
594 }
595 else {
596 //partitionstack &P = G.PB.P;
597 l = G.P->startCell[1];
598 }
599 s = 0;
600 if (f_vv) {
601 cout << "r=" << r << " l=" << l << endl;
602 }
603 while (i < nb_point_types) {
604 a = distributions[t * nb_point_types + i];
605 if (a == 0) {
606 i++;
607 continue;
608 }
609 if (f_vv) {
610 cout << "h=" << h << " i=" << i << " a=" << a << " s=" << s << " S=" << S << endl;
611 }
612 type_index[h++] = i;
613 if (s == 0) {
614 }
615 else {
616 GP2.part[new_nb_parts++] = S + s;
617 }
618 s += a;
619 i++;
620 if (s == l) {
621 break;
622 }
623 if (s > l) {
624 cout << "tdo_refinement::do_row_refinement: s > l" << endl;
625 exit(1);
626 }
627 }
628 S += l;
629 }
630 if (S != G.m) {
631 cout << "tdo_refinement::do_row_refinement: S != G.m" << endl;
632 exit(1);
633 }
634
635 new_nb_entries = GP.nb_entries;
636 GP2.part[new_nb_parts] = -1;
637 GP2.entries[new_nb_entries * 4 + 0] = -1;
638 if (f_vv) {
639 cout << "new_part:" << endl;
640 for (i = 0; i < new_nb_parts; i++)
641 cout << GP2.part[i] << " ";
642 cout << endl;
643 cout << "type_index:" << endl;
644 for (i = 0; i < h; i++)
645 cout << type_index[i] << " ";
646 cout << endl;
647 }
648
649
650
651 {
652 tdo_scheme_synthetic G2;
653
654 G2.init_part_and_entries_int(GP2.part, GP2.entries, verbose_level - 2);
655
656 G2.row_level = new_nb_parts;
657 G2.col_level = G.col_level;
658 G2.extra_row_level = G.row_level; // GP.extra_row_level;
659 G2.extra_col_level = GP.extra_col_level;
660 G2.lambda_level = G.lambda_level;
661 G2.level[ROW_SCHEME] = new_nb_parts;
662 G2.level[COL_SCHEME] = G.col_level;
663 G2.level[EXTRA_ROW_SCHEME] = G.row_level; // G.extra_row_level;
664 G2.level[EXTRA_COL_SCHEME] = G.extra_col_level;
665 G2.level[LAMBDA_SCHEME] = G.lambda_level;
666
667 G2.init_partition_stack(verbose_level - 2);
668
669 if (f_v) {
670 cout << "found a " << G2.nb_row_classes[ROW_SCHEME] << " x " << G2.nb_col_classes[ROW_SCHEME] << " scheme" << endl;
671 }
672 for (i = 0; i < G2.nb_row_classes[ROW_SCHEME]; i++) {
673 c1 = G2.row_classes[ROW_SCHEME][i];
674 for (j = 0; j < point_type_len /*G2.nb_col_classes[ROW]*/; j++) {
675 c2 = G2.col_classes[ROW_SCHEME][j];
676 idx = type_index[i];
677 if (idx == -1) {
678 continue;
679 }
680 a = point_types[idx * point_type_len + j];
681 if (f_vv) {
682 cout << "i=" << i << " j=" << j << " idx=" << idx << " a=" << a << endl;
683 }
684 GP2.entries[new_nb_entries * 4 + 0] = new_nb_parts;
685 GP2.entries[new_nb_entries * 4 + 1] = c1;
686 GP2.entries[new_nb_entries * 4 + 2] = c2;
687 GP2.entries[new_nb_entries * 4 + 3] = a;
688 new_nb_entries++;
689 }
690 }
691
692 if (f_vvv) {
693 for (i = 0; i < new_nb_entries; i++) {
694 for (j = 0; j < 4; j++) {
695 cout << setw(2) << GP2.entries[i * 4 + j] << " ";
696 }
697 cout << endl;
698 }
699 }
700
701 char str[1000];
702
703 //sprintf(GP2.label, "%s.%d", label_in, t + 1);
704 sprintf(str, ".%d", t + 1);
705 GP2.label.assign(label_in);
706 GP2.label.append(str);
707
708 GP2.nb_parts = new_nb_parts;
709 GP2.nb_entries = new_nb_entries;
710 GP2.row_level = new_nb_parts;
715
717
718#if 0
719 tdo_write(g, GP2.label,
720 GP2.part, new_nb_parts, GP2.entries, new_nb_entries,
721 new_nb_parts, G.col_level, G.lambda_level,
722 G.row_level/*G.extra_row_level*/, G.extra_col_level);
723#endif
724
725 if (f_vv) {
726 cout << GP2.label << " written" << endl;
727 }
728 if (new_nb_parts == G.col_level) {
729 f_tactical = TRUE;
730 }
731 else {
732 f_tactical = FALSE;
733 }
734 }
735
736 FREE_int(type_index);
737 if (f_v) {
738 cout << "tdo_refinement::do_row_refinement t=" << t << " done" << endl;
739 }
740 return f_tactical;
741}
742
744 int t, std::string &label_in,
745 ofstream &g, tdo_scheme_synthetic &G,
746 int *line_types, int nb_line_types, int line_type_len,
747 int *distributions, int nb_distributions,
748 int verbose_level)
749// returns TRUE or FALSE depending on whether the
750// refinement gave a tactical decomposition
751{
752 int r, i, j, h, a, l, R, c1, c2, S, s, idx, new_nb_parts, new_nb_entries;
753 int *type_index;
754 //char label_out[1000];
755 int f_v = (verbose_level >= 1);
756 int f_vv = (verbose_level >= 6);
757 int f_vvv = (verbose_level >= 7);
758 int f_tactical;
759
760 if (f_v) {
761 cout << "tdo_refinement::do_column_refinement t=" << t << endl;
762 }
763
764 type_index = NEW_int(nb_line_types);
765
766 for (i = 0; i < nb_line_types; i++) {
767 type_index[i] = -1;
768 }
769 new_nb_parts = GP.nb_parts;
771 i = 0;
772 h = 0;
773 S = G.m;
774 for (r = 0; r < R; r++) {
775 l = G.col_classes_len[COL_SCHEME][r];
776 s = 0;
777 if (f_vv) {
778 cout << "r=" << r << " l=" << l << endl;
779 }
780 while (i < nb_line_types) {
781 a = distributions[t * nb_line_types + i];
782 if (a == 0) {
783 i++;
784 continue;
785 }
786 if (f_vv) {
787 cout << "h=" << h << " i=" << i << " a=" << a << " s=" << s << " S=" << S << endl;
788 }
789 type_index[h++] = i;
790 if (s == 0) {
791 }
792 else {
793 GP2.part[new_nb_parts++] = S + s;
794 }
795 s += a;
796 i++;
797 if (s == l) {
798 break;
799 }
800 if (s > l) {
801 cout << "tdo_refinement::do_column_refinement: s > l" << endl;
802 cout << "r=" << r << endl;
803 cout << "s=" << s << endl;
804 cout << "l=" << l << endl;
805 cout << "a=" << a << endl;
806 Int_vec_print(cout, distributions + t * nb_line_types, nb_line_types);
807 cout << endl;
808 exit(1);
809 }
810 }
811 S += l;
812 }
813 if (S != G.m + G.n) {
814 cout << "tdo_refinement::do_column_refinement: S != G.m + G.n" << endl;
815 exit(1);
816 }
817
818 new_nb_entries = G.nb_entries;
819 GP2.part[new_nb_parts] = -1;
820 GP2.entries[new_nb_entries * 4 + 0] = -1;
821 if (f_vv) {
822 cout << "new_part:" << endl;
823 for (i = 0; i < new_nb_parts; i++) {
824 cout << GP2.part[i] << " ";
825 }
826 cout << endl;
827 cout << "type_index:" << endl;
828 for (i = 0; i < h; i++) {
829 cout << type_index[i] << " ";
830 }
831 cout << endl;
832 }
833
834 {
836
838
839 G2->init_part_and_entries_int(GP2.part, GP2.entries, verbose_level - 2);
840
841 G2->row_level = GP.row_level;
842 G2->col_level = new_nb_parts;
844 G2->extra_col_level = GP.col_level; // GP.extra_col_level;
846 G2->level[ROW_SCHEME] = G.row_level;
847 G2->level[COL_SCHEME] = new_nb_parts;
849 G2->level[EXTRA_COL_SCHEME] = GP.col_level; // G.extra_col_level;
851
852 G2->init_partition_stack(verbose_level - 2);
853
854 if (f_v) {
855 cout << "found a " << G2->nb_row_classes[COL_SCHEME] << " x " << G2->nb_col_classes[COL_SCHEME] << " scheme" << endl;
856 }
857 for (i = 0; i < G2->nb_row_classes[COL_SCHEME]; i++) {
858 c1 = G2->row_classes[COL_SCHEME][i];
859 for (j = 0; j < G2->nb_col_classes[COL_SCHEME]; j++) {
860 c2 = G2->col_classes[COL_SCHEME][j];
861 idx = type_index[j];
862 if (idx == -1) {
863 continue;
864 }
865 a = line_types[idx * line_type_len + i];
866 if (f_vv) {
867 cout << "i=" << i << " j=" << j << " idx=" << idx << " a=" << a << endl;
868 }
869 GP2.entries[new_nb_entries * 4 + 0] = new_nb_parts;
870 GP2.entries[new_nb_entries * 4 + 1] = c2;
871 GP2.entries[new_nb_entries * 4 + 2] = c1;
872 GP2.entries[new_nb_entries * 4 + 3] = a;
873 new_nb_entries++;
874 }
875 }
876
877 if (f_vvv) {
878 for (i = 0; i < new_nb_entries; i++) {
879 for (j = 0; j < 4; j++) {
880 cout << setw(2) << GP2.entries[i * 4 + j] << " ";
881 }
882 cout << endl;
883 }
884 }
885
886 char str[1000];
887
888 //sprintf(GP2.label, "%s.%d", label_in, t + 1);
889 sprintf(str, ".%d", t + 1);
890 GP2.label.assign(label_in);
891 GP2.label.append(str);
892
893 GP2.nb_parts = new_nb_parts;
894 GP2.nb_entries = new_nb_entries;
896 GP2.col_level = new_nb_parts;
900
902
903#if 0
904
905 tdo_write(g, GP2.label, GP2.part, new_nb_parts, GP2.entries, new_nb_entries,
906 G.row_level, new_nb_parts, G.lambda_level,
907 G.extra_row_level, GP.col_level /*G.extra_col_level*/);
908#endif
909
910 if (f_vv) {
911 cout << GP2.label << " written" << endl;
912 }
913 if (new_nb_parts == G.row_level) {
914 f_tactical = TRUE;
915 }
916 else {
917 f_tactical = FALSE;
918 }
919 FREE_OBJECT(G2);
920 }
921
922 FREE_int(type_index);
923 if (f_v) {
924 cout << "tdo_refinement::do_column_refinement t=" << t << " done" << endl;
925 }
926 return f_tactical;
927}
928
929// global stuff:
930
931
932static void print_distribution(ostream &ost,
933 int *types, int nb_types, int type_len,
934 int *distributions, int nb_distributions)
935{
936 int i, j;
937
938
939 ost << "types:" << endl;
940 for (i = 0; i < nb_types; i++) {
941 ost << setw(3) << i + 1 << " : ";
942 for (j = 0; j < type_len; j++) {
943 ost << setw(3) << types[i * type_len + j];
944 }
945 ost << endl;
946 }
947 ost << endl;
948
949
950 for (j = 0; j < type_len; j++) {
951 ost << setw(3) << j + 1 << " & ";
952 for (i = 0; i < nb_types; i++) {
953 ost << setw(2) << types[i * type_len + j];
954 if (i < nb_types - 1) {
955 ost << " & ";
956 }
957 }
958 ost << "\\\\" << endl;
959 }
960 ost << endl;
961
962 ost << "distributions:" << endl;
963 for (i = 0; i < nb_distributions; i++) {
964 ost << setw(3) << i + 1 << " : ";
965 for (j = 0; j < nb_types; j++) {
966 ost << setw(3) << distributions[i * nb_types + j];
967 }
968 ost << endl;
969 }
970 ost << endl;
971 for (i = 0; i < nb_distributions; i++) {
972 ost << setw(3) << i + 1 << " & ";
973 for (j = 0; j < nb_types; j++) {
974 ost << setw(2) << distributions[i * nb_types + j];
975 if (j < nb_types - 1) {
976 ost << " & ";
977 }
978 }
979 ost << "\\\\" << endl;
980 }
981 ost << endl;
982
983 ost << "distributions (in compact format):" << endl;
984 int f_first, a;
985 for (i = 0; i < nb_distributions; i++) {
986 ost << setw(3) << i + 1 << " & ";
987 f_first = TRUE;
988 for (j = 0; j < nb_types; j++) {
989 a = distributions[i * nb_types + j];
990 if (a == 0) {
991 continue;
992 }
993 if (!f_first) {
994 ost << ",";
995 }
996 ost << nb_types - 1 - j << "^{" << a << "}";
997 f_first = FALSE;
998 }
999 ost << "\\\\" << endl;
1000 }
1001 ost << endl;
1002}
1003
1004
1005int static compare_func_int_vec(void *a, void *b, void *data)
1006{
1007 int *p = (int *)a;
1008 int *q = (int *)b;
1009 int *d = (int *) data;
1010 int size = d[0];
1011 int i;
1012
1013 for (i = 0; i < size; i++) {
1014 if (p[i] > q[i]) {
1015 return -1;
1016 }
1017 if (p[i] < q[i]) {
1018 return 1;
1019 }
1020 }
1021 return 0;
1022}
1023
1024int static compare_func_int_vec_inverse(void *a, void *b, void *data)
1025{
1026 int *p = (int *)a;
1027 int *q = (int *)b;
1028 int *d = (int *) data;
1029 int size = d[0];
1030 int i;
1031
1032 for (i = 0; i < size; i++) {
1033 if (p[i] > q[i]) {
1034 return 1;
1035 }
1036 if (p[i] < q[i]) {
1037 return -1;
1038 }
1039 }
1040 return 0;
1041}
1042
1043static void distribution_reverse_sorting(int f_increasing,
1044 int *types, int nb_types, int type_len,
1045 int *distributions, int nb_distributions)
1046{
1047 int i, j;
1048 int *D;
1049 int **P;
1050 data_structures::sorting Sorting;
1051
1052 D = NEW_int(nb_distributions * nb_types);
1053 P = NEW_pint(nb_distributions);
1054
1055 for (i = 0; i < nb_distributions; i++) {
1056 P[i] = D + i * nb_types;
1057 for (j = 0; j < nb_types; j++) {
1058 D[i * nb_types + nb_types - 1 - j] = distributions[i * nb_types + j];
1059 }
1060 }
1061
1062 int p[1];
1063
1064 p[0] = nb_types;
1065
1066 if (f_increasing) {
1067 Sorting.quicksort_array(nb_distributions, (void **) P,
1068 compare_func_int_vec_inverse, (void *)p);
1069 }
1070 else {
1071 Sorting.quicksort_array(nb_distributions, (void **) P,
1072 compare_func_int_vec, (void *)p);
1073 }
1074
1075 for (i = 0; i < nb_distributions; i++) {
1076 for (j = 0; j < nb_types; j++) {
1077 distributions[i * nb_types + j] = P[i][nb_types - 1 - j];
1078 }
1079 }
1080 FREE_int(D);
1081 FREE_pint(P);
1082
1083}
1084
1085
1086}}}
1087
1088
1089
void write_mode_stack(std::ofstream &aStream, std::string &label)
int input_mode_stack(std::ifstream &aStream, int verbose_level)
void init_tdo_scheme(tdo_scheme_synthetic &G, int verbose_level)
void init(tdo_refinement_description *Descr, int verbose_level)
void do_all_column_refinements(std::string &label_in, std::ofstream &g, tdo_scheme_synthetic &G, int *line_types, int nb_line_types, int line_type_len, int *distributions, int nb_distributions, int &nb_tactical, int verbose_level)
void do_all_row_refinements(std::string &label_in, std::ofstream &g, tdo_scheme_synthetic &G, int *point_types, int nb_point_types, int point_type_len, int *distributions, int nb_distributions, int &nb_tactical, int verbose_level)
int do_column_refinement(int t, std::string &label_in, std::ofstream &g, tdo_scheme_synthetic &G, int *line_types, int nb_line_types, int line_type_len, int *distributions, int nb_distributions, int verbose_level)
void do_col_refinement(std::ofstream &g, tdo_scheme_synthetic &G, data_structures::partitionstack &P, int verbose_level)
void do_row_refinement(std::ofstream &g, tdo_scheme_synthetic &G, data_structures::partitionstack &P, int verbose_level)
void do_it(std::ofstream &g, int verbose_level)
canonical tactical decomposition of an incidence structure
int td3_refine_rows(int verbose_level, int f_once, int lambda3, int block_size, int *&point_types, int &nb_point_types, int &point_type_len, int *&distributions, int &nb_distributions)
int td3_refine_columns(int verbose_level, int f_once, int lambda3, int block_size, int f_scale, int scaling, int *&line_types, int &nb_line_types, int &line_type_len, int *&distributions, int &nb_distributions)
int refine_columns(int verbose_level, int f_once, data_structures::partitionstack &P, int *&line_types, int &nb_line_types, int &line_type_len, int *&distributions, int &nb_distributions, int &cnt_second_system, solution_file_data *Sol, int f_omit1, int omit1, int f_omit, int omit, int f_D1_upper_bound_x0, int D1_upper_bound_x0, int f_use_mckay_solver, int f_use_packing_numbers)
void init_part_and_entries_int(int *part, int *entries, int verbose_level)
int refine_rows(int verbose_level, int f_use_mckay, int f_once, data_structures::partitionstack &P, int *&point_types, int &nb_point_types, int &point_type_len, int *&distributions, int &nb_distributions, int &cnt_second_system, solution_file_data *Sol, int f_omit1, int omit1, int f_omit2, int omit2, int f_use_packing_numbers, int f_dual_is_linear_space, int f_do_the_geometric_test)
data structure for set partitions following Jeffrey Leon
functions related to strings and character arrays
#define LAMBDA_SCHEME
#define EXTRA_ROW_SCHEME
#define EXTRA_COL_SCHEME
#define COL_SCHEME
#define ROW_SCHEME
#define FREE_int(p)
Definition: foundations.h:640
#define NEW_pint(n)
Definition: foundations.h:627
#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_pint(p)
Definition: foundations.h:641
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects