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;
112 const char* suit =
"SCHD";
113 std::ostringstream o;
114 o << std::setw(2) << (1 + (val%13)) << suit[val/13];
128 PROPAGATION_TUPLE_SET
132 : x(*this, 52, 0,51), y(*this, 52, 0,51)
145 for (
int i = 0;
i < 52; ++
i) {
148 for (
int i = 0;
i < 51; ++
i) {
149 IntVar x1(*
this, 0, 12), x2(*
this, 0, 12);
151 element(*
this, modtable, x[i+1], x2);
152 const int dr[2] = {1, 12};
159 for (
int r = 13;
r--; ) {
160 for (
int s1 = 4; s1--; ) {
161 for (
int s2 = 4; s2--; ) {
162 for (
int i = -1;
i <= 1;
i+=2) {
171 DFA table(expression);
173 for (
int i = 51;
i--; )
179 for (
int r = 13;
r--; )
180 for (
int s1 = 4; s1--; )
181 for (
int s2 = 4; s2--; )
182 for (
int i = -1;
i <= 1;
i+=2) {
187 for (
int i = 51;
i--; )
192 for (
int i = 17;
i--; )
193 for (
int j = 2; j--; )
194 rel(*
this, y[layout[
i][j]] < y[layout[
i][j+1]]);
201 if (opt.
symmetry() == SYMMETRY_CONDITIONAL) {
203 for (
int r = 13;
r--; ) {
205 for (
int s1 = 4; s1--; ) {
206 for (
int s2 = s1; s2--; ) {
210 if (c1 == 0 || c2 == 0)
continue;
212 if (pile[c1] == pile[c2])
continue;
214 int o1 = c1, o2 = c2;
215 if (pile[c1] > pile[c2] && layer[c2] >= layer[c1])
220 for (
int i = 0;
i < layer[o1]; ++
i)
221 ba <<
expr(*
this, (y[layout[pile[o1]][
i]] < y[o2]));
222 for (
int i = 0;
i < layer[o2]; ++
i)
223 ba <<
expr(*
this, (y[layout[pile[o2]][
i]] < y[o1]));
225 for (
int i = layer[o1]+1;
i < 3; ++
i)
226 ba <<
expr(*
this, (y[o2] < y[layout[pile[o1]][
i]]));
227 for (
int i = layer[o2]+1; i < 3; ++
i)
228 ba <<
expr(*
this, (y[o1] < y[layout[pile[o2]][i]]));
235 rel(*
this, !cond || (y[o1] < y[o2]));
249 if (layer[vals.val()] < w) {
251 if ((w = layer[vals.val()]) == 0)
254 assert(v >= 1 && v < 52);
260 os <<
"Layout:" << std::endl;
261 for (
int i = 0;
i < 17;
i++) {
262 for (
int j = 0; j < 3; j++)
263 os <<
card(layout[
i][j]) <<
" ";
269 os << std::endl << std::endl;
271 os <<
"Solution:" << std::endl;
272 for (
int i = 0;
i < 52; ++
i) {
274 os <<
card(x[
i].val()) <<
" ";
277 if ((
i + 1) % 13 == 0)
304 "no symmetry breaking");
306 "break conditional symmetries");
309 "reified",
"use reified propagation");
311 "dfa",
"use DFA-based extensional propagation");
313 "tuple-set",
"use TupleSet-based extensional propagation");
315 opt.
parse(argc,argv);
317 generate(opt.
size());
318 Script::run<BlackHole,DFS,SizeOptions>(
opt);
Value iterator for integer variables.
void size(unsigned int s)
Set default size.
Options for scripts with additional size parameter
Extensional propagation using automatons.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void finalize(void)
Finalize tuple set.
std::string card(int val) const
Return a string representing the card of value val.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
void propagation(int v)
Set default propagation value.
Extensional propagation using tables.
Regular expressions over integer values.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
static int val(const Space &, IntVar x, int)
Value selection function for branching.
bool pos(const View &x)
Test whether x is postive.
IntVarArray x
Card at position.
const unsigned int card
Maximum cardinality of an integer set.
Parametric base-class for scripts.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Example: Black hole patience
BlackHole(const SizeOptions &opt)
Actual model.
Deterministic finite automaton (DFA)
Gecode::IntArgs i(4, 1, 2, 3, 4)
BlackHole(bool share, BlackHole &s)
Constructor for cloning s.
Template for linear congruential generators.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
Passing integer variables.
Passing integer arguments.
Passing Boolean variables.
virtual void print(std::ostream &os) const
Print instance and solution.
Boolean integer variables.
Class represeting a set of tuples.
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntConLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
BoolVar expr(Home home, const BoolExpr &e, IntConLevel icl)
Post Boolean expression and return its value.
Node * x
Pointer to corresponding Boolean expression node.
Breaking conditional symmetries.
IntVarArray y
Position of card.
bool assigned(View x, int v)
Whether x is assigned to value v.
void symmetry(int v)
Set default symmetry value.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Gecode toplevel namespace
IntValBranch INT_VAL(IntBranchVal v, IntBranchCommit c)
Select value as defined by the value function v and commit function c Uses a commit function as defau...
BrancherHandle 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 add(const IntArgs &tuple)
Add tuple to tuple set.
int main(int argc, char *argv[])
Main-function.
void icl(IntConLevel i)
Set default integer consistency level.
Domain propagation or consistency.
virtual Space * copy(bool share)
Copy during cloning.