91#ifndef ADOBE_NO_DOCUMENTATION
93 : toroid_m(row_count, column_count), output_m(column_count, 0), solutions_m(0)
102 inline void set(std::size_t row, std::size_t col,
char color = 0) {
103 toroid_m.set(row, col, color);
108 template <
typename ResultCallback,
typename SearchHeuristic>
109 inline std::size_t
search(std::size_t max_solutions, ResultCallback callback,
110 SearchHeuristic heuristic) {
111 max_solutions_m = max_solutions;
115 do_search(0, callback, heuristic);
120 inline std::size_t
search(std::size_t max_solutions) {
121 return search(max_solutions, implementation::do_nothing_callback_t(),
122 implementation::select_most_constrained_heuristic_t());
125#if ADOBE_STD_SERIALIZATION
132 template <
typename ResultCallback,
typename SearchHeuristic>
133 void do_search(std::size_t k, ResultCallback callback, SearchHeuristic heuristic) {
134 if (toroid_m.right_of(&toroid_m.header_m) == &toroid_m.header_m) {
138 std::cout << adobe::indents(tab_count_m) <<
"<solved/>" << std::endl;
141 for (std::size_t i(0); i < k; ++i)
142 callback(toroid_m.row_index_of(output_m[i]), i + 1 == k);
147 std::size_t next_k(k + 1);
149 toroid_header_t* c(heuristic(toroid_m));
153 std::cout << adobe::indents(tab_count_m) <<
"<c"
154 << toroid_m.column_index_of(toroid_m.down_of(c)) <<
">" << std::endl;
157 toroid_m.cover_column(c);
160 for (toroid_node_t* r(toroid_m.down_of(c)); r != c; r = toroid_m.down_of(r)) {
162 std::cout << adobe::indents(tab_count_m) <<
"<r" << toroid_m.row_index_of(r) <<
">"
169 for (toroid_node_t* j(toroid_m.right_of(r)); j != r; j = toroid_m.right_of(j)) {
170 if (j->color_m == 0) {
172 std::cout << adobe::indents(tab_count_m) <<
"<c" << toroid_m.column_index_of(j)
175 toroid_m.cover_column(toroid_m.column_of(j));
176 }
else if (j->color_m > 0) {
178 std::cout << adobe::indents(tab_count_m) <<
"<p" << toroid_m.column_index_of(j)
189 do_search(next_k, callback, heuristic);
191 if (solutions_m >= max_solutions_m)
196 c = toroid_m.column_of(r);
199 for (toroid_node_t* j(toroid_m.left_of(r)); j != r; j = toroid_m.left_of(j)) {
200 if (j->color_m == 0) {
202 std::cout << adobe::indents(tab_count_m) <<
"</c" << toroid_m.column_index_of(j)
205 toroid_m.uncover_column(toroid_m.column_of(j));
206 }
else if (j->color_m > 0) {
208 std::cout << adobe::indents(tab_count_m) <<
"</p" << toroid_m.column_index_of(j)
211 toroid_m.unpurify(j);
216 std::cout << adobe::indents(tab_count_m) <<
"</r" << toroid_m.row_index_of(r) <<
">"
221 toroid_m.uncover_column(c);
224 std::cout << adobe::indents(tab_count_m) <<
"</c"
225 << toroid_m.column_index_of(toroid_m.down_of(c)) <<
">" << std::endl;
230 byte_toroid_t toroid_m;
231 std::vector<toroid_node_t*> output_m;
232 std::size_t solutions_m;
233 std::size_t max_solutions_m;
235 std::size_t tab_count_m;