Orbiter 2022
Combinatorial Objects
orthogonal_io.cpp
Go to the documentation of this file.
1/*
2 * orthogonal_io.cpp
3 *
4 * Created on: Oct 31, 2019
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11using namespace std;
12
13
14namespace orbiter {
15namespace layer1_foundations {
16namespace orthogonal_geometry {
17
18
19void orthogonal::list_points_by_type(int verbose_level)
20{
21 int t;
22
23 for (t = 1; t <= nb_point_classes; t++) {
24 list_points_of_given_type(t, verbose_level);
25 }
26}
27
28void orthogonal::report_points_by_type(std::ostream &ost, int verbose_level)
29{
30 int t;
31
32 for (t = 1; t <= nb_point_classes; t++) {
33 report_points_of_given_type(ost, t, verbose_level);
34 }
35}
36
37void orthogonal::list_points_of_given_type(int t, int verbose_level)
38{
39 long int i, j, rk, u;
40
41 cout << "points of type P" << t << ":" << endl;
42 for (i = 0; i < P[t - 1]; i++) {
43 rk = type_and_index_to_point_rk(t, i, verbose_level);
44 cout << i << " : " << rk << " : ";
45 unrank_point(v1, 1, rk, verbose_level - 1);
46 Int_vec_print(cout, v1, n);
47 point_rk_to_type_and_index(rk, u, j, verbose_level);
48 cout << " : " << u << " : " << j << endl;
49 if (u != t) {
50 cout << "type wrong" << endl;
51 exit(1);
52 }
53 if (j != i) {
54 cout << "index wrong" << endl;
55 exit(1);
56 }
57 }
58 cout << endl;
59}
60
61void orthogonal::report_points_of_given_type(std::ostream &ost, int t, int verbose_level)
62{
63 long int i, j, rk, u;
64
65 ost << "points of type P" << t << ":\\\\" << endl;
66 for (i = 0; i < P[t - 1]; i++) {
67 rk = type_and_index_to_point_rk(t, i, verbose_level);
68 ost << i << " : " << rk << " : ";
69 unrank_point(v1, 1, rk, verbose_level - 1);
70 Int_vec_print(ost, v1, n);
71 ost << "\\\\" << endl;
72 point_rk_to_type_and_index(rk, u, j, verbose_level);
73 //ost << " : " << u << " : " << j << endl;
74 if (u != t) {
75 cout << "type wrong" << endl;
76 exit(1);
77 }
78 if (j != i) {
79 cout << "index wrong" << endl;
80 exit(1);
81 }
82 }
83 //ost << endl;
84}
85
86void orthogonal::report_points(std::ostream &ost, int verbose_level)
87{
88 long int rk;
89
90 ost << "The number of points is " << nb_points << "\\\\" << endl;
91 if (nb_points < 3000) {
92 ost << "points:\\\\" << endl;
93 for (rk = 0; rk < nb_points; rk++) {
94 unrank_point(v1, 1, rk, 0 /*verbose_level*/);
95 ost << "$P_{" << rk << "} = ";
96 Int_vec_print(ost, v1, n);
97 ost << "$\\\\" << endl;
98 }
99 }
100 else {
101 ost << "Too many points to print.\\\\" << endl;
102 }
103 //ost << endl;
104}
105
106void orthogonal::report_lines(std::ostream &ost, int verbose_level)
107{
108 int len;
109 int i, a, d = n + 1;
110 long int p1, p2;
113
114 ost << "The number of lines is " << nb_lines << "\\\\" << endl;
115
116 if (nb_lines < 1000) {
117
118 len = nb_lines; // O.L[0] + O.L[1] + O.L[2];
119
120
121 long int *Line;
122 int *L;
123
124 Line = NEW_lint(q + 1);
125 L = NEW_int(2 * d);
126
127 for (i = 0; i < len; i++) {
128 ost << "$L_{" << i << "} = ";
129 unrank_line(p1, p2, i, 0 /* verbose_level - 1*/);
130 //cout << "(" << p1 << "," << p2 << ") : ";
131
132 unrank_point(v1, 1, p1, 0);
133 unrank_point(v2, 1, p2, 0);
134
135 Int_vec_copy(v1, L, d);
136 Int_vec_copy(v2, L + d, d);
137
138 ost << "\\left[" << endl;
139 Li.print_integer_matrix_tex(ost, L, 2, d);
140 ost << "\\right]" << endl;
141
143 if (a) {
144 cout << "not orthogonal" << endl;
145 exit(1);
146 }
147
148 #if 0
149 cout << " & ";
150 j = O.rank_line(p1, p2, 0 /*verbose_level - 1*/);
151 if (i != j) {
152 cout << "error: i != j" << endl;
153 exit(1);
154 }
155 #endif
156
157 #if 1
158
159 points_on_line(p1, p2, Line, 0 /*verbose_level - 1*/);
160 Sorting.lint_vec_heapsort(Line, q + 1);
161
162 Li.lint_set_print_masked_tex(ost, Line, q + 1, "P_{", "}");
163 ost << "$\\\\" << endl;
164 #if 0
165 for (r1 = 0; r1 <= q; r1++) {
166 for (r2 = 0; r2 <= q; r2++) {
167 if (r1 == r2)
168 continue;
169 //p3 = p1;
170 //p4 = p2;
171 p3 = O.line1[r1];
172 p4 = O.line1[r2];
173 cout << p3 << "," << p4 << " : ";
174 j = O.rank_line(p3, p4, verbose_level - 1);
175 cout << " : " << j << endl;
176 if (i != j) {
177 cout << "error: i != j" << endl;
178 exit(1);
179 }
180 }
181 }
182 cout << endl;
183 #endif
184 #endif
185 }
186 FREE_lint(Line);
187 FREE_int(L);
188 }
189 else {
190 //ost << "Too many lines to print. \\\\" << endl;
191 }
192}
194{
195 int t1, t2;
196
197 for (t1 = 1; t1 <= nb_point_classes; t1++) {
198 for (t2 = 1; t2 <= nb_point_classes; t2++) {
199 list_points_vs_points(t1, t2, verbose_level);
200 }
201 }
202}
203
204void orthogonal::list_points_vs_points(int t1, int t2, int verbose_level)
205{
206 int i, j, rk1, rk2, u, cnt;
207
208 cout << "lines between points of type P" << t1
209 << " and points of type P" << t2 << endl;
210 for (i = 0; i < P[t1 - 1]; i++) {
211 rk1 = type_and_index_to_point_rk(t1, i, verbose_level);
212 cout << i << " : " << rk1 << " : ";
213 unrank_point(v1, 1, rk1, verbose_level - 1);
214 Int_vec_print(cout, v1, n);
215 cout << endl;
216 cout << "is incident with:" << endl;
217
218 cnt = 0;
219
220 for (j = 0; j < P[t2 - 1]; j++) {
221 rk2 = type_and_index_to_point_rk(t2, j, verbose_level);
222 unrank_point(v2, 1, rk2, verbose_level - 1);
223
224 //cout << "testing: " << j << " : " << rk2 << " : ";
225 //int_vec_print(cout, v2, n);
226 //cout << endl;
227
229 if (u == 0 && rk2 != rk1) {
230 //cout << "yes" << endl;
232 cout << cnt << " : " << j << " : " << rk2 << " : ";
233 Int_vec_print(cout, v2, n);
234 cout << endl;
235 cnt++;
236 }
237 }
238 }
239 cout << endl;
240 }
241
242}
243
244
246{
247 int i, j;
248
249
250 cout << " ";
251 for (j = 0; j < nb_line_classes; j++) {
252 cout << setw(7) << L[j];
253 }
254 cout << endl;
255 for (i = 0; i < nb_point_classes; i++) {
256 cout << setw(7) << P[i];
257 for (j = 0; j < nb_line_classes; j++) {
258 cout << setw(7) << A[i * nb_line_classes + j];
259 }
260 cout << endl;
261 }
262 cout << endl;
263 cout << " ";
264 for (j = 0; j < nb_line_classes; j++) {
265 cout << setw(7) << L[j];
266 }
267 cout << endl;
268 for (i = 0; i < nb_point_classes; i++) {
269 cout << setw(7) << P[i];
270 for (j = 0; j < nb_line_classes; j++) {
271 cout << setw(7) << B[i * nb_line_classes + j];
272 }
273 cout << endl;
274 }
275 cout << endl;
276
277}
278
279void orthogonal::report_quadratic_form(std::ostream &ost, int verbose_level)
280{
281 int f_v = (verbose_level >= 1);
282
283 if (f_v) {
284 cout << "orthogonal::report_quadratic_form" << endl;
285 }
286
287 ost << "The quadratic form is: " << endl;
288 ost << "$$" << endl;
290 ost << " = 0";
291 ost << "$$" << endl;
292
293 if (f_v) {
294 cout << "orthogonal::report_quadratic_form done" << endl;
295 }
296
297}
298
299
300void orthogonal::report(std::ostream &ost, int verbose_level)
301{
302 int f_v = (verbose_level >= 1);
303
304 if (f_v) {
305 cout << "orthogonal::report" << endl;
306 }
307
308 report_quadratic_form(ost, verbose_level);
309
310
311 if (f_v) {
312 cout << "orthogonal::report before report_schemes_easy" << endl;
313 }
314
316
317 if (f_v) {
318 cout << "orthogonal::report after report_schemes_easy" << endl;
319 }
320
321#if 0
322 if (f_v) {
323 cout << "orthogonal::report before report_schemes" << endl;
324 }
325
326 report_schemes(ost, verbose_level);
327
328 if (f_v) {
329 cout << "orthogonal::report after report_schemes" << endl;
330 }
331#endif
332
333 if (f_v) {
334 cout << "orthogonal::report before report_points" << endl;
335 }
336
337 report_points(ost, verbose_level);
338
339 if (f_v) {
340 cout << "orthogonal::report after report_points" << endl;
341 }
342
343
344 //report_points_by_type(ost, verbose_level);
345
346 if (f_v) {
347 cout << "orthogonal::report before report_lines" << endl;
348 }
349
350
351 report_lines(ost, verbose_level);
352
353 if (f_v) {
354 cout << "orthogonal::report after report_lines" << endl;
355 }
356
357
358 if (f_v) {
359 cout << "orthogonal::report done" << endl;
360 }
361}
362
363void orthogonal::report_schemes(std::ostream &ost, int verbose_level)
364{
365 int f_v = (verbose_level >= 1);
366 int i, j;
367 int f, l;
368 int nb_rows = 0;
369 int nb_cols = 0;
371 int *set;
372 int *row_classes;
373 int *col_classes;
374 int *row_scheme;
375 int *col_scheme;
376
377 if (f_v) {
378 cout << "orthogonal::report_schemes" << endl;
379 }
380
381
382 if (nb_points < 10000 && nb_lines < 1000) {
384
385
386 if (f_v) {
387 cout << "orthogonal::report_schemes nb_points=" << nb_points << endl;
388 cout << "orthogonal::report_schemes nb_lines=" << nb_lines << endl;
389 }
390
391 if (f_v) {
392 cout << "orthogonal::report_schemes before Stack->allocate_with_two_classes" << endl;
393 }
394
395 Stack->allocate_with_two_classes(nb_points + nb_lines, nb_points, nb_lines, 0 /* verbose_level */);
396
397 if (f_v) {
398 cout << "orthogonal::report_schemes after Stack->allocate_with_two_classes" << endl;
399 }
400 #if 0
401 row_classes = NEW_int(nb_point_classes);
402 for (i = 0; i < nb_point_classes; i++) {
403 row_classes[i] = P[i];
404 }
405 col_classes = NEW_int(nb_line_classes);
406 for (i = 0; i < nb_line_classes; i++) {
407 col_classes[i] = L[i];
408 }
409 #endif
410
411 int *original_row_class;
412 int *original_col_class;
413
414 original_row_class = NEW_int(nb_point_classes);
415 original_col_class = NEW_int(nb_line_classes);
416 nb_rows = 0;
417 for (i = 0; i < nb_point_classes; i++) {
418 if (P[i]) {
419 original_row_class[nb_rows] = i;
420 nb_rows++;
421 }
422 }
423 nb_cols = 0;
424 for (i = 0; i < nb_line_classes; i++) {
425 if (L[i]) {
426 original_col_class[nb_cols] = i;
427 nb_cols++;
428 }
429 }
430 row_scheme = NEW_int(nb_rows * nb_cols);
431 for (i = 0; i < nb_rows; i++) {
432 for (j = 0; j < nb_cols; j++) {
433 row_scheme[i * nb_cols + j] = A[original_row_class[i] * nb_line_classes + original_col_class[j]];
434 }
435 }
436 col_scheme = NEW_int(nb_rows * nb_cols);
437 for (i = 0; i < nb_rows; i++) {
438 for (j = 0; j < nb_cols; j++) {
439 col_scheme[i * nb_cols + j] = B[original_row_class[i] * nb_line_classes + original_col_class[j]];
440 }
441 }
442 set = NEW_int(nb_points);
443 f = 0;
444 for (i = 0; i < nb_rows - 1; i++) {
445 l = P[original_row_class[i]];
446 if (l == 0) {
447 cout << "l == 0" << endl;
448 exit(1);
449 }
450 for (j = 0; j < l; j++) {
451 set[j] = f + j;
452 }
453 if (f_v) {
454 cout << "orthogonal::report_schemes before Stack->split_cell_front_or_back for points" << endl;
455 }
456 Stack->split_cell_front_or_back(set, l, TRUE /* f_front */, 0 /*verbose_level*/);
457 f += l;
458 }
459 FREE_int(set);
460
461
462 set = NEW_int(nb_lines);
463 f = nb_points;
464 for (i = 0; i < nb_cols - 1; i++) {
465 l = L[original_col_class[i]];
466 if (l == 0) {
467 cout << "l == 0" << endl;
468 exit(1);
469 }
470 for (j = 0; j < l; j++) {
471 set[j] = f + j;
472 }
473 if (f_v) {
474 cout << "orthogonal::report_schemes before Stack->split_cell_front_or_back for lines" << endl;
475 }
476 Stack->split_cell_front_or_back(set, l, TRUE /* f_front */, 0 /*verbose_level*/);
477 f += l;
478 }
479 FREE_int(set);
480
481
482 int nb_row_classes;
483 int nb_col_classes;
484
485 row_classes = NEW_int(Stack->ht);
486 col_classes = NEW_int(Stack->ht);
487
488 if (f_v) {
489 cout << "orthogonal::report_schemes before Stack->get_row_and_col_classes" << endl;
490 }
492 row_classes, nb_row_classes,
493 col_classes, nb_col_classes, 0 /* verbose_level*/);
494
495 if (f_v) {
496 cout << "orthogonal::report_schemes before Stack->print_row_tactical_decomposition_scheme_tex" << endl;
497 }
498 Stack->print_row_tactical_decomposition_scheme_tex(ost, TRUE /*f_enter_math*/,
499 row_classes, nb_row_classes,
500 col_classes, nb_col_classes,
501 row_scheme, FALSE /* f_print_subscripts */);
502
503 if (f_v) {
504 cout << "orthogonal::report_schemes before Stack->print_column_tactical_decomposition_scheme_tex" << endl;
505 }
506 Stack->print_column_tactical_decomposition_scheme_tex(ost, TRUE /*f_enter_math*/,
507 row_classes, nb_row_classes,
508 col_classes, nb_col_classes,
509 col_scheme, FALSE /* f_print_subscripts */);
510
511 FREE_int(row_classes);
512 FREE_int(col_classes);
513 FREE_int(row_scheme);
514 FREE_int(col_scheme);
515
516 FREE_int(original_row_class);
517 FREE_int(original_col_class);
518
519
520 FREE_OBJECT(Stack);
521 }
522 if (f_v) {
523 cout << "orthogonal::report_schemes done" << endl;
524 }
525}
526
527
528void orthogonal::report_schemes_easy(std::ostream &ost)
529{
531
533 ost, TRUE /* f_enter_math_mode */,
536 A);
537
539 ost, TRUE /* f_enter_math_mode */,
542 B);
543
544}
545
546void orthogonal::create_latex_report(int verbose_level)
547{
548 int f_v = (verbose_level >= 1);
549
550
551 if (f_v) {
552 cout << "orthogonal::create_latex_report" << endl;
553 }
554
555 {
556 char str[1000];
557 string fname;
558 char title[1000];
559 char author[1000];
560
561 snprintf(str, 1000, "O_%d_%d_%d.tex", epsilon, n, F->q);
562 fname.assign(str);
563 snprintf(title, 1000, "Orthogonal Space ${\\rm O}(%d,%d,%d)$", epsilon, n, F->q);
564 //strcpy(author, "");
565 author[0] = 0;
566
567
568 {
569 ofstream ost(fname);
571
572 L.head(ost,
573 FALSE /* f_book*/,
574 TRUE /* f_title */,
575 title, author,
576 FALSE /* f_toc */,
577 FALSE /* f_landscape */,
578 TRUE /* f_12pt */,
579 TRUE /* f_enlarged_page */,
580 TRUE /* f_pagenumbers */,
581 NULL /* extra_praeamble */);
582
583
584 if (f_v) {
585 cout << "orthogonal::create_latex_report before report" << endl;
586 }
587 report(ost, verbose_level);
588 if (f_v) {
589 cout << "orthogonal::create_latex_report after report" << endl;
590 }
591
592
593 L.foot(ost);
594
595 }
597
598 cout << "written file " << fname << " of size "
599 << Fio.file_size(fname) << endl;
600 }
601
602 if (f_v) {
603 cout << "orthogonal::create_latex_report done" << endl;
604 }
605}
606
608{
609 int f_v = (verbose_level >= 1);
610
611 if (f_v) {
612 cout << "orthogonal::export_incidence_matrix_to_csv" << endl;
613 }
614
615
616 int N_points = nb_points;
617 int N_lines = nb_lines;
618
619 long int *line;
620
621 long int i, line_rk, h;
622 int *T;
624
625 line = NEW_lint(q + 1);
626 T = NEW_int(N_points * N_lines);
627 Int_vec_zero(T, N_points * N_lines);
628
629 for (line_rk = 0; line_rk < N_lines; line_rk++) {
630
631
633 line, verbose_level);
634
635 for (h = 0; h < q + 1; h++) {
636 i = line[h];
637 T[i * N_lines + line_rk] = 1;
638 }
639 }
640 string fname;
641
643
644 Fio.int_matrix_write_csv(fname, T, N_points, N_lines);
645
646 if (f_v) {
647 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
648 }
649
650 FREE_int(T);
651 FREE_lint(line);
652
653 if (f_v) {
654 cout << "orthogonal::export_incidence_matrix_to_csv done" << endl;
655 }
656}
657
659{
660 fname.assign(label_txt);
661 fname.append("_incidence_matrix.csv");
662}
663
664
665
666}}}
667
668
669
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)
void split_cell_front_or_back(int *set, int set_size, int f_front, int verbose_level)
void print_row_tactical_decomposition_scheme_tex(std::ostream &ost, int f_enter_math_mode, int *row_classes, int nb_row_classes, int *col_classes, int nb_col_classes, int *row_scheme, int f_print_subscripts)
void print_column_tactical_decomposition_scheme_tex(std::ostream &ost, int f_enter_math_mode, int *row_classes, int nb_row_classes, int *col_classes, int nb_col_classes, int *col_scheme, int f_print_subscripts)
void allocate_with_two_classes(int n, int v, int b, int verbose_level)
a collection of functions related to sorted vectors
void int_matrix_write_csv(std::string &fname, int *M, int m, int n)
Definition: file_io.cpp:1300
void print_row_tactical_decomposition_scheme_tex(std::ostream &ost, int f_enter_math_mode, long int *row_class_size, int nb_row_classes, long int *col_class_size, int nb_col_classes, long int *row_scheme)
void print_column_tactical_decomposition_scheme_tex(std::ostream &ost, int f_enter_math_mode, long int *row_class_size, int nb_row_classes, long int *col_class_size, int nb_col_classes, long int *col_scheme)
void lint_set_print_masked_tex(std::ostream &ost, long int *v, int len, const char *mask_begin, const char *mask_end)
void print_integer_matrix_tex(std::ostream &ost, int *p, int m, int n)
void points_on_line_by_line_rank(long int line_rk, long int *line, int verbose_level)
void report_schemes(std::ostream &ost, int verbose_level)
void list_points_vs_points(int t1, int t2, int verbose_level)
void unrank_point(int *v, int stride, long int rk, int verbose_level)
void report(std::ostream &ost, int verbose_level)
void report_points_of_given_type(std::ostream &ost, int t, int verbose_level)
void report_points(std::ostream &ost, int verbose_level)
ring_theory::homogeneous_polynomial_domain * Poly
Definition: orthogonal.h:204
void unrank_line(long int &p1, long int &p2, long int index, int verbose_level)
void point_rk_to_type_and_index(long int rk, long int &type, long int &index, int verbose_level)
long int type_and_index_to_point_rk(long int type, long int index, int verbose_level)
void points_on_line(long int pi, long int pj, long int *line, int verbose_level)
void report_quadratic_form(std::ostream &ost, int verbose_level)
void report_points_by_type(std::ostream &ost, int verbose_level)
void report_lines(std::ostream &ost, int verbose_level)
#define FREE_int(p)
Definition: foundations.h:640
#define Int_vec_zero(A, B)
Definition: foundations.h:713
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define Int_vec_copy(A, B, C)
Definition: foundations.h:693
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects