52 extern const int *specs[];
95 width(spec[0]), height(spec[1]),
96 x(*this, (width+1)*height, 0, 28) {
100 IntArgs board((width+1)*height);
101 for (
int i=0;
i<width;
i++)
102 for (
int j=0; j<height; j++)
103 board[j*(width+1)+
i] = spec[j*width+
i];
106 for (
int i=0;
i<height;
i++) {
107 board[
i*(width+1)+8] = -1;
108 rel(*
this,
x[
i*(width+1)+8]==28);
113 IntVarArgs p1(*
this, 28, 0, (width+1)*height-1);
114 IntVarArgs p2(*
this, 28, 0, (width+1)*height-1);
117 if (
opt.propagation() == PROP_ELEMENT) {
120 int possibleDiffsA[] = {1, width+1};
121 IntSet possibleDiffs(possibleDiffsA, 2);
123 for (
int i=0;
i<=6;
i++)
124 for (
int j=
i; j<=6; j++) {
131 IntVar diff(*
this, possibleDiffs);
132 abs(*
this,
expr(*
this, p1[dominoCount]-p2[dominoCount]),
137 rel(*
this, p1[dominoCount],
IRT_LE, p2[dominoCount]);
140 element(*
this, board, p1[dominoCount],
i);
141 element(*
this, board, p2[dominoCount], j);
145 element(*
this,
x, p1[dominoCount], dominoCount);
146 element(*
this,
x, p2[dominoCount], dominoCount);
152 for (
int i=0;
i<=6;
i++)
153 for (
int j=
i; j<=6; j++) {
159 for (
int pos = 0;
pos < (width+1)*height; ++
pos) {
160 if ((
pos+1) % (width+1) != 0) {
161 if (board[
pos] ==
i && board[
pos+1] == j)
163 if (board[
pos] == j && board[
pos+1] ==
i &&
i != j)
166 if (
pos/(width+1) < height-1) {
167 if (board[
pos] ==
i && board[
pos+width+1] == j)
169 if (board[
pos] == j && board[
pos+width+1] ==
i &&
i != j)
174 piece[0] = p1[dominoCount];
175 piece[1] = p2[dominoCount];
181 element(*
this,
x, p1[dominoCount], dominoCount);
182 element(*
this,
x, p2[dominoCount], dominoCount);
189 for (
int i=0;
i<28;
i++) {
200 for (
int h = 0; h < height; ++h) {
202 for (
int w = 0; w < width; ++w) {
203 int val =
x[h*(width+1)+w].
min();
204 char c = val < 10 ?
'0'+val :
'A' + (val-10);
213 Script(share,s), spec(s.spec), width(s.width), height(s.height) {
219 return new Domino(share,*
this);
236 if (
opt.size() >= n_examples) {
237 std::cerr <<
"Error: size must be between 0 and " 238 << n_examples-1 << std::endl;
241 Script::run<Domino,DFS,SizeOptions>(
opt);
255 const int domino0[] =
269 const int domino1[] =
283 const int domino2[] =
297 const int domino3[] =
311 const int domino4[] =
325 const int domino5[] =
340 {domino0,domino1,domino2,domino3,domino4,domino5};
342 const unsigned n_examples =
sizeof(specs)/
sizeof(
int*);
Use extensional constraints.
Options for scripts with additional size parameter
virtual Space * copy(bool share)
Copy space during cloning.
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, bool share, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Regular expressions over integer values.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
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.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual void print(std::ostream &os) const
Print solution.
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 parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
const unsigned int n_examples
Number of board specifications.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Domain propagation Preferences: prefer speed or memory.
Post propagator for SetVar x
Gecode toplevel namespace
Example: Solitaire domino
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .