48 extern const int *specs[];
90 spec(specs[opt.
size()]),
91 width(spec[0]), height(spec[1]),
92 x(*this, (width+1)*height, 0, 28) {
96 IntArgs board((width+1)*height);
97 for (
int i=0;
i<width;
i++)
98 for (
int j=0; j<height; j++)
99 board[j*(width+1)+
i] = spec[j*width+
i];
102 for (
int i=0;
i<height;
i++) {
103 board[
i*(width+1)+8] = -1;
104 rel(*
this, x[
i*(width+1)+8]==28);
109 IntVarArgs p1(*
this, 28, 0, (width+1)*height-1);
110 IntVarArgs p2(*
this, 28, 0, (width+1)*height-1);
116 int possibleDiffsA[] = {1, width+1};
117 IntSet possibleDiffs(possibleDiffsA, 2);
119 for (
int i=0;
i<=6;
i++)
120 for (
int j=
i; j<=6; j++) {
127 IntVar diff(*
this, possibleDiffs);
128 abs(*
this,
expr(*
this, p1[dominoCount]-p2[dominoCount]),
133 rel(*
this, p1[dominoCount],
IRT_LE, p2[dominoCount]);
136 element(*
this, board, p1[dominoCount],
i);
137 element(*
this, board, p2[dominoCount], j);
141 element(*
this, x, p1[dominoCount], dominoCount);
142 element(*
this, x, p2[dominoCount], dominoCount);
148 for (
int i=0;
i<=6;
i++)
149 for (
int j=
i; j<=6; j++) {
155 for (
int pos = 0;
pos < (width+1)*height; ++
pos) {
156 if ((
pos+1) % (width+1) != 0) {
157 if (board[
pos] ==
i && board[
pos+1] == j)
159 if (board[
pos] == j && board[
pos+1] ==
i &&
i != j)
162 if (
pos/(width+1) < height-1) {
163 if (board[
pos] ==
i && board[
pos+width+1] == j)
165 if (board[
pos] == j && board[
pos+width+1] ==
i &&
i != j)
175 element(*
this, x, p1[dominoCount], dominoCount);
176 element(*
this, x, p2[dominoCount], dominoCount);
183 for (
int i=0;
i<28;
i++) {
194 for (
int h = 0; h < height; ++h) {
196 for (
int w = 0; w < width; ++w) {
197 int val = x[h*(width+1)+w].
min();
198 char c = val < 10 ?
'0'+val :
'A' + (val-10);
207 Script(s), spec(s.spec), width(s.width), height(s.height) {
229 opt.
parse(argc,argv);
230 if (opt.
size() >= n_examples) {
231 std::cerr <<
"Error: size must be between 0 and " 232 << n_examples-1 << std::endl;
235 Script::run<Domino,DFS,SizeOptions>(
opt);
249 const int domino0[] =
263 const int domino1[] =
277 const int domino2[] =
291 const int domino3[] =
305 const int domino4[] =
319 const int domino5[] =
334 {domino0,domino1,domino2,domino3,domino4,domino5};
336 const unsigned n_examples =
sizeof(specs)/
sizeof(
int*);
void size(unsigned int s)
Set default size.
Options for scripts with additional size parameter
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Domino(const SizeOptions &opt)
Actual model.
void 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.
void propagation(int v)
Set default propagation value.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
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.
Parametric base-class for scripts.
Gecode::FloatVal c(-8, 8)
Domino(Domino &s)
Constructor for cloning s.
virtual void print(std::ostream &os) const
Print solution.
Gecode::IntArgs i({1, 2, 3, 4})
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Passing integer variables.
Passing integer arguments.
BoolVar expr(Home home, const BoolExpr &e, IntPropLevel ipl)
Post Boolean expression and return its value.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
virtual Space * copy(void)
Copy space during cloning.
const unsigned int n_examples
Number of board specifications.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Domain propagation Options: basic versus advanced propagation.
Post propagator for SetVar x
Use extensional constraints.
Gecode toplevel namespace
Example: Solitaire domino
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .