Orbiter 2022
Combinatorial Objects
diophant_create.cpp
Go to the documentation of this file.
1/*
2 * diophant_create.cpp
3 *
4 * Created on: May 28, 2020
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11
12using namespace std;
13
14namespace orbiter {
15namespace layer1_foundations {
16namespace solvers {
17
18
20{
21 Descr = NULL;
22 D = NULL;
23}
24
26{
27 if (D) {
29 }
30}
31
34 int verbose_level)
35{
36 int f_v = (verbose_level >= 1);
37
38 if (f_v) {
39 cout << "diophant_create::init" << endl;
40 }
42
43 D = NULL;
44
45
46
47 if (!Descr->f_label) {
48 cout << "please use -label <label> to give the system a name" << endl;
49 exit(1);
50 }
51
52
53
54
55 if (Descr->f_maximal_arc) {
56
58
59 if (Descr->f_q) {
61
63 cout << "creating finite field of order q=" << Descr->input_q
64 << " using override polynomial " << Descr->override_polynomial << endl;
66 Descr->override_polynomial, FALSE /* f_without_tables */, verbose_level);
67 }
68 else {
69 cout << "diophant_create::init creating finite field "
70 "of order q=" << Descr->input_q
71 << " using the default polynomial (if necessary)" << endl;
72 F->finite_field_init(Descr->input_q, FALSE /* f_without_tables */, 0);
73 }
74
75 }
76
77
79
81
83 TRUE /* f_init_incidence_structure */,
84 verbose_level);
85
90 D,
91 verbose_level);
92
93 char str[1000];
94 string fname;
96
97 sprintf(str, "max_arc_%d_%d_%d.diophant", Descr->input_q,
99 fname.assign(str);
100 D->save_in_general_format(fname, verbose_level);
101 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
102
103 FREE_OBJECT(P);
104 if (F) {
105 FREE_OBJECT(F);
106 }
107 }
109 int *A;
110 int sz;
111 int i, j;
112
114
117
119 cout << "sz != m * n" << endl;
120 exit(1);
121 }
122 for (i = 0; i < Descr->coefficient_matrix_m; i++) {
123 for (j = 0; j < Descr->coefficient_matrix_n; j++) {
124 D->Aij(i, j) = A[i * Descr->coefficient_matrix_n + j];
125 }
126 }
127 FREE_int(A);
128 }
131 int *Covering_matrix;
132 int nb_rows, nb_cols;
133 int i, j, h;
134
135 if (f_v) {
136 cout << "f_problem_of_Steiner_type" << endl;
137 cout << "reading coefficient matrix from file "
138 << Descr->coefficient_matrix_csv << endl;
139 }
141 Covering_matrix,
142 nb_rows, nb_cols, verbose_level);
143
145 int nb_k_orbits = nb_rows;
146
148 D->open(nb_t_orbits, nb_k_orbits);
149
150 for (j = 0; j < nb_k_orbits; j++) {
151 for (h = 0; h < nb_cols; h++) {
152 i = Covering_matrix[j * nb_cols + h];
153 D->Aij(i, j) = 1;
154 }
155 }
156 FREE_int(Covering_matrix);
157
158 for (i = 0; i < D->m; i++) {
159 D->RHS_low[i] = 1;
160 D->RHS[i] = 1;
161 D->type[i] = t_EQ;
162 }
163 for (i = 0; i < D->n; i++) {
164 D->x_max[i] = 1;
165 }
166 }
167
170 int *A;
171 int m, n;
172 int i, j;
173
174 if (f_v) {
175 cout << "reading coefficient matrix from file "
176 << Descr->coefficient_matrix_csv << endl;
177 }
179 A,
180 m, n, verbose_level);
181
183
184 D->open(m, n);
185
186 for (i = 0; i < m; i++) {
187 for (j = 0; j < n; j++) {
188 D->Aij(i, j) = A[i * n + j];
189 }
190 }
191 FREE_int(A);
192 }
193
194 if (Descr->f_RHS) {
195 int *RHS;
196 int sz;
197 int i;
198
199 if (D == NULL) {
200 cout << "-RHS please specify the coefficient matrix first" << endl;
201 exit(1);
202 }
203 Int_vec_scan(Descr->RHS_text, RHS, sz);
204 if (sz != 3 * D->m) {
205 cout << "number of values for RHS must be 3 times the number of rows of the system" << endl;
206 exit(1);
207 }
208 for (i = 0; i < D->m; i++) {
209 if (RHS[3 * i + 2] == 1) {
210 D->RHS_low[i] = RHS[3 * i + 0];
211 D->RHS[i] = RHS[3 * i + 1];
212 D->type[i] = t_EQ;
213 }
214 else if (RHS[3 * i + 2] == 2) {
215 D->RHS_low[i] = 0;
216 D->RHS[i] = RHS[3 * i + 1];
217 D->type[i] = t_LE;
218 }
219 else if (RHS[3 * i + 2] == 3) {
220 D->RHS_low[i] = RHS[3 * i + 0];
221 D->RHS[i] = RHS[3 * i + 1];
222 D->type[i] = t_INT;
223 }
224 else if (RHS[3 * i + 2] == 4) {
225 D->RHS_low[i] = 0;
226 D->RHS[i] = RHS[3 * i + 1];
227 D->type[i] = t_ZOR;
228 }
229 else {
230 cout << "type of RHS not recognized" << endl;
231 exit(1);
232 }
233 }
234 FREE_int(RHS);
235
236 }
237
238 if (Descr->f_RHS_csv) {
239 int *RHS;
240 int m, n;
241 int i;
243
244 if (D == NULL) {
245 cout << "-RHS_csv please specify the coefficient matrix first" << endl;
246 exit(1);
247 }
249 RHS,
250 m, n, verbose_level);
251 if (n != 3) {
252 cout << "reading RHS from file " << Descr->RHS_csv_text << ". Csv file must have exactly 3 column2." << endl;
253 exit(1);
254 }
255 if (m != D->m) {
256 cout << "number of rows in csv file must match number of rows of the system" << endl;
257 exit(1);
258 }
259 for (i = 0; i < m; i++) {
260 if (RHS[3 * i + 2] == 1) {
261 D->RHS_low[i] = RHS[3 * i + 0];
262 D->RHS[i] = RHS[3 * i + 1];
263 D->type[i] = t_EQ;
264 }
265 else if (RHS[3 * i + 2] == 2) {
266 D->RHS_low[i] = 0;
267 D->RHS[i] = RHS[3 * i + 1];
268 D->type[i] = t_LE;
269 }
270 else if (RHS[3 * i + 2] == 3) {
271 D->RHS_low[i] = RHS[3 * i + 0];
272 D->RHS[i] = RHS[3 * i + 1];
273 D->type[i] = t_INT;
274 }
275 else if (RHS[3 * i + 2] == 4) {
276 D->RHS_low[i] = 0;
277 D->RHS[i] = RHS[3 * i + 1];
278 D->type[i] = t_ZOR;
279 }
280 else {
281 cout << "type of RHS not recognized" << endl;
282 exit(1);
283 }
284 }
285 FREE_int(RHS);
286
287 }
288
289 if (Descr->f_RHS_constant) {
290 int *RHS;
291 int sz;
292 int i;
293
294 if (D == NULL) {
295 cout << "-RHS_constant please specify the coefficient matrix first" << endl;
296 exit(1);
297 }
299 if (sz != 3) {
300 cout << "sz != 3" << endl;
301 exit(1);
302 }
303 for (i = 0; i < D->m; i++) {
304 if (RHS[2] == 1) {
305 D->RHS_low[i] = RHS[0];
306 D->RHS[i] = RHS[1];
307 D->type[i] = t_EQ;
308 }
309 else if (RHS[2] == 2) {
310 D->RHS_low[i] = 0;
311 D->RHS[i] = RHS[1];
312 D->type[i] = t_LE;
313 }
314 else if (RHS[2] == 3) {
315 D->RHS_low[i] = RHS[0];
316 D->RHS[i] = RHS[1];
317 D->type[i] = t_INT;
318 }
319 else if (RHS[2] == 4) {
320 D->RHS_low[i] = 0;
321 D->RHS[i] = RHS[1];
322 D->type[i] = t_ZOR;
323 }
324 else {
325 cout << "type of RHS not recognized" << endl;
326 exit(1);
327 }
328 }
329 FREE_int(RHS);
330
331 }
332
333
334 if (Descr->f_x_max_global) {
335 int j;
336
337 if (D == NULL) {
338 cout << "-x_max_global please specify the coefficient matrix first" << endl;
339 exit(1);
340 }
341 for (j = 0; j < D->n; j++) {
342 D->x_max[j] = Descr->x_max_global;
343 }
344 }
345
346 if (Descr->f_x_min_global) {
347 int j;
348
349 if (D == NULL) {
350 cout << "-x_min_global please specify the coefficient matrix first" << endl;
351 exit(1);
352 }
353 for (j = 0; j < D->n; j++) {
354 D->x_min[j] = Descr->x_min_global;
355 }
356 }
357
358 if (Descr->f_x_bounds) {
359 if (D == NULL) {
360 cout << "-x_bounds please specify the coefficient matrix first" << endl;
361 exit(1);
362 }
363 int *x_bounds;
364 int sz;
365 int j;
366
367 Int_vec_scan(Descr->x_bounds_text, x_bounds, sz);
368 if (sz != 2 * D->n) {
369 cout << "sz != 2 * D->n" << endl;
370 exit(1);
371 }
372 for (j = 0; j < D->n; j++) {
373 D->x_min[j] = x_bounds[2 * j + 0];
374 D->x_max[j] = x_bounds[2 * j + 1];
375 }
376 FREE_int(x_bounds);
377 }
378
379 if (Descr->f_x_bounds_csv) {
380 int *x_bounds;
381 int m1, n1;
382 int j;
384
385 if (D == NULL) {
386 cout << "-x_bounds_csv please specify the coefficient matrix first" << endl;
387 exit(1);
388 }
390 x_bounds,
391 m1, n1, verbose_level);
392 if (m1 != D->n) {
393 cout << "reading RHS from file " << Descr->x_bounds_csv
394 << ". Csv file must have exactly " << D->n << " rows." << endl;
395 exit(1);
396 }
397 if (n1 != 2) {
398 cout << "reading RHS from file " << Descr->x_bounds_csv
399 << ". The csv file must have exactly 2 columns." << endl;
400 exit(1);
401 }
402 for (j = 0; j < D->n; j++) {
403 D->x_min[j] = x_bounds[2 * j + 0];
404 D->x_max[j] = x_bounds[2 * j + 1];
405 }
406 FREE_int(x_bounds);
407 }
408
409 if (Descr->f_has_sum) {
410
411 if (D == NULL) {
412 cout << "-has_sum please specify the coefficient matrix first" << endl;
413 exit(1);
414 }
415 D->f_has_sum = TRUE;
416 D->sum = Descr->has_sum;
417 }
418
419
420
421 string fname;
423
424
425 D->label.assign(Descr->label);
426
427 fname.assign(Descr->label);
428 fname.append(".diophant");
429
430 D->save_in_general_format(fname, verbose_level);
431 cout << "Written file " << fname << " of size " << Fio.file_size(fname) << endl;
432
433 if (f_v) {
434 cout << "diophant_create::init done" << endl;
435 }
436}
437
438
439}}}
440
441
442
void finite_field_init(int q, int f_without_tables, int verbose_level)
void init_override_polynomial(int q, std::string &poly, int f_without_tables, int verbose_level)
void maximal_arc_by_diophant(int arc_sz, int arc_d, std::string &secant_lines_text, std::string &external_lines_as_subset_of_secants_text, solvers::diophant *&D, int verbose_level)
projective space PG(n,q) of dimension n over Fq
Definition: geometry.h:1916
void projective_space_init(int n, field_theory::finite_field *F, int f_init_incidence_structure, int verbose_level)
void int_matrix_read_csv(std::string &fname, int *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1477
void init(diophant_description *Descr, int verbose_level)
to describe a diophantine system from command line arguments
Definition: solvers.h:125
diophantine systems of equations (i.e., linear systems over the integers)
Definition: solvers.h:209
void save_in_general_format(std::string &fname, int verbose_level)
Definition: diophant.cpp:2879
#define Int_vec_scan(A, B, C)
Definition: foundations.h:716
#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 TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
the orbiter library for the classification of combinatorial objects