24namespace layer1_foundations {
30#define DLX_FANCY_LEVEL 30
102 int f_v = (verbose_level >= 1);
105 cout <<
"dlx_solver::init" << endl;
122 cout <<
"dlx_solver::init please use option -data_label or use data_matrix" << endl;
127 cout <<
"dlx_solver::init done" << endl;
135 return i - 1 < 0 ?
nCol - 1 : i - 1;
140 return (i + 1) %
nCol;
145 return i - 1 < 0 ?
nRow - 1 : i - 1;
150 return (i + 1) %
nRow;
155 void (*callback_solution_found)(
156 int *solution,
int len,
int nb_sol,
void *data),
157 void *callback_solution_found_data)
198 for (i = 0; i <
nb_rows; i++) {
199 for (j = 0; j <
nb_cols; j++) {
217 for (i = 0; i <
nb_rows; i++) {
218 for (j = 0; j <
nb_cols; j++) {
223 RHS, f_has_type,
type,
236 for (i = 0; i <
nb_rows; i++) {
237 for (j = 0; j <
nb_cols; j++) {
242 for (j = 0; j <
nb_cols; j++) {
259 for (i = 0; i <
nb_rows; i++) {
260 for (j = 0; j <
nb_cols; j++) {
267 for (j = 0; j <
nb_cols; j++) {
268 Data2[i *
nb_cols + j] = RHS[j];
273 RHS, f_has_type,
type,
282 int f_v = (verbose_level >= 1);
285 cout <<
"dlx_solver::Solve nb_rows = " <<
nb_rows <<
" nb_cols = "
289 int *Input_data_transposed;
298 Input_data_transposed =
NEW_int(nr * nc);
299 for (i = 0; i <
nb_cols; i++) {
300 for (j = 0; j < nc; j++) {
305 for (j = 0; j < nc; j++) {
306 Input_data_transposed[i * nc + j] = 1;
311 cout <<
"dlx_solver::Solve before CreateMatrix" << endl;
313 CreateMatrix(Input_data_transposed, nr, nc, verbose_level - 1);
315 cout <<
"dlx_solver::Solve after CreateMatrix" << endl;
329 cout <<
"dlx_solver::Solve finds " <<
nb_sol <<
" solutions "
344 cout <<
"dlx_solver::Solve done" << endl;
352 int f_v = (verbose_level >= 1);
355 cout <<
"dlx_solver::Solve_with_RHS nb_rows = " <<
nb_rows
356 <<
" nb_cols = " <<
nb_cols << endl;
379 cout <<
"dlx_solver::Solve_with_RHS finds "
380 <<
nb_sol <<
" solutions "
381 "with nb_backtrack_nodes="
396 cout <<
"dlx_solver::Solve_with_RHS done" << endl;
453 int f_v = (verbose_level >= 1);
457 cout <<
"dlx_solver::Create_RHS" << endl;
462 cout <<
"dlx_solver::Create_RHS nb_cols != nCol" << endl;
471 for (i = 0; i <
nCol; i++) {
478 for (i = 0; i <
nCol; i++) {
483 cout <<
"sum_rhs=" << sum_rhs << endl;
490 for (i = 0; i <
nCol; i++) {
495 for (i = 0; i <
nCol; i++) {
504 cout <<
"dlx_solver::Create_RHS done" << endl;
533 int nb_rows,
int nb_cols,
int verbose_level)
535 int f_v = (verbose_level >= 1);
539 cout <<
"dlx_solver::CreateMatrix" << endl;
546 cout <<
"dlx_solver::CreateMatrix" << endl;
548 <<
" matrix is:" << endl;
549 for (i = 0; i <
nb_rows; i++) {
550 for (j = 0; j <
nb_cols; j++) {
570 for (j = 0; j <
nCol; j++) {
576 for (a = 0; a <
nRow; a++) {
577 for (b = 0; b <
nCol; b++) {
587 cout <<
"dlx_solver::CreateMatrix building the toroidal matrix" << endl;
589 for (a = 0; a <
nRow; a++) {
590 for (b = 0; b <
nCol; b++) {
591 if (Data[a *
nCol + b] != 0) {
598 }
while (Data[i *
nCol + j] == 0);
607 }
while (Data[i *
nCol + j] == 0);
616 }
while (Data[i *
nCol + j] == 0);
625 }
while (Data[i *
nCol + j] == 0);
630 cout <<
"at " << a <<
"/" << b <<
":";
631 cout <<
" Left="; print_position(
Matrix[a *
nCol + b].Left);
632 cout <<
" Right="; print_position(
Matrix[a *
nCol + b].Right);
633 cout <<
" Up="; print_position(
Matrix[a *
nCol + b].Up);
634 cout <<
" Down="; print_position(
Matrix[a *
nCol + b].Down);
646 cout <<
"dlx_solver::CreateMatrix building the toroidal matrix finished" << endl;
651 for (j = 0; j <
nCol; j++) {
655 cout <<
"dlx_solver::CreateMatrix counting nodes in column " << j << endl;
662 for (RowNode = ColNode->
Down; RowNode != ColNode; RowNode = RowNode->
Down) {
668 for (a = 0; a <
nCol; a++) {
681 cout <<
"dlx_solver::CreateMatrix done" << endl;
700 if (Node->
col == c) {
704 cout <<
"dlx_solver::get_column_header cannot find column " << c << endl;
710 int j, nb_node, nb_node_min = 0;
716 if (Node_min == NULL) {
718 nb_node_min = nb_node;
721 if (nb_node < nb_node_min) {
723 nb_node_min = nb_node;
733 cout <<
"dlx_solver::ChooseColumn Root->Right == Root" << endl;
741 int j, nb_node, nb_node_min = 0;
750 if (Node_min == NULL) {
752 nb_node_min = nb_node;
755 if (nb_node < nb_node_min) {
757 nb_node_min = nb_node;
770 cout <<
"dlx_solver::ChooseColumn Root->Right == Root" << endl;
781 cout <<
"dlx_solver::ChooseColumnRHS could not find a node" << endl;
790 for (i = 0; i < k; i++) {
804 cout <<
"Search: " << a <<
" * 2^20 nodes, "
805 <<
" nb_sol=" <<
nb_sol <<
" position ";
809 for (
int i = 0; i < d; i++) {
823 cout <<
"solution " <<
nb_sol <<
" : ";
825 int_vec_print(cout,
Result, k);
832 for (i = 0; i < k; i++) {
838 (*callback_solution_found)(
Result,
854 for (RowNode = Column->
Down;
856 RowNode = RowNode->
Down) {
861 cout <<
"Choice set: ";
862 for (RowNode = Column->
Down;
864 RowNode = RowNode->
Down) {
879 cout <<
"c : current_RHS[c] : target_RHS[c]" << endl;
880 for (c = 0; c <
nCol; c++) {
956 for (RowNode = Column->
Down;
967 for (RightNode = RowNode->
Right;
968 RightNode != RowNode;
969 RightNode = RightNode->
Right) {
978 for (LeftNode = RowNode->
Left;
980 LeftNode = LeftNode->
Left) {
990 int f_v = (verbose_level >= 1);
1002 cout <<
"dlx_solver::SearchRHS k=" << k
1003 <<
" nb_backtrack_nodes="
1005 for (i = 0; i < k; i++) {
1023 cout <<
"dlx_solver::SearchRHS k=" << k <<
" solution ";
1025 cout <<
" found" << endl;
1034 int r, c, f_done, c0, c2;
1049 if (Column == NULL) {
1061 cout <<
"dlx_solver::SearchRHS k=" << k
1062 <<
" choosing column " << c << endl;
1072 cout <<
"dlx_solver::SearchRHS k=" << k <<
" choosing column " << c
1078 cout <<
"dlx_solver::SearchRHS current_RHS[c] > "
1079 "target_RHS[c] error" << endl;
1089 cout <<
"dlx_solver::SearchRHS k=" << k <<
" column " << c
1090 <<
" is done, so we cover it" << endl;
1106 cout <<
"dlx_solver::SearchRHS k=" << k <<
" column " << c
1107 <<
" number of choices is " <<
Nb_choices[k] << endl;
1116 for (RowNode = Column->
Down; RowNode != Column;
1128 cout <<
"dlx_solver::SearchRHS k=" << k <<
" column " << c
1149 cout <<
"dlx_solver::SearchRHS skip" << endl;
1171 for (RightNode = RowNode->
Right;
1172 RightNode != RowNode;
1173 RightNode = RightNode->
Right) {
1174 c2 = RightNode->
col;
1178 cout <<
"dlx_solver::SearchRHS current_RHS[c2] > "
1179 "target_RHS[c2] error" << endl;
1197 cout <<
"dlx_solver::SearchRHS nb_changed_type_columns_total >= nCol" << endl;
1209 cout <<
"dlx_solver::SearchRHS k=" << k <<
" column " << c
1213 cout <<
" recursing" << endl;
1221 cout <<
"dlx_solver::SearchRHS k=" << k <<
" column " << c
1225 cout <<
" after recursion" << endl;
1230 for (LeftNode = RowNode->
Left;
1231 LeftNode != RowNode;
1232 LeftNode = LeftNode->
Left) {
1251 cout <<
"dlx_solver::SearchRHS current_RHS[c2] != 0 error, "
1254 <<
" c=" << c <<
" k=" << k << endl;
1298 for (RowNode = ColNode->
Down;
1300 RowNode = RowNode->
Down) {
1304 for (RightNode = RowNode->
Right;
1305 RightNode != RowNode;
1306 RightNode = RightNode->
Right) {
1310 RightNode->
Down->
Up = RightNode->
Up;
1327 for (RowNode = ColNode->
Up;
1329 RowNode = RowNode->
Up) {
1330 for (LeftNode = RowNode->
Left;
1331 LeftNode != RowNode;
1332 LeftNode = LeftNode->
Left) {
1335 LeftNode->
Up->
Down = LeftNode;
1336 LeftNode->
Down->
Up = LeftNode;
void get_matrix_from_label(std::string &label, int *&v, int &m, int &n)
description of a problem instance for dancing links solver
void TransposeAndSolveRHS(int *Data, int nb_rows, int nb_cols, int *RHS, int f_has_type, diophant_equation_type *type, int verbose_level)
void SearchRHS(int k, int verbose_level)
int * nb_changed_type_columns
void UnCover(dlx_node *ColNode)
void init(dlx_problem_description *Descr, int verbose_level)
void open_solution_file(int verbose_level)
void TransposeAppendAndSolve(int *Data, int nb_rows, int nb_cols, int verbose_level)
std::string solutions_fname
void count_nb_choices(int k, dlx_node *Column)
dlx_node * ChooseColumnFancyRHS()
void AppendRowAndSolveRHS(int *Data, int nb_rows, int nb_cols, int *RHS, int f_has_type, diophant_equation_type *type, int verbose_level)
void * callback_solution_found_data
dlx_node * get_column_header(int c)
int * changed_type_columns
void install_callback_solution_found(void(*callback_solution_found)(int *solution, int len, int nb_sol, void *data), void *callback_solution_found_data)
void de_install_callback_solution_found()
void Create_RHS(int nb_cols, int *RHS, int f_has_type, diophant_equation_type *type, int verbose_level)
void AppendRowAndSolve(int *Data, int nb_rows, int nb_cols, int verbose_level)
dlx_node * ChooseColumn()
void Solve_with_RHS(int *RHS, int f_has_type, diophant_equation_type *type, int verbose_level)
void(* callback_solution_found)(int *solution, int len, int nb_sol, void *data)
void print_if_necessary(int k)
dlx_node * ChooseColumnFancy()
diophant_equation_type * type
int IsColumnNotDone(int c)
dlx_problem_description * Descr
dlx_node * ChooseColumnRHS()
int nb_changed_type_columns_total
void close_solution_file()
void open_tree_file(int verbose_level)
void Cover(dlx_node *ColNode)
void CreateMatrix(int *Data, int nb_rows, int nb_cols, int verbose_level)
void process_solution(int k)
int f_has_callback_solution_found
void Solve(int verbose_level)
#define NEW_OBJECTS(type, n)
#define Int_vec_copy(A, B, C)
#define Int_vec_print(A, B, C)
orbiter_kernel_system::orbiter_session * Orbiter
global Orbiter session
the orbiter library for the classification of combinatorial objects
internal class for the dancing links exact cover algorithm