Orbiter 2022
Combinatorial Objects
classify_using_canonical_forms.cpp
Go to the documentation of this file.
1/*
2 * classify_using_canonical_forms.cpp
3 *
4 * Created on: Aug 28, 2021
5 * Author: betten
6 */
7
8
9
10
11
12
13#include "foundations.h"
14
15using namespace std;
16
17namespace orbiter {
18namespace layer1_foundations {
19namespace data_structures {
20
21
23{
25}
26
28{
29}
30
33 int &f_accept, int verbose_level)
34{
35 int f_v = (verbose_level >= 1);
36
37 if (f_v) {
38 cout << "classify_using_canonical_forms::orderly_test" << endl;
39 }
40
41 nauty_output *NO;
42
43
44 if (f_v) {
45 cout << "classify_using_canonical_forms::orderly_test "
46 "before OwCF->run_nauty_basic" << endl;
47 }
48 OwCF->run_nauty_basic(
49 NO,
50 verbose_level);
51 if (f_v) {
52 cout << "classify_using_canonical_forms::orderly_test "
53 "after OwCF->run_nauty_basic" << endl;
54 }
55
56 int nb_rows, nb_cols;
57
58 OwCF->encoding_size(
59 nb_rows, nb_cols,
60 verbose_level);
61
62 int last_row, last_pt;
63
64 last_row = nb_rows - 1;
65
66 last_pt = NO->canonical_labeling[last_row];
67
68 if (f_v) {
69 cout << "classify_using_canonical_forms::orderly_test "
70 "last_row=" << last_row << " last_pt=" << last_pt
71 << endl;
72 }
73
74 if (f_v) {
75 cout << "classify_using_canonical_forms::orderly_test "
76 "before NO->belong_to_the_same_orbit" << endl;
77 }
78 if (NO->belong_to_the_same_orbit(last_row, last_pt, 0 /* verbose_level*/)) {
79 f_accept = TRUE;
80 }
81 else {
82 f_accept = FALSE;
83 }
84 if (f_v) {
85 cout << "classify_using_canonical_forms::orderly_test "
86 "after NO->belong_to_the_same_orbit f_accept = " << f_accept << endl;
87 }
88
89 //cout << "before FREE_OBJECT(NO);" << endl;
90 FREE_OBJECT(NO);
91 //cout << "after FREE_OBJECT(NO);" << endl;
92
93 if (f_v) {
94 cout << "classify_using_canonical_forms::orderly_test" << endl;
95 }
96}
97
100 int &f_found, int &idx,
101 nauty_output *&NO,
102 bitvector *&Canonical_form,
103 int verbose_level)
104// if f_found is TRUE, B[idx] agrees with the given object
105{
106 int f_v = (verbose_level >= 1);
107
108 if (f_v) {
109 cout << "classify_using_canonical_forms::find_object" << endl;
110 }
111
112 if (f_v) {
113 cout << "classify_using_canonical_forms::find_object "
114 "before OwCF->run_nauty" << endl;
115 }
116 OwCF->run_nauty(
117 TRUE /* f_compute_canonical_form */, Canonical_form,
118 NO,
119 verbose_level);
120 if (f_v) {
121 cout << "classify_using_canonical_forms::find_object "
122 "after OwCF->run_nauty" << endl;
123 }
124
125 uint32_t h;
126 int c;
128
129 h = Canonical_form->compute_hash();
130
131 map<uint32_t, int>::iterator itr, itr1, itr2;
132
133 itr1 = Hashing.lower_bound(h);
134 itr2 = Hashing.upper_bound(h);
135 f_found = FALSE;
136 for (itr = itr1; itr != itr2; ++itr) {
137 idx = itr->second;
139 Canonical_form->get_data(),
140 B[idx]->get_data(),
141 Canonical_form->get_allocated_length());
142 if (c == 0) {
143 if (f_v) {
144 cout << "classify_using_canonical_forms::find_object "
145 "found object at position " << idx << endl;
146 }
147 f_found = TRUE;
148 break;
149 }
150 }
151 if (f_v) {
152 cout << "classify_using_canonical_forms::find_object done" << endl;
153 }
154}
155
158 int &f_new_object, int verbose_level)
159{
160 int f_v = (verbose_level >= 1);
161
162 if (f_v) {
163 cout << "classify_using_canonical_forms::add_object" << endl;
164 }
165
166 nauty_output *NO;
167 bitvector *Canonical_form;
168
169#if 0
170 if (f_v) {
171 cout << "classify_using_canonical_forms::add_object "
172 "before OwCF->run_nauty" << endl;
173 }
174 OwCF->run_nauty(
175 TRUE /* f_compute_canonical_form */, Canonical_form,
176 NO,
177 verbose_level);
178 if (f_v) {
179 cout << "classify_using_canonical_forms::add_object "
180 "after OwCF->run_nauty" << endl;
181 }
182
183 uint32_t h;
184 int f_found, c;
186
187 h = Canonical_form->compute_hash();
188
189 map<uint32_t, int>::iterator itr, itr1, itr2;
190
191 itr1 = Hashing.lower_bound(h);
192 itr2 = Hashing.upper_bound(h);
193 f_found = FALSE;
194 for (itr = itr1; itr != itr2; ++itr) {
195 idx = itr->second;
197 Canonical_form->get_data(),
198 B[idx]->get_data(),
199 Canonical_form->get_allocated_length());
200 if (c == 0) {
201 f_found = TRUE;
202 break;
203 }
204 }
205#else
206
207 int f_found;
208 int idx;
209
210 find_object(OwCF,
211 f_found, idx,
212 NO,
213 Canonical_form,
214 verbose_level);
215
216#endif
217
218 uint32_t h;
219
220 h = Canonical_form->compute_hash();
221
222 if (!f_found) {
223 f_new_object = TRUE;
224 idx = B.size();
225 B.push_back(Canonical_form);
226 Objects.push_back(OwCF);
227 Ago.push_back(NO->Ago->as_lint());
228 Hashing.insert(pair<uint32_t, int>(h, idx));
229 input_index.push_back(nb_input_objects);
230 }
231 else {
232 f_new_object = FALSE;
233 FREE_OBJECT(Canonical_form);
234 FREE_OBJECT(OwCF);
235 }
236
237 FREE_OBJECT(NO);
239
240 if (f_v) {
241 cout << "classify_using_canonical_forms::add_object done" << endl;
242 }
243
244
245}
246
247
248}}}
249
250
compact storage of 0/1-data as bitvectors
void add_object(geometry::object_with_canonical_form *OwCF, int &f_new_object, int verbose_level)
void orderly_test(geometry::object_with_canonical_form *OwCF, int &f_accept, int verbose_level)
void find_object(geometry::object_with_canonical_form *OwCF, int &f_found, int &idx, nauty_output *&NO, bitvector *&Canonical_form, int verbose_level)
int belong_to_the_same_orbit(int a, int b, int verbose_level)
a collection of functions related to sorted vectors
int uchar_vec_compare(uchar *p, uchar *q, int len)
Definition: sorting.cpp:2851
a combinatorial object for which a canonical form can be computed using Nauty
Definition: geometry.h:1487
void encoding_size(int &nb_rows, int &nb_cols, int verbose_level)
void run_nauty(int f_compute_canonical_form, data_structures::bitvector *&Canonical_form, data_structures::nauty_output *&NO, int verbose_level)
void run_nauty_basic(data_structures::nauty_output *&NO, int verbose_level)
#define FREE_OBJECT(p)
Definition: foundations.h:651
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
the orbiter library for the classification of combinatorial objects