52 extern const int *specs[];
93 : spec(specs[opt.
size()]),
94 width(spec[0]), height(spec[1]),
95 x(*this, (width+1)*height, 0, 28) {
99 IntArgs board((width+1)*height);
100 for (
int i=0;
i<width;
i++)
101 for (
int j=0; j<height; j++)
102 board[j*(width+1)+
i] = spec[j*width+
i];
105 for (
int i=0;
i<height;
i++) {
106 board[
i*(width+1)+8] = -1;
107 rel(*
this, x[
i*(width+1)+8]==28);
119 int possibleDiffsA[] = {1, width+1};
120 IntSet possibleDiffs(possibleDiffsA, 2);
122 for (
int i=0;
i<=6;
i++)
123 for (
int j=
i; j<=6; j++) {
130 IntVar diff(*
this, possibleDiffs);
131 abs(*
this,
expr(*
this, p1[dominoCount]-p2[dominoCount]),
136 rel(*
this, p1[dominoCount],
IRT_LE, p2[dominoCount]);
139 element(*
this, board, p1[dominoCount],
i);
140 element(*
this, board, p2[dominoCount], j);
144 element(*
this, x, p1[dominoCount], dominoCount);
145 element(*
this, x, p2[dominoCount], dominoCount);
151 for (
int i=0;
i<=6;
i++)
152 for (
int j=
i; j<=6; j++) {
158 for (
int pos = 0;
pos < (width+1)*height; ++
pos) {
159 if ((
pos+1) % (width+1) != 0) {
160 if (board[
pos] ==
i && board[
pos+1] == j)
162 if (board[
pos] == j && board[
pos+1] ==
i &&
i != j)
165 if (
pos/(width+1) < height-1) {
166 if (board[
pos] ==
i && board[
pos+width+1] == j)
168 if (board[
pos] == j && board[
pos+width+1] ==
i &&
i != j)
173 piece[0] = p1[dominoCount];
174 piece[1] = p2[dominoCount];
180 element(*
this, x, p1[dominoCount], dominoCount);
181 element(*
this, x, p2[dominoCount], dominoCount);
188 for (
int i=0;
i<28;
i++) {
199 for (
int h = 0; h < height; ++h) {
201 for (
int w = 0; w < width; ++w) {
202 int val = x[h*(width+1)+w].
min();
203 char c = val < 10 ?
'0'+val :
'A' + (val-10);
212 Script(share,s), spec(s.spec), width(s.width), height(s.height) {
213 x.
update(*
this, share, s.x);
218 return new Domino(share,*
this);
234 opt.
parse(argc,argv);
235 if (opt.
size() >= n_examples) {
236 std::cerr <<
"Error: size must be between 0 and "
237 << n_examples-1 << std::endl;
240 Script::run<Domino,DFS,SizeOptions>(
opt);
254 const int domino0[] =
268 const int domino1[] =
282 const int domino2[] =
296 const int domino3[] =
310 const int domino4[] =
324 const int domino5[] =
339 {domino0,domino1,domino2,domino3,domino4,domino5};
341 const unsigned n_examples =
sizeof(specs)/
sizeof(
int*);
void size(unsigned int s)
Set default size.
Options for scripts with additional size parameter
virtual Space * copy(bool share)
Copy space during cloning.
Use extensional constraints.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Domino(const SizeOptions &opt)
Actual model.
void propagation(int v)
Set default propagation value.
Regular expressions over integer values.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
bool pos(const View &x)
Test whether x is postive.
int main(int argc, char *argv[])
Main-function.
Domino(bool share, Domino &s)
Constructor for cloning s.
Parametric base-class for scripts.
virtual void print(std::ostream &os) const
Print solution.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs p2(4, 4, 3, 3, 5)
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
Passing integer variables.
Passing integer arguments.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntConLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
BoolVar expr(Home home, const BoolExpr &e, IntConLevel icl)
Post Boolean expression and return its value.
const unsigned int n_examples
Number of board specifications.
Node * x
Pointer to corresponding Boolean expression node.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Gecode toplevel namespace
Example: Solitaire domino
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Gecode::IntArgs p1(4, 2, 2, 2, 2)
Domain propagation or consistency.