00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "examples/support.hh"
00041 #include "gecode/minimodel.hh"
00042
00043 namespace {
00044
00049 extern const int *specs[];
00054 extern const unsigned int n_examples;
00055
00056 }
00057
00069 class Domino : public Example {
00070 private:
00072 const int *spec;
00074 int width;
00076 int height;
00077
00079 IntVarArray x;
00080
00081 public:
00083 Domino(const SizeOptions& opt)
00084 : spec(specs[opt.size()]),
00085 width(spec[0]), height(spec[1]),
00086 x(this, (width+1)*height, 0, 28) {
00087 spec+=2;
00088
00089
00090 IntArgs board((width+1)*height);
00091 for (int i=0; i<width; i++)
00092 for (int j=0; j<height; j++)
00093 board[j*(width+1)+i] = spec[j*width+i];
00094
00095
00096 for (int i=0; i<height; i++) {
00097 board[i*(width+1)+8] = -1;
00098 post(this, x[i*(width+1)+8]==28);
00099 }
00100
00101
00102
00103 IntVarArray p1(this, 28, 0, (width+1)*height-1);
00104 IntVarArray p2(this, 28, 0, (width+1)*height-1);
00105
00106
00107 int dominoCount = 0;
00108
00109 int possibleDiffsA[] = {1, width+1};
00110 IntSet possibleDiffs(possibleDiffsA, 2);
00111
00112 for (int i=0; i<=6; i++)
00113 for (int j=i; j<=6; j++) {
00114
00115
00116
00117
00118
00119
00120 IntVar diff(this, possibleDiffs);
00121 abs(this, minus(this, p1[dominoCount], p2[dominoCount]),
00122 diff, ICL_DOM);
00123
00124
00125 if (i == j)
00126 rel(this, p1[dominoCount], IRT_LE, p2[dominoCount]);
00127
00128
00129 element(this, board, p1[dominoCount], i);
00130 element(this, board, p2[dominoCount], j);
00131
00132
00133
00134 element(this, x, p1[dominoCount], dominoCount);
00135 element(this, x, p2[dominoCount], dominoCount);
00136 dominoCount++;
00137 }
00138
00139
00140 IntVarArgs ps(28*2);
00141 for (int i=0; i<28; i++) {
00142 ps[2*i] = p1[i];
00143 ps[2*i+1] = p2[i];
00144 }
00145
00146
00147 branch(this, ps, INT_VAR_NONE, INT_VAL_MIN);
00148 }
00149
00151 virtual void
00152 print(std::ostream& os) {
00153 for (int h = 0; h < height; ++h) {
00154 os << "\t";
00155 for (int w = 0; w < width; ++w) {
00156 int val = x[h*(width+1)+w].min();
00157 char c = val < 10 ? '0'+val : 'A' + (val-10);
00158 os << c;
00159 }
00160 os << std::endl;
00161 }
00162 os << std::endl;
00163 }
00165 Domino(bool share, Domino& s) :
00166 Example(share,s), spec(s.spec), width(s.width), height(s.height) {
00167 x.update(this, share, s.x);
00168 }
00170 virtual Space*
00171 copy(bool share) {
00172 return new Domino(share,*this);
00173 }
00174
00175 };
00176
00177
00181 int
00182 main(int argc, char* argv[]) {
00183 SizeOptions opt("Domino");
00184 opt.size(0);
00185 opt.parse(argc,argv);
00186 if (opt.size() >= n_examples) {
00187 std::cerr << "Error: size must be between 0 and "
00188 << n_examples-1 << std::endl;
00189 return 1;
00190 }
00191 Example::run<Domino,DFS,SizeOptions>(opt);
00192 return 0;
00193 }
00194
00195
00196 namespace {
00197
00203
00205 const int domino0[] =
00206 {
00207 8,7,
00208
00209 2,1,0,3,0,4,5,5,
00210 6,2,0,6,3,1,4,0,
00211 3,2,3,6,2,5,4,3,
00212 5,4,5,1,1,2,1,2,
00213 0,0,1,5,0,5,4,4,
00214 4,6,2,1,3,6,6,1,
00215 4,2,0,6,5,3,3,6
00216 };
00217
00219 const int domino1[] =
00220 {
00221 8,7,
00222
00223 5,1,2,4,6,2,0,5,
00224 6,6,4,3,5,0,1,5,
00225 2,0,4,0,4,0,5,0,
00226 6,1,3,6,3,5,4,3,
00227 3,1,0,1,2,2,1,4,
00228 3,6,6,2,4,0,5,4,
00229 1,3,6,1,2,3,5,2
00230 };
00231
00233 const int domino2[] =
00234 {
00235 8,7,
00236
00237 4,4,5,4,0,3,6,5,
00238 1,6,0,1,5,3,4,1,
00239 2,6,2,2,5,3,6,0,
00240 1,3,0,6,4,4,2,3,
00241 3,5,5,2,4,2,2,1,
00242 2,1,3,3,5,6,6,1,
00243 5,1,6,0,0,0,4,0
00244 };
00245
00247 const int domino3[] =
00248 {
00249 8,7,
00250
00251 3,0,2,3,3,4,4,3,
00252 6,5,3,4,2,0,2,1,
00253 6,5,1,2,3,0,2,0,
00254 4,5,4,1,6,6,2,5,
00255 4,3,6,1,0,4,5,5,
00256 1,3,2,5,6,0,0,1,
00257 0,5,4,6,2,1,6,1
00258 };
00259
00261 const int domino4[] =
00262 {
00263 8,7,
00264
00265 4,1,5,2,4,4,6,2,
00266 2,5,6,1,4,6,0,2,
00267 6,5,1,1,0,1,4,3,
00268 6,2,1,1,3,2,0,6,
00269 3,6,3,3,5,5,0,5,
00270 3,0,1,0,0,5,4,3,
00271 3,2,4,5,4,2,6,0
00272 };
00273
00275 const int domino5[] =
00276 {
00277 8,7,
00278
00279 4,1,2,1,0,2,4,4,
00280 5,5,6,6,0,4,6,3,
00281 6,0,5,1,1,0,5,3,
00282 3,4,2,2,0,3,1,2,
00283 3,6,5,6,1,2,3,2,
00284 2,5,0,6,6,3,3,5,
00285 4,1,0,0,4,1,4,5
00286 };
00287
00289 const int *specs[] =
00290 {domino0,domino1,domino2,domino3,domino4,domino5};
00292 const unsigned n_examples = sizeof(specs)/sizeof(int*);
00294
00295 }
00296
00297