45 using namespace Gecode;
51 vector<vector<int> > layout;
53 vector<int> layer, pile;
61 void generate(
int seed) {
63 layout = vector<vector<int> >(17, vector<int>(3));
66 for (
int i = 51;
i--; ) deck[
i] =
i+1;
68 std::random_shuffle(deck.begin(), deck.end(), rnd);
72 for (
int i = 17;
i--; )
73 for (
int j = 3; j--; )
74 layout[
i][j] = deck[pos++];
77 layer = vector<int>(52);
78 pile = vector<int>(52);
79 for (
int i = 17;
i--; ) {
80 for (
int j = 3; j--; ) {
81 layer[layout[
i][j]] = j;
82 pile[ layout[
i][j]] =
i;
115 : Gecode::
Choice(b,2), pos(pos0), val(val0) {}
117 virtual size_t size(
void)
const {
129 :
Brancher(home), x(xv), start(0) {}
132 :
Brancher(home, share, b), start(b.start) {
133 x.update(home, share, b.
x);
139 for (
int i = start;
i < x.
size(); ++
i)
152 if (layer[vals.val()] < w) {
154 if ((w = layer[vals.val()]) == 0)
break;
157 assert(val >= 1 && val < 52);
158 return new Choice(*
this, start, val);
164 return new Choice(*
this, pos, val);
186 return sizeof(*this);
215 const char* suit =
"SCHD";
216 std::ostringstream o;
217 o << std::setw(2) << (1 + (val%13)) << suit[val/13];
231 PROPAGATION_TUPLE_SET
235 : x(*this, 52, 0,51), y(*this, 52, 0,51)
248 for (
int i = 0;
i < 52; ++
i) {
251 for (
int i = 0;
i < 51; ++
i) {
252 IntVar x1(*
this, 0, 12), x2(*
this, 0, 12);
254 element(*
this, modtable, x[i+1], x2);
255 const int dr[2] = {1, 12};
262 for (
int r = 13;
r--; ) {
263 for (
int s1 = 4; s1--; ) {
264 for (
int s2 = 4; s2--; ) {
265 for (
int i = -1;
i <= 1;
i+=2) {
274 DFA table(expression);
276 for (
int i = 51;
i--; )
282 for (
int r = 13;
r--; )
283 for (
int s1 = 4; s1--; )
284 for (
int s2 = 4; s2--; )
285 for (
int i = -1;
i <= 1;
i+=2) {
290 for (
int i = 51;
i--; )
295 for (
int i = 17;
i--; )
296 for (
int j = 2; j--; )
297 rel(*
this, y[layout[
i][j]] < y[layout[
i][j+1]]);
304 if (opt.
symmetry() == SYMMETRY_CONDITIONAL) {
306 for (
int r = 13;
r--; ) {
308 for (
int s1 = 4; s1--; ) {
309 for (
int s2 = s1; s2--; ) {
313 if (c1 == 0 || c2 == 0)
continue;
315 if (pile[c1] == pile[c2])
continue;
317 int o1 = c1, o2 = c2;
318 if (pile[c1] > pile[c2] && layer[c2] >= layer[c1])
323 for (
int i = 0;
i < layer[o1]; ++
i)
324 ba <<
expr(*
this, (y[layout[pile[o1]][
i]] < y[o2]));
325 for (
int i = 0;
i < layer[o2]; ++
i)
326 ba <<
expr(*
this, (y[layout[pile[o2]][
i]] < y[o1]));
328 for (
int i = layer[o1]+1;
i < 3; ++
i)
329 ba <<
expr(*
this, (y[o2] < y[layout[pile[o1]][
i]]));
330 for (
int i = layer[o2]+1; i < 3; ++
i)
331 ba <<
expr(*
this, (y[o1] < y[layout[pile[o2]][i]]));
338 rel(*
this, !cond || (y[o1] < y[o2]));
351 os <<
"Layout:" << std::endl;
352 for (
int i = 0;
i < 17;
i++) {
353 for (
int j = 0; j < 3; j++)
354 os <<
card(layout[
i][j]) <<
" ";
360 os << std::endl << std::endl;
362 os <<
"Solution:" << std::endl;
363 for (
int i = 0;
i < 52; ++
i) {
365 os <<
card(x[
i].val()) <<
" ";
368 if ((
i + 1) % 13 == 0)
377 x.update(*
this, share, s.
x);
378 y.update(*
this, share, s.
y);
395 "no symmetry breaking");
397 "break conditional symmetries");
400 "reified",
"use reified propagation");
402 "dfa",
"use DFA-based extensional propagation");
404 "tuple-set",
"use TupleSet-based extensional propagation");
406 opt.
parse(argc,argv);
408 generate(opt.
size());
409 Script::run<BlackHole,DFS,SizeOptions>(
opt);