Orbiter 2022
Combinatorial Objects
design_tables.cpp
Go to the documentation of this file.
1/*
2 * design_tables.cpp
3 *
4 * Created on: May 26, 2021
5 * Author: betten
6 */
7
8
9
10
11#include "orbiter.h"
12
13using namespace std;
14
15namespace orbiter {
16namespace layer5_applications {
17namespace apps_combinatorics {
18
19
20static int design_tables_compare_func(void *data, int i, int j, void *extra_data);
21static void design_tables_swap_func(void *data, int i, int j, void *extra_data);
22
23
24
26{
27 A = NULL;
28 A2 = NULL;
29 initial_set = NULL;
30 design_size = 0;
31 //std::string label;
32 //std::string fname_design_table;
33 Strong_generators = NULL;
34 nb_designs = 0;
35 the_table = NULL; // [nb_designs * design_size]
36
37}
38
39
41{
42 if (the_table) {
44 }
45}
46
47
49 long int *initial_set, int design_size,
50 std::string &label,
51 groups::strong_generators *Strong_generators, int verbose_level)
52{
53 int f_v = (verbose_level >= 1);
54
55 if (f_v) {
56 cout << "design_tables::init" << endl;
57 }
58
59
61 label,
62 verbose_level)) {
63
64
67 label,
68 Strong_generators, verbose_level);
69
70
71 }
72 else {
73
74
81
82
83 if (f_v) {
84 cout << "design_tables::init before create_table" << endl;
85 }
86 create_table(verbose_level);
87 if (f_v) {
88 cout << "design_tables::init after create_table" << endl;
89 }
90
91 if (f_v) {
92 cout << "design_tables::init before save" << endl;
93 }
94 save(verbose_level);
95 if (f_v) {
96 cout << "design_tables::init after save" << endl;
97 }
98
99 actions::action *A_on_designs;
100
101 if (f_v) {
102 cout << "design_tables::init before create_action" << endl;
103 }
104 create_action(A_on_designs, verbose_level);
105 if (f_v) {
106 cout << "design_tables::init after create_action" << endl;
107 }
108
109 }
110
111 if (f_v) {
112 cout << "design_tables::init done" << endl;
113 }
114}
115
116void design_tables::create_table(int verbose_level)
117{
118 int f_v = (verbose_level >= 1);
119
120 if (f_v) {
121 cout << "design_tables::create_table" << endl;
122 }
123
124
126 fname_design_table.append("_design_table.csv");
127
128 orbit_of_sets *SetOrb;
129
130 SetOrb = NEW_OBJECT(orbit_of_sets);
131
132 cout << "design_tables::init computing orbit:" << endl;
133 SetOrb->init(A, A2,
135 verbose_level);
136 cout << "design_tables::init computing orbit done" << endl;
137
138 long int **Sets;
139 int i;
142
143 if (f_v) {
144 cout << "design_tables::init" << endl;
145 }
146
147 nb_designs = SetOrb->used_length;
148 Sets = NEW_plint(nb_designs);
149 for (i = 0; i < nb_designs; i++) {
150
151 Sets[i] = NEW_lint(design_size);
152 Lint_vec_copy(SetOrb->Sets[i], Sets[i], design_size);
153 }
154
155 if (f_v) {
156 cout << "design_tables::init before "
157 "sorting design table of size " << nb_designs << endl;
158 }
159
160 Sorting.Heapsort_general(Sets, nb_designs,
161 design_tables_compare_func,
162 design_tables_swap_func,
163 this);
164
165 if (f_v) {
166 cout << "design_tables::init after "
167 "sorting design table of size " << nb_designs << endl;
168 }
169
171 for (i = 0; i < nb_designs; i++) {
173 }
174
175 if (f_v) {
176 cout << "design_tables::init "
177 "nb_designs = " << nb_designs << endl;
178 }
179 if (nb_designs < 100) {
180 for (i = 0; i < nb_designs; i++) {
181 cout << i << " : ";
183 cout << endl;
184 }
185 }
186 else {
187 cout << "too many to print" << endl;
188 }
189
190
191
192
193 for (i = 0; i < nb_designs; i++) {
194 FREE_lint(Sets[i]);
195 }
196 FREE_plint(Sets);
197 FREE_OBJECT(SetOrb);
198
199 if (f_v) {
200 cout << "design_tables::create_table done" << endl;
201 }
202}
203
204void design_tables::create_action(actions::action *&A_on_designs, int verbose_level)
205{
206 int f_v = (verbose_level >= 1);
207
208 if (f_v) {
209 cout << "design_tables::create_action" << endl;
210 }
211
212 A_on_designs = NEW_OBJECT(actions::action);
213
214 if (f_v) {
215 cout << "design_tables::create_action "
216 "creating action A_on_designs" << endl;
217 }
218 A_on_designs = A2->create_induced_action_on_sets(
220 the_table,
221 0 /* verbose_level */);
222
223 if (f_v) {
224 cout << "design_tables::create_action "
225 "A_on_designs->degree=" << A_on_designs->degree << endl;
226 }
227
228 string fname_group;
229
230 fname_group.assign(label);
231 fname_group.append("_on_design_table.makefile");
232
233 if (f_v) {
234 cout << "design_tables::create_action "
235 "fname_group = " << fname_group << endl;
236 }
237
238
239 if (f_v) {
240 cout << "design_tables::create_action "
241 "before A_on_designs->export_to_orbiter_as_bsgs" << endl;
242 }
243
244 A_on_designs->export_to_orbiter_as_bsgs(
245 fname_group, label, label,
246 Strong_generators, verbose_level);
247
248 if (f_v) {
249 cout << "design_tables::create_action "
250 "after A_on_designs->export_to_orbiter_as_bsgs" << endl;
251 }
252
253 if (f_v) {
254 cout << "design_tables::create_action" << endl;
255 }
256}
257
259 int nb_sol, int Index_width, int *Index,
260 std::string &ouput_fname_csv,
261 int verbose_level)
262{
263 int f_v = (verbose_level >= 1);
264 long int i, j, k, idx, N;
265 long int *Sol;
267
268 if (f_v) {
269 cout << "design_tables::extract_solutions_by_index" << endl;
270 }
271 N = Index_width * design_size;
272
273 Sol = NEW_lint(nb_sol * N);
274 for (i = 0; i < nb_sol; i++) {
275 k = 0;
276 for (j = 0; j < Index_width; j++, k += design_size) {
277 idx = Index[i * Index_width + j];
279 Sol + i * N + j * design_size,
281 }
282 }
283
284
285 Fio.lint_matrix_write_csv(ouput_fname_csv, Sol, nb_sol, N);
286 if (f_v) {
287 cout << "design_tables::extract_solutions_by_index "
288 "Written file "
289 << ouput_fname_csv << " of size " << Fio.file_size(ouput_fname_csv) << endl;
290 }
291
292 if (f_v) {
293 cout << "design_tables::extract_solutions_by_index done" << endl;
294 }
295}
296
297
298
300 long int *set, int set_sz,
301 long int *&reduced_table, long int *&reduced_table_idx, int &nb_reduced_designs,
302 int verbose_level)
303// reduced_table[nb_designs * design_size]
304{
305 int f_v = (verbose_level >= 1);
306 long int i, j, a;
307
308 if (f_v) {
309 cout << "design_tables::make_reduced_design_table" << endl;
310 }
311 reduced_table = NEW_lint(nb_designs * design_size);
312 reduced_table_idx = NEW_lint(nb_designs);
313 nb_reduced_designs = 0;
314 for (i = 0; i < nb_designs; i++) {
315 for (j = 0; j < set_sz; j++) {
316 a = set[j];
317 if (!test_if_designs_are_disjoint(i, a)) {
318 break;
319 }
320 }
321 if (j == set_sz) {
323 reduced_table + nb_reduced_designs * design_size, design_size);
324 reduced_table_idx[nb_reduced_designs] = i;
325 nb_reduced_designs++;
326 }
327 }
328 if (f_v) {
329 cout << "design_tables::make_reduced_design_table done" << endl;
330 }
331}
332
334 long int *initial_set, int design_size,
335 std::string &label,
336 groups::strong_generators *Strong_generators, int verbose_level)
337{
338 int f_v = (verbose_level >= 1);
339
340 if (f_v) {
341 cout << "design_tables::init_from_file" << endl;
342 }
343
344
351
352
354 fname_design_table.append("_design_table.csv");
355
356
357 if (f_v) {
358 cout << "design_tables::init_from_file before load" << endl;
359 }
360
361 load(verbose_level);
362
363 if (f_v) {
364 cout << "design_tables::init_from_file after load" << endl;
365 }
366
367
368 if (f_v) {
369 cout << "design_tables::init_from_file done" << endl;
370 }
371
372}
373
375 std::string &label,
376 int verbose_level)
377{
378 int f_v = (verbose_level >= 1);
379
380 if (f_v) {
381 cout << "design_tables::test_if_table_exists" << endl;
382 }
383
384
386 fname_design_table.append("_design_table.csv");
387
389
390 if (Fio.file_size(fname_design_table) > 0) {
391 if (f_v) {
392 cout << "design_tables::test_if_table_exists design table " << fname_design_table << " exists" << endl;
393 }
394 return TRUE;
395 }
396 else {
397 if (f_v) {
398 cout << "design_tables::test_if_table_exists design table " << fname_design_table << " does not exist" << endl;
399 }
400 return FALSE;
401 }
402}
403
404
405
406void design_tables::save(int verbose_level)
407{
408 int f_v = (verbose_level >= 1);
410
411 if (f_v) {
412 cout << "design_tables::save" << endl;
413 }
414
415 if (f_v) {
416 cout << "design_tables::save "
417 "writing file " << fname_design_table << endl;
418 }
419
422 if (f_v) {
423 cout << "design_tables::save "
424 "written file " << fname_design_table << endl;
425 }
426
427
428 if (f_v) {
429 cout << "design_tables::save done" << endl;
430 }
431}
432
433void design_tables::load(int verbose_level)
434{
435 int f_v = (verbose_level >= 1);
436 int b;
438
439 if (f_v) {
440 cout << "design_tables::load" << endl;
441 }
442
443 if (f_v) {
444 cout << "design_tables::load "
445 "reading file " << fname_design_table << endl;
446 }
447
450 0 /* verbose_level */);
451 if (b != design_size) {
452 cout << "design_tables::load b != design_size" << endl;
453 exit(1);
454 }
455 if (f_v) {
456 cout << "design_tables::load "
457 "reading " << fname_design_table << " done" << endl;
458 }
459
460
461
462 if (f_v) {
463 cout << "design_tables::load done" << endl;
464 }
465}
466
467
469{
470 long int *p1, *p2;
472
473 p1 = the_table + i * design_size;
474 p2 = the_table + j * design_size;
476 p1, p2, design_size, design_size)) {
477 return TRUE;
478 }
479 else {
480 return FALSE;
481 }
482}
483
484
485int design_tables::test_set_within_itself(long int *set_of_designs_by_index, int set_size)
486{
487 int i, j, a, b;
488 long int *p1;
489 long int *p2;
491
492 for (i = 0; i < set_size; i++) {
493 a = set_of_designs_by_index[i];
494 p1 = the_table + a * design_size;
495 for (j = i + 1; j < set_size; j++) {
496 b = set_of_designs_by_index[j];
497 p2 = the_table + b * design_size;
499 p1, p2, design_size, design_size)) {
500 return FALSE;
501 }
502 }
503 }
504 return TRUE;
505}
506
508 long int *set_of_designs_by_index1, int set_size1,
509 long int *set_of_designs_by_index2, int set_size2)
510{
511 int i, j, a, b;
512 long int *p1;
513 long int *p2;
515
516 for (i = 0; i < set_size1; i++) {
517 a = set_of_designs_by_index1[i];
518 p1 = the_table + a * design_size;
519 for (j = 0; j < set_size2; j++) {
520 b = set_of_designs_by_index2[j];
521 p2 = the_table + b * design_size;
523 p1, p2, design_size, design_size)) {
524 return FALSE;
525 }
526 }
527 }
528 return TRUE;
529}
530
531
532// global functions:
533
534
535static int design_tables_compare_func(void *data, int i, int j, void *extra_data)
536{
537 design_tables *D = (design_tables *) extra_data;
538 int **Sets = (int **) data;
539 int ret;
541
542 ret = Sorting.int_vec_compare(Sets[i], Sets[j], D->design_size);
543 return ret;
544}
545
546static void design_tables_swap_func(void *data, int i, int j, void *extra_data)
547{
548 //design_tables *D = (design_tables *) extra_data;
549 int **Sets = (int **) data;
550 int *p;
551
552 p = Sets[i];
553 Sets[i] = Sets[j];
554 Sets[j] = p;
555}
556
557
558
559
560}}}
561
a collection of functions related to sorted vectors
int test_if_sets_are_disjoint_assuming_sorted_lint(long int *set1, long int *set2, int sz1, int sz2)
Definition: sorting.cpp:2820
void Heapsort_general(void *data, int len, int(*compare_func)(void *data, int i, int j, void *extra_data), void(*swap_func)(void *data, int i, int j, void *extra_data), void *extra_data)
Definition: sorting.cpp:1806
void lint_matrix_write_csv(std::string &fname, long int *M, int m, int n)
Definition: file_io.cpp:1323
void lint_matrix_read_csv(std::string &fname, long int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1558
a permutation group in a fixed action.
Definition: actions.h:99
action * create_induced_action_on_sets(int nb_sets, int set_size, long int *sets, int verbose_level)
void export_to_orbiter_as_bsgs(std::string &fname, std::string &label, std::string &label_tex, groups::strong_generators *SG, int verbose_level)
Definition: action_io.cpp:1077
a strong generating set for a permutation group with respect to a fixed action
Definition: groups.h:1703
data_structures_groups::vector_ge * gens
Definition: groups.h:1708
orbit of sets using a Schreier tree, used in packing::make_spread_table
Definition: orbits.h:106
void init(actions::action *A, actions::action *A2, long int *set, int sz, data_structures_groups::vector_ge *gens, int verbose_level)
int test_between_two_sets(long int *set_of_designs_by_index1, int set_size1, long int *set_of_designs_by_index2, int set_size2)
void init_from_file(actions::action *A, actions::action *A2, long int *initial_set, int design_size, std::string &label, groups::strong_generators *Strong_generators, int verbose_level)
int test_set_within_itself(long int *set_of_designs_by_index, int set_size)
void extract_solutions_by_index(int nb_sol, int Index_width, int *Index, std::string &ouput_fname_csv, int verbose_level)
void create_action(actions::action *&A_on_designs, int verbose_level)
void init(actions::action *A, actions::action *A2, long int *initial_set, int design_size, std::string &label, groups::strong_generators *Strong_generators, int verbose_level)
void make_reduced_design_table(long int *set, int set_sz, long int *&reduced_table, long int *&reduced_table_idx, int &nb_reduced_designs, int verbose_level)
int test_if_table_exists(std::string &label, int verbose_level)
#define Lint_vec_copy(A, B, C)
Definition: foundations.h:694
#define NEW_plint(n)
Definition: foundations.h:629
#define FREE_plint(p)
Definition: foundations.h:643
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define FREE_OBJECT(p)
Definition: foundations.h:651
#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