ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
FastExactCover.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*------------------------- File FastExactCover.h --------------------------*/
3
/*--------------------------------------------------------------------------*/
68
/*--------------------------------------------------------------------------*/
69
/*----------------------------- DEFINITIONS --------------------------------*/
70
/*--------------------------------------------------------------------------*/
71
72
#ifndef __ADS_FastExactCover
73
#define __ADS_FastExactCover
74
/* self-identification: #endif constant */
75
76
/*--------------------------------------------------------------------------*/
77
/*------------------------------ INCLUDES ----------------------------------*/
78
/*--------------------------------------------------------------------------*/
79
80
#include "
ADS/Contract.h
"
81
82
#include <algorithm>
83
#include <type_traits>
84
#include <utility>
85
#include <vector>
86
87
/*--------------------------------------------------------------------------*/
88
/*--------------------------- NAMESPACE ------------------------------------*/
89
/*--------------------------------------------------------------------------*/
90
91
namespace
ADS
92
{
93
94
/*--------------------------------------------------------------------------*/
95
/*------------------------- CLASS FastExactCover ---------------------------*/
96
/*--------------------------------------------------------------------------*/
97
99
class
FastExactCover
100
{
101
102
/*--------------------------------------------------------------------------*/
103
public
:
107
FastExactCover
(
int
primary ,
int
secondary = 0 );
108
115
int
addOption
(
const
std::vector< int > & items ,
116
const
std::vector< int > & colors = {} );
117
170
template
<
class
F >
171
long
solve
( F && visit );
172
174
[[nodiscard]]
long
updates
(
void
)
const
{
return
( f_updates ); }
175
177
[[nodiscard]]
long
nodes
(
void
)
const
{
return
( f_nodes ); }
178
179
/*--------------------------------------------------------------------------*/
180
private
:
182
struct
Node
183
{
184
int
item;
185
int
loc;
187
int
color;
188
int
pad;
189
};
190
192
struct
Item
193
{
194
int
start ,
195
size ,
196
pos ,
197
pad;
198
};
199
200
void
build(
void
);
201
bool
hide(
int
c ,
int
color ,
bool
check
);
202
203
[[nodiscard]]
int
optionOf(
int
x )
const
;
204
[[nodiscard]]
bool
solution(
const
std::vector< int > & options )
const
;
205
206
int
f_primary , f_items;
207
std::vector< std::vector< int > > f_options , f_colors;
208
209
std::vector< Node > f_node;
210
std::vector< Item > f_item;
211
std::vector< int > f_set , f_active , f_force;
212
int
f_nActive = 0 , f_oActive = 0;
213
long
f_updates = 0 , f_nodes = 0;
214
215
};
// end( class FastExactCover )
216
217
/*--------------------------------------------------------------------------*/
218
219
}
// end( namespace ADS )
220
221
/*--------------------------------------------------------------------------*/
222
/*-------------------------- IMPLEMENTATION --------------------------------*/
223
/*--------------------------------------------------------------------------*/
224
225
#include "ADS/backtrack/impl/FastExactCover.tpp"
226
227
/*--------------------------------------------------------------------------*/
228
229
#endif
/* FastExactCover.h included */
230
231
/*--------------------------------------------------------------------------*/
232
/*------------------------ End File FastExactCover.h -----------------------*/
233
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::FastExactCover::nodes
long nodes(void) const
the nodes of the tree of the search of the last solve()
Definition
FastExactCover.h:177
ADS::FastExactCover::FastExactCover
FastExactCover(int primary, int secondary=0)
the items primary, the next ones secondary, and no option
ADS::FastExactCover::updates
long updates(void) const
the options taken out of a set by the last solve()
Definition
FastExactCover.h:174
ADS::FastExactCover::addOption
int addOption(const std::vector< int > &items, const std::vector< int > &colors={})
a new option, made of items, and its index; colors[ k ] is the color of items[ k ],...
ADS::FastExactCover::solve
long solve(F &&visit)
calls visit( options ) on each solution, the indices of its options in the order chosen,...
ADS::check
bool check(const Grid &S, std::size_t x, std::size_t y, int c)
whether can be written in the square of , i.e., it is not on its row, its column or its block
ADS
Definition
ADT.h:96
ADS
backtrack
FastExactCover.h
Generated by
1.17.0