ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
DancingLinks.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*-------------------------- File DancingLinks.h ---------------------------*/
3
/*--------------------------------------------------------------------------*/
40
/*--------------------------------------------------------------------------*/
41
/*----------------------------- DEFINITIONS --------------------------------*/
42
/*--------------------------------------------------------------------------*/
43
44
#ifndef __ADS_DancingLinks
45
#define __ADS_DancingLinks
46
/* self-identification: #endif constant */
47
48
/*--------------------------------------------------------------------------*/
49
/*------------------------------ INCLUDES ----------------------------------*/
50
/*--------------------------------------------------------------------------*/
51
52
#include "
ADS/Contract.h
"
53
54
#include <algorithm>
55
#include <cstddef>
56
#include <utility>
57
#include <vector>
58
59
/*--------------------------------------------------------------------------*/
60
/*--------------------------- NAMESPACE ------------------------------------*/
61
/*--------------------------------------------------------------------------*/
62
63
namespace
ADS
64
{
65
66
/*--------------------------------------------------------------------------*/
67
/*--------------------------- CLASS ExactCover -----------------------------*/
68
/*--------------------------------------------------------------------------*/
69
72
class
ExactCover
73
{
74
75
/*--------------------------------------------------------------------------*/
76
public
:
80
ExactCover
(
int
primary ,
int
secondary = 0 );
81
87
int
addOption
(
const
std::vector< int > & items );
88
138
template
<
class
F >
139
long
solve
( F && visit );
140
142
[[nodiscard]]
long
updates
(
void
)
const
{
return
( f_updates ); }
143
144
/*--------------------------------------------------------------------------*/
145
private
:
146
void
cover(
int
i );
147
void
uncover(
int
i );
148
void
hide(
int
p );
149
void
unhide(
int
p );
150
151
[[nodiscard]]
bool
exact(
const
std::vector< int > & options )
const
;
152
153
int
f_primary , f_items;
154
std::vector< int > f_L , f_R;
155
std::vector< int > f_U , f_D , f_top;
156
std::vector< int > f_len;
157
std::vector< int > f_option;
158
std::vector< std::vector< int > > f_options;
159
long
f_updates = 0;
160
161
};
// end( class ExactCover )
162
163
/*--------------------------------------------------------------------------*/
164
165
}
// end( namespace ADS )
166
167
/*--------------------------------------------------------------------------*/
168
/*-------------------------- IMPLEMENTATION --------------------------------*/
169
/*--------------------------------------------------------------------------*/
170
171
#include "ADS/backtrack/impl/DancingLinks.tpp"
172
173
/*--------------------------------------------------------------------------*/
174
175
#endif
/* DancingLinks.h included */
176
177
/*--------------------------------------------------------------------------*/
178
/*------------------------ End File DancingLinks.h -------------------------*/
179
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::ExactCover::solve
long solve(F &&visit)
calls visit( options ) on each solution, the indices of its options, until it returns true; the numbe...
ADS::ExactCover::updates
long updates(void) const
the nodes updated by the last solve(), Knuth's measure of the work
Definition
DancingLinks.h:142
ADS::ExactCover::ExactCover
ExactCover(int primary, int secondary=0)
the items primary, the next ones secondary, and no option
ADS::ExactCover::addOption
int addOption(const std::vector< int > &items)
a new option, made of items, and its index; a node at the bottom of the list of each of its items
ADS
Definition
ADT.h:96
ADS
backtrack
DancingLinks.h
Generated by
1.17.0