48 vector<vector<int> > layout;
50 vector<int> layer, pile;
58 void generate(
int seed) {
60 layout = vector<vector<int> >(17, vector<int>(3));
63 for (
int i = 51; i--; ) deck[i] = i+1;
65 std::shuffle(deck.begin(), deck.end(), rnd);
69 for (
int i = 17; i--; )
70 for (
int j = 3; j--; )
71 layout[i][j] = deck[pos++];
74 layer = vector<int>(52);
75 pile = vector<int>(52);
76 for (
int i = 17; i--; ) {
77 for (
int j = 3; j--; ) {
78 layer[layout[i][j]] = j;
79 pile[ layout[i][j]] = i;
109 const char* suit =
"SCHD";
110 std::ostringstream o;
111 o << std::setw(2) << (1 + (
val%13)) << suit[
val/13];
129 :
Script(opt),
x(*this, 52, 0,51),
y(*this, 52, 0,51) {
141 for (
int i = 0; i < 52; ++i) {
144 for (
int i = 0; i < 51; ++i) {
145 IntVar x1(*
this, 0, 12), x2(*
this, 0, 12);
147 element(*
this, modtable,
x[i+1], x2);
148 const int dr[2] = {1, 12};
155 for (
int r = 13; r--; ) {
156 for (
int s1 = 4; s1--; ) {
157 for (
int s2 = 4; s2--; ) {
158 for (
int i = -1; i <= 1; i+=2) {
160 REG r2 =
REG((r+i+52+13*s2)%52);
167 DFA table(expression);
169 for (
int i = 51; i--; )
175 for (
int r = 13; r--; )
176 for (
int s1 = 4; s1--; )
177 for (
int s2 = 4; s2--; )
178 for (
int i = -1; i <= 1; i+=2)
179 ts.
add({r+13*s1, (r+i+52+13*s2)%52});
182 for (
int i = 51; i--; )
187 for (
int i = 17; i--; )
188 for (
int j = 2; j--; )
189 rel(*
this,
y[layout[i][j]] <
y[layout[i][j+1]]);
198 for (
int r = 13; r--; ) {
200 for (
int s1 = 4; s1--; ) {
201 for (
int s2 = s1; s2--; ) {
205 if (c1 == 0 || c2 == 0)
continue;
207 if (pile[c1] == pile[c2])
continue;
209 int o1 = c1, o2 = c2;
210 if (pile[c1] > pile[c2] && layer[c2] >= layer[c1])
215 for (
int i = 0; i < layer[o1]; ++i)
216 ba <<
expr(*
this, (
y[layout[pile[o1]][i]] <
y[o2]));
217 for (
int i = 0; i < layer[o2]; ++i)
218 ba <<
expr(*
this, (
y[layout[pile[o2]][i]] <
y[o1]));
220 for (
int i = layer[o1]+1; i < 3; ++i)
221 ba <<
expr(*
this, (
y[o2] <
y[layout[pile[o1]][i]]));
222 for (
int i = layer[o2]+1; i < 3; ++i)
223 ba <<
expr(*
this, (
y[o1] <
y[layout[pile[o2]][i]]));
230 rel(*
this, !cond || (
y[o1] <
y[o2]));
244 if (layer[vals.val()] < w) {
246 if ((w = layer[vals.val()]) == 0)
249 assert(v >= 1 && v < 52);
255 os <<
"Layout:" << std::endl;
256 for (
int i = 0; i < 17; i++) {
257 for (
int j = 0; j < 3; j++)
258 os <<
card(layout[i][j]) <<
" ";
264 os << std::endl << std::endl;
266 os <<
"Solution:" << std::endl;
267 for (
int i = 0; i < 52; ++i) {
272 if ((i + 1) % 13 == 0)
299 "no symmetry breaking");
301 "break conditional symmetries");
304 "reified",
"use reified propagation");
306 "dfa",
"use DFA-based extensional propagation");
308 "tuple-set",
"use TupleSet-based extensional propagation");
310 opt.
parse(argc,argv);
312 generate(opt.size());
int main(int argc, char *argv[])
Main-function.
BlackHole(BlackHole &s)
Constructor for cloning s.
@ SYMMETRY_CONDITIONAL
Breaking conditional symmetries.
@ SYMMETRY_NONE
No symmetry breaking.
IntVarArray x
Card at position.
std::string card(int val) const
Return a string representing the card of value val.
BlackHole(const SizeOptions &opt)
Actual model.
virtual Space * copy(void)
Copy during cloning.
static int val(const Space &, IntVar x, int)
Value selection function for branching.
IntVarArray y
Position of card.
@ PROPAGATION_REIFIED
Reified propagation.
@ PROPAGATION_DFA
Extensional propagation using automatons.
@ PROPAGATION_TUPLE_SET
Extensional propagation using tables.
virtual void print(std::ostream &os) const
Print instance and solution.
Passing Boolean variables.
Boolean integer variables.
Finite automaton with deterministic construction by default.
static void run(const Options &opt, Script *s=nullptr)
Passing integer arguments.
IntSet(void)
Initialize as empty set.
IntVarArgs(void)
Allocate empty array.
Value iterator for integer variables.
Regular expressions over integer values.
REG(void)
Initialize as empty sequence (epsilon).
Options for scripts with additional size parameter
Class representing a set of tuples.
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
void finalize(void)
Finalize tuple set with dense support data.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
void parse(int argc, char *argv[])
Parse commandline arguments.
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
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.
@ EPK_AUTO
Select dense or compressed representation automatically.
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
bool pos(const View &x)
Test whether x is positive.
Gecode toplevel namespace
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
IntValBranch INT_VAL(IntBranchVal v, IntBranchCommit c=nullptr)
Select value as defined by the value function v and commit function c Uses a commit function as defau...
IntPropLevel ba(IntPropLevel ipl)
Extract basic or advanced from propagation level.
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 .