Orbiter 2022
Combinatorial Objects
diophant_activity.cpp
Go to the documentation of this file.
1/*
2 * diophant_activity.cpp
3 *
4 * Created on: May 29, 2020
5 * Author: betten
6 */
7
8
9
10
11#include "foundations.h"
12
13
14using namespace std;
15
16namespace orbiter {
17namespace layer1_foundations {
18namespace solvers {
19
20
21
23{
24 Descr = NULL;
25}
26
28{
29}
30
31
33 int verbose_level)
34{
35 int f_v = (verbose_level >= 1);
36
37 if (f_v) {
38 cout << "diophant_activity::init_from_file" << endl;
39 }
40
43
44 if (!Descr->f_input_file) {
45 cout << "diophant_activity::init_from_file please use option -q <q>" << endl;
46 exit(1);
47 }
48
49 diophant *Dio;
50
51 Dio = NEW_OBJECT(diophant);
52 Dio->read_general_format(Descr->input_file, verbose_level);
53
54}
55
57 int verbose_level)
58{
59 int f_v = (verbose_level >= 1);
60
61 if (f_v) {
62 cout << "diophant_activity::perform_activity" << endl;
63 }
64
67
68
69 if (Descr->f_solve_mckay) {
70
71 long int nb_backtrack_nodes;
72
73 cout << "solving with mckay" << endl;
74 Dio->solve_all_mckay(nb_backtrack_nodes, INT_MAX, verbose_level - 2);
75 Dio->nb_steps_betten = nb_backtrack_nodes;
76
77 cout << "Found " << Dio->_resultanz << " solutions with "
78 << Dio->nb_steps_betten << " backtrack steps" << endl;
79
80 if (TRUE) {
81 string output_file;
82
83 output_file.assign(Dio->label);
84 ST.replace_extension_with(output_file, ".sol");
85
86
87 Dio->write_solutions(output_file, verbose_level);
88 }
89 }
90 else if (Descr->f_solve_standard) {
91 //long int nb_backtrack_nodes;
92
93 cout << "solving with standard method" << endl;
94
95 Dio->solve_all_betten(verbose_level - 2);
96
97 cout << "Found " << Dio->_resultanz << " solutions with "
98 << Dio->nb_steps_betten << " backtrack steps" << endl;
99
100 if (TRUE) {
101 string output_file;
102
103 output_file.assign(Dio->label);
104 ST.replace_extension_with(output_file, ".sol");
105
106
107 Dio->write_solutions(output_file, verbose_level);
108 }
109 }
110 else if (Descr->f_solve_DLX) {
111 //long int nb_backtrack_nodes;
112
113 cout << "solving with DLX" << endl;
114
115 Dio->solve_all_DLX(verbose_level - 2);
116
117 cout << "Found " << Dio->_resultanz << " solutions with "
118 << Dio->nb_steps_betten << " backtrack steps" << endl;
119
120 if (TRUE) {
121 string output_file;
122
123 output_file.assign(Dio->label);
124 ST.replace_extension_with(output_file, ".sol");
125
126
127 Dio->write_solutions(output_file, verbose_level);
128 }
129 }
130 else if (Descr->f_draw_as_bitmap) {
131 string fname_base;
132
133 fname_base.assign(Descr->input_file);
134 ST.replace_extension_with(fname_base, "_drawing");
135 Dio->draw_as_bitmap(fname_base, TRUE, Descr->box_width, Descr->bit_depth,
136 verbose_level);
137
138 }
139 else if (Descr->f_test_single_equation) {
142 verbose_level);
143 }
146 Descr->eqn_idx,
147 TRUE,
149 verbose_level);
150 }
152
153 if (Descr->solve_case_idx_r == -1) {
157 FALSE,
158 0, 1,
159 verbose_level);
160 }
161 else {
165 TRUE,
168 verbose_level);
169 }
170 }
171 else if (Descr->f_draw) {
172 string fname_base;
173
174 fname_base.assign(Descr->input_file);
175 ST.replace_extension_with(fname_base, "_drawing");
176
177 Dio->draw_partitioned(fname_base,
178 orbiter_kernel_system::Orbiter->draw_options,
179 FALSE, 0, 0,
180 verbose_level);
181 }
183 diophant *D2;
184
185 D2 = Dio->trivial_column_reductions(verbose_level);
186
187 string fname2;
189
190 fname2.assign(Descr->input_file);
191 ST.replace_extension_with(fname2, "_red.diophant");
192
193 D2->save_in_general_format(fname2, verbose_level);
194 cout << "Written file " << fname2 << " of size " << Fio.file_size(fname2) << endl;
195
196 }
197 else {
198 cout << "diophant_activity::perform_activity no activity found" << endl;
199 exit(1);
200 }
201
202
203 if (f_v) {
204 cout << "diophant_activity::perform_activity done" << endl;
205 }
206}
207
208
209
210}}}
211
functions related to strings and character arrays
void replace_extension_with(char *p, const char *new_ext)
to describe an activity for a diophantine system from command line arguments
Definition: solvers.h:27
void perform_activity(diophant_activity_description *Descr, diophant *Dio, int verbose_level)
void init_from_file(diophant_activity_description *Descr, int verbose_level)
diophantine systems of equations (i.e., linear systems over the integers)
Definition: solvers.h:209
void draw_partitioned(std::string &fname_base, graphics::layered_graph_draw_options *Draw_options, int f_solution, int *solution, int solution_sz, int verbose_level)
Definition: diophant.cpp:4068
int solve_all_mckay(long int &nb_backtrack_nodes, int maxresults, int verbose_level)
Definition: diophant.cpp:1435
void write_solutions(std::string &fname, int verbose_level)
Definition: diophant.cpp:958
void draw_as_bitmap(std::string &fname, int f_box_width, int box_width, int bit_depth, int verbose_level)
Definition: diophant.cpp:3974
void split_by_two_equations(int eqn1_idx, int eqn2_idx, int f_solve_case, int solve_case_idx_r, int solve_case_idx_m, int verbose_level)
Definition: diophant.cpp:3456
void project_to_single_equation_and_solve(int max_number_of_coefficients, int verbose_level)
Definition: diophant.cpp:3529
void read_general_format(std::string &fname, int verbose_level)
Definition: diophant.cpp:3049
void split_by_equation(int eqn_idx, int f_solve_case, int solve_case_idx, int verbose_level)
Definition: diophant.cpp:3388
diophant * trivial_column_reductions(int verbose_level)
Definition: diophant.cpp:2467
void save_in_general_format(std::string &fname, int verbose_level)
Definition: diophant.cpp:2879
#define NEW_OBJECT(type)
Definition: foundations.h:638
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects