Orbiter 2022
Combinatorial Objects
tdo_scheme_synthetic.cpp
Go to the documentation of this file.
1// tdo_scheme_synthetic.cpp
2//
3// Anton Betten 8/27/07
4//
5//
6// refine_rows and refine_columns started: December 2006
7// moved away from inc_gen: 8/27/07
8// separated out from refine: 1/24/08
9// corrected a memory problem in refine_rows_hard: Dec 6 2010
10
11
12#include "foundations.h"
13
14
15using namespace std;
16
17
18namespace orbiter {
19namespace layer1_foundations {
20namespace combinatorics {
21
22
24{
25 int i;
26
27 P = NULL;
28 part_length = 0;
29 part = NULL;
30 nb_entries = 0;
31 entries = NULL;
32
33 row_level = 0;
34 col_level = 0;
35 lambda_level = 0;
38 mn = 0;
39 m = 0;
40 n = 0;
41 for (i = 0; i < NUMBER_OF_SCHEMES; i++) {
42 row_classes[i] = NULL;
43 col_classes[i] = NULL;
44 row_class_index[i] = NULL;
45 col_class_index[i] = NULL;
46 row_classes_first[i] = NULL;
47 row_classes_len[i] = NULL;
48 row_class_no[i] = NULL;
49 col_classes_first[i] = NULL;
50 col_classes_len[i] = NULL;
51 col_class_no[i] = NULL;
52 }
53 the_row_scheme = NULL;
54 the_col_scheme = NULL;
57 the_row_scheme_cur = NULL;
58 the_col_scheme_cur = NULL;
61
62}
63
65{
66 int i;
67
68 if (part) {
70 part = NULL;
71 }
72 if (entries) {
74 entries = NULL;
75 }
76 for (i = 0; i < NUMBER_OF_SCHEMES; i++) {
78 }
79 if (the_row_scheme) {
81 the_row_scheme = NULL;
82 }
83 if (the_col_scheme) {
85 the_col_scheme = NULL;
86 }
90 }
94 }
97 the_row_scheme_cur = NULL;
98 }
101 the_col_scheme_cur = NULL;
102 }
106 }
110 }
111 if (P) {
112 FREE_OBJECT(P);
113 P = NULL;
114 }
115}
116
118 int *Part, int *Entries, int verbose_level)
119{
120 int i;
121 int f_v = (verbose_level >= 1);
122
123 for (part_length = 0; ; part_length++) {
124 if (Part[part_length] == -1) {
125 break;
126 }
127 }
128 if (f_v) {
129 cout << "partition of length " << part_length << endl;
130 }
131
132 for (nb_entries = 0; ; nb_entries++) {
133 if (Entries[4 * nb_entries + 0] == -1) {
134 break;
135 }
136 }
137 if (f_v) {
138 cout << "nb_entries = " << nb_entries << endl;
139 }
140
141 if (part) {
142 FREE_int(part);
143 }
144 if (entries) {
146 }
147 part = NEW_int(part_length + 1);
148 for (i = 0; i <= part_length; i++) {
149 part[i] = Part[i];
150 }
151 entries = NEW_int(4 * nb_entries + 1);
152 for (i = 0; i <= 4 * nb_entries; i++) {
153 entries[i] = Entries[i];
154 }
155}
156
158 int *Part, int *Entries, int verbose_level)
159{
160 int i;
161 int f_v = (verbose_level >= 1);
162
163 for (part_length = 0; ; part_length++) {
164 if (Part[part_length] == -1) {
165 break;
166 }
167 }
168 if (f_v) {
169 cout << "partition of length " << part_length << endl;
170 }
171
172 for (nb_entries = 0; ; nb_entries++) {
173 if (Entries[4 * nb_entries + 0] == -1) {
174 break;
175 }
176 }
177 if (f_v) {
178 cout << "nb_entries = " << nb_entries << endl;
179 }
180
181 if (part) {
182 FREE_int(part);
183 }
184 if (entries) {
186 }
187 part = NEW_int(part_length + 1);
188 for (i = 0; i <= part_length; i++) {
189 part[i] = Part[i];
190 }
191 entries = NEW_int(4 * nb_entries + 1);
192 for (i = 0; i <= 4 * nb_entries; i++) {
193 entries[i] = Entries[i];
194 }
195}
196
197void tdo_scheme_synthetic::init_TDO(int *Part, int *Entries,
198 int Row_level, int Col_level,
199 int Extra_row_level, int Extra_col_level,
200 int Lambda_level, int verbose_level)
201{
202 int f_v = (verbose_level >= 1);
203 int f_vv = (verbose_level >= 2);
204 int f_vvv = (verbose_level >= 3);
205
206 if (f_v) {
207 cout << "tdo_scheme::init_TDO" << endl;
208 }
209 init_part_and_entries(Part, Entries, verbose_level);
210 if (f_vv) {
211 cout << "partition of length " << part_length << endl;
212 }
213 if (f_vv) {
214 cout << "nb_entries = " << nb_entries << endl;
215 }
216
217 row_level = Row_level;
218 col_level = Col_level;
219 extra_row_level = Extra_row_level;
220 extra_col_level = Extra_col_level;
221 lambda_level = Lambda_level;
222 if (f_vvv) {
223 cout << "row_level = " << row_level << endl;
224 cout << "col_level = " << col_level << endl;
225 cout << "extra_row_level = " << extra_row_level << endl;
226 cout << "extra_col_level = " << extra_col_level << endl;
227 cout << "lambda_level = " << lambda_level << endl;
228 }
234
235 init_partition_stack(verbose_level - 2);
236
237 //cout << "after init_partition_stack" << endl;
238
239 //print_row_test_data();
240
241}
242
244{
246
247 if (the_row_scheme_cur) {
249 the_row_scheme_cur = NULL;
250 }
251 if (the_col_scheme_cur) {
253 the_col_scheme_cur = NULL;
254 }
258 }
262 }
263}
264
266{
267 int k, at, f, c, l, i;
268 int f_v = (verbose_level >= 1);
269 int f_vv = (verbose_level >= 2);
270 int f_vvv = (verbose_level >= 3);
271
272 if (f_v) {
273 cout << "tdo_scheme_synthetic::init_partition_stack" << endl;
274 }
275 if (f_vv) {
276 cout << "part_length=" << part_length << endl;
277 cout << "row_level=" << row_level << endl;
278 cout << "col_level=" << col_level << endl;
279 cout << "verbose_level=" << verbose_level << endl;
280 }
281 mn = part[0];
282 m = part[1];
283 n = mn - m;
284 if (part_length < 2) {
285 cout << "part_length < 2" << endl;
286 exit(1);
287 }
288 if (f_vvv) {
289 cout << "init_partition_stack: m=" << m << " n=" << n << endl;
290 Int_vec_print(cout, part, part_length + 1);
291 cout << endl;
292 }
293
295 P->allocate(m + n, 0 /* verbose_level */);
296 //PB.init_partition_backtrack_basic(m, n, verbose_level - 10);
297 if (f_vvv) {
298 cout << "after PB.init_partition_backtrack_basic" << endl;
299 }
300
301 //partitionstack &P = PB.P;
302
303 if (f_vvv) {
304 cout << "initial partition stack: " << endl;
305 P->print(cout);
306 }
307 for (k = 1; k < part_length; k++) {
308 at = part[k];
309 c = P->cellNumber[at];
310 f = P->startCell[c];
311 l = P->cellSize[c];
312 if (f_vvv) {
313 cout << "part[" << k << "]=" << at << endl;
314 cout << "P->cellNumber[at]=" << c << endl;
315 cout << "P->startCell[c]=" << f << endl;
316 cout << "P->cellSize[c]=" << l << endl;
317 cout << "f + l - at=" << f + l - at << endl;
318 }
319 P->subset_continguous(at, f + l - at);
321 if (f_vvv) {
322 cout << "after splitting at " << at << endl;
323 P->print(cout);
324 }
325 if (P->ht == row_level) {
326 l = P->ht;
327 if (the_row_scheme) {
329 the_row_scheme = NULL;
330 }
331 the_row_scheme = NEW_int(l * l);
332 for (i = 0; i < l * l; i++) {
333 the_row_scheme[i] = -1;
334 }
335 get_partition(ROW_SCHEME, l, verbose_level - 3);
336 get_row_or_col_scheme(ROW_SCHEME, l, verbose_level - 3);
337 }
338
339 if (P->ht == col_level) {
340 l = P->ht;
341 if (the_col_scheme) {
343 the_col_scheme = NULL;
344 }
345 the_col_scheme = NEW_int(l * l);
346 for (i = 0; i < l * l; i++) {
347 the_col_scheme[i] = -1;
348 }
349 get_partition(COL_SCHEME, l, verbose_level - 3);
350 get_row_or_col_scheme(COL_SCHEME, l, verbose_level - 3);
351 }
352
353 if (P->ht == extra_row_level) {
354 l = P->ht;
358 }
360 for (i = 0; i < l * l; i++) {
361 the_extra_row_scheme[i] = -1;
362 }
363 get_partition(EXTRA_ROW_SCHEME, l, verbose_level - 3);
364 get_row_or_col_scheme(EXTRA_ROW_SCHEME, l, verbose_level - 3);
365 }
366
367 if (P->ht == extra_col_level) {
368 l = P->ht;
372 }
374 for (i = 0; i < l * l; i++) {
375 the_extra_col_scheme[i] = -1;
376 }
377 get_partition(EXTRA_COL_SCHEME, l, verbose_level - 3);
378 get_row_or_col_scheme(EXTRA_COL_SCHEME, l, verbose_level - 3);
379 }
380
381 if (P->ht == lambda_level) {
382 l = P->ht;
383 get_partition(LAMBDA_SCHEME, l, verbose_level - 3);
384 }
385
386 } // next k
387
388 if (f_vvv) {
389 cout << "before complete_partition_info" << endl;
390 }
391 if (row_level >= 2) {
392 complete_partition_info(ROW_SCHEME, 0/*verbose_level*/);
393 }
394 if (col_level >= 2) {
395 complete_partition_info(COL_SCHEME, 0/*verbose_level*/);
396 }
397 if (extra_row_level >= 2) {
398 complete_partition_info(EXTRA_ROW_SCHEME, 0/*verbose_level*/);
399 }
401 complete_partition_info(EXTRA_COL_SCHEME, 0/*verbose_level*/);
402 }
403 complete_partition_info(LAMBDA_SCHEME, 0/*verbose_level*/);
404
405 if (f_vv) {
406 if (row_level >= 2) {
408 }
409 if (col_level >= 2) {
411 }
412 if (extra_row_level >= 2) {
414 }
415 if (extra_col_level >= 2) {
417 }
419 }
420}
421
423{
424 if (the_row_scheme) {
426 the_row_scheme = NULL;
427 }
428 if (the_col_scheme) {
430 the_col_scheme = NULL;
431 }
435 }
439 }
442 //if (extra_row_level >= 0)
444 //if (extra_col_level >= 0)
447
448}
449
450void tdo_scheme_synthetic::get_partition(int h, int l, int verbose_level)
451{
452 int f_v = (verbose_level >= 1);
453 int f_vv = (verbose_level >= 10);
454 int i;
455
456 if (f_v) {
457 cout << "tdo_scheme_synthetic::get_partition h=" << h << " l=" << l
458 << " m=" << m << " n=" << n << endl;
459 }
460 if (l < 0) {
461 cout << "tdo_scheme_synthetic::get_partition l is negative" << endl;
462 exit(1);
463 }
465 row_classes[h] = NEW_int(l);
466 col_classes[h] = NEW_int(l);
467 row_class_index[h] = NEW_int(l);
468 col_class_index[h] = NEW_int(l);
470 row_classes_len[h] = NEW_int(l);
472 col_classes_len[h] = NEW_int(l);
473 row_class_no[h] = NEW_int(m);
474 col_class_no[h] = NEW_int(n);
475
476 for (i = 0; i < l; i++) {
477 row_class_index[h][i] = -1;
478 col_class_index[h][i] = -1;
479 }
480
482 col_classes[h], nb_col_classes[h], verbose_level - 1);
483
484 for (i = 0; i < nb_row_classes[h]; i++) {
485 row_class_index[h][row_classes[h][i]] = i;
486 if (f_vv) {
487 cout << "row_class_index[h][" << row_classes[h][i] << "] = "
488 << row_class_index[h][row_classes[h][i]] << endl;
489 }
490 }
491 for (i = 0; i < nb_col_classes[h]; i++) {
492 col_class_index[h][col_classes[h][i]] = i;
493 if (f_vv) {
494 cout << "col_class_index[h][" << col_classes[h][i] << "] = "
495 << col_class_index[h][col_classes[h][i]] << endl;
496 }
497 }
498 if (f_vv) {
499 cout << "nb_row_classes[h]=" << nb_row_classes[h] << endl;
500 cout << "nb_col_classes[h]=" << nb_col_classes[h] << endl;
501 }
502}
503
505{
506 if (row_classes[i]) {
508 row_classes[i] = NULL;
509 }
510 if (col_classes[i]) {
512 col_classes[i] = NULL;
513 }
514 if (row_class_index[i]) {
516 row_class_index[i] = NULL;
517 }
518 if (col_class_index[i]) {
520 col_class_index[i] = NULL;
521 }
522 if (row_classes_first[i]) {
524 row_classes_first[i] = NULL;
525 }
526 if (row_classes_len[i]) {
528 row_classes_len[i] = NULL;
529 }
530 if (row_class_no[i]) {
532 row_class_no[i] = NULL;
533 }
534 if (col_classes_first[i]) {
536 col_classes_first[i] = NULL;
537 }
538 if (col_classes_len[i]) {
540 col_classes_len[i] = NULL;
541 }
542 if (col_class_no[i]) {
544 col_class_no[i] = NULL;
545 }
546}
547
549{
550 int f_v = (verbose_level >= 1);
551 int f_vv = (verbose_level >= 5);
552 int f, i, j, c1, S, k;
553
554 if (f_v) {
555 cout << "tdo_scheme_synthetic::complete_partition_info h=" << h << endl;
556 cout << "# of row classes = " << nb_row_classes[h] << endl;
557 cout << "# of col classes = " << nb_col_classes[h] << endl;
558 }
559 f = 0;
560 for (i = 0; i < nb_row_classes[h]; i++) {
561 if (f_vv) {
562 cout << "i=" << i << endl;
563 }
564 c1 = row_classes[h][i];
565 if (f_vv) {
566 cout << "c1=" << c1 << endl;
567 }
568 S = P->cellSizeAtLevel(c1, level[h]);
569 if (f_vv) {
570 cout << "S=" << S << endl;
571 }
572 row_classes_first[h][i] = f;
573 row_classes_len[h][i] = S;
574 for (k = 0; k < S; k++) {
575 row_class_no[h][f + k] = i;
576 if (f_vv) {
577 cout << "row_class_no[h][" << f + k << "]="
578 << row_class_no[h][f + k] << endl;
579 }
580 }
581 f += S;
582 }
583 f = 0;
584 for (j = 0; j < nb_col_classes[h]; j++) {
585 if (f_vv) {
586 cout << "j=" << j << endl;
587 }
588 c1 = col_classes[h][j];
589 if (f_vv) {
590 cout << "c1=" << c1 << endl;
591 }
592 S = P->cellSizeAtLevel(c1, level[h]);
593 if (f_vv) {
594 cout << "S=" << S << endl;
595 }
596 col_classes_first[h][j] = f;
597 col_classes_len[h][j] = S;
598 for (k = 0; k < S; k++) {
599 col_class_no[h][f + k] = j;
600 if (f_vv) {
601 cout << "col_class_no[h][" << f + k << "]="
602 << col_class_no[h][f + k] << endl;
603 }
604 }
605 f += S;
606 }
607}
608
609void tdo_scheme_synthetic::get_row_or_col_scheme(int h, int l, int verbose_level)
610{
611 int f_v = (verbose_level >= 1);
612 int i, j, d, c1, c2, s1, s2, v;
613
614 if (f_v) {
615 cout << "tdo_scheme_synthetic::get_row_or_col_scheme" << endl;
616 }
617 for (i = 0; i < nb_entries; i++) {
618 d = entries[i * 4 + 0];
619 c1 = entries[i * 4 + 1];
620 c2 = entries[i * 4 + 2];
621 v = entries[i * 4 + 3];
622 if (d == l) {
623 //cout << "entry " << i << " : " << d << " "
624 //<< c1 << " " << c2 << " " << v << endl;
625 if (h == ROW_SCHEME && row_class_index[h][c1] >= 0) {
626 // row scheme
627 s1 = row_class_index[h][c1];
628 s2 = col_class_index[h][c2];
629 //cout << "the_row_scheme[" << s1 << " * "
630 //<< nb_col_classes[h] << " + " << s2 << "] = "
631 //<< v << endl;
632 the_row_scheme[s1 * nb_col_classes[h] + s2] = v;
633 }
634 else if (h == COL_SCHEME && col_class_index[h][c1] >= 0) {
635 // col scheme
636 s1 = row_class_index[h][c2];
637 s2 = col_class_index[h][c1];
638 //cout << "the_col_scheme[" << s1 << " * "
639 //<< nb_col_classes[h] << " + " << s2 << "] = "
640 //<< v << endl;
641 the_col_scheme[s1 * nb_col_classes[h] + s2] = v;
642 }
643 else if (h == EXTRA_ROW_SCHEME && row_class_index[h][c1] >= 0) {
644 // col scheme
645 s1 = row_class_index[h][c1];
646 s2 = col_class_index[h][c2];
647 //cout << "the_extra_row_scheme[" << s1 << " * "
648 //<< nb_col_classes[h] << " + " << s2 << "] = "
649 //<< v << endl;
650 the_extra_row_scheme[s1 * nb_col_classes[h] + s2] = v;
651 }
652 else if (h == EXTRA_COL_SCHEME && col_class_index[h][c1] >= 0) {
653 // col scheme
654 s1 = row_class_index[h][c2];
655 s2 = col_class_index[h][c1];
656 //cout << "EXTRA_COL:" << endl;
657 //cout << "c1=" << c1 << endl;
658 //cout << "c2=" << c2 << endl;
659 //cout << "s1=" << s1 << endl;
660 //cout << "s2=" << s2 << endl;
661 //cout << "the_extra_col_scheme[" << s1 << " * "
662 //<< nb_col_classes[h] << " + "
663 //<< s2 << "] = " << v << endl;
664 the_extra_col_scheme[s1 * nb_col_classes[h] + s2] = v;
665 }
666 //print_row_test_data();
667 } // if
668 } // next i
669 if (h == ROW_SCHEME) {
670 if (the_row_scheme_cur) {
672 the_row_scheme_cur = NULL;
673 }
675 for (i = 0; i < m; i++) {
676 for (j = 0; j < nb_col_classes[h]; j++) {
677 the_row_scheme_cur[i * nb_col_classes[h] + j] = 0;
678 }
679 }
680 //print_row_test_data();
681 }
682 if (h == COL_SCHEME) {
683 if (the_col_scheme_cur) {
685 the_col_scheme_cur = NULL;
686 }
688 for (i = 0; i < n; i++) {
689 for (j = 0; j < nb_row_classes[h]; j++) {
690 the_col_scheme_cur[i * nb_row_classes[h] + j] = 0;
691 }
692 }
693 }
694 if (h == EXTRA_ROW_SCHEME) {
698 }
700 for (i = 0; i < m; i++) {
701 for (j = 0; j < nb_col_classes[h]; j++) {
703 }
704 }
705 }
706 if (h == EXTRA_COL_SCHEME) {
710 }
712 for (i = 0; i < n; i++) {
713 for (j = 0; j < nb_row_classes[h]; j++) {
715 }
716 }
717 }
718 if (f_v) {
719 cout << "tdo_scheme_synthetic::get_row_or_col_scheme finished" << endl;
720 }
721}
722
725{
726 int f_v = (verbose_level >= 1);
727 int f_vv = (verbose_level >= 2);
728 //int f_vvv = (verbose_level >= 3);
729 int i, j, h, j1, cc, f, l, ci, cj, l1, l2, R;
730
731 if (f_v) {
732 cout << "get_column_split_partition" << endl;
733 }
737 if (FALSE) {
738 cout << "l1=" << l1 << " at level " << level[ROW_SCHEME] << endl;
739 cout << "l2=" << l2 << " at level " << level[COL_SCHEME] << endl;
740 cout << "R=" << R << endl;
741 }
742 P.allocate(l2, FALSE);
743 for (i = 0; i < l1; i++) {
744 ci = col_classes[ROW_SCHEME][i];
745 j1 = col_class_index[COL_SCHEME][ci];
746 cc = P.cellNumber[j1];
747 f = P.startCell[cc];
748 l = P.cellSize[cc];
749 if (FALSE) {
750 cout << "i=" << i << " ci=" << ci << " j1=" << j1
751 << " cc=" << cc << endl;
752 }
753 P.subset_size = 0;
754 for (h = 0; h < l; h++) {
755 j = P.pointList[f + h];
756 cj = col_classes[COL_SCHEME][j];
757 if (FALSE) {
758 cout << "j=" << j << " cj=" << cj << endl;
759 }
760 if (!tdo_scheme_synthetic::P->is_descendant_of_at_level(cj, ci,
762 if (FALSE) {
763 cout << j << "/" << cj << " is not a "
764 "descendant of " << i << "/" << ci << endl;
765 }
766 P.subset[P.subset_size++] = j;
767 }
768 }
769 if (FALSE) {
770 cout << "non descendants of " << i << "/" << ci << " : ";
772 cout << endl;
773 }
774 if (P.subset_size > 0) {
776 if (FALSE) {
777 P.print(cout);
778 }
779 }
780 }
781 if (f_vv) {
782 cout << "column-split partition:" << endl;
783 P.print(cout);
784 }
785 if (f_v) {
786 cout << "get_column_split_partition done" << endl;
787 }
788}
789
792{
793 int f_v = (verbose_level >= 1);
794 int f_vv = (verbose_level >= 2);
795 //int f_vvv = (verbose_level >= 3);
796 int i, j, h, j1, cc, f, l, ci, cj, l1, l2, R;
797
798 if (f_v) {
799 cout << "get_row_split_partition" << endl;
800 }
804 if (FALSE) {
805 cout << "l1=" << l1 << endl;
806 cout << "l2=" << l2 << endl;
807 cout << "R=" << R << endl;
808 }
809 P.allocate(l2, FALSE);
810 for (i = 0; i < l1; i++) {
811 ci = row_classes[COL_SCHEME][i];
812 j1 = row_class_index[ROW_SCHEME][ci];
813 cc = P.cellNumber[j1];
814 f = P.startCell[cc];
815 l = P.cellSize[cc];
816 if (FALSE) {
817 cout << "i=" << i << " ci=" << ci << " j1=" << j1
818 << " cc=" << cc << endl;
819 }
820 P.subset_size = 0;
821 for (h = 0; h < l; h++) {
822 j = P.pointList[f + h];
823 cj = row_classes[ROW_SCHEME][j];
824 if (FALSE) {
825 cout << "j=" << j << " cj=" << cj << endl;
826 }
827 if (!tdo_scheme_synthetic::P->is_descendant_of_at_level(cj, ci,
829 if (FALSE) {
830 cout << j << "/" << cj << " is not a descendant "
831 "of " << i << "/" << ci << endl;
832 }
833 P.subset[P.subset_size++] = j;
834 }
835 else {
836 if (FALSE) {
837 cout << cj << " is a descendant of " << ci << endl;
838 }
839 }
840 }
841 if (FALSE) {
842 cout << "non descendants of " << i << "/" << ci << " : ";
844 cout << endl;
845 }
846 if (P.subset_size > 0) {
848 if (FALSE) {
849 P.print(cout);
850 }
851 }
852 }
853 if (f_vv) {
854 cout << "row-split partition:" << endl;
855 P.print(cout);
856 }
857}
858
860{
861 if (lambda_level >= 2) {
863 }
864 if (extra_row_level >= 2) {
866 }
867 if (extra_col_level >= 2) {
869 }
870 if (row_level >= 2) {
872 }
873 if (col_level >= 2) {
875 }
876}
877
878void tdo_scheme_synthetic::print_scheme(int h, int verbose_level)
879{
880 int f_v = (verbose_level >= 1);
881 int i, j, c1, c2, a = 0;
882
883 if (h == ROW_SCHEME) {
884 cout << "row_scheme at level " << level[h] << " : " << endl;
885 }
886 else if (h == COL_SCHEME) {
887 cout << "col_scheme at level " << level[h] << " : " << endl;
888 }
889 else if (h == EXTRA_ROW_SCHEME) {
890 cout << "extra_row_scheme at level " << level[h] << " : " << endl;
891 }
892 else if (h == EXTRA_COL_SCHEME) {
893 cout << "extra_col_scheme at level " << level[h] << " : " << endl;
894 }
895 else if (h == LAMBDA_SCHEME) {
896 cout << "lambda_scheme at level " << level[h] << " : " << endl;
897 }
898 cout << "is " << nb_row_classes[h] << " x "
899 << nb_col_classes[h] << endl;
900 cout << " | ";
901 for (j = 0; j < nb_col_classes[h]; j++) {
902 c2 = col_classes[h][j];
903 cout << setw(3) << col_classes_len[h][j]
904 << "_{" << setw(3) << c2 << "}";
905 }
906 cout << endl;
907 cout << "============";
908 for (j = 0; j < nb_col_classes[h]; j++) {
909 cout << "=========";
910 }
911 cout << endl;
912 for (i = 0; i < nb_row_classes[h]; i++) {
913 c1 = row_classes[h][i];
914 cout << setw(3) << row_classes_len[h][i] << "_{"
915 << setw(3) << c1 << "} | ";
916 if (h != LAMBDA_SCHEME) {
917 for (j = 0; j < nb_col_classes[h]; j++) {
918 if (h == ROW_SCHEME) {
919 a = the_row_scheme[i * nb_col_classes[h] + j];
920 }
921 else if (h == COL_SCHEME) {
922 a = the_col_scheme[i * nb_col_classes[h] + j];
923 }
924 else if (h == EXTRA_ROW_SCHEME) {
925 a = the_extra_row_scheme[i * nb_col_classes[h] + j];
926 }
927 else if (h == EXTRA_COL_SCHEME) {
928 a = the_extra_col_scheme[i * nb_col_classes[h] + j];
929 }
930
931 cout << setw(9) << a;
932 }
933 }
934 cout << endl;
935 }
936 cout << endl;
937 if (f_v) {
938 cout << "row_classes_first / len:" << endl;
939 for (i = 0; i < nb_row_classes[h]; i++) {
940 cout << i << " : " << row_classes_first[h][i] << " : "
941 << row_classes_len[h][i] << endl;
942 }
943 cout << "class_no:" << endl;
944 for (i = 0; i < m; i++) {
945 cout << i << " : " << row_class_no[h][i] << endl;
946 }
947 cout << "col_classes first / len:" << endl;
948 for (i = 0; i < nb_col_classes[h]; i++) {
949 cout << i << " : " << col_classes_first[h][i] << " : "
950 << col_classes_len[h][i] << endl;
951 }
952 cout << "col_class_no:" << endl;
953 for (i = 0; i < n; i++) {
954 cout << i << " : " << col_class_no[h][i] << endl;
955 }
956 }
957}
958
960{
961 std::string dummy;
962
963 print_scheme_tex_fancy(ost, h, FALSE, dummy);
964}
965
967 int h, int f_label, std::string &label)
968{
969 int i, j, a = 0, n, m, c1, c2;
970
971 n = nb_row_classes[h];
972 m = nb_col_classes[h];
973 ost << "$$" << endl;
974 ost << "\\begin{array}{r|*{" << m << "}{r}}" << endl;
975 if (f_label) {
976 ost << "\\multicolumn{" << m + 1
977 << "}{c}{\\mbox{" << label << "}}\\\\" << endl;
978 }
979 if (h == ROW_SCHEME || h == EXTRA_ROW_SCHEME) {
980 ost << "\\rightarrow";
981 }
982 else if (h == COL_SCHEME || h == EXTRA_COL_SCHEME) {
983 ost << "\\downarrow";
984 }
985 else if (h == LAMBDA_SCHEME) {
986 ost << "\\lambda";
987 }
988 for (j = 0; j < m; j++) {
989 c2 = col_classes[h][j];
990 ost << " & " << setw(3) << col_classes_len[h][j]
991 << "_{" << setw(3) << c2 << "}";
992 }
993 ost << "\\\\" << endl;
994 ost << "\\hline" << endl;
995 for (i = 0; i < n; i++) {
996 c1 = row_classes[h][i];
997 ost << row_classes_len[h][i] << "_{" << setw(3) << c1 << "}";
998 for (j = 0; j < m; j++) {
999 if (h == ROW_SCHEME) {
1000 a = the_row_scheme[i * m + j];
1001 }
1002 else if (h == COL_SCHEME) {
1003 a = the_col_scheme[i * m + j];
1004 }
1005 else if (h == EXTRA_ROW_SCHEME) {
1006 a = the_extra_row_scheme[i * m + j];
1007 }
1008 else if (h == EXTRA_COL_SCHEME) {
1009 a = the_extra_col_scheme[i * m + j];
1010 }
1011 ost << " & " << setw(3) << a;
1012 }
1013 ost << "\\\\" << endl;
1014 }
1015 ost << "\\end{array}" << endl;
1016 ost << "$$" << endl;
1017 ost << endl;
1018}
1019
1021 int *f_first_inc_must_be_moved, int verbose_level)
1022{
1023 int i, j, ii, fi, fii, fj, row_cell0, row_cell, col_cell, a, b, c;
1024 int f_v = (verbose_level >= 1);
1025 int f_vv = (verbose_level >= 2);
1026 int f_vvv = (verbose_level >= 3);
1027
1028 if (f_v) {
1029 cout << "tdo_scheme_synthetic::compute_whether_first_inc_must_be_moved" << endl;
1030 }
1031 for (i = 0; i < nb_row_classes[ROW_SCHEME]; i++) {
1032 f_first_inc_must_be_moved[i] = TRUE;
1033 if (col_level < 2) {
1034 continue;
1035 }
1037 row_cell0 = row_class_no[COL_SCHEME][fi];
1038 for (j = 0; j < nb_col_classes[ROW_SCHEME]; j++) {
1040 if (a > 0) {
1041 break;
1042 }
1043 }
1044
1045 if (f_vv) {
1046 cout << "considering whether incidence in block " << i << ","
1047 << j << " must be moved" << endl;
1048 }
1049
1051 col_cell = col_class_no[COL_SCHEME][fj];
1052 c = the_col_scheme[row_cell0 * nb_col_classes[COL_SCHEME] + col_cell];
1053 if (f_vvv) {
1054 cout << "c=" << c << endl;
1055 }
1056 if (c >= 0) {
1057 if (f_vvv) {
1058 cout << "looking at COL scheme:" << endl;
1059 }
1060 f_first_inc_must_be_moved[i] = FALSE;
1061 for (ii = i + 1; ii < nb_row_classes[ROW_SCHEME]; ii++) {
1063 fii = row_classes_first[ROW_SCHEME][ii];
1064 row_cell = row_class_no[COL_SCHEME][fii];
1065 if (row_cell != row_cell0) {
1066 if (f_vvv) {
1067 cout << "i=" << i << " ii=" << ii
1068 << " different "
1069 "COL fuse, hence it must not "
1070 "be moved" << endl;
1071 cout << "fi=" << fi << endl;
1072 cout << "fii=" << fii << endl;
1073 cout << "row_cell0=" << row_cell0 << endl;
1074 cout << "row_cell=" << row_cell << endl;
1075 }
1076 f_first_inc_must_be_moved[i] = FALSE;
1077 //ii = nb_row_classes[ROW];
1078 break;
1079 }
1080 if (b) {
1081 if (f_vvv) {
1082 cout << "ii=" << ii << " seeing non zero entry "
1083 << b << ", hence it must be moved" << endl;
1084 }
1085 f_first_inc_must_be_moved[i] = TRUE;
1086 break;
1087 }
1088 } // next ii
1089 }
1090 else {
1091 if (f_vvv) {
1092 cout << "looking at EXTRA_COL scheme:" << endl;
1093 }
1095 row_cell0 = row_class_no[EXTRA_COL_SCHEME][fi];
1096 if (f_vvv) {
1097 cout << "row_cell0=" << row_cell0 << endl;
1098 }
1099 for (ii = i + 1; ii < nb_row_classes[ROW_SCHEME]; ii++) {
1101 fii = row_classes_first[ROW_SCHEME][ii];
1102 row_cell = row_class_no[EXTRA_COL_SCHEME][fii];
1103 if (row_cell != row_cell0) {
1104 if (f_vvv) {
1105 cout << "i=" << i << " ii=" << ii
1106 << " different "
1107 "EXTRACOL fuse, hence it must "
1108 "not be moved" << endl;
1109 cout << "fi=" << fi << endl;
1110 cout << "fii=" << fii << endl;
1111 cout << "row_cell0=" << row_cell0 << endl;
1112 cout << "row_cell=" << row_cell << endl;
1113 }
1114 f_first_inc_must_be_moved[i] = FALSE;
1115 //ii = nb_row_classes[ROW];
1116 break;
1117 }
1118 if (b) {
1119 if (f_vvv) {
1120 cout << "ii=" << ii << " seeing non zero entry "
1121 << b << ", hence it must be moved" << endl;
1122 }
1123 f_first_inc_must_be_moved[i] = TRUE;
1124 break;
1125 }
1126 } // next ii
1127 }
1128
1129 }
1130 if (f_v) {
1131 cout << "tdo_scheme_synthetic::compute_whether_first_inc_must_be_moved done" << endl;
1132 }
1133}
1134
1136{
1137 int i, j, a, b = 0, nb_inc;
1138 int f_v = (verbose_level > 1);
1139
1140 if (f_v) {
1141 cout << "tdo_scheme_synthetic::count_nb_inc_from_row_scheme" << endl;
1142 }
1143 nb_inc = 0;
1144 for (i = 0; i < nb_row_classes[ROW_SCHEME]; i++) {
1145 for (j = 0; j < nb_col_classes[ROW_SCHEME]; j++) {
1147 if (a == -1) {
1148 cout << "incomplete row_scheme" << endl;
1149 cout << "i=" << i << "j=" << j << endl;
1150 cout << "ignoring this" << endl;
1151 }
1152 else {
1153 b = a * row_classes_len[ROW_SCHEME][i];
1154 }
1155 nb_inc += b;
1156 }
1157 }
1158 //cout << "nb_inc=" << nb_inc << endl;
1159 return nb_inc;
1160}
1161
1163{
1164 int i, j, a, b = 0, nb_inc;
1165 int f_v = (verbose_level > 1);
1166
1167 if (f_v) {
1168 cout << "tdo_scheme_synthetic::count_nb_inc_from_extra_row_scheme" << endl;
1169 }
1170 nb_inc = 0;
1171 for (i = 0; i < nb_row_classes[EXTRA_ROW_SCHEME]; i++) {
1172 for (j = 0; j < nb_col_classes[EXTRA_ROW_SCHEME]; j++) {
1174 if (a == -1) {
1175 cout << "incomplete extra_row_scheme" << endl;
1176 cout << "i=" << i << "j=" << j << endl;
1177 cout << "ignoring this" << endl;
1178 }
1179 else {
1181 }
1182 nb_inc += b;
1183 }
1184 }
1185 //cout << "nb_inc=" << nb_inc << endl;
1186 return nb_inc;
1187}
1188
1190 int *point_types, int nb_point_types, int point_type_len,
1191 int *distributions, int nb_distributions,
1192 int f_omit1, int omit1, int verbose_level)
1193{
1194 int f_v = (verbose_level >= 1);
1195 int f_vv = (verbose_level >= 2);
1196 int f_vvv = (verbose_level >= 3);
1197 int f_vvvv = (verbose_level >= 4);
1198 int f_v5 = (verbose_level >= 7);
1199 int i, s, d, /*l2,*/ L1, L2, cnt, new_nb_distributions;
1200 int f_ruled_out;
1201 int *ruled_out_by;
1202 int *non_zero_blocks, nb_non_zero_blocks;
1203
1204 if (f_vvv) {
1205 cout << "tdo_scheme_synthetic::geometric_test_for_row_scheme "
1206 "nb_distributions=" << nb_distributions << endl;
1207 }
1208 //l2 = nb_col_classes[COL];
1209 row_refinement_L1_L2(P, f_omit1, omit1, L1, L2, verbose_level - 3);
1210 if (L2 != point_type_len) {
1211 cout << "tdo_scheme_synthetic::geometric_test_for_row_scheme "
1212 "L2 != point_type_len" << endl;
1213 exit(1);
1214 }
1215
1216 ruled_out_by = NEW_int(nb_point_types + 1);
1217 non_zero_blocks = NEW_int(nb_point_types);
1218 for (i = 0; i <= nb_point_types; i++) {
1219 ruled_out_by[i] = 0;
1220 }
1221
1222 new_nb_distributions = 0;
1223 for (cnt = 0; cnt < nb_distributions; cnt++) {
1224 nb_non_zero_blocks = 0;
1225 for (i = 0; i < nb_point_types; i++) {
1226 d = distributions[cnt * nb_point_types + i];
1227 if (d == 0) {
1228 continue;
1229 }
1230 non_zero_blocks[nb_non_zero_blocks++] = i;
1231 }
1232
1233 if (f_vvvv) {
1234 cout << "geometric_test_for_row_scheme: testing distribution "
1235 << cnt << " / " << nb_distributions << " : ";
1236 Int_vec_print(cout,
1237 distributions + cnt * nb_point_types,
1238 nb_point_types);
1239 cout << endl;
1240 if (f_v5) {
1241 cout << "that is" << endl;
1242 for (i = 0; i < nb_non_zero_blocks; i++) {
1243 d = distributions[cnt *
1244 nb_point_types + non_zero_blocks[i]];
1245 cout << setw(3) << i << " : " << setw(3) << d << " x ";
1246 Int_vec_print(cout,
1247 point_types + non_zero_blocks[i] * point_type_len,
1248 point_type_len);
1249 cout << endl;
1250 }
1251 }
1252 }
1253 f_ruled_out = FALSE;
1254 for (s = 1; s <= nb_non_zero_blocks; s++) {
1256 point_types, nb_point_types, point_type_len,
1257 distributions + cnt * nb_point_types,
1258 non_zero_blocks, nb_non_zero_blocks,
1259 f_omit1, omit1, verbose_level - 4)) {
1260 f_ruled_out = TRUE;
1261 ruled_out_by[s]++;
1262 if (f_vv) {
1263 cout << "geometric_test_for_row_scheme: distribution "
1264 << cnt << " / " << nb_distributions
1265 << " eliminated by test of order " << s << endl;
1266 }
1267 if (f_vvv) {
1268 cout << "the eliminated scheme is:" << endl;
1269 for (i = 0; i < nb_non_zero_blocks; i++) {
1270 d = distributions[cnt * nb_point_types +
1271 non_zero_blocks[i]];
1272 cout << setw(3) << i << " : "
1273 << setw(3) << d << " x ";
1274 Int_vec_print(cout,
1275 point_types + non_zero_blocks[i] * point_type_len,
1276 point_type_len);
1277 cout << endl;
1278 }
1279 cout << "we repeat the test with more printout:" << endl;
1281 point_types, nb_point_types, point_type_len,
1282 distributions + cnt * nb_point_types,
1283 non_zero_blocks, nb_non_zero_blocks,
1284 f_omit1, omit1, verbose_level - 3);
1285 }
1286 break;
1287 }
1288 }
1289
1290
1291
1292 if (!f_ruled_out) {
1293 for (i = 0; i < nb_point_types; i++) {
1294 distributions[new_nb_distributions * nb_point_types + i] =
1295 distributions[cnt * nb_point_types + i];
1296 }
1297 new_nb_distributions++;
1298 }
1299 } // next cnt
1300 if (f_v) {
1301 cout << "geometric_test_for_row_scheme: number of distributions "
1302 "reduced from " << nb_distributions << " to "
1303 << new_nb_distributions << ", i.e. Eliminated "
1304 << nb_distributions - new_nb_distributions << " cases" << endl;
1305 cout << "# of ruled out by test of order ";
1306 Int_vec_print(cout, ruled_out_by, nb_point_types + 1);
1307 cout << endl;
1308 //cout << "nb ruled out by first order test = "
1309 //<< nb_ruled_out_by_order1 << endl;
1310 //cout << "nb ruled out by second order test = "
1311 //<< nb_ruled_out_by_order2 << endl;
1312 for (i = nb_point_types; i >= 1; i--) {
1313 if (ruled_out_by[i]) {
1314 break;
1315 }
1316 }
1317 if (i) {
1318 cout << "highest order test that was successfully "
1319 "applied is order " << i << endl;
1320 }
1321 }
1322 FREE_int(ruled_out_by);
1323 FREE_int(non_zero_blocks);
1324 return new_nb_distributions;
1325}
1326
1327#if 0
1328int tdo_scheme_synthetic::test_row_distribution(
1329 int *point_types, int nb_point_types, int point_type_len,
1330 int *distributions, int nb_distributions, int verbose_level)
1331{
1332 int f_v = (verbose_level >= 1);
1333 int f_vv = (verbose_level >= 2);
1334 int f_vvv = (verbose_level >= 3);
1335 int l2, cnt, J, len, k, i, d, c, new_nb_distributions, bound;
1336 int f_ruled_out, f_ruled_out_by_braun, f_ruled_out_by_packing;
1337 int nb_ruled_out_by_braun = 0, nb_ruled_out_by_packing = 0;
1338 int nb_ruled_out_by_both = 0;
1339
1340 if (f_v) {
1341 cout << "tdo_scheme_synthetic::test_row_distribution "
1342 "nb_distributions=" << nb_distributions << endl;
1343 }
1344 l2 = nb_col_classes[COL];
1345 if (l2 != point_type_len) {
1346 cout << "tdo_scheme_synthetic::test_row_distribution "
1347 "l2 != point_type_len" << endl;
1348 exit(1);
1349 }
1350
1351 new_nb_distributions = 0;
1352
1353 for (cnt = 0; cnt < nb_distributions; cnt++) {
1354 if (f_vv) {
1355 cout << "testing distribution " << cnt << " : ";
1356 int_vec_print(cout,
1357 distributions + cnt * nb_point_types,
1358 nb_point_types);
1359 cout << endl;
1360 if (f_vvv) {
1361 cout << "that is" << endl;
1362 for (i = 0; i < nb_point_types; i++) {
1363 d = distributions[cnt * nb_point_types + i];
1364 if (d == 0)
1365 continue;
1366 cout << setw(3) << d << " x ";
1367 int_vec_print(cout,
1368 point_types + i * point_type_len,
1369 point_type_len);
1370 cout << endl;
1371 }
1372 }
1373 }
1374 f_ruled_out = FALSE;
1375 f_ruled_out_by_braun = FALSE;
1376 f_ruled_out_by_packing = FALSE;
1377
1378 for (J = 0; J < l2; J++) {
1379 len = col_classes_len[COL][J];
1380 int *type;
1381
1382 if (f_vvv) {
1383 cout << "testing distribution " << cnt << " in block "
1384 << J << " len=" << len << endl;
1385 }
1386 type = NEW_int(len + 1);
1387 for (k = 0; k <= len; k++)
1388 type[k] = 0;
1389 for (i = 0; i < nb_point_types; i++) {
1390 d = distributions[cnt * nb_point_types + i];
1391 c = point_types[i * point_type_len + J];
1392 type[c] += d;
1393 }
1394 if (f_vvv) {
1395 cout << "line type: ";
1396 int_vec_print(cout, type + 1, len);
1397 cout << endl;
1398 }
1399 if (!braun_test_on_line_type(len, type)) {
1400 if (f_vv) {
1401 cout << "distribution " << cnt << " is eliminated "
1402 "in block " << J << " using Braun test" << endl;
1403 }
1404 f_ruled_out = TRUE;
1405 f_ruled_out_by_braun = TRUE;
1406 FREE_int(type);
1407 break;
1408 }
1409 FREE_int(type);
1410 } // next J
1411 for (J = 0; J < l2; J++) {
1412 len = col_classes_len[COL][J];
1413 if (len == 1)
1414 continue;
1415 for (i = 0; i < nb_point_types; i++) {
1416 d = distributions[cnt * nb_point_types + i];
1417 if (d == 0)
1418 continue;
1419 c = point_types[i * point_type_len + J];
1420 // now we want d lines of size c on len points
1421 if (c > 1) {
1422 if (c > len) {
1423 cout << "c > len" << endl;
1424 cout << "J=" << J << " i=" << i << " d="
1425 << d << " c=" << c << endl;
1426 exit(1);
1427 }
1428 bound = TDO_upper_bound(len, c);
1429 if (d > bound) {
1430 if (f_vv) {
1431 cout << "distribution " << cnt
1432 << " is eliminated in block "
1433 << J << " row-block " << i
1434 << " using packing numbers" << endl;
1435 cout << "len=" << len << endl;
1436 cout << "d=" << d << endl;
1437 cout << "c=" << c << endl;
1438 cout << "bound=" << bound << endl;
1439 }
1440 f_ruled_out = TRUE;
1441 f_ruled_out_by_packing = TRUE;
1442 break;
1443 }
1444 }
1445 }
1446 if (f_ruled_out)
1447 break;
1448 }
1449 if (f_ruled_out) {
1450 if (f_ruled_out_by_braun)
1451 nb_ruled_out_by_braun++;
1452 if (f_ruled_out_by_packing)
1453 nb_ruled_out_by_packing++;
1454 if (f_ruled_out_by_braun && f_ruled_out_by_packing)
1455 nb_ruled_out_by_both++;
1456 }
1457 else {
1458 for (i = 0; i < nb_point_types; i++) {
1459 distributions[new_nb_distributions * nb_point_types + i] =
1460 distributions[cnt * nb_point_types + i];
1461 }
1462 new_nb_distributions++;
1463 }
1464 } // next cnt
1465 if (f_v) {
1466 cout << "number of distributions reduced from "
1467 << nb_distributions << " to "
1468 << new_nb_distributions << ", i.e. Eliminated "
1469 << nb_distributions - new_nb_distributions << " cases" << endl;
1470 cout << "nb_ruled_out_by_braun = "
1471 << nb_ruled_out_by_braun << endl;
1472 cout << "nb_ruled_out_by_packing = "
1473 << nb_ruled_out_by_packing << endl;
1474 cout << "nb_ruled_out_by_both = "
1475 << nb_ruled_out_by_both << endl;
1476 }
1477 return new_nb_distributions;
1478}
1479#endif
1480
1483 int *point_types, int nb_point_types, int point_type_len,
1484 int *distribution,
1485 int *non_zero_blocks, int nb_non_zero_blocks,
1486 int f_omit1, int omit1,
1487 int verbose_level)
1488{
1489 int f_v = (verbose_level >= 1);
1490 int f_vvv = (verbose_level >= 3);
1491 int set[1000];
1492 int J, L1, L2, len, max, cur, u, D, d, c;
1493 int nb_inc, e, f, nb_ordererd_pairs;
1495
1496 if (f_vvv) {
1497 cout << "geometric_test_for_row_scheme_level_s s=" << s << endl;
1498 }
1499 if (s >= 1000) {
1500 cout << "level too deep" << endl;
1501 exit(1);
1502 }
1503 row_refinement_L1_L2(P, f_omit1, omit1, L1, L2, verbose_level - 3);
1504 Combi.first_k_subset(set, nb_non_zero_blocks, s);
1505 while (TRUE) {
1506 D = 0;
1507 for (u = 0; u < s; u++) {
1508 d = distribution[non_zero_blocks[set[u]]];
1509 D += d;
1510 }
1511 max = D * (D - 1);
1512 cur = 0;
1513 for (J = 0; J < L2; J++) {
1514 len = col_classes_len[COL_SCHEME][J];
1515 nb_inc = 0;
1516 for (u = 0; u < s; u++) {
1517 c = point_types[non_zero_blocks[set[u]] * point_type_len + J];
1518 d = distribution[non_zero_blocks[set[u]]];
1519 // we have d rows with c incidences in len columns
1520 nb_inc += d * c;
1521 }
1522
1523 e = nb_inc % len; // the number of incidences in the extra row
1524 f = nb_inc / len; // the number of full rows
1525
1526 nb_ordererd_pairs = 0;
1527 if (n) {
1528 nb_ordererd_pairs = e * (f + 1) * f + (len - e) * f * (f - 1);
1529 }
1530 cur += nb_ordererd_pairs;
1531 if (cur > max) {
1532 if (f_v) {
1533 cout << "tdo_scheme_synthetic::geometric_test_for_row_scheme_"
1534 "level_s s=" << s << " failure in point type ";
1535 Int_vec_print(cout, set, s);
1536 cout << endl;
1537 cout << "max=" << max << endl;
1538 cout << "J=" << J << endl;
1539 cout << "nb_inc=" << nb_inc << endl;
1540 cout << "nb_ordererd_pairs=" << nb_ordererd_pairs << endl;
1541 cout << "cur=" << cur << endl;
1542 }
1543 return FALSE;
1544 }
1545 } // next J
1546 if (!Combi.next_k_subset(set, nb_non_zero_blocks, s)) {
1547 break;
1548 }
1549 }
1550 return TRUE;
1551}
1552
1553// #############################################################################
1554// parameter refinement: refine rows
1555// #############################################################################
1556
1558 int f_use_mckay, int f_once,
1560 int *&point_types, int &nb_point_types, int &point_type_len,
1561 int *&distributions, int &nb_distributions,
1562 int &cnt_second_system, solution_file_data *Sol,
1563 int f_omit1, int omit1,
1564 int f_omit2, int omit2,
1565 int f_use_packing_numbers,
1566 int f_dual_is_linear_space,
1567 int f_do_the_geometric_test)
1568{
1569 int f_v = (verbose_level >= 1);
1570 int f_vv = (verbose_level >= 2);
1571 //int f_vvv = (verbose_level >= 3);
1572 //int f_easy;
1573 int l1, l2, R;
1574
1575 if (f_v) {
1576 cout << "tdo_scheme_synthetic::refine_rows" << endl;
1577 }
1578 if (f_vv) {
1579 cout << "f_omit1=" << f_omit1 << " omit1=" << omit1 << endl;
1580 cout << "f_omit2=" << f_omit2 << " omit2=" << omit2 << endl;
1581 cout << "f_use_packing_numbers=" << f_use_packing_numbers << endl;
1582 cout << "f_dual_is_linear_space=" << f_dual_is_linear_space << endl;
1583 cout << "f_use_mckay=" << f_use_mckay << endl;
1584 }
1585 if (row_level >= 2) {
1589 if (f_vv) {
1590 cout << "l1=" << l1 << " at level " << level[ROW_SCHEME] << endl;
1591 cout << "l2=" << l2 << " at level " << level[COL_SCHEME] << endl;
1592 cout << "R=" << R << endl;
1593 }
1594 get_column_split_partition(0 /*verbose_level*/, P);
1595 if (f_vv) {
1596 cout << "column split partition: " << endl;
1597 P.print(cout);
1598 cout << endl;
1599 }
1600 if (P.ht != l1) {
1601 cout << "P.ht != l1" << endl;
1602 exit(1);
1603 }
1604 if ((R == 1) && (l1 == 1) && (the_row_scheme[0] == -1)) {
1605 if (!refine_rows_easy(verbose_level - 1,
1606 point_types, nb_point_types, point_type_len,
1607 distributions, nb_distributions, cnt_second_system)) {
1608
1609 if (f_v) {
1610 cout << "tdo_scheme_synthetic::refine_rows refine_rows_easy returns FALSE" << endl;
1611 }
1612
1613 return FALSE;
1614 }
1615 }
1616 else {
1617 if (!refine_rows_hard(P,
1618 verbose_level - 1, f_use_mckay, f_once,
1619 point_types, nb_point_types, point_type_len,
1620 distributions, nb_distributions, cnt_second_system,
1621 f_omit1, omit1, f_omit2, omit2,
1622 f_use_packing_numbers, f_dual_is_linear_space)) {
1623
1624 if (f_v) {
1625 cout << "tdo_scheme_synthetic::refine_rows refine_rows_hard returns FALSE" << endl;
1626 }
1627
1628 return FALSE;
1629 }
1630 }
1631 }
1632 else {
1633 if (!refine_rows_easy(verbose_level - 1,
1634 point_types, nb_point_types, point_type_len,
1635 distributions, nb_distributions, cnt_second_system)) {
1636
1637 if (f_v) {
1638 cout << "tdo_scheme_synthetic::refine_rows refine_rows_easy returns FALSE" << endl;
1639 }
1640 return FALSE;
1641 }
1642 }
1643
1644 if (f_do_the_geometric_test) {
1645 if (f_v) {
1646 cout << "tdo_scheme_synthetic::refine_rows before geometric_test_for_row_scheme" << endl;
1647 }
1648 nb_distributions = geometric_test_for_row_scheme(P,
1649 point_types, nb_point_types, point_type_len,
1650 distributions, nb_distributions,
1651 f_omit1, omit1,
1652 verbose_level);
1653 if (f_v) {
1654 cout << "tdo_scheme_synthetic::refine_rows after geometric_test_for_row_scheme" << endl;
1655 }
1656 }
1657 if (f_v) {
1658 cout << "tdo_scheme_synthetic::refine_rows done" << endl;
1659 }
1660 return TRUE;
1661}
1662
1664 int *&point_types, int &nb_point_types, int &point_type_len,
1665 int *&distributions, int &nb_distributions,
1666 int &cnt_second_system)
1667{
1668 int nb_rows;
1669 int i, j, J, S, l2, nb_eqns, nb_vars;
1670 int nb_eqns_joining, nb_eqns_upper_bound;
1671 int nb_sol, len, k, a2, a, b, ab;
1672 int f_used, j1, j2, len1, len2, cnt;
1673 int Nb_eqns, Nb_vars;
1674 int f_v = (verbose_level >= 1);
1675 int f_vv = (verbose_level >= 2);
1676 char label[100];
1679
1680 if (f_v) {
1681 cout << "tdo_scheme_synthetic::refine_rows_easy" << endl;
1682 }
1684
1685 //partitionstack &P = PB.P;
1686 nb_rows = P->startCell[1];
1687 S = nb_rows - 1;
1688 if (f_v) {
1689 cout << "nb_rows=" << nb_rows << endl;
1690 }
1691
1692 nb_vars = l2 + 1; // 1 slack variable
1693 nb_eqns = 1;
1694
1696
1697 D.open(nb_eqns, nb_vars);
1698
1699 // 1st equation: connections within the same row-partition
1700 for (J = 0; J < nb_vars; J++) {
1701 D.Aij(0, J) = Combi.minus_one_if_positive(the_col_scheme[0 * l2 + J]);
1702 }
1703 D.Aij(0, nb_vars - 1) = 0;
1704 if (f_vv) {
1705 cout << "nb_rows=" << nb_rows << endl;
1706 }
1707 D.RHS[0] = nb_rows - 1;
1708 if (f_vv) {
1709 cout << "RHS[0]=" << D.RHS[0] << endl;
1710 }
1711
1712 for (j = 0; j < l2; j++) {
1713 D.x_min[j] = 0;
1714 D.x_max[j] = col_classes_len[COL_SCHEME][j];
1715 }
1716 D.x_min[nb_vars - 1] = 0;
1717 D.x_max[nb_vars - 1] = nb_rows - 1;
1718
1719 //D.f_x_max = TRUE;
1720
1721
1722 D.eliminate_zero_rows_quick(verbose_level);
1723 D.sum = S;
1724 if (f_vv) {
1725 cout << "tdo_scheme_synthetic::refine_rows_easy The first system is" << endl;
1726 D.print();
1727 }
1728 if (f_vv) {
1729 char label[1000];
1730
1731 snprintf(label, 1000, "first");
1732 D.write_xml(cout, label);
1733 }
1734
1735 nb_sol = 0;
1736 point_type_len = nb_vars - 1;
1737
1738 if (D.solve_first(verbose_level - 2)) {
1739
1740 while (TRUE) {
1741 if (f_vv) {
1742 cout << nb_sol << " : ";
1743 for (i = 0; i < nb_vars; i++) {
1744 cout << " " << D.x[i];
1745 }
1746 cout << endl;
1747 }
1748 nb_sol++;
1749 if (!D.solve_next()) {
1750 break;
1751 }
1752 }
1753 }
1754 if (f_v) {
1755 cout << "tdo_scheme_synthetic::refine_rows_easy found " << nb_sol << " point types" << endl;
1756 }
1757 if (nb_sol == 0) {
1758 return FALSE;
1759 }
1760 nb_point_types = nb_sol;
1761
1762 nb_eqns_upper_bound = 0;
1763 for (j = 0; j < l2; j++) {
1764 len = col_classes_len[COL_SCHEME][j];
1765 if (len > 2) {
1766 nb_eqns_upper_bound += len - 2;
1767 }
1768 }
1769 nb_eqns_joining = l2 + ((l2 * (l2 - 1)) >> 1);
1770 Nb_eqns = l2 + nb_eqns_joining + nb_eqns_upper_bound;
1771 Nb_vars = nb_sol;
1772
1774
1775 D2.open(Nb_eqns, Nb_vars);
1776 point_types = NEW_int(nb_point_types * point_type_len);
1777 if (f_v) {
1778 cout << "tdo_scheme_synthetic::refine_rows_easy: opening second "
1779 << cnt_second_system << " system with "
1780 << Nb_eqns << " equations and " << Nb_vars
1781 << " variables" << endl;
1782 }
1783
1784 nb_sol = 0;
1785 if (D.solve_first(verbose_level - 2)) {
1786
1787 while (TRUE) {
1788 if (f_vv) {
1789 cout << nb_sol << " : ";
1790 for (i = 0; i < nb_vars; i++) {
1791 cout << " " << D.x[i];
1792 }
1793 cout << endl;
1794 }
1795 for (i = 0; i < point_type_len; i++) {
1796 D2.Aij(i, nb_sol) = D.x[i];
1797 point_types[nb_sol * point_type_len + i] = D.x[i];
1798 }
1799 nb_sol++;
1800 if (!D.solve_next()) {
1801 break;
1802 }
1803 }
1804 }
1805 for (j = 0; j < l2; j++) {
1806 len = col_classes_len[COL_SCHEME][j];
1807 for (i = 0; i < Nb_vars; i++) {
1808 a = point_types[i * point_type_len + j];
1809 a2 = Combi.binomial2(a);
1810 D2.Aij(l2 + j, i) = a2;
1811 }
1812 D2.RHS[l2 + j] = Combi.binomial2(len);
1813 D2.type[l2 + j] = t_LE;
1814 snprintf(label, 1000, "J_{%d}", j + 1);
1815 D2.init_eqn_label(l2 + j, label);
1816 }
1817 cnt = 0;
1818 for (j1 = 0; j1 < l2; j1++) {
1819 len1 = col_classes_len[COL_SCHEME][j1];
1820 for (j2 = j1 + 1; j2 < l2; j2++) {
1821 len2 = col_classes_len[COL_SCHEME][j2];
1822 for (i = 0; i < Nb_vars; i++) {
1823 a = point_types[i * point_type_len + j1];
1824 b = point_types[i * point_type_len + j2];
1825 ab = a * b;
1826 D2.Aij(l2 + l2 + cnt, i) = ab;
1827 }
1828 D2.RHS[l2 + l2 + cnt] = len1 * len2;
1829 D2.type[l2 + l2 + cnt] = t_LE;
1830 snprintf(label, 1000, "J_{%d,%d}", j1 + 1, j2 + 1);
1831 D2.init_eqn_label(l2 + l2 + cnt, label);
1832 cnt++;
1833 }
1834 }
1835
1836 nb_eqns_upper_bound = 0;
1837 for (j = 0; j < l2; j++) {
1838 len = col_classes_len[COL_SCHEME][j];
1839 for (k = 3; k <= len; k++) {
1840 for (i = 0; i < Nb_vars; i++) {
1841 D2.Aij(l2 + nb_eqns_joining + nb_eqns_upper_bound, i) = 0;
1842 }
1843 f_used = FALSE;
1844 for (i = 0; i < Nb_vars; i++) {
1845 a = point_types[i * point_type_len + j];
1846 if (a < k) {
1847 continue;
1848 }
1849 D2.Aij(l2 + nb_eqns_joining + nb_eqns_upper_bound, i) = 1;
1850 f_used = TRUE;
1851 }
1852 if (f_used) {
1853 int bound = Gg.TDO_upper_bound(len, k);
1854 D2.RHS[l2 + nb_eqns_joining + nb_eqns_upper_bound] = bound;
1855 D2.type[l2 + nb_eqns_joining + nb_eqns_upper_bound] = t_LE;
1856 snprintf(label, 1000, "P_{%d,%d} \\,\\mbox{using}\\, "
1857 "P(%d,%d)=%d", j + 1, k, len, k, bound);
1858 D2.init_eqn_label(l2 +
1859 nb_eqns_joining + nb_eqns_upper_bound, label);
1860 nb_eqns_upper_bound++;
1861 }
1862 } // next k
1863 } // next j
1864 Nb_eqns = l2 + nb_eqns_joining + nb_eqns_upper_bound;
1865 D2.m = Nb_eqns;
1866
1867 if (f_v) {
1868 cout << "tdo_scheme_synthetic::refine_rows_easy second system " << cnt_second_system << " found "
1869 << nb_sol << " point types" << endl;
1870 }
1871 cnt_second_system++;
1872 if (nb_sol == 0) {
1873 FREE_int(point_types);
1874 return FALSE;
1875 }
1876 D2.sum = nb_rows;
1877 for (i = 0; i < l2; i++) {
1879 snprintf(label, 1000, "F_{%d}", i + 1);
1880 D2.init_eqn_label(i, label);
1881 }
1882 D2.eliminate_zero_rows_quick(verbose_level);
1883 if (f_vv) {
1884 cout << "The second system is" << endl;
1885 D2.print();
1886 }
1887 if (f_vv) {
1888 char label[1000];
1889
1890 snprintf(label, 1000, "second");
1891 D2.write_xml(cout, label);
1892 }
1893 nb_sol = 0;
1894 if (D2.solve_first(verbose_level - 2)) {
1895 while (TRUE) {
1896 if (f_vv) {
1897 cout << nb_sol << " : ";
1898 for (i = 0; i < Nb_vars; i++) {
1899 cout << " " << D2.x[i];
1900 }
1901 cout << endl;
1902 }
1903 nb_sol++;
1904 if (!D2.solve_next()) {
1905 break;
1906 }
1907 }
1908 }
1909 nb_distributions = nb_sol;
1910 distributions = NEW_int(nb_distributions * nb_point_types);
1911 nb_sol = 0;
1912 if (D2.solve_first(verbose_level - 2)) {
1913 while (TRUE) {
1914 if (f_vv) {
1915 cout << nb_sol << " : ";
1916 for (i = 0; i < Nb_vars; i++) {
1917 cout << " " << D2.x[i];
1918 }
1919 cout << endl;
1920 }
1921 for (i = 0; i < Nb_vars; i++) {
1922 distributions[nb_sol * nb_point_types + i] = D2.x[i];
1923 }
1924 nb_sol++;
1925 if (!D2.solve_next()) {
1926 break;
1927 }
1928 }
1929 }
1930 if (f_v) {
1931 cout << "tdo_scheme_synthetic::refine_rows_easy: found " << nb_distributions
1932 << " point type distributions." << endl;
1933 }
1934 return TRUE;
1935}
1936
1938 data_structures::partitionstack &P, int verbose_level,
1939 int f_use_mckay, int f_once,
1940 int *&point_types, int &nb_point_types, int &point_type_len,
1941 int *&distributions, int &nb_distributions,
1942 int &cnt_second_system,
1943 int f_omit1, int omit1, int f_omit, int omit,
1944 int f_use_packing_numbers, int f_dual_is_linear_space)
1945{
1946 int f_v = (verbose_level >= 1);
1947 int f_vv = (verbose_level >= 2);
1948 int i, r, R, l1, /*l2,*/ L1, L2;
1949 int nb_sol;
1950 int point_types_allocated;
1951 int h, u;
1952 tdo_data T;
1953
1954 if (f_v) {
1955 cout << "tdo_scheme_synthetic::refine_rows_hard" << endl;
1956 }
1957 if (f_vv) {
1958 if (f_omit1) {
1959 cout << "omitting the last " << omit1
1960 << " column blocks from the previous row-scheme" << endl;
1961 }
1962 if (f_omit) {
1963 cout << "omitting the last " << omit << " row blocks" << endl;
1964 }
1965 cout << "f_use_packing_numbers=" << f_use_packing_numbers << endl;
1966 cout << "f_dual_is_linear_space=" << f_dual_is_linear_space << endl;
1967 cout << "f_use_mckay=" << f_use_mckay << endl;
1968 }
1971 //l2 = nb_col_classes[COL];
1972
1973 if (f_vv) {
1974 cout << "tdo_scheme::refine_rows_hard the_row_scheme is:" << endl;
1975 int i, j;
1976 for (i = 0; i < R; i++) {
1977 for (j = 0; j < l1; j++) {
1978 cout << setw(4) << the_row_scheme[i * l1 + j];
1979 }
1980 cout << endl;
1981 }
1982 }
1983
1984 row_refinement_L1_L2(P, f_omit1, omit1, L1, L2, verbose_level);
1985
1986 T.allocate(R);
1987
1988 T.types_first[0] = 0;
1989
1990 point_types_allocated = 100;
1991 nb_point_types = 0;
1992 point_type_len = L2 + L1; // + slack variables
1993 point_types = NEW_int(point_types_allocated * point_type_len);
1994 // detected and corrected an error: Dec 6 2010
1995 // it was allocated to point_types_allocated * L2
1996 // which is not enough
1997
1998 // when we are done, it is [point_types_allocated * L2]
1999
2000
2001 T.nb_only_one_type = 0;
2002 T.nb_multiple_types = 0;
2003
2004
2005 if (f_v) {
2006 cout << "tdo_scheme_synthetic::refine_rows_hard computing refined point types:" << endl;
2007 cout << "point_type_len = " << point_type_len << endl;
2008 cout << "L1 = " << L1 << endl;
2009 cout << "L2 = " << L2 << endl;
2010 }
2011
2012
2013 for (r = 0; r < R; r++) {
2014
2015 if (f_v) {
2016 cout << "tdo_scheme_synthetic::refine_rows_hard r=" << r << endl;
2017 cout << "T.types_first[r]=" << T.types_first[r] << endl;
2018 }
2019
2020 tdo_rows_setup_first_system(verbose_level,
2021 T, r, P,
2022 f_omit1, omit1,
2023 point_types, nb_point_types);
2024
2025 if (f_vv) {
2026 char label[1000];
2027
2028 snprintf(label, 1000, "first_%d", r);
2029 T.D1->write_xml(cout, label);
2030 }
2031 nb_sol = T.solve_first_system(verbose_level - 1,
2032 point_types, nb_point_types, point_types_allocated);
2033
2034 if (f_v) {
2035 cout << "tdo_scheme_synthetic::refine_rows_hard r = " << r << ", found " << nb_sol
2036 << " refined point types" << endl;
2037 }
2038 if (f_vv) {
2039 cout << "tdo_scheme_synthetic::refine_rows_hard r = " << r << ", found " << nb_sol
2040 << " refined point types:" << endl;
2042 point_types + T.types_first[r] * point_type_len,
2043 nb_sol, point_type_len, point_type_len, 3);
2044 }
2045
2046#if 0
2047 // MARUTA Begin
2048 if (r == 1) {
2049 int h, a;
2050
2051 for (h = nb_sol - 1; h >= 0; h--) {
2052 a = (point_types + (T.types_first[r] + h)
2053 * point_type_len)[0];
2054 if (a == 0) {
2055 cout << "removing last solution" << endl;
2056 nb_sol--;
2057 nb_point_types--;
2058 }
2059 }
2060 }
2061 // MARUTA End
2062#endif
2063
2064
2065 if (f_vv) {
2066 cout << "tdo_scheme_synthetic::refine_rows_hard r = " << r << ", found " << nb_sol
2067 << " refined point types:" << endl;
2069 point_types + T.types_first[r] * point_type_len,
2070 nb_sol, point_type_len, point_type_len, 3);
2071 }
2072 if (nb_sol == 0) {
2073 FREE_int(point_types);
2074 if (f_v) {
2075 cout << "tdo_scheme_synthetic::refine_rows_hard no solution for this point type, we are done" << endl;
2076 }
2077 return FALSE;
2078 }
2079
2080 T.types_len[r] = nb_sol;
2081 T.types_first[r + 1] = T.types_first[r] + nb_sol;
2082
2083 if (nb_sol == 1) {
2084 if (f_v) {
2085 cout << "tdo_scheme_synthetic::refine_rows_hard only one solution in block r=" << r << endl;
2086 }
2088 }
2089 else {
2091 }
2092
2093 T.D1->freeself();
2094 //diophant_close(T.D1);
2095 //T.D1 = NULL;
2096
2097 } // next r
2098
2099 if (f_v) {
2100 cout << "tdo_scheme_synthetic::refine_rows_hard computing refined point types done" << endl;
2101 }
2102
2103 // eliminate the slack variables from point_types:
2104 for (r = 0; r < nb_point_types; r++) {
2105 int f, l, a, j, J;
2106
2107 for (i = 0; i < L1; i++) {
2108 f = P.startCell[i];
2109 l = P.cellSize[i];
2110 for (j = 0; j < l; j++) {
2111 J = f + i + j;
2112 a = point_types[r * point_type_len + J];
2113 point_types[r * L2 + f + j] = a;
2114 }
2115 }
2116 }
2117 point_type_len = L2;
2118 if (f_v) {
2119 cout << "tdo_scheme_synthetic::refine_rows_hard altogether, we found " << nb_point_types
2120 << " refined point types" << endl;
2121 }
2122 if (f_vv) {
2123 cout << "tdo_scheme_synthetic::refine_rows_hard altogether, we found " << nb_point_types
2124 << " refined point types:" << endl;
2125 Int_vec_print_integer_matrix_width(cout, point_types,
2126 nb_point_types, point_type_len, point_type_len, 3);
2127 }
2128
2129
2130 // now we compute the distributions:
2131
2132 if (f_v) {
2133 cout << "tdo_scheme_synthetic::refine_rows_hard before tdo_rows_setup_second_system" << endl;
2134 }
2135
2137 verbose_level,
2138 T, P,
2139 f_omit1, omit1,
2140 f_use_packing_numbers,
2141 f_dual_is_linear_space,
2142 point_types, nb_point_types)) {
2143
2144 if (f_v) {
2145 cout << "tdo_scheme_synthetic::refine_rows_hard tdo_rows_setup_second_system returns FALSE, we are done" << endl;
2146 }
2147
2148 FREE_int(point_types);
2149 return FALSE;
2150 }
2151 if (f_v) {
2152 cout << "tdo_scheme_synthetic::refine_rows_hard after tdo_rows_setup_second_system" << endl;
2153 }
2154 if (f_vv) {
2155 char label[1000];
2156
2157 snprintf(label, 1000, "second");
2158 T.D2->write_xml(cout, label);
2159 }
2160
2161
2162 if (T.D2->n == 0) {
2163 distributions = NEW_int(1 * nb_point_types);
2164 nb_distributions = 0;
2165 for (h = 0; h < T.nb_only_one_type; h++) {
2166 r = T.only_one_type[h];
2167 u = T.types_first[r];
2168 //cout << "only one type, r=" << r << " u=" << u
2169 //<< " row_classes_len[ROW][r]="
2170 //<< row_classes_len[ROW][r] << endl;
2171 distributions[nb_distributions * nb_point_types + u] =
2173 }
2174 nb_distributions++;
2175 if (f_v) {
2176 cout << "tdo_scheme_synthetic::refine_rows_hard done" << endl;
2177 }
2178 return TRUE;
2179 }
2180
2181
2182#if 0
2183 if (cnt_second_system == 1) {
2184 int j;
2185 int x[] = {4,1,5,0,2,0,7,2,4,0,0,0,1,0,0,4,0,0};
2186 cout << "testing solution:" << endl;
2187 int_vec_print(cout, x, 18);
2188 cout << endl;
2189 if (T.D2->n != 18) {
2190 cout << "T.D2->n != 18" << endl;
2191 }
2192 for (j = 0; j < 18; j++) {
2193 T.D2->x[j] = x[j];
2194 }
2196 for (i = 0; i < T.D2->m; i++) {
2197 cout << i << " : " << T.D2->RHS1[i] << " : "
2198 << T.D2->RHS[i] - T.D2->RHS1[i] << endl;
2199 }
2200 }
2201#endif
2202
2203 if (f_v) {
2204 cout << "tdo_scheme_synthetic::refine_rows_hard: solving second system "
2205 << cnt_second_system << " which is " << T.D2->m
2206 << " x " << T.D2->n << endl;
2207 cout << T.nb_multiple_types << " variable blocks:" << endl;
2208 int f, l;
2209 for (i = 0; i < T.nb_multiple_types; i++) {
2210 r = T.multiple_types[i];
2211 f = T.types_first2[i];
2212 l = T.types_len[r];
2213 cout << i << " : " << r << " : " << setw(3)
2214 << row_classes_len[ROW_SCHEME][r] << " : " << setw(3) << f
2215 << " : " << setw(3) << l << endl;
2216 }
2217 }
2218 if (f_omit) {
2219 if (f_v) {
2220 cout << "tdo_scheme_synthetic::refine_rows_hard before T.solve_second_system_omit" << endl;
2221 }
2222 T.solve_second_system_omit(verbose_level - 1,
2224 point_types, nb_point_types,
2225 distributions, nb_distributions, omit);
2226 }
2227 else {
2228 int f_scale = FALSE;
2229 int scaling = 0;
2230 if (f_v) {
2231 cout << "tdo_scheme_synthetic::refine_rows_hard before T.solve_second_system" << endl;
2232 }
2233 T.solve_second_system(verbose_level - 1,
2234 f_use_mckay, f_once,
2235 row_classes_len[ROW_SCHEME], f_scale, scaling,
2236 point_types, nb_point_types,
2237 distributions, nb_distributions);
2238 }
2239
2240
2241
2242 if (f_v) {
2243 cout << "tdo_scheme_synthetic::refine_rows_hard: second system "
2244 << cnt_second_system
2245 << " found " << nb_distributions
2246 << " distributions." << endl;
2247 }
2248 cnt_second_system++;
2249 if (f_v) {
2250 cout << "tdo_scheme_synthetic::refine_rows_hard done" << endl;
2251 }
2252 return TRUE;
2253}
2254
2256 int f_omit, int omit,
2257 int &L1, int &L2, int verbose_level)
2258{
2259 int f_v = (verbose_level >= 1);
2260 int l1, l2, omit2, i;
2263
2264 omit2 = 0;
2265 if (f_omit) {
2266 for (i = l1 - omit; i < l1; i++) {
2267 omit2 += P.cellSize[i];
2268 }
2269 }
2270 else {
2271 omit = 0;
2272 }
2273 L1 = l1 - omit;
2274 L2 = l2 - omit2;
2275 if (f_v) {
2276 cout << "tdo_scheme_synthetic::row_refinement_L1_L2: l1 = " << l1 << " l2=" << l2
2277 << " L1=" << L1 << " L2=" << L2 << endl;
2278 }
2279}
2280
2283 int f_omit, int omit,
2284 int *&point_types, int &nb_point_types)
2285{
2286 int f_v = (verbose_level >= 1);
2287 int f_vv = (verbose_level >= 2);
2288 int S, s_default, s_or_s_default, R, l1, l2, L1, L2;
2289 int J, r2, i, j, s, f, l;
2290 int nb_vars, nb_eqns;
2292
2293 if (f_v) {
2294 cout << "tdo_rows_setup_first_system r=" << r << endl;
2295 }
2296
2297 if (!f_omit) {
2298 omit = 0;
2299 }
2300
2301 if (f_v) {
2302 if (f_omit) {
2303 cout << "omit=" << omit << endl;
2304 }
2305 }
2309
2310 row_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
2311
2312 nb_vars = L2 + L1; // possible up to L1 slack variables
2313 nb_eqns = R + L1;
2314 if (f_v) {
2315 cout << "tdo_rows_setup_first_system L1=" << L1 << endl;
2316 cout << "tdo_rows_setup_first_system L2=" << L2 << endl;
2317 }
2318
2319 T.D1->open(nb_eqns, nb_vars);
2321 S = 0;
2322
2323 for (r2 = 0; r2 < R; r2++) {
2324
2325 if (r2 == r) {
2326 // connections within the same row-partition
2327 for (i = 0; i < L1; i++) {
2328 f = P.startCell[i];
2329 l = P.cellSize[i];
2330 for (j = 0; j < l; j++) {
2331 J = f + i + j; // +i for the slack variables
2332 T.D1->Aij(r2, J) =
2334 the_col_scheme[r2 * l2 + f + j]);
2335 }
2336 T.D1->Aij(r2, f + i + l) = 0;
2337 // the slack variable is not needed
2338 }
2339#if 0
2340 for (J = 0; J < nb_vars; J++) {
2341 T.D1->Aij(r2, J) =
2342 minus_one_if_positive(the_col_scheme[r2 * l2 + J]);
2343 }
2344#endif
2345 T.D1->RHS[r] = row_classes_len[ROW_SCHEME][r] - 1;
2346 if (f_omit) {
2347 T.D1->type[r] = t_LE;
2348 }
2349 }
2350 else {
2351 // connections to the point from different row-partitions
2352 for (i = 0; i < L1; i++) {
2353 f = P.startCell[i];
2354 l = P.cellSize[i];
2355 for (j = 0; j < l; j++) {
2356 J = f + i + j; // +i for the slack variables
2357 T.D1->Aij(r2, J) = the_col_scheme[r2 * l2 + f + j];
2358 }
2359 T.D1->Aij(r2, f + i + l) = 0;
2360 // the slack variable is not needed
2361 }
2362#if 0
2363 for (J = 0; J < nb_vars; J++) {
2364 T.D1->Aij(r2, J) = the_col_scheme[r2 * l2 + J];
2365 }
2366#endif
2367 T.D1->RHS[r2] = row_classes_len[ROW_SCHEME][r2];
2368 if (f_omit) {
2369 T.D1->type[r2] = t_LE;
2370 }
2371 }
2372 }
2373
2374 for (i = 0; i < L1; i++) {
2375 s = the_row_scheme[r * l1 + i];
2376 if (FALSE) {
2377 cout << "r=" << r << " i=" << i << " s=" << s << endl;
2378 }
2379 if (s == -1) {
2380 cout << "row scheme entry " << r << "," << i
2381 << " is -1, using slack variable" << endl;
2382 cout << "using " << col_classes_len[ROW_SCHEME][i]
2383 << " as upper bound" << endl;
2384 s_default = col_classes_len[ROW_SCHEME][i];
2385 s_or_s_default = s_default;
2386 }
2387 else {
2388 s_default = 0; // not needed but compiler likes it
2389 s_or_s_default = s;
2390 }
2391
2392 T.D1->RHS[R + i] = s_or_s_default;
2393 S += s_or_s_default;
2394
2395 f = P.startCell[i];
2396 l = P.cellSize[i];
2397 if (FALSE) {
2398 cout << "f=" << f << " l=" << l << endl;
2399 }
2400
2401 for (j = 0; j < l; j++) {
2402 J = f + i + j; // +i for the slack variables
2403 T.D1->Aij(R + i, J) = 1;
2404 T.D1->x_min[J] = 0;
2405 T.D1->x_max[J] = MINIMUM(col_classes_len[COL_SCHEME][f + j],
2406 s_or_s_default);
2407 }
2408 T.D1->Aij(R + i, f + i + l) = 1; // the slack variable
2409 if (s == -1) {
2410 T.D1->x_max[f + i + l] = s_default;
2411 }
2412 else {
2413 T.D1->x_max[f + i + l] = 0;
2414 }
2415 T.D1->x_min[f + i + l] = 0;
2416 }
2417 T.D1->f_has_sum = TRUE;
2418 T.D1->sum = S;
2419 //T.D1->f_x_max = TRUE;
2420
2421 T.D1->eliminate_zero_rows_quick(verbose_level);
2422
2423 if (f_vv) {
2424 cout << "The first system for r=" << r << " is:" << endl;
2425 T.D1->print();
2426 }
2427 if (f_v) {
2428 cout << "tdo_rows_setup_first_system r=" << r << " finished" << endl;
2429 }
2430 return TRUE;
2431
2432}
2433
2436 int f_omit, int omit,
2437 int f_use_packing_numbers,
2438 int f_dual_is_linear_space,
2439 int *&point_types, int &nb_point_types)
2440{
2441 int f_v = (verbose_level >= 1);
2442 int f_vv = (verbose_level >= 2);
2443 int nb_eqns_joining, nb_eqns_counting, nb_eqns_packing, nb_eqns_used = 0;
2444 int Nb_vars, Nb_eqns;
2445 int l2, i, j, len, r, L1, L2;
2447
2448 if (f_v) {
2449 cout << "tdo_rows_setup_second_system" << endl;
2450 }
2451 if (f_vv) {
2452 cout << "f_omit=" << f_omit << " omit=" << omit << endl;
2453 cout << "f_use_packing_numbers=" << f_use_packing_numbers << endl;
2454 cout << "f_dual_is_linear_space=" << f_dual_is_linear_space << endl;
2455 }
2456
2458
2459 row_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
2460
2461 nb_eqns_joining = L2 + Combi.binomial2(L2);
2462 nb_eqns_counting = T.nb_multiple_types * (L2 + 1);
2463 nb_eqns_packing = 0;
2464 if (f_use_packing_numbers) {
2465 for (j = 0; j < L2; j++) {
2466 len = col_classes_len[COL_SCHEME][j];
2467 if (len > 2) {
2468 nb_eqns_packing += len - 2;
2469 }
2470 }
2471 }
2472
2473 Nb_eqns = nb_eqns_joining + nb_eqns_counting + nb_eqns_packing;
2474 Nb_vars = 0;
2475 for (i = 0; i < T.nb_multiple_types; i++) {
2476 r = T.multiple_types[i];
2477 T.types_first2[i] = Nb_vars;
2478 Nb_vars += T.types_len[r];
2479 }
2480
2481
2482 T.D2->open(Nb_eqns, Nb_vars);
2484
2485#if 0
2486 if (Nb_vars == 0) {
2487 return TRUE;
2488 }
2489#endif
2490
2491 if (f_v) {
2492 cout << "tdo_rows_setup_second_system: opening second system with "
2493 << Nb_eqns << " equations and " << Nb_vars
2494 << " variables" << endl;
2495 cout << "nb_eqns_joining=" << nb_eqns_joining << endl;
2496 cout << "nb_eqns_counting=" << nb_eqns_counting << endl;
2497 cout << "nb_eqns_packing=" << nb_eqns_packing << endl;
2498 cout << "l2=" << l2 << endl;
2499 cout << "L2=" << L2 << endl;
2500 cout << "T.nb_multiple_types=" << T.nb_multiple_types << endl;
2501 }
2502
2504 T, P,
2505 f_omit, omit, f_dual_is_linear_space,
2506 point_types, nb_point_types,
2507 0 /*eqn_offset*/)) {
2508
2509 if (f_v) {
2510 cout << "tdo_rows_setup_second_system_eqns_joining returns FALSE" << endl;
2511 }
2512 if (f_vv) {
2513 T.D2->print();
2514 }
2515 return FALSE;
2516 }
2517
2519 T, P,
2520 f_omit, omit,
2521 point_types, nb_point_types,
2522 nb_eqns_joining /*eqn_offset*/)) {
2523
2524 if (f_v) {
2525 cout << "tdo_rows_setup_second_system_eqns_counting returns FALSE" << endl;
2526 }
2527 if (f_vv) {
2528 T.D2->print();
2529 }
2530 return FALSE;
2531 }
2532 if (f_use_packing_numbers) {
2534 T, P,
2535 f_omit, omit,
2536 point_types, nb_point_types,
2537 nb_eqns_joining + nb_eqns_counting /* eqn_start */,
2538 nb_eqns_used)) {
2539
2540 if (f_v) {
2541 cout << "tdo_rows_setup_second_system_eqns_packing returns FALSE" << endl;
2542 }
2543 if (f_vv) {
2544 T.D2->print();
2545 }
2546 return FALSE;
2547 }
2548 }
2549 Nb_eqns = nb_eqns_joining + nb_eqns_counting + nb_eqns_used;
2550 T.D2->m = Nb_eqns;
2551
2552 T.D2->eliminate_zero_rows_quick(verbose_level);
2553
2554
2555
2556 if (f_vv) {
2557 cout << "The second system is:" << endl;
2558 T.D2->print();
2559 }
2560 if (f_v) {
2561 cout << "tdo_rows_setup_second_system done" << endl;
2562 }
2563 return TRUE;
2564}
2565
2567 int verbose_level,
2569 int f_omit, int omit, int f_dual_is_linear_space,
2570 int *point_types, int nb_point_types,
2571 int eqn_offset)
2572{
2573 int f_v = (verbose_level >= 1);
2574 int f_vv = (verbose_level >= 2);
2575 int l2, I1, I2, k, b, ab, i, j, r, I, J;
2576 int f, l, c, a, a2, rr, p, u, h, L1, L2;
2577 char label[1000];
2579
2580 if (f_v) {
2581 cout << "tdo_scheme::tdo_rows_setup_second_system_eqns_joining" << endl;
2582 }
2584 row_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
2585
2586 if (f_vv) {
2587 cout << "l2 = " << l2 << endl;
2588 cout << "L2 = " << L2 << endl;
2589 cout << "eqn_offset = " << eqn_offset << endl;
2590 cout << "T.nb_multiple_types = " << T.nb_multiple_types << endl;
2591 }
2592
2593 for (I = 0; I < L2; I++) {
2594 snprintf(label, 1000, "J_{%d}", I + 1);
2595 T.D2->init_eqn_label(eqn_offset + I, label);
2596 }
2597 for (I1 = 0; I1 < L2; I1++) {
2598 for (I2 = I1 + 1; I2 < L2; I2++) {
2599 k = Combi.ij2k(I1, I2, L2);
2600 snprintf(label, 1000, "J_{%d,%d}", I1 + 1, I2 + 1);
2601 T.D2->init_eqn_label(eqn_offset + L2 + k, label);
2602 }
2603 }
2604 if (f_vv) {
2605 cout << "filling coefficient matrix" << endl;
2606 }
2607 for (i = 0; i < T.nb_multiple_types; i++) {
2608 r = T.multiple_types[i];
2609 f = T.types_first[r];
2610 l = T.types_len[r];
2611 for (j = 0; j < l; j++) {
2612 c = f + j;
2613 J = T.types_first2[i] + j;
2614 for (I = 0; I < L2; I++) {
2615 a = point_types[c * L2 + I];
2616 a2 = Combi.binomial2(a);
2617 T.D2->Aij(eqn_offset + I, J) = a2;
2618 }
2619 for (I1 = 0; I1 < L2; I1++) {
2620 for (I2 = I1 + 1; I2 < L2; I2++) {
2621 k = Combi.ij2k(I1, I2, L2);
2622 a = point_types[c * L2 + I1];
2623 b = point_types[c * L2 + I2];
2624 ab = a * b;
2625 T.D2->Aij(eqn_offset + L2 + k, J) = ab;
2626 }
2627 }
2628 }
2629 }
2630
2631 if (f_vv) {
2632 cout << "filling RHS" << endl;
2633 }
2634 for (I = 0; I < L2; I++) {
2636 a2 = Combi.binomial2(a);
2637 T.D2->RHS[eqn_offset + I] = a2;
2638 if (f_dual_is_linear_space) {
2639 T.D2->type[eqn_offset + I] = t_EQ;
2640 }
2641 else {
2642 T.D2->type[eqn_offset + I] = t_LE;
2643 }
2644 }
2645 for (I1 = 0; I1 < L2; I1++) {
2646 a = col_classes_len[COL_SCHEME][I1];
2647 for (I2 = I1 + 1; I2 < L2; I2++) {
2648 b = col_classes_len[COL_SCHEME][I2];
2649 k = Combi.ij2k(I1, I2, L2);
2650 T.D2->RHS[eqn_offset + L2 + k] = a * b;
2651 if (f_dual_is_linear_space) {
2652 T.D2->type[eqn_offset + L2 + k] = t_EQ;
2653 }
2654 else {
2655 T.D2->type[eqn_offset + L2 + k] = t_LE;
2656 }
2657 }
2658 }
2659 if (f_vv) {
2660 cout << "subtracting contribution from one-type blocks:" << endl;
2661 }
2662 // now subtract the contribution from one-type blocks:
2663 for (h = 0; h < T.nb_only_one_type; h++) {
2664 rr = T.only_one_type[h];
2665 p = row_classes_len[ROW_SCHEME][rr];
2666 u = T.types_first[rr];
2667 for (I = 0; I < L2; I++) {
2668 a = point_types[u * L2 + I];
2669 a2 = Combi.binomial2(a);
2670 T.D2->RHS[eqn_offset + I] -= a2 * p;
2671 if (T.D2->RHS[eqn_offset + I] < 0) {
2672 if (f_vv) {
2673 cout << "tdo_rows_setup_second_system_eqns_joining: "
2674 "RHS is negative, no solution for the "
2675 "distribution" << endl;
2676 cout << "h=" << h << endl;
2677 cout << "rr=T.only_one_type[h]=" << rr << endl;
2678 cout << "p=row_classes_len[ROW][rr]=" << p << endl;
2679 cout << "u=T.types_first[rr]="
2680 << T.types_first[rr] << endl;
2681 cout << "I=" << I << endl;
2682 cout << "a=point_types[u * L2 + I]=" << a << endl;
2683 cout << "a2=binomial2(a)=" << a2 << endl;
2684 cout << "T.D2->RHS[eqn_offset + I]="
2685 << T.D2->RHS[eqn_offset + I] << endl;
2686 }
2687 return FALSE;
2688 }
2689 }
2690 for (I1 = 0; I1 < L2; I1++) {
2691 a = point_types[u * L2 + I1];
2692 for (I2 = I1 + 1; I2 < L2; I2++) {
2693 b = point_types[u * L2 + I2];
2694 k = Combi.ij2k(I1, I2, L2);
2695 ab = a * b * p;
2696 T.D2->RHS[eqn_offset + L2 + k] -= ab;
2697 if (T.D2->RHS[eqn_offset + L2 + k] < 0) {
2698 if (f_vv) {
2699 cout << "tdo_rows_setup_second_system_eqns_"
2700 "joining: RHS is negative, no solution "
2701 "for the distribution" << endl;
2702 cout << "h=" << h << endl;
2703 cout << "rr=T.only_one_type[h]=" << rr << endl;
2704 cout << "p=row_classes_len[ROW][rr]=" << p << endl;
2705 cout << "u=T.types_first[rr]="
2706 << T.types_first[rr] << endl;
2707 cout << "I1=" << I1 << endl;
2708 cout << "I2=" << I2 << endl;
2709 cout << "k=" << k << endl;
2710 cout << "a=point_types[u * L2 + I1]=" << a << endl;
2711 cout << "b=point_types[u * L2 + I2]=" << b << endl;
2712 cout << "ab=" << ab << endl;
2713 cout << "T.D2->RHS[eqn_offset + L2 + k]="
2714 << T.D2->RHS[eqn_offset + L2 + k] << endl;
2715 }
2716 return FALSE;
2717 }
2718 }
2719 }
2720 }
2721 if (f_v) {
2722 cout << "tdo_scheme_synthetic::tdo_rows_setup_second_system_eqns_joining done" << endl;
2723 }
2724 return TRUE;
2725}
2726
2728 int verbose_level,
2730 int f_omit, int omit,
2731 int *point_types, int nb_point_types,
2732 int eqn_offset)
2733{
2734 int f_v = (verbose_level >= 1);
2735 int l2, b, i, j, r, I, J, f, l, c, a, S, s, L1, L2;
2736 char label[1000];
2737 //int nb_vars = T.D1->n;
2738
2739 if (f_v) {
2740 cout << "tdo_scheme_synthetic::tdo_rows_setup_second_system_eqns_counting" << endl;
2741 }
2743 row_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
2744
2745 for (i = 0; i < T.nb_multiple_types; i++) {
2746 r = T.multiple_types[i];
2747 f = T.types_first[r];
2748 l = T.types_len[r];
2749 for (j = 0; j < l; j++) {
2750 c = f + j;
2751 J = T.types_first2[i] + j;
2752 for (I = 0; I < L2; I++) {
2753 snprintf(label, 1000, "F_{%d,%d}", I+1, r+1);
2754 T.D2->init_eqn_label(eqn_offset + i * (L2 + 1) + I, label);
2755 }
2756 }
2757 snprintf(label, 1000, "F_{%d}", r+1);
2758 T.D2->init_eqn_label(eqn_offset + i * (L2 + 1) + l2, label);
2759 }
2760
2761 // equations counting flags
2762 for (i = 0; i < T.nb_multiple_types; i++) {
2763 r = T.multiple_types[i];
2764 f = T.types_first[r];
2765 l = T.types_len[r];
2766 for (j = 0; j < l; j++) {
2767 c = f + j;
2768 J = T.types_first2[i] + j;
2769 for (I = 0; I < L2; I++) {
2770 a = point_types[c * L2 + I];
2771 T.D2->Aij(eqn_offset + i * (L2 + 1) + I, J) = a;
2772 }
2773 T.D2->Aij(eqn_offset + i * (L2 + 1) + L2, J) = 1;
2774 }
2775 }
2776 S = 0;
2777 for (i = 0; i < T.nb_multiple_types; i++) {
2778 r = T.multiple_types[i];
2779 for (I = 0; I < L2; I++) {
2782 T.D2->RHS[eqn_offset + i * (L2 + 1) + I] = a * b;
2783 }
2785 T.D2->RHS[eqn_offset + i * (L2 + 1) + L2] = s;
2786 S += s;
2787 }
2788
2789 T.D2->f_has_sum = TRUE;
2790 T.D2->sum = S;
2791 //T.D2->f_x_max = TRUE;
2792 if (f_v) {
2793 cout << "tdo_scheme_synthetic::tdo_rows_setup_second_system_eqns_counting done" << endl;
2794 }
2795 return TRUE;
2796}
2797
2799 int verbose_level,
2801 int f_omit, int omit,
2802 int *point_types, int nb_point_types,
2803 int eqn_start, int &nb_eqns_used)
2804{
2805 int f_v = (verbose_level >= 1);
2806 int nb_eqns_packing;
2807 int /*l2,*/ i, r, f, l, j, c, J, JJ, k, h;
2808 int rr, p, u, a, len, f_used, L1, L2;
2809 char label[1000];
2810 //int nb_vars = T.D1->n;
2812
2813 if (f_v) {
2814 cout << "tdo_scheme_synthetic::tdo_rows_setup_second_system_eqns_packing" << endl;
2815 }
2816 //l2 = nb_col_classes[COL];
2817 row_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
2818
2819 nb_eqns_packing = 0;
2820 for (J = 0; J < L2; J++) {
2821 len = col_classes_len[COL_SCHEME][J];
2822 if (len <= 2) {
2823 continue;
2824 }
2825 for (k = 3; k <= len; k++) {
2826 f_used = FALSE;
2827 for (i = 0; i < T.nb_multiple_types; i++) {
2828 r = T.multiple_types[i];
2829 f = T.types_first[r];
2830 l = T.types_len[r];
2831 for (j = 0; j < l; j++) {
2832 c = f + j;
2833 a = point_types[c * L2 + J];
2834 if (a < k) {
2835 continue;
2836 }
2837 JJ = T.types_first2[i] + j;
2838 f_used = TRUE;
2839 T.D2->Aij(eqn_start + nb_eqns_packing, JJ) = 1;
2840 }
2841 } // next i
2842 if (f_used) {
2843 int bound;
2844 bound = Gg.TDO_upper_bound(len, k);
2845 T.D2->RHS[eqn_start + nb_eqns_packing] = bound;
2846 T.D2->type[eqn_start + nb_eqns_packing] = t_LE;
2847 for (h = 0; h < T.nb_only_one_type; h++) {
2848 rr = T.only_one_type[h];
2849 p = row_classes_len[COL_SCHEME][rr];
2850 u = T.types_first[rr];
2851 a = point_types[u * L2 + J];
2852 if (a < k) {
2853 continue;
2854 }
2855 T.D2->RHS[eqn_start + nb_eqns_packing] -= p;
2856 if (T.D2->RHS[eqn_start + nb_eqns_packing] < 0) {
2857 if (f_v) {
2858 cout << "tdo_scheme::tdo_rows_setup_second_"
2859 "system_eqns_packing RHS < 0" << endl;
2860 }
2861 return FALSE;
2862 }
2863 }
2864 snprintf(label, 1000, "P_{%d,%d} \\,\\mbox{using}\\, "
2865 "P(%d,%d)=%d", J + 1, k, len, k, bound);
2866 T.D2->init_eqn_label(eqn_start + nb_eqns_packing, label);
2867 if (f_v) {
2868 cout << "packing equation " << nb_eqns_packing
2869 << " J=" << J << " k=" << k
2870 << " len=" << len << endl;
2871 }
2872 nb_eqns_packing++;
2873 }
2874 } // next k
2875 }
2876 nb_eqns_used = nb_eqns_packing;
2877 if (f_v) {
2878 cout << "tdo_rows_setup_second_system_eqns_packing "
2879 "nb_eqns_used = " << nb_eqns_used << endl;
2880 }
2881 if (f_v) {
2882 cout << "tdo_scheme_synthetic::tdo_rows_setup_second_system_eqns_packing done" << endl;
2883 }
2884 return TRUE;
2885}
2886
2887// #############################################################################
2888// parameter refinement: refine columns
2889// #############################################################################
2890
2892 int f_once, data_structures::partitionstack &P,
2893 int *&line_types, int &nb_line_types, int &line_type_len,
2894 int *&distributions, int &nb_distributions,
2895 int &cnt_second_system, solution_file_data *Sol,
2896 int f_omit1, int omit1, int f_omit, int omit,
2897 int f_D1_upper_bound_x0, int D1_upper_bound_x0,
2898 int f_use_mckay_solver,
2899 int f_use_packing_numbers)
2900{
2901 int f_v = (verbose_level >= 1);
2902 int f_vv = (verbose_level >= 2);
2903 //int f_vvv = (verbose_level >= 3);
2904 int f_easy;
2905 int l1, l2, R;
2906 int ret = FALSE;
2907
2908 if (f_v) {
2909 cout << "tdo_scheme_synthetic::refine_columns" << endl;
2910 }
2911 if (f_vv) {
2912 cout << "f_omit1=" << f_omit1 << " omit1=" << omit1 << endl;
2913 cout << "f_omit=" << f_omit << " omit=" << omit << endl;
2914 cout << "f_use_packing_numbers=" << f_use_packing_numbers << endl;
2915 cout << "f_D1_upper_bound_x0=" << f_D1_upper_bound_x0 << endl;
2916 cout << "f_use_mckay_solver=" << f_use_mckay_solver << endl;
2917 }
2921 if (f_vv) {
2922 cout << "l1=" << l1 << endl;
2923 cout << "l2=" << l2 << endl;
2924 cout << "R=" << R << endl;
2925 }
2926
2927 get_row_split_partition(0 /*verbose_level*/, P);
2928 if (f_vv) {
2929 cout << "tdo_scheme_synthetic::refine_columns "
2930 "row split partition: " << endl;
2931 P.print(cout);
2932 cout << endl;
2933 }
2934 if (P.ht != l1) {
2935 cout << "P.ht != l1" << endl;
2936 }
2937
2938 if ((R == 1) && (l1 == 1) && (the_col_scheme[0] == -1)) {
2939 f_easy = TRUE;
2940 if (FALSE) {
2941 cout << "easy mode" << endl;
2942 }
2943 }
2944 else {
2945 f_easy = FALSE;
2946 if (FALSE) {
2947 cout << "full mode" << endl;
2948 }
2949 }
2950
2951
2952 if (f_easy) {
2953 cout << "tdo_scheme_synthetic::refine_columns "
2954 "refine_cols_easy nyi" << endl;
2955 exit(1);
2956
2957 }
2958 else {
2959 ret = refine_cols_hard(P, verbose_level - 1, f_once,
2960 line_types, nb_line_types, line_type_len,
2961 distributions, nb_distributions, cnt_second_system, Sol,
2962 f_omit1, omit1, f_omit, omit,
2963 f_D1_upper_bound_x0, D1_upper_bound_x0,
2964 f_use_mckay_solver,
2965 f_use_packing_numbers);
2966 }
2967 if (f_v) {
2968 cout << "tdo_scheme_synthetic::refine_columns finished" << endl;
2969 }
2970 return ret;
2971}
2972
2975 int verbose_level, int f_once,
2976 int *&line_types, int &nb_line_types, int &line_type_len,
2977 int *&distributions, int &nb_distributions,
2978 int &cnt_second_system, solution_file_data *Sol,
2979 int f_omit1, int omit1, int f_omit, int omit,
2980 int f_D1_upper_bound_x0, int D1_upper_bound_x0,
2981 int f_use_mckay_solver,
2982 int f_use_packing_numbers)
2983{
2984 int f_v = (verbose_level >= 1);
2985 int f_vv = (verbose_level >= 2);
2986 //int nb_eqns, nb_vars;
2987 int R, /*l1,*/ l2, L1, L2, r;
2988 int line_types_allocated;
2989 int nb_sol, nb_sol1, f_survive;
2990
2991
2992 if (f_v) {
2993 cout << "tdo_scheme_synthetic::refine_cols_hard" << endl;
2994 }
2995
2996 {
2997 tdo_data T;
2998 int i, j, u;
2999
3000 if (f_vv) {
3001 cout << "f_omit1=" << f_omit1 << " omit1=" << omit1 << endl;
3002 cout << "f_omit=" << f_omit << " omit=" << omit << endl;
3003 cout << "f_use_packing_numbers=" << f_use_packing_numbers << endl;
3004 cout << "f_D1_upper_bound_x0=" << f_D1_upper_bound_x0 << endl;
3005 cout << "f_use_mckay_solver=" << f_use_mckay_solver << endl;
3006 }
3008 //l1 = nb_row_classes[COL_SCHEME];
3010
3011 if (f_v) {
3012 cout << "tdo_scheme_synthetic::refine_cols_hard "
3013 "the_row_scheme is:" << endl;
3014 for (i = 0; i < l2; i++) {
3015 for (j = 0; j < R; j++) {
3016 cout << setw(4) << the_row_scheme[i * R + j];
3017 }
3018 cout << endl;
3019 }
3020 }
3021
3022 column_refinement_L1_L2(P, f_omit1, omit1,
3023 L1, L2, verbose_level);
3024
3025 T.allocate(R);
3026
3027 T.types_first[0] = 0;
3028
3029 line_types_allocated = 100;
3030 nb_line_types = 0;
3031 line_types = NEW_int(line_types_allocated * l2);
3032 line_type_len = l2;
3033
3034 T.nb_only_one_type = 0;
3035 T.nb_multiple_types = 0;
3036
3037
3038 for (r = 0; r < R; r++) {
3039
3040 if (f_v) {
3041 cout << "tdo_scheme_synthetic::refine_cols_hard r=" << r << " / " << R << endl;
3042 }
3043
3044 if (f_v) {
3045 cout << "tdo_scheme_synthetic::refine_cols_hard "
3046 "before tdo_columns_setup_first_system" << endl;
3047 }
3048 if (!tdo_columns_setup_first_system(verbose_level,
3049 T, r, P,
3050 f_omit1, omit1,
3051 line_types, nb_line_types)) {
3052 if (f_v) {
3053 cout << "tdo_scheme_synthetic::refine_cols_hard "
3054 "tdo_columns_setup_first_system returns FALSE" << endl;
3055 }
3056 FREE_int(line_types);
3057 return FALSE;
3058 }
3059 if (f_v) {
3060 cout << "tdo_scheme_synthetic::refine_cols_hard "
3061 "after tdo_columns_setup_first_system" << endl;
3062 }
3063
3064 if (f_D1_upper_bound_x0) {
3065 T.D1->x_min[0] = 0;
3066 T.D1->x_max[0] = D1_upper_bound_x0;
3067 cout << "setting upper bound for D1->x[0] to "
3068 << T.D1->x_max[0] << endl;
3069 }
3070
3071
3072#if 0
3073 // ATTENTION, this is from a specific problem
3074 // on arcs in a plane (MARUTA)
3075
3076 // now we are interested in (42,6)_8 arcs
3077 // a line intersects the arc in at most 6 points:
3078 //T.D1->x_max[0] = 6;
3079
3080 // now we are interested in (33,5)_8 arcs
3081 //T.D1->x_max[0] = 5;
3082 //cout << "ATTENTION: MARUTA, limiting x_max[0] to 5" << endl;
3083
3084 // now we are interested in (49,7)_8 arcs
3085 //T.D1->x_max[0] = 7;
3086 //cout << "ATTENTION: MARUTA, limiting x_max[0] to 7" << endl;
3087
3088 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3089#endif
3090
3091
3092 if (f_vv) {
3093 char label[1000];
3094
3095 sprintf(label, "first_%d", r);
3096 T.D1->write_xml(cout, label);
3097 }
3098
3099 if (f_v) {
3100 cout << "tdo_scheme_synthetic::refine_cols_hard "
3101 "before T.solve_first_system" << endl;
3102 }
3103 nb_sol = T.solve_first_system(verbose_level - 1,
3104 line_types, nb_line_types, line_types_allocated);
3105 if (f_v) {
3106 cout << "tdo_scheme_synthetic::refine_cols_hard "
3107 "after T.solve_first_system" << endl;
3108 }
3109
3110 if (f_v) {
3111 cout << "tdo_scheme_synthetic::refine_cols_hard "
3112 "r = " << r << ", found " << nb_sol
3113 << " refined line types" << endl;
3114 }
3115 if (f_vv) {
3117 line_types + T.types_first[r] * L2, nb_sol, L2, L2, 2);
3118 }
3119 nb_sol1 = 0;
3120 for (u = 0; u < nb_sol; u++) {
3121 f_survive = TRUE;
3122 for (i = 0; i < L2; i++) {
3123 int len1, len2, flags;
3124 len1 = row_classes_len[ROW_SCHEME][i];
3125 if (len1 > 1) {
3126 continue;
3127 }
3128 len2 = col_classes_len[ROW_SCHEME][r];
3129 flags = the_row_scheme[i * R + r];
3130 if (flags == len2) {
3131 if (line_types[(T.types_first[r] + u) * L2 + i] == 0) {
3132 f_survive = FALSE;
3133 if (f_vv) {
3134 cout << "line type " << u << " eliminated, "
3135 "line_types[] = 0" << endl;
3136 cout << "row block " << i << endl;
3137 cout << "col block=" << r << endl;
3138 cout << "length of col block " << len2 << endl;
3139 cout << "flags " << flags << endl;
3140
3141 }
3142 break;
3143 }
3144 }
3145 }
3146 if (f_survive) {
3147 for (i = 0; i < L2; i++) {
3148 line_types[(T.types_first[r] + nb_sol1) * L2 + i] =
3149 line_types[(T.types_first[r] + u) * L2 + i];
3150 }
3151 nb_sol1++;
3152 }
3153 }
3154 if (nb_sol1 < nb_sol) {
3155 if (f_v) {
3156 cout << "tdo_scheme_synthetic::refine_cols_hard "
3157 "eliminated " << nb_sol - nb_sol1
3158 << " types" << endl;
3159 }
3160 nb_sol = nb_sol1;
3161 nb_line_types = T.types_first[r] + nb_sol1;
3162 if (f_v) {
3163 cout << "tdo_scheme_synthetic::refine_cols_hard "
3164 "r = " << r << ", found " << nb_sol
3165 << " refined line types" << endl;
3166 }
3167 }
3168
3169 if (f_vv) {
3171 line_types + T.types_first[r] * L2, nb_sol, L2, L2, 2);
3172 }
3173 if (nb_sol == 0) {
3174 FREE_int(line_types);
3175 return FALSE;
3176 }
3177
3178 T.types_len[r] = nb_sol;
3179 T.types_first[r + 1] = T.types_first[r] + nb_sol;
3180
3181 if (nb_sol == 1) {
3182 if (f_v) {
3183 cout << "tdo_scheme_synthetic::refine_cols_hard "
3184 "only one solution in block "
3185 "r=" << r << endl;
3186 }
3188 }
3189 else {
3191 }
3192
3193 T.D1->freeself();
3194 //diophant_close(T.D1);
3195 //T.D1 = NULL;
3196
3197 } // next r
3198 if (f_v) {
3199 cout << "tdo_scheme_synthetic::refine_cols_hard "
3200 "R=" << R << endl;
3201 cout << "r : T.types_first[r] : T.types_len[r]" << endl;
3202 for (r = 0; r < R; r++) {
3203 cout << r << " : " << T.types_first[r] << " : "
3204 << T.types_len[r] << endl;
3205 }
3206 }
3207 if (f_vv) {
3208 Int_vec_print_integer_matrix_width(cout, line_types,
3209 nb_line_types, line_type_len, line_type_len, 3);
3210 }
3211
3212 // now we compute the distributions:
3213 //
3214 int f_scale = FALSE;
3215 int scaling = 0;
3216
3217 if (!tdo_columns_setup_second_system(verbose_level,
3218 T, P,
3219 f_omit1, omit1,
3220 f_use_packing_numbers,
3221 line_types, nb_line_types)) {
3222
3223 FREE_int(line_types);
3224 return FALSE;
3225 }
3226
3227
3228#if 0
3229 // ATTENTION, this is for the classification
3230 // of (42,6)_8 arcs where a_1 = 0 (MARUTA)
3231
3232 //T.D2->x_max[5] = 0; // a_1 is known to be zero
3233
3234 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3235#endif
3236
3237
3238
3239 if (f_vv) {
3240 char label[1000];
3241
3242 sprintf(label, "second");
3243 T.D2->write_xml(cout, label);
3244 }
3245
3246
3247
3248
3249 int idx, /*f,*/ l;
3250 idx = 0;
3251 for (r = 0; r < R; r++) {
3252 l = T.types_len[r];
3253 if (l > 1) {
3254 if (T.multiple_types[idx] != r) {
3255 cout << "T.multiple_types[idx] != r" << endl;
3256 exit(1);
3257 }
3258 //f = T.types_first2[idx];
3259 idx++;
3260 }
3261 else {
3262 //f = -1;
3263 }
3264 }
3265
3266 if (f_v) {
3267 cout << "tdo_scheme_synthetic::refine_cols_hard "
3268 "solving second system "
3269 << cnt_second_system << " which is " << T.D2->m
3270 << " x " << T.D2->n << endl;
3271 cout << "variable blocks:" << endl;
3272 cout << "i : r : col_classes_len[COL][r] : types_first2[i] : "
3273 "types_len[r]" << endl;
3274 int f, l;
3275 for (i = 0; i < T.nb_multiple_types; i++) {
3276 r = T.multiple_types[i];
3277 f = T.types_first2[i];
3278 l = T.types_len[r];
3279 cout << i << " : " << r << " : " << setw(3)
3280 << col_classes_len[COL_SCHEME][r] << " : " << setw(3)
3281 << f << " : " << setw(3) << l << endl;
3282 }
3283 }
3284
3285 if (f_omit) {
3286 if (f_v) {
3287 cout << "tdo_scheme_synthetic::refine_cols_hard "
3288 "before T.solve_second_system_omit" << endl;
3289 }
3290 T.solve_second_system_omit(verbose_level,
3292 line_types, nb_line_types, distributions, nb_distributions,
3293 omit);
3294 if (f_v) {
3295 cout << "tdo_scheme_synthetic::refine_cols_hard "
3296 "after T.solve_second_system_omit" << endl;
3297 }
3298 }
3299 else {
3300 if (f_v) {
3301 cout << "tdo_scheme_synthetic::refine_cols_hard "
3302 "before T.solve_second_system_with_help" << endl;
3303 }
3304 T.solve_second_system_with_help(verbose_level,
3305 f_use_mckay_solver, f_once,
3306 col_classes_len[COL_SCHEME], f_scale, scaling,
3307 line_types, nb_line_types, distributions, nb_distributions,
3308 cnt_second_system, Sol);
3309 if (f_v) {
3310 cout << "tdo_scheme_synthetic::refine_cols_hard "
3311 "after T.solve_second_system_with_help" << endl;
3312 }
3313 }
3314
3315 if (f_v) {
3316 cout << "tdo_scheme_synthetic::refine_cols_hard "
3317 "second system " << cnt_second_system
3318 << " found " << nb_distributions << " distributions." << endl;
3319 }
3320 if (f_v) {
3321 cout << "tdo_scheme_synthetic::refine_cols_hard "
3322 "The distributions are:" << endl;
3323 orbiter_kernel_system::Orbiter->Int_vec->matrix_print(distributions, nb_distributions, nb_line_types);
3324 }
3325
3326#if 0
3327 // ATTENTION: this is from a specific problem of CHEON !!!!
3328
3329 cout << "ATTENTION, we are running specific code "
3330 "for a problem of Cheon" << endl;
3331 int cnt, h, x0;
3332
3333 cnt = 0;
3334 for (h = 0; h < nb_distributions; h++) {
3335 x0 = distributions[h * nb_line_types + 0];
3336 if (x0 == 12) {
3337 for (j = 0; j < nb_line_types; j++) {
3338 distributions[cnt * nb_line_types + j] =
3339 distributions[h * nb_line_types + j];
3340 }
3341 cnt++;
3342 }
3343 if (x0 > 12) {
3344 cout << "x0 > 12, something is wrong" << endl;
3345 exit(1);
3346 }
3347 }
3348 cout << "CHEON: we found " << cnt << " refinements with x0=12" << endl;
3349 nb_distributions = cnt;
3350
3351 // ATTENTION
3352#endif
3353
3354 cnt_second_system++;
3355 if (f_v) {
3356 cout << "tdo_scheme_synthetic::refine_cols_hard before freeing T" << endl;
3357 }
3358 }
3359 if (f_v) {
3360 cout << "tdo_scheme_synthetic::refine_cols_hard after closing T." << endl;
3361 }
3362 if (f_v) {
3363 cout << "tdo_scheme_synthetic::refine_cols_hard done" << endl;
3364 }
3365 return TRUE;
3366}
3367
3370 int f_omit, int omit,
3371 int &L1, int &L2, int verbose_level)
3372{
3373 int f_v = (verbose_level >= 1);
3374 int l1, l2, omit2, i;
3376 l2 = nb_row_classes[ROW_SCHEME]; // the finer scheme
3377
3378 omit2 = 0;
3379 if (f_omit) {
3380 for (i = l1 - omit; i < l1; i++) {
3381 omit2 += P.cellSize[i];
3382 }
3383 }
3384 L1 = l1 - omit;
3385 L2 = l2 - omit2;
3386 if (f_v) {
3387 cout << "tdo_scheme_synthetic::column_refinement_L1_L2 "
3388 "l1 = " << l1
3389 << " l2=" << l2 << " L1=" << L1 << " L2=" << L2 << endl;
3390 }
3391}
3392
3394 tdo_data &T, int r,
3396 int f_omit, int omit,
3397 int *&line_types, int &nb_line_types)
3398{
3399 int f_v = (verbose_level >= 1);
3400 int f_vv = (verbose_level >= 2);
3401 int i, j, f, l, I, J, rr, R, S, a, a2, s, /*l1, l2,*/ L1, L2;
3402 int h, u, d, d2, o, e, p, eqn_number, nb_vars, nb_eqns;
3404
3405 if (f_v) {
3406 cout << "tdo_scheme_synthetic::tdo_columns_setup_first_system "
3407 "r=" << r << endl;
3408 }
3409 // create all partitions which are refined line types
3410
3411 if (!f_omit) {
3412 omit = 0;
3413 }
3414
3415 if (f_v) {
3416 if (f_omit) {
3417 cout << "omit=" << omit << endl;
3418 }
3419 }
3420
3422 //l1 = nb_row_classes[COL_SCHEME];
3423 //l2 = nb_row_classes[ROW_SCHEME]; // the finer scheme
3424
3425 column_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
3426
3427 nb_vars = L2;
3428 nb_eqns = L1 + 1 + (R - 1);
3429
3430
3431 T.D1->open(nb_eqns, nb_vars);
3432 S = 0;
3433
3434 for (I = 0; I < nb_eqns; I++) {
3435 for (J = 0; J < nb_vars; J++) {
3436 T.D1->A[I * nb_vars + J] = 0;
3437 }
3438 }
3439
3440 // the m equalities that come from the fact that the n e w type
3441 // is a partition of the old type.
3442
3443 // we are in the r-th column class (r is given)
3444
3445 for (I = 0; I < L1; I++) {
3446 f = P.startCell[I];
3447 l = P.cellSize[I];
3448 for (j = 0; j < l; j++) {
3449 J = f + j;
3450 T.D1->Aij(I, J) = 1;
3451 a = the_row_scheme[J * R + r];
3452 if (a == 0) {
3453 T.D1->x_max[J] = 0;
3454 }
3455 else {
3456 T.D1->x_max[J] = row_classes_len[ROW_SCHEME][J];
3457 }
3458 T.D1->x_min[J] = 0;
3459 }
3460 s = the_col_scheme[I * R + r];
3461 T.D1->RHS[I] = s;
3462 T.D1->type[I] = t_EQ;
3463 S += s;
3464 }
3465
3466 eqn_number = L1;
3467
3468 for (i = 0; i < L2; i++) {
3469 a = Combi.minus_one_if_positive(the_row_scheme[i * R + r]);
3470 T.D1->Aij(eqn_number, i) = a;
3471 }
3472 T.D1->RHS[eqn_number] = col_classes_len[ROW_SCHEME][r] - 1;
3473 // the -1 was missing!!!
3474 T.D1->type[eqn_number] = t_LE;
3475 eqn_number++;
3476
3477 for (j = 0; j < R; j++) {
3478 if (j == r) {
3479 continue;
3480 }
3481 for (i = 0; i < L2; i++) {
3482 a = the_row_scheme[i * R + j];
3483 T.D1->Aij(eqn_number, i) = a;
3484 }
3485 T.D1->RHS[eqn_number] = col_classes_len[ROW_SCHEME][j];
3486 T.D1->type[eqn_number] = t_LE;
3487 eqn_number++;
3488 }
3489 T.D1->m = eqn_number;
3490
3491
3492 // try to reduce the upper bounds:
3493
3494 for (h = 0; h < T.nb_only_one_type; h++) {
3495 rr = T.only_one_type[h];
3496 u = T.types_first[rr];
3497 //cout << "u=" << u << endl;
3498 for (j = 0; j < nb_vars; j++) {
3499 //cout << "j=" << j << endl;
3500 if (T.D1->x_max[j] == 0) {
3501 continue;
3502 }
3504 p = col_classes_len[COL_SCHEME][rr];
3505 d2 = Combi.binomial2(d);
3506 a = line_types[u * nb_vars + j];
3507 a2 = Combi.binomial2(a);
3508 o = d2 - a2 * p;
3509 if (o < 0) {
3510 if (f_vv) {
3511 cout << "only one type, but no solution because of "
3512 "joining in row-class " << j << endl;
3513 //cout << "u=" << u << " j=" << j << endl;
3514 }
3515 return FALSE;
3516 }
3517 e = Combi.largest_binomial2_below(o);
3518 T.D1->x_min[j] = 0;
3519 T.D1->x_max[j] = MINIMUM(T.D1->x_max[j], e);
3520 }
3521 }
3522
3523
3524 T.D1->f_has_sum = TRUE;
3525 T.D1->sum = S;
3526 //T.D1->f_x_max = TRUE;
3527
3528 T.D1->eliminate_zero_rows_quick(verbose_level);
3529
3530 if (f_vv) {
3531 T.D1->print();
3532 }
3533 if (f_v) {
3534 cout << "tdo_scheme_synthetic::tdo_columns_setup_first_system done" << endl;
3535 }
3536 return TRUE;
3537}
3538
3540 int verbose_level,
3541 tdo_data &T,
3543 int f_omit, int omit,
3544 int f_use_packing_numbers,
3545 int *&line_types, int &nb_line_types)
3546{
3547 int f_v = (verbose_level >= 1);
3548 int f_vv = (verbose_level >= 2);
3549 int i, len, r, I, J, L1, L2, Nb_eqns, Nb_vars;
3551
3552 if (f_v) {
3553 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system" << endl;
3554 cout << "f_use_packing_numbers="
3555 << f_use_packing_numbers << endl;
3556 }
3557
3558 int nb_eqns_joining, nb_eqns_counting;
3559 int nb_eqns_upper_bound, nb_eqns_used;
3560 int l2;
3561
3562 l2 = nb_row_classes[ROW_SCHEME]; // the finer scheme
3563
3564 column_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
3565
3566 nb_eqns_joining = L2 + Combi.binomial2(L2);
3567 nb_eqns_counting = T.nb_multiple_types * (L2 + 1);
3568 nb_eqns_upper_bound = 0;
3569 if (f_use_packing_numbers) {
3570 for (i = 0; i < l2; i++) {
3571 len = row_classes_len[ROW_SCHEME][i];
3572 if (len > 2) {
3573 nb_eqns_upper_bound += len - 2;
3574 }
3575 }
3576 }
3577
3578 Nb_eqns = nb_eqns_joining + nb_eqns_counting + nb_eqns_upper_bound;
3579 Nb_vars = 0;
3580 for (i = 0; i < T.nb_multiple_types; i++) {
3581 r = T.multiple_types[i];
3582 T.types_first2[i] = Nb_vars;
3583 Nb_vars += T.types_len[r];
3584 }
3585
3586 T.D2->open(Nb_eqns, Nb_vars);
3587 if (f_v) {
3588 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system "
3589 "opening second system with "
3590 << Nb_eqns << " equations and " << Nb_vars
3591 << " variables" << endl;
3592 }
3593 if (f_vv) {
3594 cout << "l2=" << l2 << endl;
3595 cout << "L2=" << L2 << endl;
3596 cout << "nb_eqns_joining=" << nb_eqns_joining << endl;
3597 cout << "nb_eqns_counting=" << nb_eqns_counting << endl;
3598 cout << "nb_eqns_upper_bound=" << nb_eqns_upper_bound << endl;
3599 cout << "T.nb_multiple_types=" << T.nb_multiple_types << endl;
3600 cout << "i : r = T.multiple_types[i] : T.types_first2[i] "
3601 ": T.types_len[r]" << endl;
3602 for (i = 0; i < T.nb_multiple_types; i++) {
3603 r = T.multiple_types[i];
3604 cout << i << " : " << r << " : " << T.types_first2[i]
3605 << " : " << T.types_len[r] << endl;
3606 }
3607 }
3608
3609 for (I = 0; I < Nb_eqns; I++) {
3610 for (J = 0; J < Nb_vars; J++) {
3611 T.D2->A[I * Nb_vars + J] = 0;
3612 }
3613 }
3614
3616 T, P,
3617 f_omit, omit,
3618 line_types, nb_line_types,
3619 0 /*eqn_start*/)) {
3620 if (f_v) {
3621 T.D2->print();
3622 }
3623 return FALSE;
3624 }
3626 T, P,
3627 f_omit, omit,
3628 line_types, nb_line_types,
3629 nb_eqns_joining /* eqn_start */);
3630 if (f_use_packing_numbers) {
3632 verbose_level,
3633 T, P,
3634 f_omit, omit,
3635 line_types, nb_line_types,
3636 nb_eqns_joining + nb_eqns_counting /* eqn_start */,
3637 nb_eqns_used)) {
3638 if (f_v) {
3639 T.D2->print();
3640 }
3641 return FALSE;
3642 }
3643 }
3644
3645
3646
3647 T.D2->eliminate_zero_rows_quick(verbose_level);
3648
3649
3650 if (f_vv) {
3651 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system, "
3652 "The second system is" << endl;
3653 T.D2->print();
3654 }
3655 if (f_v) {
3656 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system done" << endl;
3657 }
3658 return TRUE;
3659}
3660
3662 int verbose_level,
3663 tdo_data &T,
3665 int f_omit, int omit,
3666 int *line_types, int nb_line_types,
3667 int eqn_start)
3668{
3669 int f_v = (verbose_level >= 1);
3670 int l2, L1, L2, i, r, f, l, j, c;
3671 int J, I, I1, I2, a, b, ab, a2, k, h, rr, p, u;
3672 char label[100];
3674
3675 if (f_v) {
3676 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_joining" << endl;
3677 }
3679 column_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
3680
3681 for (I = 0; I < L2; I++) {
3682 sprintf(label, "J_{%d}", I + 1);
3683 T.D2->init_eqn_label(eqn_start + I, label);
3684 }
3685 for (I1 = 0; I1 < L2; I1++) {
3686 for (I2 = I1 + 1; I2 < L2; I2++) {
3687 k = Combi.ij2k(I1, I2, L2);
3688 sprintf(label, "J_{%d,%d}", I1 + 1, I2 + 1);
3689 T.D2->init_eqn_label(eqn_start + L2 + k, label);
3690 }
3691 }
3692 for (i = 0; i < T.nb_multiple_types; i++) {
3693 r = T.multiple_types[i];
3694 f = T.types_first[r];
3695 l = T.types_len[r];
3696 for (j = 0; j < l; j++) {
3697 c = f + j;
3698 J = T.types_first2[i] + j;
3699 for (I = 0; I < L2; I++) {
3700 a = line_types[c * L2 + I];
3701 a2 = Combi.binomial2(a);
3702 T.D2->Aij(eqn_start + I, J) = a2;
3703 }
3704 for (I1 = 0; I1 < L2; I1++) {
3705 for (I2 = I1 + 1; I2 < L2; I2++) {
3706 k = Combi.ij2k(I1, I2, L2);
3707 a = line_types[c * L2 + I1];
3708 b = line_types[c * L2 + I2];
3709 ab = a * b;
3710 T.D2->Aij(eqn_start + L2 + k, J) = ab;
3711 }
3712 }
3713 }
3714 }
3715
3716 // prepare RHS:
3717
3718 for (I = 0; I < L2; I++) {
3720 a2 = Combi.binomial2(a);
3721 T.D2->RHS[eqn_start + I] = a2;
3722 }
3723 for (I1 = 0; I1 < L2; I1++) {
3724 a = row_classes_len[ROW_SCHEME][I1];
3725 for (I2 = I1 + 1; I2 < L2; I2++) {
3726 b = row_classes_len[ROW_SCHEME][I2];
3727 k = Combi.ij2k(I1, I2, L2);
3728 T.D2->RHS[eqn_start + l2 + k] = a * b;
3729 }
3730 }
3731
3732 // now subtract the contribution from one-type blocks:
3733 for (h = 0; h < T.nb_only_one_type; h++) {
3734 rr = T.only_one_type[h];
3735 p = col_classes_len[COL_SCHEME][rr];
3736 u = T.types_first[rr];
3737 for (I = 0; I < L2; I++) {
3738 a = line_types[u * L2 + I];
3739 a2 = Combi.binomial2(a);
3740 T.D2->RHS[eqn_start + I] -= a2 * p;
3741 if (T.D2->RHS[eqn_start + I] < 0) {
3742 if (f_v) {
3743 cout << "tdo_columns_setup_second_system_eqns_"
3744 "joining: RHS is negative, no solution for "
3745 "the distribution" << endl;
3746 }
3747 return FALSE;
3748 }
3749 }
3750 for (I1 = 0; I1 < L2; I1++) {
3751 a = line_types[u * L2 + I1];
3752 for (I2 = I1 + 1; I2 < L2; I2++) {
3753 b = line_types[u * L2 + I2];
3754 k = Combi.ij2k(I1, I2, L2);
3755 ab = a * b * p;
3756 T.D2->RHS[eqn_start + L2 + k] -= ab;
3757 if (T.D2->RHS[eqn_start + L2 + k] < 0) {
3758 if (f_v) {
3759 cout << "tdo_columns_setup_second_system_eqns_"
3760 "joining: RHS is negative, no solution for "
3761 "the distribution" << endl;
3762 }
3763 return FALSE;
3764 }
3765 }
3766 }
3767 }
3768 if (f_v) {
3769 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_joining done" << endl;
3770 }
3771 return TRUE;
3772}
3773
3775 int verbose_level,
3776 tdo_data &T,
3778 int f_omit, int omit,
3779 int *line_types, int nb_line_types,
3780 int eqn_start)
3781{
3782 int f_v = (verbose_level >= 1);
3783 int /*l2,*/ L1, L2, i, r, f, l, j, c, J, I, a, b, S, s;
3784 char label[1000];
3785
3786 if (f_v) {
3787 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_counting" << endl;
3788 }
3789
3790 //l2 = nb_row_classes[ROW];
3791 column_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
3792
3793 for (i = 0; i < T.nb_multiple_types; i++) {
3794 r = T.multiple_types[i];
3795 f = T.types_first[r];
3796 l = T.types_len[r];
3797 for (j = 0; j < l; j++) {
3798 c = f + j;
3799 J = T.types_first2[i] + j;
3800 for (I = 0; I < L2; I++) {
3801 snprintf(label, 1000, "F_{%d,%d}", r + 1, I + 1);
3802 T.D2->init_eqn_label(eqn_start + i * (L2 + 1) + I, label);
3803 }
3804 }
3805 snprintf(label, 1000, "F_{%d}", r + 1);
3806 T.D2->init_eqn_label(eqn_start + i * (L2 + 1) + L2, label);
3807 }
3808
3809 for (i = 0; i < T.nb_multiple_types; i++) {
3810 r = T.multiple_types[i];
3811 f = T.types_first[r];
3812 l = T.types_len[r];
3813 for (j = 0; j < l; j++) {
3814 c = f + j;
3815 J = T.types_first2[i] + j;
3816 for (I = 0; I < L2; I++) {
3817 a = line_types[c * L2 + I];
3818 T.D2->Aij(eqn_start + i * (L2 + 1) + I, J) = a;
3819 }
3820 T.D2->Aij(eqn_start + i * (L2 + 1) + L2, J) = 1;
3821 }
3822 }
3823
3824 // set upper bound x_max:
3825
3826 for (i = 0; i < T.nb_multiple_types; i++) {
3827 r = T.multiple_types[i];
3828 f = T.types_first[r];
3829 l = T.types_len[r];
3831 for (j = 0; j < l; j++) {
3832 c = f + j;
3833 J = T.types_first2[i] + j;
3834 T.D2->x_min[J] = 0;
3835 T.D2->x_max[J] = s;
3836 }
3837 }
3838
3839 // prepare RHS:
3840
3841 S = 0;
3842 for (i = 0; i < T.nb_multiple_types; i++) {
3843 r = T.multiple_types[i];
3844 for (I = 0; I < L2; I++) {
3847 T.D2->RHS[eqn_start + i * (L2 + 1) + I] = a * b;
3848 }
3850 T.D2->RHS[eqn_start + i * (L2 + 1) + L2] = s;
3851 S += s;
3852 }
3853
3854 T.D2->f_has_sum = TRUE;
3855 T.D2->sum = S;
3856 //T.D2->f_x_max = TRUE;
3857 if (f_v) {
3858 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_counting done" << endl;
3859 }
3860}
3861
3863 int verbose_level,
3864 tdo_data &T,
3866 int f_omit, int omit,
3867 int *line_types, int nb_line_types,
3868 int eqn_start, int &nb_eqns_used)
3869{
3870 int f_v = (verbose_level >= 1);
3871 int nb_eqns_packing;
3872 int /*l2,*/ L1, L2, i, r, f, l, j, c, J, I;
3873 int k, h, rr, p, u, a, len, f_used;
3874 char label[1000];
3876
3877 if (f_v) {
3878 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_upper_bound" << endl;
3879 }
3880 nb_eqns_packing = 0;
3881 //l2 = nb_row_classes[ROW];
3882 column_refinement_L1_L2(P, f_omit, omit, L1, L2, verbose_level);
3883 for (I = 0; I < L2; I++) {
3884 len = row_classes_len[ROW_SCHEME][I];
3885 if (len <= 2) {
3886 continue;
3887 }
3888 for (k = 3; k <= len; k++) {
3889 f_used = FALSE;
3890 for (i = 0; i < T.nb_multiple_types; i++) {
3891 r = T.multiple_types[i];
3892 f = T.types_first[r];
3893 l = T.types_len[r];
3894 for (j = 0; j < l; j++) {
3895 c = f + j;
3896 J = T.types_first2[i] + j;
3897 a = line_types[c * L2 + I];
3898 if (a < k) {
3899 continue;
3900 }
3901 f_used = TRUE;
3902 T.D2->Aij(eqn_start + nb_eqns_packing, J) = 1;
3903 }
3904 } // next i
3905 if (f_used) {
3906 int bound;
3907
3908 bound = Gg.TDO_upper_bound(len, k);
3909 T.D2->RHS[eqn_start + nb_eqns_packing] = bound;
3910 T.D2->type[eqn_start + nb_eqns_packing] = t_LE;
3911 for (h = 0; h < T.nb_only_one_type; h++) {
3912 rr = T.only_one_type[h];
3913 p = col_classes_len[ROW_SCHEME][rr];
3914 u = T.types_first[rr];
3915 a = line_types[u * L2 + I];
3916 if (a < k) {
3917 continue;
3918 }
3919 T.D2->RHS[eqn_start + nb_eqns_packing] -= p;
3920 if (T.D2->RHS[eqn_start + nb_eqns_packing] < 0) {
3921 if (f_v) {
3922 cout << "tdo_scheme::tdo_columns_setup_"
3923 "second_system_eqns_upper_bound "
3924 "RHS < 0" << endl;
3925 }
3926 return FALSE;
3927 }
3928 }
3929 snprintf(label, 1000, "P_{%d,%d} \\,\\mbox{using}\\, P(%d,%d)=%d",
3930 I + 1, k, len, k, bound);
3931 T.D2->init_eqn_label(eqn_start + nb_eqns_packing, label);
3932 nb_eqns_packing++;
3933 }
3934 } // next k
3935 }
3936 nb_eqns_used = nb_eqns_packing;
3937 if (f_v) {
3938 cout << "tdo_columns_setup_second_system_eqns_upper_bound "
3939 "nb_eqns_used = " << nb_eqns_used << endl;
3940 }
3941 if (f_v) {
3942 cout << "tdo_scheme_synthetic::tdo_columns_setup_second_system_eqns_upper_bound done" << endl;
3943 }
3944 return TRUE;
3945}
3946
3947// #############################################################################
3948// TDO parameter refinement for 3-designs - row refinement
3949// #############################################################################
3950
3951
3953 int f_once,
3954 int lambda3, int block_size,
3955 int *&point_types, int &nb_point_types, int &point_type_len,
3956 int *&distributions, int &nb_distributions)
3957{
3958 int f_v = (verbose_level >= 1);
3959 int f_vv = (verbose_level >= 2);
3960 int f_vvv = (verbose_level >= 3);
3961 int R, /*l1,*/ l2, r;
3962 int nb_eqns, nb_vars = 0;
3963 int point_types_allocated;
3965 int lambda2;
3966 int nb_points;
3967 int nb_sol;
3968 tdo_data T;
3969
3970 if (f_v) {
3971 cout << "tdo_scheme_synthetic::td3_refine_rows" << endl;
3972 }
3973 nb_points = m;
3974 lambda2 = lambda3 * (nb_points - 2) / (block_size - 2);
3975 if (f_v) {
3976 cout << "nb_points = " << nb_points
3977 << " lambda2 = " << lambda2 << endl;
3978 }
3979 if ((block_size - 2) * lambda2 != lambda3 * (nb_points - 2)) {
3980 cout << "parameters are wrong" << endl;
3981 exit(1);
3982 }
3983
3984 get_column_split_partition(verbose_level, P);
3985
3987 //l1 = nb_col_classes[ROW_SCHEME];
3989
3990
3991 T.allocate(R);
3992
3993 T.types_first[0] = 0;
3994
3995 point_types_allocated = 100;
3996 nb_point_types = 0;
3997 point_types = NEW_int(point_types_allocated * l2);
3998 point_type_len = l2;
3999
4000 T.nb_only_one_type = 0;
4001 T.nb_multiple_types = 0;
4002
4003 for (r = 0; r < R; r++) {
4004
4005 if (f_vvv) {
4006 cout << "r=" << r << endl;
4007 }
4008 if (!td3_rows_setup_first_system(verbose_level - 1,
4009 lambda3, block_size, lambda2,
4010 T, r, P,
4011 nb_vars, nb_eqns,
4012 point_types, nb_point_types)) {
4013 FREE_int(point_types);
4014 return FALSE;
4015 }
4016
4017 nb_sol = T.solve_first_system(verbose_level - 1,
4018 point_types, nb_point_types, point_types_allocated);
4019
4020 if (f_vv) {
4021 cout << "r = " << r << ", found " << nb_sol
4022 << " refined point types" << endl;
4023 }
4024 if (nb_sol == 0) {
4025 FREE_int(point_types);
4026 return FALSE;
4027 }
4028
4029 T.types_len[r] = nb_sol;
4030 T.types_first[r + 1] = T.types_first[r] + nb_sol;
4031
4032 if (nb_sol == 1) {
4033 if (f_vv) {
4034 cout << "only one solution in block r=" << r << endl;
4035 }
4037 }
4038 else {
4040 }
4041
4042 T.D1->freeself();
4043 //diophant_close(T.D1);
4044 //T.D1 = NULL;
4045
4046 } // next r
4047
4048
4049 // now we compute the distributions:
4050 //
4051 int Nb_vars, Nb_eqns;
4052
4053 if (!td3_rows_setup_second_system(verbose_level,
4054 lambda3, block_size, lambda2,
4055 T,
4056 nb_vars, Nb_vars, Nb_eqns,
4057 point_types, nb_point_types)) {
4058 FREE_int(point_types);
4059 return FALSE;
4060 }
4061
4062 if (Nb_vars == 0) {
4063 int h, r, u;
4064
4065 distributions = NEW_int(1 * nb_point_types);
4066 nb_distributions = 0;
4067 for (h = 0; h < T.nb_only_one_type; h++) {
4068 r = T.only_one_type[h];
4069 u = T.types_first[r];
4070 //cout << "only one type, r=" << r << " u=" << u
4071 //<< " row_classes_len[ROW][r]="
4072 //<< row_classes_len[ROW][r] << endl;
4073 distributions[nb_distributions * nb_point_types + u] =
4075 }
4076 nb_distributions++;
4077 return TRUE;
4078 }
4079
4080 int f_scale = FALSE;
4081 int scaling = 0;
4082
4083 T.solve_second_system(verbose_level - 1, FALSE /* f_use_mckay */,f_once,
4084 row_classes_len[ROW_SCHEME], f_scale, scaling,
4085 point_types, nb_point_types, distributions, nb_distributions);
4086
4087
4088 if (f_v) {
4089 cout << "tdo_scheme_synthetic::td3_refine_rows "
4090 "found " << nb_distributions
4091 << " distributions." << endl;
4092 }
4093 if (f_v) {
4094 cout << "tdo_scheme_synthetic::td3_refine_rows done" << endl;
4095 }
4096 return TRUE;
4097}
4098
4100 int lambda3, int block_size, int lambda2,
4101 tdo_data &T, int r,
4103 int &nb_vars, int &nb_eqns,
4104 int *&point_types, int &nb_point_types)
4105{
4106 int f_v = (verbose_level >= 1);
4107 int f_vv = (verbose_level >= 2);
4108 int f_vvv = (verbose_level >= 3);
4109 int i, j, R, l1, l2, r2, r3, S, I, J, f, l, s;
4110 int eqn_offset, eqn_cnt;
4112
4113 if (f_v) {
4114 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system r=" << r << endl;
4115 }
4116
4117
4118 // create all partitions which are refined
4119 // point types of points in block r
4120
4124
4125 nb_vars = l2;
4126 nb_eqns = R + R + (R - 1) + (((R - 1) * (R - 2)) >> 1) + l1;
4127
4128
4129 T.D1->open(nb_eqns, nb_vars);
4130 S = 0;
4131
4132 for (I = 0; I < nb_eqns; I++) {
4133 for (J = 0; J < nb_vars; J++) {
4134 T.D1->A[I * nb_vars + J] = 0;
4135 }
4136 }
4137 for (I = 0; I < nb_eqns; I++) {
4138 T.D1->RHS[I] = 9999;
4139 }
4140
4141 // pair joinings
4142 for (r2 = 0; r2 < R; r2++) {
4143 if (r2 == r) {
4144 // connections within the same row-partition
4145 for (J = 0; J < nb_vars; J++) {
4146 T.D1->A[r2 * nb_vars + J] =
4147 Combi.minus_one_if_positive(the_col_scheme[r2 * l2 + J]);
4148 }
4149 T.D1->RHS[r2] = (row_classes_len[ROW_SCHEME][r2] - 1) * lambda2;
4150 }
4151 else {
4152 // connections to the point from different row-partitions
4153 for (J = 0; J < nb_vars; J++) {
4154 T.D1->A[r2 * nb_vars + J] = the_col_scheme[r2 * l2 + J];
4155 }
4156 T.D1->RHS[r2] = row_classes_len[ROW_SCHEME][r2] * lambda2;
4157 }
4158 }
4159 if (f_vv) {
4160 cout << "r=" << r << " after pair joining, the system is" << endl;
4161 T.D1->print();
4162 }
4163
4164 // triple joinings
4165 eqn_offset = R;
4166 for (r2 = 0; r2 < R; r2++) {
4167 if (r2 == r) {
4168 // connections to pairs within the same row-partition
4169 for (J = 0; J < nb_vars; J++) {
4170 T.D1->A[(eqn_offset + r2) * nb_vars + J] =
4171 Combi.binomial2(Combi.minus_one_if_positive(
4172 the_col_scheme[r2 * l2 + J]));
4173 }
4174 T.D1->RHS[eqn_offset + r2] =
4175 Combi.binomial2((row_classes_len[ROW_SCHEME][r2] - 1)) * lambda3;
4176 }
4177 else {
4178 // connections to pairs with one
4179 // in the same and one in the other part
4180 for (J = 0; J < nb_vars; J++) {
4181 T.D1->A[(eqn_offset + r2) * nb_vars + J] =
4182 Combi.minus_one_if_positive(the_col_scheme[r * l2 + J])
4183 * the_col_scheme[r2 * l2 + J];
4184 }
4185 T.D1->RHS[eqn_offset + r2] =
4186 (row_classes_len[ROW_SCHEME][r] - 1) *
4187 row_classes_len[ROW_SCHEME][r2] * lambda3;
4188 }
4189 }
4190 if (f_vv) {
4191 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system "
4192 "r=" << r << " after triple joining, the system is" << endl;
4193 T.D1->print();
4194 }
4195
4196 eqn_offset += R;
4197 eqn_cnt = 0;
4198 for (r2 = 0; r2 < R; r2++) {
4199 if (r2 == r) {
4200 continue;
4201 }
4202 // connections to pairs from one different row-partition
4203 for (J = 0; J < nb_vars; J++) {
4204 T.D1->A[(eqn_offset + eqn_cnt) * nb_vars + J] =
4205 Combi.binomial2(the_col_scheme[r2 * l2 + J]);
4206 }
4207 T.D1->RHS[eqn_offset + eqn_cnt] = Combi.binomial2(
4208 row_classes_len[ROW_SCHEME][r2]) * lambda3;
4209 eqn_cnt++;
4210 }
4211 if (f_vv) {
4212 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system "
4213 "r=" << r << " after connections to pairs "
4214 "from one different row-partition, the system is" << endl;
4215 T.D1->print();
4216 }
4217
4218 eqn_offset += (R - 1);
4219 eqn_cnt = 0;
4220 for (r2 = 0; r2 < R; r2++) {
4221 if (r2 == r) {
4222 continue;
4223 }
4224 for (r3 = r2 + 1; r3 < R; r3++) {
4225 if (r3 == r) {
4226 continue;
4227 }
4228 // connections to pairs from two different row-partitions
4229 for (J = 0; J < nb_vars; J++) {
4230 T.D1->A[(eqn_offset + eqn_cnt) * nb_vars + J] =
4231 the_col_scheme[r2 * l2 + J] * the_col_scheme[r3 * l2 + J];
4232 }
4233 T.D1->RHS[eqn_offset + eqn_cnt] =
4235 eqn_cnt++;
4236 }
4237 }
4238 eqn_offset += eqn_cnt;
4239 if (f_vv) {
4240 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system "
4241 "r=" << r << " after connections to pairs from two "
4242 "different row-partitions, the system is" << endl;
4243 T.D1->print();
4244 }
4245
4246 S = 0;
4247 for (i = 0; i < l1; i++) {
4248 s = the_row_scheme[r * l1 + i];
4249 if (f_vvv) {
4250 cout << "r=" << r << " i=" << i << " s=" << s << endl;
4251 }
4252 T.D1->RHS[eqn_offset + i] = s;
4253 S += s;
4254 f = P.startCell[i];
4255 l = P.cellSize[i];
4256 if (f_vvv) {
4257 cout << "f=" << f << " l=" << l << endl;
4258 }
4259
4260 for (j = 0; j < l; j++) {
4261 T.D1->A[(eqn_offset + i) * nb_vars + f + j] = 1;
4262 T.D1->x_min[f + j] = 0;
4263 T.D1->x_max[f + j] = s;
4264 }
4265 }
4266 if (f_vv) {
4267 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system "
4268 "r=" << r << " after adding extra equations, "
4269 "the system is" << endl;
4270 T.D1->print();
4271 }
4272
4273 T.D1->f_has_sum = TRUE;
4274 T.D1->sum = S;
4275 //T.D1->f_x_max = TRUE;
4276
4277
4278 if (f_vv) {
4279 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system "
4280 "r=" << r << " the system is" << endl;
4281 T.D1->print();
4282 }
4283
4284 if (f_v) {
4285 cout << "tdo_scheme_synthetic::td3_rows_setup_first_system done" << endl;
4286 }
4287
4288 return TRUE;
4289}
4290
4292 int lambda3, int block_size, int lambda2,
4293 tdo_data &T,
4294 int nb_vars, int &Nb_vars, int &Nb_eqns,
4295 int *&point_types, int &nb_point_types)
4296{
4297 int f_v = (verbose_level >= 1);
4298 int f_vv = (verbose_level >= 2);
4299 //int f_vvv = (verbose_level >= 3);
4300 int l2, i, r, I, J, nb_eqns_counting;
4301 int S;
4302
4303 if (f_v) {
4304 cout << "tdo_scheme_synthetic::td3_rows_setup_second_system" << endl;
4305 }
4307
4308 nb_eqns_counting = T.nb_multiple_types * (l2 + 1);
4309 Nb_eqns = nb_eqns_counting;
4310 Nb_vars = 0;
4311 for (i = 0; i < T.nb_multiple_types; i++) {
4312 r = T.multiple_types[i];
4313 T.types_first2[i] = Nb_vars;
4314 Nb_vars += T.types_len[r];
4315 }
4316
4317
4318 T.D2->open(Nb_eqns, Nb_vars);
4319 if (f_v) {
4320 cout << "td3_rows_setup_second_system: "
4321 "opening second system with "
4322 << Nb_eqns << " equations and "
4323 << Nb_vars << " variables" << endl;
4324 }
4325
4326 for (I = 0; I < Nb_eqns; I++) {
4327 for (J = 0; J < Nb_vars; J++) {
4328 T.D2->A[I * Nb_vars + J] = 0;
4329 }
4330 }
4331 for (I = 0; I < Nb_eqns; I++) {
4332 T.D2->RHS[I] = 9999;
4333 }
4334
4335
4336 if (!td3_rows_counting_flags(verbose_level,
4337 lambda3, block_size, lambda2, S,
4338 T,
4339 nb_vars, Nb_vars,
4340 point_types, nb_point_types, 0)) {
4341 return FALSE;
4342 }
4343
4344
4345 T.D2->f_has_sum = TRUE;
4346 T.D2->sum = S;
4347
4348
4349 if (f_vv) {
4350 cout << "The second system is" << endl;
4351
4352 T.D2->print();
4353 }
4354
4355 if (f_v) {
4356 cout << "tdo_scheme_synthetic::td3_rows_setup_second_system "
4357 "done" << endl;
4358 }
4359 return TRUE;
4360
4361}
4362
4364 int lambda3, int block_size, int lambda2, int &S,
4365 tdo_data &T,
4366 int nb_vars, int Nb_vars,
4367 int *&point_types, int &nb_point_types, int eqn_offset)
4368{
4369 int f_v = (verbose_level >= 1);
4370 //int f_vv = (verbose_level >= 2);
4371 int f_vvv = (verbose_level >= 3);
4372 int I, i, r, f, l, j, c, J, a, b, rr, p, u, l2, h, s;
4373
4375
4376 if (f_v) {
4377 cout << "tdo_scheme_synthetic::td3_rows_counting_flags "
4378 "eqn_offset=" << eqn_offset
4379 << " nb_multiple_types=" << T.nb_multiple_types << endl;
4380 }
4381 // counting flags, a block diagonal system with
4382 // nb_multiple_types * (l2 + 1) equations
4383 for (i = 0; i < T.nb_multiple_types; i++) {
4384 r = T.multiple_types[i];
4385 f = T.types_first[r];
4386 l = T.types_len[r];
4387 for (I = 0; I < l2; I++) {
4388 for (j = 0; j < l; j++) {
4389 c = f + j;
4390 J = T.types_first2[i] + j;
4391 a = point_types[c * nb_vars + I];
4392 T.D2->A[(eqn_offset + i * (l2 + 1) + I) * Nb_vars + J] = a;
4393 }
4396 T.D2->RHS[eqn_offset + i * (l2 + 1) + I] = a * b;
4397 for (h = 0; h < T.nb_only_one_type; h++) {
4398 rr = T.only_one_type[h];
4399 p = col_classes_len[COL_SCHEME][rr];
4400 u = T.types_first[rr];
4401 a = point_types[u * nb_vars + I];
4402 T.D2->RHS[eqn_offset + i * (l2 + 1) + I] -= a * p;
4403 if (T.D2->RHS[eqn_offset + i * (l2 + 1) + I] < 0) {
4404 if (f_v) {
4405 cout << "td3_rows_counting_flags: RHS["
4406 "nb_eqns_joining + i * (l2 + 1) + I] "
4407 "is negative, no solution for the "
4408 "distribution" << endl;
4409 }
4410 return FALSE;
4411 }
4412 } // next h
4413 } // next I
4414 } // next i
4415
4416
4417 S = 0;
4418 for (i = 0; i < T.nb_multiple_types; i++) {
4419 r = T.multiple_types[i];
4420 f = T.types_first[r];
4421 l = T.types_len[r];
4422 // one extra equation for the sum
4423 for (j = 0; j < l; j++) {
4424 c = f + j;
4425 J = T.types_first2[i] + j;
4426 // counting: extra row of ones
4427 T.D2->A[(eqn_offset + i * (l2 + 1) + l2) * Nb_vars + J] = 1;
4428 }
4429
4431 T.D2->RHS[eqn_offset + i * (l2 + 1) + l2] = s;
4432 S += s;
4433 }
4434 if (f_vvv) {
4435 cout << "tdo_scheme_synthetic::td3_rows_counting_flags, the system is" << endl;
4436 T.D2->print();
4437 }
4438
4439 if (f_v) {
4440 cout << "tdo_scheme_synthetic::td3_rows_counting_flags done" << endl;
4441 }
4442
4443 return TRUE;
4444}
4445
4446// #############################################################################
4447// TDO parameter refinement for 3-designs - column refinement
4448// #############################################################################
4449
4450
4451
4452int tdo_scheme_synthetic::td3_refine_columns(int verbose_level, int f_once,
4453 int lambda3, int block_size,
4454 int f_scale, int scaling,
4455 int *&line_types, int &nb_line_types, int &line_type_len,
4456 int *&distributions, int &nb_distributions)
4457{
4458 int f_v = (verbose_level >= 1);
4459 int f_vv = (verbose_level >= 2);
4460 int f_vvv = (verbose_level >= 3);
4461 int R, /*l1,*/ l2, r, nb_eqns, nb_vars = 0;
4462 int line_types_allocated;
4464 int lambda2;
4465 int nb_points;
4466 int nb_sol;
4467 tdo_data T;
4468
4469 if (f_v) {
4470 cout << "tdo_scheme_synthetic::td3_refine_columns" << endl;
4471 }
4472
4473 nb_points = m;
4474 lambda2 = lambda3 * (nb_points - 2) / (block_size - 2);
4475 if (f_v) {
4476 cout << "nb_points = " << nb_points
4477 << " lambda2 = " << lambda2 << endl;
4478 }
4479 if ((block_size - 2) * lambda2 != lambda3 * (nb_points - 2)) {
4480 cout << "tdo_scheme_synthetic::td3_refine_columns parameters are wrong" << endl;
4481 exit(1);
4482 }
4483
4484 get_row_split_partition(verbose_level, P);
4485
4487 //l1 = nb_row_classes[COL_SCHEME];
4489
4490 T.allocate(R);
4491
4492 T.types_first[0] = 0;
4493
4494 line_types_allocated = 100;
4495 nb_line_types = 0;
4496 line_types = NEW_int(line_types_allocated * l2);
4497 line_type_len = l2;
4498
4499 T.nb_only_one_type = 0;
4500 T.nb_multiple_types = 0;
4501
4502 for (r = 0; r < R; r++) {
4503
4504 if (f_vvv) {
4505 cout << "r=" << r << endl;
4506 }
4507 if (!td3_columns_setup_first_system(verbose_level - 1,
4508 lambda3, block_size, lambda2,
4509 T, r, P,
4510 nb_vars, nb_eqns,
4511 line_types, nb_line_types)) {
4512
4513 FREE_int(line_types);
4514 return FALSE;
4515 }
4516
4517 nb_sol = T.solve_first_system(verbose_level - 1,
4518 line_types, nb_line_types, line_types_allocated);
4519
4520 if (f_vv) {
4521 cout << "r = " << r << ", found " << nb_sol
4522 << " refine line types" << endl;
4523 }
4524 if (nb_sol == 0) {
4525 FREE_int(line_types);
4526 return FALSE;
4527 }
4528
4529 T.types_len[r] = nb_sol;
4530 T.types_first[r + 1] = T.types_first[r] + nb_sol;
4531
4532 if (nb_sol == 1) {
4533 if (f_vv) {
4534 cout << "only one solution in block r=" << r << endl;
4535 }
4537 }
4538 else {
4540 }
4541
4542 T.D1->freeself();
4543 //diophant_close(T.D1);
4544 //T.D1 = NULL;
4545
4546 } // next r
4547
4548
4549 // now we compute the distributions:
4550 //
4551 int Nb_vars, Nb_eqns;
4552
4553 if (!td3_columns_setup_second_system(verbose_level,
4554 lambda3, block_size, lambda2, f_scale, scaling,
4555 T,
4556 nb_vars, Nb_vars, Nb_eqns,
4557 line_types, nb_line_types)) {
4558
4559 FREE_int(line_types);
4560 return FALSE;
4561 }
4562
4563 T.solve_second_system(verbose_level - 1,
4564 FALSE /* f_use_mckay */, f_once,
4566 f_scale, scaling,
4567 line_types, nb_line_types,
4568 distributions, nb_distributions);
4569
4570
4571 if (f_v) {
4572 cout << "tdo_scheme_synthetic::td3_refine_columns: found "
4573 << nb_distributions << " distributions." << endl;
4574 }
4575 return TRUE;
4576}
4577
4579 int lambda3, int block_size, int lambda2,
4580 tdo_data &T, int r,
4582 int &nb_vars,int &nb_eqns,
4583 int *&line_types, int &nb_line_types)
4584{
4585 int f_v = (verbose_level >= 1);
4586 int f_vv = (verbose_level >= 2);
4587 int f_vvv = (verbose_level >= 3);
4588 int j, R, l1, l2, S, I, J, f, l, a, a2;
4589 int s, d, d2, d3, o, h, rr, p, u, a3, e;
4591
4592 if (f_v) {
4593 cout << "tdo_scheme_synthetic::td3_columns_setup_first_system r=" << r << endl;
4594 }
4595
4596
4597 // create all partitions which are refined line types
4598
4602
4603 nb_vars = l2; // P.n
4604 nb_eqns = l1; // = P.ht
4605
4606
4607 T.D1->open(nb_eqns, nb_vars);
4608 S = 0;
4609
4610 for (I = 0; I < nb_eqns; I++) {
4611 for (J = 0; J < nb_vars; J++) {
4612 T.D1->A[I * nb_vars + J] = 0;
4613 }
4614 }
4615
4616 for (I = 0; I < nb_eqns; I++) {
4617 f = P.startCell[I];
4618 l = P.cellSize[I];
4619 for (j = 0; j < l; j++) {
4620 J = f + j;
4621 T.D1->A[I * nb_vars + J] = 1;
4622 a = the_row_scheme[J * R + r];
4623 if (a == 0) {
4624 T.D1->x_max[J] = 0;
4625 }
4626 else {
4627 T.D1->x_max[J] = row_classes_len[ROW_SCHEME][J];
4628 }
4629 T.D1->x_min[J] = 0;
4630 }
4631 s = the_col_scheme[I * R + r];
4632 T.D1->RHS[I] = s;
4633 S += s;
4634 }
4635
4636 // try to reduce the upper bounds:
4637
4638 for (j = 0; j < nb_vars; j++) {
4639 //cout << "j=" << j << endl;
4640 if (T.D1->x_max[j] == 0) {
4641 continue;
4642 }
4644 d2 = Combi.binomial2(d) * lambda2;
4645 o = d2;
4646 for (h = 0; h < T.nb_only_one_type; h++) {
4647 rr = T.only_one_type[h];
4648 p = col_classes_len[COL_SCHEME][rr];
4649
4650 u = T.types_first[rr];
4651 //cout << "u=" << u << endl;
4652
4653 a = line_types[u * nb_vars + j];
4654 a2 = Combi.binomial2(a);
4655 o -= a2 * p;
4656 if (o < 0) {
4657 if (f_vvv) {
4658 cout << "only one type, but no solution because "
4659 "of joining in row-class " << j << endl;
4660 //cout << "u=" << u << " j=" << j << endl;
4661 }
4662 return FALSE;
4663 }
4664 }
4665 e = Combi.largest_binomial2_below(o);
4666 T.D1->x_min[j] = 0;
4667 T.D1->x_max[j] = MINIMUM(T.D1->x_max[j], e);
4668 }
4669 for (j = 0; j < nb_vars; j++) {
4670 //cout << "j=" << j << endl;
4671 if (T.D1->x_max[j] == 0) {
4672 continue;
4673 }
4675 d3 = Combi.binomial3(d) * lambda3;
4676 o = d3;
4677 for (h = 0; h < T.nb_only_one_type; h++) {
4678 rr = T.only_one_type[h];
4679 p = col_classes_len[COL_SCHEME][rr];
4680 u = T.types_first[rr];
4681 //cout << "u=" << u << endl;
4682
4683 a = line_types[u * nb_vars + j];
4684 a3 = Combi.binomial3(a);
4685 o -= a3 * p;
4686 if (o < 0) {
4687 if (f_vvv) {
4688 cout << "only one type, but no solution because "
4689 "of joining in row-class " << j << endl;
4690 //cout << "u=" << u << " j=" << j << endl;
4691 }
4692 return FALSE;
4693 }
4694 }
4695 e = Combi.largest_binomial3_below(o);
4696 T.D1->x_min[j] = 0;
4697 T.D1->x_max[j] = MINIMUM(T.D1->x_max[j], e);
4698 }
4699
4700 T.D1->f_has_sum = TRUE;
4701 T.D1->sum = S;
4702 //T.D1->f_x_max = TRUE;
4703
4704 if (f_vv) {
4705 cout << "r=" << r << " the system is" << endl;
4706 T.D1->print();
4707 }
4708 if (f_v) {
4709 cout << "tdo_scheme_synthetic::td3_columns_setup_first_system done" << endl;
4710 }
4711 return TRUE;
4712}
4713
4714
4716 int verbose_level,
4717 int lambda3, int block_size, int lambda2,
4718 int f_scale, int scaling,
4719 tdo_data &T,
4720 int nb_vars, int &Nb_vars, int &Nb_eqns,
4721 int *&line_types, int &nb_line_types)
4722{
4723 int f_v = (verbose_level >= 1);
4724 int f_vv = (verbose_level >= 2);
4725 //int f_vvv = (verbose_level >= 3);
4726 int l2, i, r, I, J, a;
4727 int S;
4728 int nb_eqns_joining, nb_eqns_joining_pairs;
4729 int nb_eqns_joining_triples, nb_eqns_counting;
4731
4732 if (f_v) {
4733 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system" << endl;
4734 }
4735
4737
4738 nb_eqns_joining_triples = l2 + l2 * (l2 - 1) + Combi.binomial3(l2);
4739 // l2 times: triples within a given class
4740 // l2 * (l2 - 1) times (ordered pairs from an l2 set):
4741 // triples with 2 in a given class, 1 in another given class
4742 // binomial3(l2) triples from different classes
4743 nb_eqns_joining_pairs = l2 + Combi.binomial2(l2);
4744 // l2 times: pairs within a given class
4745 // binomial2(l2) pairs from different classes
4746 nb_eqns_joining = nb_eqns_joining_triples + nb_eqns_joining_pairs;
4747 nb_eqns_counting = T.nb_multiple_types * (l2 + 1);
4748 Nb_eqns = nb_eqns_joining + nb_eqns_counting;
4749 Nb_vars = 0;
4750 for (i = 0; i < T.nb_multiple_types; i++) {
4751 r = T.multiple_types[i];
4752 T.types_first2[i] = Nb_vars;
4753 Nb_vars += T.types_len[r];
4754 }
4755
4756 T.D2->open(Nb_eqns, Nb_vars);
4757 if (f_v) {
4758 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system: "
4759 "opening second system with "
4760 << Nb_eqns << " equations and "
4761 << Nb_vars << " variables" << endl;
4762 }
4763
4764 for (I = 0; I < Nb_eqns; I++) {
4765 for (J = 0; J < Nb_vars; J++) {
4766 T.D2->A[I * Nb_vars + J] = 0;
4767 }
4768 }
4769 for (I = 0; I < Nb_eqns; I++) {
4770 T.D2->RHS[I] = 9999;
4771 }
4772
4773
4774 if (f_v) {
4775 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4776 "before td3_columns_triples_same_class" << endl;
4777 }
4778 if (!td3_columns_triples_same_class(verbose_level - 2,
4779 lambda3, block_size,
4780 T,
4781 nb_vars, Nb_vars,
4782 line_types, nb_line_types, 0)) {
4783
4784 return FALSE;
4785 }
4786 if (f_v) {
4787 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4788 "after td3_columns_triples_same_class" << endl;
4789 }
4790
4791 if (f_v) {
4792 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4793 "before td3_columns_pairs_same_class" << endl;
4794 }
4795 if (!td3_columns_pairs_same_class(verbose_level - 2,
4796 lambda3, block_size, lambda2,
4797 T,
4798 nb_vars, Nb_vars,
4799 line_types, nb_line_types, nb_eqns_joining_triples)) {
4800
4801 return FALSE;
4802 }
4803 if (f_v) {
4804 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4805 "after td3_columns_pairs_same_class" << endl;
4806 }
4807
4808 if (f_v) {
4809 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4810 "before td3_columns_counting_flags" << endl;
4811 }
4812 if (!td3_columns_counting_flags(verbose_level - 2,
4813 lambda3, block_size, lambda2, S,
4814 T,
4815 nb_vars, Nb_vars,
4816 line_types, nb_line_types, nb_eqns_joining)) {
4817
4818 return FALSE;
4819 }
4820 if (f_v) {
4821 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4822 "after td3_columns_counting_flags" << endl;
4823 }
4824
4825 if (f_v) {
4826 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4827 "before td3_columns_lambda2_joining_pairs_from_different_classes" << endl;
4828 }
4830 verbose_level - 2,
4831 lambda3, block_size, lambda2,
4832 T,
4833 nb_vars, Nb_vars,
4834 line_types, nb_line_types, nb_eqns_joining_triples + l2)) {
4835
4836 return FALSE;
4837 }
4838 if (f_v) {
4839 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4840 "after td3_columns_lambda2_joining_pairs_from_different_classes" << endl;
4841 }
4842
4843 if (f_v) {
4844 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4845 "before td3_columns_lambda3_joining_triples_2_1" << endl;
4846 }
4847 if (!td3_columns_lambda3_joining_triples_2_1(verbose_level - 2,
4848 lambda3, block_size, lambda2,
4849 T,
4850 nb_vars, Nb_vars,
4851 line_types, nb_line_types, l2)) {
4852
4853 return FALSE;
4854 }
4855 if (f_v) {
4856 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4857 "after td3_columns_lambda3_joining_triples_2_1" << endl;
4858 }
4859
4860 if (f_v) {
4861 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4862 "before td3_columns_lambda3_joining_triples_1_1_1" << endl;
4863 }
4864 if (!td3_columns_lambda3_joining_triples_1_1_1(verbose_level - 2,
4865 lambda3, block_size, lambda2,
4866 T,
4867 nb_vars, Nb_vars,
4868 line_types, nb_line_types, l2 + l2 * (l2 - 1))) {
4869
4870 return FALSE;
4871 }
4872 if (f_v) {
4873 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system "
4874 "before td3_columns_lambda3_joining_triples_1_1_1" << endl;
4875 }
4876
4877 if (f_scale) {
4878 if (S % scaling) {
4879 cout << "cannot scale by " << scaling
4880 << " b/c S=" << S << endl;
4881 exit(1);
4882 }
4883 S /= scaling;
4884 for (I = 0; I < Nb_eqns; I++) {
4885 a = T.D2->RHS[I];
4886 if (a % scaling) {
4887 if (a % scaling) {
4888 cout << "cannot scale by " << scaling
4889 << " b/c RHS[" << I << "]=" << a << endl;
4890 }
4891 exit(1);
4892 }
4893 a /= scaling;
4894 T.D2->RHS[I] = a;
4895 }
4896#if 0
4897 for (I = 0; I < Nb_eqns; I++)
4898 for (J = 0; J < Nb_vars; J++)
4899 T.D2->A[I * Nb_vars + J] *= scaling;
4900#endif
4901 }
4902
4903
4904
4905 T.D2->f_has_sum = TRUE;
4906 T.D2->sum = S;
4907
4908
4909 if (f_vv) {
4910 cout << "The second system is" << endl;
4911
4912 T.D2->print();
4913 }
4914
4915 if (f_v) {
4916 cout << "tdo_scheme_synthetic::td3_columns_setup_second_system done" << endl;
4917 }
4918 return TRUE;
4919
4920}
4921
4922
4924 int lambda3, int block_size,
4925 tdo_data &T,
4926 int nb_vars, int Nb_vars,
4927 int *&line_types, int &nb_line_types, int eqn_offset)
4928{
4929 int f_v = (verbose_level >= 1);
4930 //int f_vv = (verbose_level >= 2);
4931 int f_vvv = (verbose_level >= 3);
4932 int I, i, r, f, l, j, c, J, a, a3, rr, p, u, l2, h;
4934
4936
4937 if (f_v) {
4938 cout << "tdo_scheme_synthetic::td3_columns_triples_same_class: "
4939 "eqn_offset=" << eqn_offset << endl;
4940 }
4941 // triples from the same class:
4942 for (I = 0; I < l2; I++) {
4943 for (i = 0; i < T.nb_multiple_types; i++) {
4944 r = T.multiple_types[i];
4945 f = T.types_first[r];
4946 l = T.types_len[r];
4947 for (j = 0; j < l; j++) {
4948 c = f + j;
4949 J = T.types_first2[i] + j;
4950 a = line_types[c * nb_vars + I];
4951 a3 = Combi.binomial3(a);
4952 // joining triples from the same class:
4953 T.D2->A[(eqn_offset + I) * Nb_vars + J] = a3;
4954 }
4955 }
4957 a3 = Combi.binomial3(a);
4958 T.D2->RHS[eqn_offset + I] = a3 * lambda3;
4959 for (h = 0; h < T.nb_only_one_type; h++) {
4960 rr = T.only_one_type[h];
4961 p = col_classes_len[COL_SCHEME][rr];
4962 u = T.types_first[rr];
4963 a = line_types[u * nb_vars + I];
4964 a3 = Combi.binomial3(a);
4965 T.D2->RHS[eqn_offset + I] -= a3 * p;
4966 if (T.D2->RHS[eqn_offset + I] < 0) {
4967 if (f_v) {
4968 cout << "td3_refine_columns: RHS[I] is negative, "
4969 "no solution for the distribution" << endl;
4970 }
4971 return FALSE;
4972 }
4973 }
4974 }
4975 if (f_vvv) {
4976 cout << "triples from the same class, the system is" << endl;
4977 T.D2->print();
4978 }
4979 if (f_v) {
4980 cout << "tdo_scheme_synthetic::td3_columns_triples_same_class done" << endl;
4981 }
4982 return TRUE;
4983}
4984
4986 int lambda3, int block_size, int lambda2,
4987 tdo_data &T,
4988 int nb_vars, int Nb_vars,
4989 int *&line_types, int &nb_line_types, int eqn_offset)
4990{
4991 int f_v = (verbose_level >= 1);
4992 //int f_vv = (verbose_level >= 2);
4993 int f_vvv = (verbose_level >= 3);
4994 int I, i, r, f, l, j, c, J, a, a2, rr, p, u, l2, h;
4996
4998
4999 if (f_v) {
5000 cout << "tdo_scheme_synthetic::td3_columns_pairs_same_class: "
5001 "eqn_offset=" << eqn_offset << endl;
5002 }
5003 // pairs from the same class:
5004 for (I = 0; I < l2; I++) {
5005 for (i = 0; i < T.nb_multiple_types; i++) {
5006 r = T.multiple_types[i];
5007 f = T.types_first[r];
5008 l = T.types_len[r];
5009 for (j = 0; j < l; j++) {
5010 c = f + j;
5011 J = T.types_first2[i] + j;
5012 a = line_types[c * nb_vars + I];
5013 a2 = Combi.binomial2(a);
5014 // joining pairs from the same class:
5015 T.D2->A[(eqn_offset + I) * Nb_vars + J] = a2;
5016 }
5017 }
5019 a2 = Combi.binomial2(a);
5020 T.D2->RHS[eqn_offset + I] = a2 * lambda2;
5021 for (h = 0; h < T.nb_only_one_type; h++) {
5022 rr = T.only_one_type[h];
5023 p = col_classes_len[COL_SCHEME][rr];
5024 u = T.types_first[rr];
5025 a = line_types[u * nb_vars + I];
5026 a2 = Combi.binomial2(a);
5027 T.D2->RHS[eqn_offset + I] -= a2 * p;
5028 if (T.D2->RHS[eqn_offset + I] < 0) {
5029 if (f_v) {
5030 cout << "td3_refine_columns: RHS[eqn_offset + I] "
5031 "is negative, no solution for the "
5032 "distribution" << endl;
5033 }
5034 return FALSE;
5035 }
5036 }
5037 }
5038 if (f_vvv) {
5039 cout << "pairs from the same class, the system is" << endl;
5040 T.D2->print();
5041 }
5042
5043 if (f_v) {
5044 cout << "tdo_scheme_synthetic::td3_columns_pairs_same_class done" << endl;
5045 }
5046 return TRUE;
5047}
5048
5050 int lambda3, int block_size, int lambda2, int &S,
5051 tdo_data &T,
5052 int nb_vars, int Nb_vars,
5053 int *&line_types, int &nb_line_types, int eqn_offset)
5054{
5055 int f_v = (verbose_level >= 1);
5056 //int f_vv = (verbose_level >= 2);
5057 int f_vvv = (verbose_level >= 3);
5058 int I, i, r, f, l, j, c, J, a, b, rr, p, u, l2, h, s;
5059
5061
5062 if (f_v) {
5063 cout << "tdo_scheme_synthetic::td3_columns_counting_flags: "
5064 "eqn_offset=" << eqn_offset << endl;
5065 }
5066 // counting flags, a block diagonal system with
5067 // nb_multiple_types * (l2 + 1) equations
5068
5069 for (i = 0; i < T.nb_multiple_types; i++) {
5070 r = T.multiple_types[i];
5071 f = T.types_first[r];
5072 l = T.types_len[r];
5073
5074 for (I = 0; I < l2; I++) {
5075
5076 for (j = 0; j < l; j++) {
5077 c = f + j;
5078 J = T.types_first2[i] + j;
5079 a = line_types[c * nb_vars + I];
5080 T.D2->A[(eqn_offset + i * (l2 + 1) + I) * Nb_vars + J] = a;
5081 }
5084 T.D2->RHS[eqn_offset + i * (l2 + 1) + I] = a * b;
5085
5086 for (h = 0; h < T.nb_only_one_type; h++) {
5087 rr = T.only_one_type[h];
5088 p = col_classes_len[COL_SCHEME][rr];
5089 u = T.types_first[rr];
5090 a = line_types[u * nb_vars + I];
5091 T.D2->RHS[eqn_offset + i * (l2 + 1) + I] -= a * p;
5092
5093 if (T.D2->RHS[eqn_offset + i * (l2 + 1) + I] < 0) {
5094 if (f_v) {
5095 cout << "td3_columns_counting_flags: "
5096 "RHS[nb_eqns_joining + i * (l2 + 1) + I] "
5097 "is negative, no solution for the "
5098 "distribution" << endl;
5099 }
5100 return FALSE;
5101 }
5102 } // next h
5103 } // next I
5104 } // next i
5105
5106
5107 S = 0;
5108 for (i = 0; i < T.nb_multiple_types; i++) {
5109 r = T.multiple_types[i];
5110 f = T.types_first[r];
5111 l = T.types_len[r];
5112
5113 // one extra equation for the sum
5114 for (j = 0; j < l; j++) {
5115 c = f + j;
5116 J = T.types_first2[i] + j;
5117 // counting: extra row of ones
5118 T.D2->A[(eqn_offset + i * (l2 + 1) + l2) * Nb_vars + J] = 1;
5119 }
5120
5122 T.D2->RHS[eqn_offset + i * (l2 + 1) + l2] = s;
5123 S += s;
5124 }
5125 if (f_vvv) {
5126 cout << "tdo_scheme_synthetic::td3_columns_counting_flags, the system is" << endl;
5127 T.D2->print();
5128 }
5129
5130 if (f_v) {
5131 cout << "tdo_scheme_synthetic::td3_columns_counting_flags done" << endl;
5132 }
5133
5134 return TRUE;
5135}
5136
5138 int verbose_level,
5139 int lambda3, int block_size, int lambda2,
5140 tdo_data &T,
5141 int nb_vars, int Nb_vars,
5142 int *&line_types, int &nb_line_types, int eqn_offset)
5143{
5144 int f_v = (verbose_level >= 1);
5145 //int f_vv = (verbose_level >= 2);
5146 int f_vvv = (verbose_level >= 3);
5147 int I1, I2, i, r, f, l, j, c, J, a, b, ab, k, rr, p, u, l2, h;
5149
5151
5152 if (f_v) {
5153 cout << "tdo_scheme_synthetic::td3_columns_lambda2_joining_pairs_from_different_classes "
5154 "eqn_offset=" << eqn_offset << endl;
5155 }
5156 // lambda2: joining pairs from different classes
5157 for (I1 = 0; I1 < l2; I1++) {
5158
5159 for (I2 = I1 + 1; I2 < l2; I2++) {
5160 k = Combi.ij2k(I1, I2, l2);
5161
5162 for (i = 0; i < T.nb_multiple_types; i++) {
5163 r = T.multiple_types[i];
5164 f = T.types_first[r];
5165 l = T.types_len[r];
5166
5167 for (j = 0; j < l; j++) {
5168 c = f + j;
5169 J = T.types_first2[i] + j;
5170 a = line_types[c * nb_vars + I1];
5171 b = line_types[c * nb_vars + I2];
5172 ab = a * b;
5173 // joining pairs from different classes:
5174 T.D2->A[(eqn_offset + k) * Nb_vars + J] = ab;
5175 }
5176 }
5177 a = row_classes_len[ROW_SCHEME][I1];
5178 b = row_classes_len[ROW_SCHEME][I2];
5179 T.D2->RHS[eqn_offset + k] = a * b * lambda2;
5180
5181 for (h = 0; h < T.nb_only_one_type; h++) {
5182 rr = T.only_one_type[h];
5183 p = col_classes_len[COL_SCHEME][rr];
5184 u = T.types_first[rr];
5185 a = line_types[u * nb_vars + I1];
5186 b = line_types[u * nb_vars + I2];
5187 T.D2->RHS[eqn_offset + k] -= a * b * p;
5188
5189 if (T.D2->RHS[eqn_offset + k] < 0) {
5190 if (f_v) {
5191 cout << "td3_columns_lambda2_joining_pairs_"
5192 "from_different_classes: RHS[eqn_offset + k] "
5193 "is negative, no solution for the "
5194 "distribution" << endl;
5195 }
5196 return FALSE;
5197 }
5198 } // next h
5199 }
5200 }
5201 if (f_vvv) {
5202 cout << "td3_columns_lambda2_joining_pairs_from_different_classes, "
5203 "the system is" << endl;
5204 T.D2->print();
5205 }
5206
5207 if (f_v) {
5208 cout << "tdo_scheme_synthetic::td3_columns_lambda2_joining_pairs_from_different_classes done" << endl;
5209 }
5210 return TRUE;
5211}
5212
5214 int verbose_level,
5215 int lambda3, int block_size, int lambda2,
5216 tdo_data &T,
5217 int nb_vars, int Nb_vars,
5218 int *&line_types, int &nb_line_types, int eqn_offset)
5219{
5220 int f_v = (verbose_level >= 1);
5221 //int f_vv = (verbose_level >= 2);
5222 int f_vvv = (verbose_level >= 3);
5223 int I1, I2, i, r, f, l, j, c, J, a, a2, ab, b, k, rr, p, u, l2, h;
5224 int length_first, length_first2, length_second;
5226
5228
5229 if (f_v) {
5230 cout << "tdo_scheme_synthetic::td3_columns_lambda3_joining_triples_2_1: "
5231 "eqn_offset=" << eqn_offset << endl;
5232 }
5233 // lambda3: joining triples with two in the first
5234 // class and one in the second class
5235 for (I1 = 0; I1 < l2; I1++) {
5236 length_first = row_classes_len[ROW_SCHEME][I1];
5237 length_first2 = Combi.binomial2(length_first);
5238
5239 for (I2 = 0; I2 < l2; I2++) {
5240 if (I2 == I1) {
5241 continue;
5242 }
5243
5244 length_second = row_classes_len[ROW_SCHEME][I2];
5245 k = Combi.ordered_pair_rank(I1, I2, l2);
5246
5247 for (i = 0; i < T.nb_multiple_types; i++) {
5248 r = T.multiple_types[i];
5249 f = T.types_first[r];
5250 l = T.types_len[r];
5251
5252 for (j = 0; j < l; j++) {
5253 c = f + j;
5254 J = T.types_first2[i] + j;
5255 a = line_types[c * nb_vars + I1];
5256 b = line_types[c * nb_vars + I2];
5257 ab = Combi.binomial2(a) * b;
5258 T.D2->A[(l2 + k) * Nb_vars + J] = ab;
5259 }
5260 }
5261 T.D2->RHS[l2 + k] = length_first2 * length_second * lambda3;
5262
5263 for (h = 0; h < T.nb_only_one_type; h++) {
5264 rr = T.only_one_type[h];
5265 p = col_classes_len[COL_SCHEME][rr];
5266 u = T.types_first[rr];
5267 a = line_types[u * nb_vars + I1];
5268 a2 = Combi.binomial2(a);
5269 b = line_types[u * nb_vars + I2];
5270 T.D2->RHS[l2 + k] -= a2 * b * p;
5271
5272 if (T.D2->RHS[l2 + k] < 0) {
5273 if (f_v) {
5274 cout << "td3_columns_lambda3_joining_triples_2_1: "
5275 "RHS[l2 + k] is negative, no solution for "
5276 "the distribution" << endl;
5277 }
5278 return FALSE;
5279 }
5280 } // next h
5281 }
5282 }
5283 if (f_vvv) {
5284 cout << "td3_columns_lambda3_joining_triples_2_1, "
5285 "the system is" << endl;
5286 T.D2->print();
5287 }
5288
5289 if (f_v) {
5290 cout << "tdo_scheme_synthetic::td3_columns_lambda3_joining_triples_2_1 done" << endl;
5291 }
5292 return TRUE;
5293}
5294
5296 int verbose_level,
5297 int lambda3, int block_size, int lambda2,
5298 tdo_data &T,
5299 int nb_vars, int Nb_vars,
5300 int *&line_types, int &nb_line_types, int eqn_offset)
5301{
5302 int f_v = (verbose_level >= 1);
5303 //int f_vv = (verbose_level >= 2);
5304 int f_vvv = (verbose_level >= 3);
5305 int I1, I2, I3, i, r, f, l, j, c, J, a, b, k, rr, p, u, l2, h, g;
5306 int length_first, length_second, length_third;
5308
5310
5311 if (f_v) {
5312 cout << "tdo_scheme_synthetic::td3_columns_lambda3_joining_triples_1_1_1 "
5313 "eqn_offset=" << eqn_offset << endl;
5314 }
5315 // lambda3: joining triples with all in different classes
5316 for (I1 = 0; I1 < l2; I1++) {
5317 length_first = row_classes_len[ROW_SCHEME][I1];
5318
5319 for (I2 = I1 + 1; I2 < l2; I2++) {
5320 length_second = row_classes_len[ROW_SCHEME][I2];
5321
5322 for (I3 = I2 + 1; I3 < l2; I3++) {
5323 length_third = row_classes_len[ROW_SCHEME][I3];
5324
5325 k = Combi.ijk_rank(I1, I2, I3, l2);
5326 for (i = 0; i < T.nb_multiple_types; i++) {
5327 r = T.multiple_types[i];
5328 f = T.types_first[r];
5329 l = T.types_len[r];
5330 for (j = 0; j < l; j++) {
5331 c = f + j;
5332 J = T.types_first2[i] + j;
5333 a = line_types[c * nb_vars + I1];
5334 b = line_types[c * nb_vars + I2];
5335 g = line_types[c * nb_vars + I3];
5336 T.D2->A[(l2 + l2 * (l2 - 1) + k) *
5337 Nb_vars + J] = a * b * g;
5338 }
5339 }
5340 T.D2->RHS[l2 + l2 * (l2 - 1) + k] = length_first *
5341 length_second * length_third * lambda3;
5342 for (h = 0; h < T.nb_only_one_type; h++) {
5343 rr = T.only_one_type[h];
5344 p = col_classes_len[COL_SCHEME][rr];
5345 u = T.types_first[rr];
5346 a = line_types[u * nb_vars + I1];
5347 b = line_types[u * nb_vars + I2];
5348 g = line_types[u * nb_vars + I3];
5349 T.D2->RHS[l2 + l2 * (l2 - 1) + k] -= a * b * g * p;
5350 if (T.D2->RHS[l2 + l2 * (l2 - 1) + k] < 0) {
5351 if (f_v) {
5352 cout << "td3_columns_lambda3_joining_triples_"
5353 "1_1_1: RHS[l2 + l2 * (l2 - 1) + k] is "
5354 "negative, no solution for the "
5355 "distribution" << endl;
5356 }
5357 return FALSE;
5358 }
5359 } // next h
5360 }
5361 }
5362 }
5363 if (f_vvv) {
5364 cout << "td3_columns_lambda3_joining_triples_1_1_1, "
5365 "the system is" << endl;
5366 T.D2->print();
5367 }
5368 if (f_v) {
5369 cout << "tdo_scheme_synthetic::td3_columns_lambda3_joining_triples_1_1_1 done" << endl;
5370 }
5371
5372 return TRUE;
5373}
5374
5375
5376}}}
5377
a class related to the class tdo_scheme
void solve_second_system_with_help(int verbose_level, int f_use_mckay_solver, int f_once, int *classes_len, int f_scale, int scaling, int *&line_types, int &nb_line_types, int *&distributions, int &nb_distributions, int cnt_second_system, solution_file_data *Sol)
Definition: tdo_data.cpp:373
void solve_second_system(int verbose_level, int f_use_mckay_solver, int f_once, int *classes_len, int f_scale, int scaling, int *&line_types, int &nb_line_types, int *&distributions, int &nb_distributions)
Definition: tdo_data.cpp:483
int solve_first_system(int verbose_level, int *&line_types, int &nb_line_types, int &line_types_allocated)
Definition: tdo_data.cpp:93
void solve_second_system_omit(int verbose_level, int *classes_len, int *&line_types, int &nb_line_types, int *&distributions, int &nb_distributions, int omit)
Definition: tdo_data.cpp:150
int geometric_test_for_row_scheme(data_structures::partitionstack &P, int *point_types, int nb_point_types, int point_type_len, int *distributions, int nb_distributions, int f_omit1, int omit1, int verbose_level)
int td3_columns_setup_first_system(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int r, data_structures::partitionstack &P, int &nb_vars, int &nb_eqns, int *&line_types, int &nb_line_types)
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 tdo_rows_setup_second_system_eqns_joining(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int f_dual_is_linear_space, int *point_types, int nb_point_types, int eqn_offset)
int td3_rows_counting_flags(int verbose_level, int lambda3, int block_size, int lambda2, int &S, tdo_data &T, int nb_vars, int Nb_vars, int *&point_types, int &nb_point_types, int eqn_offset)
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 td3_columns_counting_flags(int verbose_level, int lambda3, int block_size, int lambda2, int &S, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
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)
int tdo_columns_setup_second_system_eqns_upper_bound(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int *line_types, int nb_line_types, int eqn_start, int &nb_eqns_used)
void tdo_columns_setup_second_system_eqns_counting(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int *line_types, int nb_line_types, int eqn_start)
int refine_cols_hard(data_structures::partitionstack &P, int verbose_level, int f_once, 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 row_refinement_L1_L2(data_structures::partitionstack &P, int f_omit, int omit, int &L1, int &L2, int verbose_level)
void get_column_split_partition(int verbose_level, data_structures::partitionstack &P)
int tdo_columns_setup_second_system_eqns_joining(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int *line_types, int nb_line_types, int eqn_start)
int td3_rows_setup_second_system(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int nb_vars, int &Nb_vars, int &Nb_eqns, int *&point_types, int &nb_point_types)
void column_refinement_L1_L2(data_structures::partitionstack &P, int f_omit, int omit, int &L1, int &L2, int verbose_level)
void print_scheme_tex_fancy(std::ostream &ost, int h, int f_label, std::string &label)
int td3_columns_setup_second_system(int verbose_level, int lambda3, int block_size, int lambda2, int f_scale, int scaling, tdo_data &T, int nb_vars, int &Nb_vars, int &Nb_eqns, int *&line_types, int &nb_line_types)
void get_row_split_partition(int verbose_level, data_structures::partitionstack &P)
int geometric_test_for_row_scheme_level_s(data_structures::partitionstack &P, int s, int *point_types, int nb_point_types, int point_type_len, int *distribution, int *non_zero_blocks, int nb_non_zero_blocks, int f_omit1, int omit1, int verbose_level)
int td3_rows_setup_first_system(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int r, data_structures::partitionstack &P, int &nb_vars, int &nb_eqns, int *&point_types, int &nb_point_types)
int refine_rows_hard(data_structures::partitionstack &P, int verbose_level, int f_use_mckay, int f_once, int *&point_types, int &nb_point_types, int &point_type_len, int *&distributions, int &nb_distributions, int &cnt_second_system, int f_omit1, int omit1, int f_omit, int omit, int f_use_packing_numbers, int f_dual_is_linear_space)
void init_TDO(int *Part, int *Entries, int Row_level, int Col_level, int Extra_row_level, int Extra_col_level, int Lambda_level, int verbose_level)
int td3_columns_triples_same_class(int verbose_level, int lambda3, int block_size, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
int tdo_rows_setup_first_system(int verbose_level, tdo_data &T, int r, data_structures::partitionstack &P, int f_omit, int omit, int *&point_types, int &nb_point_types)
int tdo_rows_setup_second_system(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int f_use_packing_numbers, int f_dual_is_linear_space, int *&point_types, int &nb_point_types)
int td3_columns_lambda3_joining_triples_2_1(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
int td3_columns_lambda3_joining_triples_1_1_1(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
int refine_rows_easy(int verbose_level, int *&point_types, int &nb_point_types, int &point_type_len, int *&distributions, int &nb_distributions, int &cnt_second_system)
void init_part_and_entries_int(int *part, int *entries, int verbose_level)
int tdo_columns_setup_first_system(int verbose_level, tdo_data &T, int r, data_structures::partitionstack &P, int f_omit, int omit, int *&line_types, int &nb_line_types)
int tdo_rows_setup_second_system_eqns_packing(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int *point_types, int nb_point_types, int eqn_start, int &nb_eqns_used)
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)
int tdo_columns_setup_second_system(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int f_use_packing_numbers, int *&line_types, int &nb_line_types)
void init_part_and_entries(int *part, int *entries, int verbose_level)
int tdo_rows_setup_second_system_eqns_counting(int verbose_level, tdo_data &T, data_structures::partitionstack &P, int f_omit, int omit, int *point_types, int nb_point_types, int eqn_offset)
void compute_whether_first_inc_must_be_moved(int *f_first_inc_must_be_moved, int verbose_level)
int td3_columns_lambda2_joining_pairs_from_different_classes(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
int td3_columns_pairs_same_class(int verbose_level, int lambda3, int block_size, int lambda2, tdo_data &T, int nb_vars, int Nb_vars, int *&line_types, int &nb_line_types, int eqn_offset)
void set_print(std::ostream &ost, int *v, int len)
Definition: int_vec.cpp:1043
data structure for set partitions following Jeffrey Leon
void get_row_and_col_classes(int *row_classes, int &nb_row_classes, int *col_classes, int &nb_col_classes, int verbose_level)
various functions related to geometries
Definition: geometry.h:721
diophantine systems of equations (i.e., linear systems over the integers)
Definition: solvers.h:209
void write_xml(std::ostream &ost, const char *label)
Definition: diophant.cpp:3682
void eliminate_zero_rows_quick(int verbose_level)
Definition: diophant.cpp:3277
#define LAMBDA_SCHEME
#define NUMBER_OF_SCHEMES
#define EXTRA_ROW_SCHEME
#define EXTRA_COL_SCHEME
#define COL_SCHEME
#define ROW_SCHEME
#define MINIMUM(x, y)
Definition: foundations.h:216
#define FREE_int(p)
Definition: foundations.h:640
#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 Int_vec_print(A, B, C)
Definition: foundations.h:685
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects