Orbiter 2022
Combinatorial Objects
representatives.cpp
Go to the documentation of this file.
1// representatives.cpp
2//
3// Anton Betten
4// started July 3, 2012
5//
6//
7//
8//
9
11#include "discreta/discreta.h"
14
15using namespace std;
16
17namespace orbiter {
18namespace layer4_classification {
19
20
22{
23 null();
24}
25
27{
28 count = 0;
29 rep = NULL;
30 stab = NULL;
31 fusion = NULL;
32 handle = NULL;
33 Elt1 = NULL;
34 tl = NULL;
35}
36
38{
39 free();
40 null();
41}
42
44{
45 int i;
46 int f_v = TRUE;
47
48 if (f_v) {
49 cout << "representatives::free" << endl;
50 }
51 if (rep) {
53 rep = NULL;
54 }
55 if (stab) {
56 for (i = 0; i < count; i++) {
57 if (stab[i]) {
58 FREE_OBJECT(stab[i]);
59 stab[i] = NULL;
60 }
61 }
62 delete [] stab;
63 stab = NULL;
64 }
65 if (fusion) {
67 fusion = NULL;
68 }
69 if (handle) {
71 handle = NULL;
72 }
73 if (Elt1) {
75 Elt1 = NULL;
76 }
77 if (tl) {
78 FREE_int(tl);
79 tl = NULL;
80 }
81}
82
84 int nb_objects, std::string &prefix, int verbose_level)
85{
86 int f_v = (verbose_level >= 1);
87 int i;
88
89 if (f_v) {
90 cout << "representatives::init prefix=" << prefix << endl;
91 }
94
96
97
103 tl = NEW_int(A->base_len());
104
105 count = 0;
106 for (i = 0; i < nb_objects; i++) {
107 stab[i] = NULL;
108 fusion[i] = -2;
109 handle[i] = -1;
110 }
111
112 fname_rep.assign(prefix);
113 fname_rep.append("classification_reps.txt");
114
115 //sprintf(fname_rep, "%sclassification_reps.txt", prefix);
116
117 fname_stabgens.assign(prefix);
118 fname_stabgens.append("classification_stabgens.bin");
119
120 //sprintf(fname_stabgens, "%sclassification_stabgens.bin", prefix);
121
122 fname_fusion.assign(prefix);
123 fname_fusion.append("classification_fusion.txt");
124
125 //sprintf(fname_fusion, "%sclassification_fusion.txt", prefix);
126
127 fname_fusion_ge.assign(prefix);
128 fname_fusion_ge.append("classification_fusion_ge.bin");
129
130 //sprintf(fname_fusion_ge, "%sclassification_fusion_ge.bin", prefix);
131}
132
133void representatives::write_fusion(int verbose_level)
134// Writes fusion[] and handle[]
135// If the object is a chosen representative for an isomorphism type
136// (i.e., if fusion[i] == i) then the identity element is written.
137{
138 int f_v = (verbose_level >= 1);
140
141 if (f_v) {
142 cout << "representatives::write_fusion" << endl;
143 }
144 if (f_v) {
145 cout << "representatives::write_fusion fname_fusion=" << fname_fusion << endl;
146 }
147 {
148 ofstream f1(fname_fusion);
149 int i;
150
151 ofstream f2(fname_fusion_ge, ios::binary);
152 //FILE *f2;
153 //f2 = fopen(fname_fusion_ge, "wb");
154
155 for (i = 0; i < nb_objects; i++) {
156 if (fusion[i] == -2) {
157 cout << "representatives::write_fusion "
158 "fusion[" << i << "] = -2" << endl;
159 exit(1);
160 }
161 f1 << setw(5) << i << " " << setw(3) << fusion[i] << endl;
162 if (fusion[i] == i) {
163 //cout << "orbit " << i << " is representative" << endl;
164 A->one(Elt1);
165 }
166 else {
168 }
169 A->element_write_file_fp(Elt1, f2, 0/* verbose_level*/);
170 }
171 f1 << -1 << endl;
172 //fclose(f2);
173 }
174 if (f_v) {
175 cout << "representatives::write_fusion finished" << endl;
176 cout << "written file " << fname_fusion << " of size "
177 << Fio.file_size(fname_fusion) << endl;
178 cout << "written file " << fname_fusion_ge << " of size "
179 << Fio.file_size(fname_fusion_ge) << endl;
180 }
181
182}
183
184void representatives::read_fusion(int verbose_level)
185// Reads fusion[] and handle[]
186{
187 int f_v = (verbose_level >= 1);
188 int a, b, i;
190
191 if (f_v) {
192 cout << "representatives::read_fusion nb_objects="
193 << nb_objects << endl;
194 }
195 if (f_v) {
196 cout << "representatives::read_fusion reading file "
197 << fname_fusion << " of size "
198 << Fio.file_size(fname_fusion) << endl;
199 }
200
201 if (Fio.file_size(fname_fusion) < 0) {
202 cout << "representatives::read_fusion the file " << fname_fusion << " does not exist" << endl;
203 exit(1);
204 }
205 {
206 ifstream f1(fname_fusion);
207 for (i = 0; i < nb_objects; i++) {
208 f1 >> a >> b;
209 if (a != i) {
210 cout << "representatives::read_fusion "
211 "a != i" << endl;
212 exit(1);
213 }
214 fusion[i] = b;
215 }
216 f1 >> a;
217 if (a != -1) {
218 cout << "representatives::read_fusion problem with end "
219 "of file marker" << endl;
220 exit(1);
221 }
222 }
223 if (f_v) {
224 cout << "representatives::read_fusion reading file "
225 << fname_fusion_ge << " of size "
226 << Fio.file_size(fname_fusion_ge) << endl;
227 }
228 {
229 ifstream f2(fname_fusion_ge, ios::binary);
230 //FILE *f2;
231
232 //f2 = fopen(fname_fusion_ge, "rb");
233
234 for (i = 0; i < nb_objects; i++) {
235 A->element_read_file_fp(Elt1, f2, 0/* verbose_level*/);
237 }
238 }
239 if (f_v) {
240 cout << "representatives::read_fusion done" << endl;
241 }
242}
243
245 int verbose_level)
246{
247 int f_v = (verbose_level >= 1);
249
250 if (f_v) {
251 cout << "representatives::write_representatives_"
252 "and_stabilizers" << endl;
253 }
254 {
255 ofstream f1(fname_rep);
256 int i, j, cnt = 0;
257
258 ofstream f2(fname_stabgens, ios::binary);
259 //FILE *f2;
260 //f2 = fopen(fname_stabgens, "wb");
261
262
263 f1 << count << " " << setw(3) << A->base_len() << " ";
264 for (i = 0; i < A->base_len(); i++) {
265 f1 << setw(3) << A->base_i(i) << " ";
266 }
267 f1 << endl;
268
269 for (i = 0; i < count; i++) {
270 groups::sims *Stab;
273
274 Stab = stab[i];
275 Stab->group_order(go);
276
278 SG, tl, 0 /* verbose_level */);
279
280 f1 << setw(3) << i << " "
281 << setw(7) << rep[i] << " "
282 << setw(5) << cnt << " "
283 << setw(5) << SG.len << " ";
284 go.print_width(f1, 10);
285 f1 << " ";
286 for (j = 0; j < A->base_len(); j++) {
287 f1 << setw(3) << tl[j] << " ";
288 }
289 f1 << endl;
290
291
292 for (j = 0; j < SG.len; j++) {
293 A->element_write_file_fp(SG.ith(j), f2,
294 0/* verbose_level*/);
295 cnt++;
296 }
297 }
298 f1 << -1 << endl;
299 //fclose(f2);
300 }
301 if (f_v) {
302 cout << "representatives::write_representatives_and_"
303 "stabilizers finished" << endl;
304 cout << "written file " << fname_rep << " of size "
305 << Fio.file_size(fname_rep) << endl;
306 cout << "written file " << fname_stabgens << " of size "
307 << Fio.file_size(fname_stabgens) << endl;
308 }
309
310}
311
313 int verbose_level)
314{
315 int f_v = (verbose_level >= 1);
316 int f_vv = FALSE;//(verbose_level >=2);
317
318 if (f_v) {
319 cout << "representatives::read_representatives_and_"
320 "stabilizers" << endl;
321 cout << "reading files " << fname_rep << " and "
322 << fname_stabgens << endl;
323 }
324 {
325 ifstream f1(fname_rep);
326 int i, j, /*first,*/ len, a, b, c, d, e;
327
328 ifstream f2(fname_stabgens, ios::binary);
329 //FILE *f2;
330 //f2 = fopen(fname_stabgens, "rb");
331
332 f1 >> count >> a;
333 if (a != A->base_len()) {
334 cout << "representatives::read_representatives_and_stabilizers "
335 "base_len does not match" << endl;
336 exit(1);
337 }
338 for (j = 0; j < A->base_len(); j++) {
339 f1 >> a;
340 if (a != A->base_i(j)) {
341 cout << "representatives::read_representatives_and_stabilizers "
342 "base point does not match" << endl;
343 exit(1);
344 }
345 }
346 for (i = 0; i < count; i++) {
347 groups::sims *Stab;
350
352 Stab = stab[i];
353 f1 >> a >> b >> c >> d >> e;
354 if (a != i) {
355 cout << "representatives::read_representatives_and_stabilizers "
356 "a != i" << endl;
357 exit(1);
358 }
359 rep[i] = b;
360 //first = c;
361 len = d;
362 gens.init(A, verbose_level - 2);
363 gens.allocate(len, verbose_level - 2);
364 for (j = 0; j < A->base_len(); j++) {
365 f1 >> tl[j];
366 }
367 for (j = 0; j < len; j++) {
368 A->element_read_file_fp(gens.ith(j), f2, 0/* verbose_level*/);
369 }
370 if (f_vv) {
371 cout << "representative of orbit " << i << " read" << endl;
372 cout << "stabilizer is generated by" << endl;
373 for (j = 0; j < len; j++) {
374 cout << "generator " << j << ":" << endl;
375 A->print(cout, gens.ith(j));
376 cout << endl;
377 }
378 cout << "transversal lengths:" << endl;
379 Int_vec_print(cout, tl, A->base_len());
380 cout << endl;
381 }
382 Stab->init(A, verbose_level - 2);
383 Stab->init_generators(gens, FALSE);
384 Stab->compute_base_orbits(0/*verbose_level - 5*/);
385 Stab->group_order(go);
386 if (f_v) {
387 cout << "representatives::read_representatives_and_stabilizers "
388 "stabilizer " << i << " has order " << go << endl;
389 }
390 }
391 f1 >> a;
392 if (a != -1) {
393 cout << "representatives::read_representatives_and_stabilizers "
394 "problems reading end of file marker" << endl;
395 exit(1);
396 }
397 //fclose(f2);
398 }
399 if (f_v) {
400 cout << "representatives::read_representatives_and_stabilizers "
401 "finished" << endl;
402 }
403}
404
405void representatives::save(int verbose_level)
406{
407 int f_v = (verbose_level >= 1);
408
409 if (f_v) {
410 cout << "representatives::save" << endl;
411 }
412 write_fusion(verbose_level - 1);
413 write_representatives_and_stabilizers(verbose_level - 1);
414 if (f_v) {
415 cout << "representatives::save done" << endl;
416 }
417}
418
419void representatives::load(int verbose_level)
420{
421 int f_v = (verbose_level >= 1);
422
423 if (f_v) {
424 cout << "representatives::load" << endl;
425 }
426 if (f_v) {
427 cout << "representatives::load before read_fusion" << endl;
428 }
429 read_fusion(verbose_level - 1);
430 if (f_v) {
431 cout << "representatives::load after read_fusion" << endl;
432 }
433 if (f_v) {
434 cout << "representatives::load before read_representatives_and_stabilizers" << endl;
435 }
436 read_representatives_and_stabilizers(verbose_level - 1);
437 if (f_v) {
438 cout << "representatives::load after read_representatives_and_stabilizers" << endl;
439 }
440 if (f_v) {
441 cout << "representatives::load done found " << count
442 << " orbit representatives" << endl;
443 }
444}
445
447{
448 int i;
449
450 nb_open = 0;
451 nb_reps = 0;
452 nb_fused = 0;
453 for (i = 0; i < nb_objects; i++) {
454 if (fusion[i] == -2) {
455 nb_open++;
456 }
457 if (fusion[i] == i) {
458 nb_reps++;
459 }
460 else if (fusion[i] >= 0) {
461 nb_fused++;
462 }
463 }
464
465}
466
468{
469 cout << "nb_reps = " << nb_reps << endl;
470 cout << "nb_fused = " << nb_fused << endl;
471 cout << "nb_open = " << nb_open << endl;
472}
473
474}}
475
476
a class to represent arbitrary precision integers
Definition: ring_theory.h:366
a permutation group in a fixed action.
Definition: actions.h:99
void element_retrieve(int hdl, void *elt, int verbose_level)
Definition: action_cb.cpp:301
void element_write_file_fp(int *Elt, std::ofstream &fp, int verbose_level)
Definition: action_cb.cpp:587
void element_read_file_fp(int *Elt, std::ifstream &fp, int verbose_level)
Definition: action_cb.cpp:604
void print(std::ostream &ost, void *elt)
Definition: action_cb.cpp:131
int element_store(void *elt, int verbose_level)
Definition: action_cb.cpp:308
void init(actions::action *A, int verbose_level)
Definition: vector_ge.cpp:55
a permutation group represented via a stabilizer chain
Definition: groups.h:1273
void init(actions::action *A, int verbose_level)
Definition: sims.cpp:289
void extract_strong_generators_in_order(data_structures_groups::vector_ge &SG, int *tl, int verbose_level)
Definition: sims.cpp:1704
void group_order(ring_theory::longinteger_object &go)
Definition: sims.cpp:951
void init_generators(data_structures_groups::vector_ge &generators, int verbose_level)
Definition: sims.cpp:660
void compute_base_orbits(int verbose_level)
Definition: sims_main.cpp:25
void write_representatives_and_stabilizers(int verbose_level)
void read_representatives_and_stabilizers(int verbose_level)
void init(actions::action *A, int nb_objects, std::string &prefix, int verbose_level)
#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 TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects