40 using namespace Gecode;
48 extern const int *specs[];
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);
113 if (
opt.propagation() == PROP_ELEMENT) {
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) {
208 x.update(*
this, s.x);
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*);
BoolVar expr(Home home, const BoolExpr &e, const IntPropLevels &ipls)
Post Boolean expression and return its value.
Node * x
Pointer to corresponding Boolean expression node.
Example: Solitaire domino
int main(int argc, char *argv[])
Main-function.
const unsigned int n_examples
Number of board specifications.
virtual Space * copy(void)
Copy space during cloning.
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.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Parametric base-class for scripts.
Passing integer arguments.
Passing integer variables.
void propagation(int v)
Set default propagation value.
Regular expressions over integer values.
Options for scripts with additional size parameter
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
bool pos(const View &x)
Test whether x is postive.
const FloatNum min
Smallest allowed float value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})