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)
158 valids |=
REG(pos) +
REG(pos+1);
159 if (board[pos] == j && board[pos+1] == i && i != j)
160 valids |=
REG(pos+1) +
REG(pos);
162 if (pos/(width+1) < height-1) {
163 if (board[pos] == i && board[pos+width+1] == j)
164 valids |=
REG(pos) +
REG(pos+width+1);
165 if (board[pos] == j && board[pos+width+1] == i && i != j)
166 valids |=
REG(pos+width+1) +
REG(pos);
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) {
208 x.update(*
this, s.x);
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;
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*);
Node * x
Pointer to corresponding Boolean expression node.
Example: Solitaire domino
int main(int argc, char *argv[])
Main-function.
virtual Space * copy(void)
Copy space during cloning.
const unsigned int n_examples
Number of board specifications.
Domino(Domino &s)
Constructor for cloning s.
virtual void print(std::ostream &os) const
Print solution.
@ PROP_EXTENSIONAL
Use extensional constraints.
@ PROP_ELEMENT
Use element constraints.
Domino(const SizeOptions &opt)
Actual model.
const int * specs[]
Board specifications.
Parametric base-class for scripts.
static void run(const Options &opt, Script *s=NULL)
Passing integer arguments.
Passing integer variables.
Regular expressions over integer values.
Options for scripts with additional size parameter
void parse(int argc, char *argv[])
Parse commandline arguments.
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Branch over x with variable selection vars and value selection vals.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
void extensional(Home home, const IntVarArgs &x, DFA d, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for extensional constraint described by a DFA.
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Gecode toplevel namespace
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
IntValBranch INT_VAL_MIN(void)
Select smallest value.