Orbiter 2022
Combinatorial Objects
poset_classification_export_source_code.cpp
Go to the documentation of this file.
1/*
2 * poset_classification_export_source_code.cpp
3 *
4 * Created on: Nov 10, 2019
5 * Author: anton
6 */
7
8
9
11#include "discreta/discreta.h"
14
15using namespace std;
16
17namespace orbiter {
18namespace layer4_classification {
19namespace poset_classification {
20
21
22
23void poset_classification::generate_source_code(
24 int level, int verbose_level)
25{
26 int f_v = (verbose_level >= 1);
27 int f_vv = (verbose_level >= 2);
28 string my_prefix;
29 string fname;
30 char str[1000];
31 int iso_type;
32 long int *rep;
33 int i, j;
34 int nb_iso;
35 long int *set;
38
39 if (f_v) {
40 cout << "poset_classification::generate_source_code" << endl;
41 }
42
43 my_prefix.assign(Control->problem_label);
44 sprintf(str, "_level_%d", level);
45 my_prefix.append(str);
46
47 fname.assign(my_prefix);
48 fname.append(".cpp");
49
50 set = NEW_lint(level);
51 nb_iso = nb_orbits_at_level(level);
52
53
54
55
56 {
57 ofstream fp(fname);
58
59 fp << "static long int " << Control->problem_label << "_nb_reps = " << nb_iso << ";" << endl;
60 fp << "static long int " << Control->problem_label << "_size = " << level << ";" << endl;
61 fp << "static long int " << Control->problem_label << "_reps[] = {" << endl;
62 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
63 get_set_by_level(level, iso_type, set);
64 rep = set;
65 fp << "\t";
66 for (i = 0; i < level; i++) {
67 fp << rep[i];
68 fp << ", ";
69 }
70 fp << endl;
71 }
72 fp << "};" << endl;
73 fp << "static const char *" << Control->problem_label << "_stab_order[] = {" << endl;
74 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
75 //rep = The_surface[iso_type]->coeff;
76
78
79 SaS = get_set_and_stabilizer(level, iso_type,
80 0 /* verbose_level */);
81 fp << "\t\"";
82
84 fp << "\"," << endl;
85
86 FREE_OBJECT(SaS);
87 }
88 fp << "};" << endl;
89
90
91 fp << "static int " << Control->problem_label << "_make_element_size = "
92 << Poset->A->make_element_size << ";" << endl;
93
94 {
95 int *stab_gens_first;
96 int *stab_gens_len;
97 int fst;
98
99 stab_gens_first = NEW_int(nb_iso);
100 stab_gens_len = NEW_int(nb_iso);
101 fst = 0;
102 fp << "static int " << Control->problem_label << "_stab_gens[] = {" << endl;
103 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
104
105
107
108
109 SaS = get_set_and_stabilizer(level,
110 iso_type, 0 /* verbose_level */);
111
112 stab_gens_first[iso_type] = fst;
113 stab_gens_len[iso_type] = SaS->Strong_gens->gens->len;
114 fst += stab_gens_len[iso_type];
115
116
117 for (j = 0; j < stab_gens_len[iso_type]; j++) {
118 if (f_vv) {
119 cout << "poset_classification::generate_source_code "
120 "before extract_strong_generators_in_order "
121 "poset_classification "
122 << j << " / " << stab_gens_len[iso_type] << endl;
123 }
124 fp << "\t";
126 SaS->Strong_gens->gens->ith(j), fp);
127 fp << endl;
128 }
129
130 FREE_OBJECT(SaS);
131
132 }
133 fp << "};" << endl;
134
135
136 fp << "static long int " << Control->problem_label << "_stab_gens_fst[] = { ";
137 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
138 fp << stab_gens_first[iso_type];
139 if (iso_type < nb_iso - 1) {
140 fp << ", ";
141 }
142 if (((iso_type + 1) % 10) == 0) {
143 fp << endl << "\t";
144 }
145 }
146 fp << "};" << endl;
147
148 fp << "static long int " << Control->problem_label << "_stab_gens_len[] = { ";
149 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
150 fp << stab_gens_len[iso_type];
151 if (iso_type < nb_iso - 1) {
152 fp << ", ";
153 }
154 if (((iso_type + 1) % 10) == 0) {
155 fp << endl << "\t";
156 }
157 }
158 fp << "};" << endl;
159
160
161
162
163 FREE_int(stab_gens_first);
164 FREE_int(stab_gens_len);
165 }
166 }
167
168 FREE_lint(set);
169
170 cout << "written file " << fname << " of size "
171 << Fio.file_size(fname) << endl;
172 if (f_v) {
173 cout << "poset_classification::generate_source_code done" << endl;
174 }
175}
176
177void poset_classification::generate_history(int level, int verbose_level)
178{
179 int f_v = (verbose_level >= 1);
180 int f_vv = (verbose_level >= 2);
181 string my_prefix;
182 string fname;
183 char str[1000];
184 int iso_type;
185 long int *rep;
186 int i, j;
187 int nb_iso;
188 long int *set;
189 int *Elt;
192
193 if (f_v) {
194 cout << "poset_classification::generate_history" << endl;
195 }
196
197 my_prefix.assign(Control->problem_label);
198 sprintf(str, "_history_level_%d", level);
199 my_prefix.append(str);
200
201 fname.assign(my_prefix);
202 fname.append(".cpp");
203
204
205
206 set = NEW_lint(level);
207 Elt = NEW_int(Poset->A->elt_size_in_int);
208
209
210
211 {
212 ofstream fp(fname);
213 int lvl;
214
215 fp << "static int " << problem_label << "_make_element_size = "
216 << Poset->A->make_element_size << ";" << endl;
217
218
219 for (lvl = 0; lvl <= level; lvl++) {
220
221 cout << "poset_classification::generate_history lvl = " << lvl << " / " << level << endl;
222 nb_iso = nb_orbits_at_level(lvl);
223
224 fp << "// level " << lvl << ":" << endl;
225 fp << "static long int " << problem_label << "_lvl_" << lvl << "_nb_reps = " << nb_iso << ";" << endl;
226 fp << "static long int " << problem_label << "_lvl_" << lvl << "_size = " << level << ";" << endl;
227 fp << "static long int " << problem_label << "_lvl_" << lvl << "_reps[] = {" << endl;
228 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
229 get_set_by_level(lvl, iso_type, set);
230 rep = set;
231 fp << "\t";
232 for (i = 0; i < lvl; i++) {
233 fp << rep[i];
234 fp << ",";
235 }
236 fp << endl;
237 }
238 fp << "};" << endl;
239
240
241 int f_progress = FALSE;
242 long int L = 0;
243 long int L100 = 0;
244
245 if (nb_iso > ONE_MILLION) {
246 f_progress = TRUE;
247 L = nb_iso;
248 L100 = L / 100 + 1;
249 }
250 fp << "static const char *" << problem_label << "_lvl_" << lvl << "_stab_order[] = {" << endl << "\t";
251 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
252 //rep = The_surface[iso_type]->coeff;
253
254
255 if (test_if_stabilizer_is_trivial(lvl, iso_type,
256 0 /* verbose_level */)) {
257 fp << "\"1\",";
258
259 }
260 else {
262
263 SaS = get_set_and_stabilizer(lvl, iso_type,
264 0 /* verbose_level */);
265
266
267 fp << "\"";
269 fp << "\",";
270 //fp << ",";
271
272 FREE_OBJECT(SaS);
273 }
274 if (((iso_type + 1) % 10) == 0) {
275 fp << endl << "\t";
276 }
277
278 if (f_progress) {
279 if ((iso_type % L100) == 0) {
280 cout << "poset_classification::generate_history "
281 "first loop at " << iso_type / L100 << "%" << endl;
282 }
283 }
284
285
286 }
287 fp << "};" << endl;
288
289
290 {
291 int *stab_gens_first;
292 int *stab_gens_len;
293 int fst;
294
295 stab_gens_first = NEW_int(nb_iso);
296 stab_gens_len = NEW_int(nb_iso);
297 fst = 0;
298 fp << "static int " << problem_label << "_lvl_" << lvl << "_stab_gens[] = {" << endl;
299 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
300
301
302 if (test_if_stabilizer_is_trivial(lvl, iso_type,
303 0 /* verbose_level */)) {
304
305 stab_gens_first[iso_type] = fst;
306 stab_gens_len[iso_type] = 0;
307
308 }
309 else {
311
312
313 SaS = get_set_and_stabilizer(lvl,
314 iso_type, 0 /* verbose_level */);
315
316 stab_gens_first[iso_type] = fst;
317 stab_gens_len[iso_type] = SaS->Strong_gens->gens->len;
318 fst += stab_gens_len[iso_type];
319
320
321 for (j = 0; j < stab_gens_len[iso_type]; j++) {
322 if (f_vv) {
323 cout << "poset_classification::generate_source_code "
324 "before extract_strong_generators_in_order "
325 "poset_classification "
326 << j << " / " << stab_gens_len[iso_type] << endl;
327 }
328 fp << "\t";
330 SaS->Strong_gens->gens->ith(j), fp);
331 fp << endl;
332 }
333 FREE_OBJECT(SaS);
334 }
335
336 if (f_progress) {
337 if ((iso_type % L100) == 0) {
338 cout << "poset_classification::generate_history "
339 "second loop at " << iso_type / L100 << "%" << endl;
340 }
341 }
342 }
343 fp << "};" << endl;
344
345
346 fp << "static long int " << problem_label << "_lvl_" << lvl << "_stab_gens_fst[] = { " << endl << "\t";
347 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
348 fp << stab_gens_first[iso_type];
349 if (iso_type < nb_iso - 1) {
350 fp << ",";
351 }
352 if (((iso_type + 1) % 10) == 0) {
353 fp << endl << "\t";
354 }
355 }
356 fp << "};" << endl;
357
358 fp << "static long int " << problem_label << "_lvl_" << lvl << "_stab_gens_len[] = { " << endl << "\t";
359 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
360 fp << stab_gens_len[iso_type];
361 if (iso_type < nb_iso - 1) {
362 fp << ",";
363 }
364 if (((iso_type + 1) % 10) == 0) {
365 fp << endl << "\t";
366 }
367 }
368 fp << "};" << endl;
369
370
371
372
373 FREE_int(stab_gens_first);
374 FREE_int(stab_gens_len);
375 }
376
377 {
378 int *flag_orbit_first;
379 int *flag_orbit_nb;
380 int total_number_flag_orbits = 0;
381 //int fst;
382
383 flag_orbit_first = NEW_int(nb_iso);
384 flag_orbit_nb = NEW_int(nb_iso);
385 //fst = 0;
386 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
387
389
390 N = get_node_ij(lvl, iso_type);
391 //N = root + Poo->first_node_at_level(lvl) + iso_type;
392
393 flag_orbit_nb[iso_type] = N->get_nb_of_extensions();
394 total_number_flag_orbits += N->get_nb_of_extensions();
395 }
396 flag_orbit_first[0] = 0;
397 for (iso_type = 1; iso_type < nb_iso; iso_type++) {
398 flag_orbit_first[iso_type] =
399 flag_orbit_first[iso_type - 1] +
400 flag_orbit_nb[iso_type - 1];
401 }
402 fp << "static long int " << problem_label << "_lvl_" << lvl << "_total_number_flag_orbits = " << total_number_flag_orbits << endl;
403 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_orbit_fst[] = { " << endl << "\t";
404 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
405 fp << flag_orbit_first[iso_type];
406 if (iso_type < nb_iso - 1) {
407 fp << ",";
408 }
409 if (((iso_type + 1) % 10) == 0) {
410 fp << endl << "\t";
411 }
412 }
413 fp << "};" << endl;
414 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_orbit_nb[] = { " << endl << "\t";
415 for (iso_type = 0; iso_type < nb_iso; iso_type++) {
416 fp << flag_orbit_nb[iso_type];
417 if (iso_type < nb_iso - 1) {
418 fp << ",";
419 }
420 if (((iso_type + 1) % 10) == 0) {
421 fp << endl << "\t";
422 }
423 }
424 fp << "};" << endl;
425
426 int f;
427 int po, so;
429
430 fp << "static int " << problem_label << "_lvl_" << lvl << "_flag_orbit_type[] = { " << endl << "\t";
431 for (f = 0; f < total_number_flag_orbits; f++) {
432
433 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
434 po--;
435 }
436 so = f - flag_orbit_first[po];
437 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
438
440
441 N = get_node_ij(lvl, po);
442 //N = root + Poo->first_node_at_level(lvl) + po;
443
444 if (so >= N->get_nb_of_extensions()) {
445 cout << "so >= N->get_nb_of_extensions()" << endl;
446 cout << "N->get_nb_of_extensions()=" << N->get_nb_of_extensions() << endl;
447 exit(1);
448 }
449
450 fp << N->get_E(so)->get_type();
451
452 if (f < total_number_flag_orbits - 1) {
453 fp << ",";
454 }
455 if (((f + 1) % 10) == 0) {
456 fp << endl << "\t";
457 }
458 }
459 fp << "};" << endl;
460
461
462 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_orbit_pt[] = { " << endl << "\t";
463 for (f = 0; f < total_number_flag_orbits; f++) {
464
465 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
466 po--;
467 }
468 so = f - flag_orbit_first[po];
469 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
470
472
473 N = get_node_ij(lvl, po);
474 //N = root + Poo->first_node_at_level(lvl) + po;
475
476 fp << N->get_E(so)->get_pt();
477
478 if (f < total_number_flag_orbits - 1) {
479 fp << ",";
480 }
481 if (((f + 1) % 10) == 0) {
482 fp << endl << "\t";
483 }
484 }
485 fp << "};" << endl;
486
487 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_orbit_ol[] = { " << endl << "\t";
488 for (f = 0; f < total_number_flag_orbits; f++) {
489
490 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
491 po--;
492 }
493 so = f - flag_orbit_first[po];
494 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
495
497
498 N = get_node_ij(lvl, po);
499 //N = root + Poo->first_node_at_level(lvl) + po;
500 fp << N->get_E(so)->get_orbit_len();
501
502 if (f < total_number_flag_orbits - 1) {
503 fp << ",";
504 }
505 if (((f + 1) % 10) == 0) {
506 fp << endl << "\t";
507 }
508 }
509 fp << "};" << endl;
510
511 int *fusion_idx;
512 int nb_fuse = 0;
513
514 fusion_idx = NEW_int(total_number_flag_orbits);
515
516 for (f = 0; f < total_number_flag_orbits; f++) {
517
518 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
519 po--;
520 }
521 so = f - flag_orbit_first[po];
522 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
523
525
526 N = get_node_ij(lvl, po);
527 //N = root + Poo->first_node_at_level(lvl) + po;
528 if (N->get_E(so)->get_type() == 2) {
529 fusion_idx[f] = nb_fuse;
530 nb_fuse++;
531 }
532 }
533 int nb_fuse_total;
534
535 nb_fuse_total = nb_fuse;
536
537 nb_fuse = 0;
538
539 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_index[] = { " << endl << "\t";
540 for (f = 0; f < total_number_flag_orbits; f++) {
541
542 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
543 po--;
544 }
545 so = f - flag_orbit_first[po];
546 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
547
549
550 N = get_node_ij(lvl, po);
551 //N = root + Poo->first_node_at_level(lvl) + po;
552 if (N->get_E(so)->get_type() == 1) {
553 fp << N->get_E(so)->get_data();
554 }
555 else if (N->get_E(so)->get_type() == 2) {
556 fp << nb_fuse;
557 nb_fuse++;
558 }
559
560 if (f < total_number_flag_orbits - 1) {
561 fp << ",";
562 }
563 if (((f + 1) % 10) == 0) {
564 fp << endl << "\t";
565 }
566 }
567 fp << "};" << endl;
568
569
570
571 int *fuse_data;
572
573 cout << "collecting data" << endl;
574 fuse_data = NEW_int(nb_fuse_total * 3);
575 nb_fuse = 0;
576 for (f = 0; f < total_number_flag_orbits; f++) {
577
578 if (!Sorting.int_vec_search(flag_orbit_first, nb_iso, f, po)) {
579 po--;
580 }
581 so = f - flag_orbit_first[po];
582 cout << "flag orbit f=" << f << " po=" << po << " so=" << so << endl;
583
585
586 N = get_node_ij(lvl, po);
587 //N = root + Poo->first_node_at_level(lvl) + po;
588 if (N->get_E(so)->get_type() == 2) {
589 fuse_data[nb_fuse * 3 + 0] = N->get_E(so)->get_data();
590 fuse_data[nb_fuse * 3 + 1] = N->get_E(so)->get_data1();
591 fuse_data[nb_fuse * 3 + 2] = N->get_E(so)->get_data2();
592 nb_fuse++;
593 }
594 }
595
596 cout << "writing data1" << endl;
597 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_fuse_data1[] = { " << endl << "\t";
598 for (nb_fuse = 0; nb_fuse < nb_fuse_total; nb_fuse++) {
599 fp << fuse_data[nb_fuse * 3 + 1];
600 if (nb_fuse < nb_fuse_total - 1) {
601 fp << ",";
602 }
603 if (((nb_fuse + 1) % 10) == 0) {
604 fp << endl << "\t";
605 }
606 }
607 fp << "};" << endl;
608
609 cout << "writing data2" << endl;
610 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_fuse_data2[] = { " << endl << "\t";
611 for (nb_fuse = 0; nb_fuse < nb_fuse_total; nb_fuse++) {
612 fp << fuse_data[nb_fuse * 3 + 2];
613 if (nb_fuse < nb_fuse_total - 1) {
614 fp << ",";
615 }
616 if (((nb_fuse + 1) % 10) == 0) {
617 fp << endl << "\t";
618 }
619 }
620 fp << "};" << endl;
621 int hdl;
622
623 cout << "writing iso" << endl;
624 fp << "static long int " << problem_label << "_lvl_" << lvl << "_flag_fuse_iso[] = { " << endl;
625 for (nb_fuse = 0; nb_fuse < nb_fuse_total; nb_fuse++) {
626 hdl = fuse_data[nb_fuse * 3 + 0];
627 Poset->A->element_retrieve(hdl, Elt, 0);
628 fp << "\t";
629 Poset->A->element_print_for_make_element(Elt, fp);
630 fp << endl;
631 }
632 fp << "};" << endl;
633
634 FREE_int(fuse_data);
635 FREE_int(fusion_idx);
636 FREE_int(flag_orbit_first);
637 FREE_int(flag_orbit_nb);
638 }
639
640 } // next lvl
641 } // end ofstream
642
643 FREE_lint(set);
644 FREE_int(Elt);
645
646 cout << "written file " << fname << " of size " << Fio.file_size(fname) << endl;
647 if (f_v) {
648 cout << "poset_classification::generate_history done" << endl;
649 }
650}
651
652
653}}}
654
a collection of functions related to sorted vectors
int int_vec_search(int *v, int len, int a, int &idx)
Definition: sorting.cpp:1094
a class to represent arbitrary precision integers
Definition: ring_theory.h:366
void element_retrieve(int hdl, void *elt, int verbose_level)
Definition: action_cb.cpp:301
void element_print_for_make_element(void *elt, std::ostream &ost)
Definition: action_cb.cpp:409
data_structures_groups::vector_ge * gens
Definition: groups.h:1708
data_structures_groups::set_and_stabilizer * get_set_and_stabilizer(int level, int orbit_at_level, int verbose_level)
int test_if_stabilizer_is_trivial(int level, int orbit_at_level, int verbose_level)
to represent one poset orbit; related to the class poset_classification
#define FREE_int(p)
Definition: foundations.h:640
#define ONE_MILLION
Definition: foundations.h:226
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define NEW_int(n)
Definition: foundations.h:625
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define FREE_lint(p)
Definition: foundations.h:642
#define NEW_lint(n)
Definition: foundations.h:628
the orbiter library for the classification of combinatorial objects