Go to the documentation of this file.
42 #ifdef GECODE_HAS_SET_VARS
60 #ifdef GECODE_HAS_SET_VARS
80 n(example_size(examples[
opt.
size()])) {}
97 #ifdef GECODE_HAS_SET_VARS
111 for (
int i=0;
i<nn;
i++) {
117 for (
int i=0;
i<nn;
i+=
n) {
118 for (
int j=0; j<nn; j+=
n) {
124 for (
int i=0;
i<nn;
i++)
125 for (
int j=0; j<nn; j++)
126 if (
int v = sudokuField(examples[
opt.size()], nn,
i, j))
129 #ifdef GECODE_HAS_SET_VARS
130 if (
opt.propagation() == PROP_SAME) {
132 for (
int b=0;
b<
n;
b++) {
139 for (
int i=0;
i<
n;
i++)
140 for (
int j=0; j<
n; j++) {
142 for (
int k=0; k<
n; k++) {
147 bc1[b1c] = bc1s[
count];
148 br1[b1c] = br1s[
count];
156 bc2[b2c] = bc2s[
count];
157 br2[b2c] = br2s[
count];
162 same(*
this, nn, bc1, bc2);
163 same(*
this, nn, br1, br2);
168 if (
opt.branching() == BRANCH_NONE) {
170 }
else if (
opt.branching() == BRANCH_SIZE) {
172 }
else if (
opt.branching() == BRANCH_SIZE_DEGREE) {
174 }
else if (
opt.branching() == BRANCH_SIZE_AFC) {
176 }
else if (
opt.branching() == BRANCH_AFC) {
196 for (
int i = 0;
i<
n*
n*
n*
n;
i++) {
201 os << (char)(
x[
i].val()+
'A'-10) <<
" ";
206 os << std::endl <<
" ";
211 #ifdef GECODE_HAS_SET_VARS
234 #ifdef GECODE_HAS_SET_VARS
249 static_cast<unsigned int>(
n*
n),static_cast<unsigned int>(
n*
n)) {
259 int* dsc =
r.alloc<
int>(nn);
260 for (
int i=0;
i<nn;
i++) {
263 for (
int j=0; j<nn; j++) {
270 int* dsb_arr =
r.alloc<
int>(nn);
271 for (
int i=0;
i<
n;
i++) {
272 for (
int j=0; j<
n; j++) {
274 for (
int ii=0; ii<
n; ii++) {
275 for (
int jj=0; jj<
n; jj++) {
276 dsb_arr[ii*
n+jj] = j*nn*
n+
i*
n+jj*nn+ii+1;
289 for (
int i=0;
i<nn;
i++)
290 for (
int j=0; j<nn; j++) {
300 for (
int i=0;
i<nn;
i++)
301 for (
int j=0; j<nn; j++)
302 if (
int idx = sudokuField(examples[
opt.size()], nn,
i, j))
305 if (
opt.branching() == BRANCH_NONE) {
307 }
else if (
opt.branching() == BRANCH_SIZE) {
309 }
else if (
opt.branching() == BRANCH_SIZE_DEGREE) {
311 }
else if (
opt.branching() == BRANCH_SIZE_AFC) {
313 }
else if (
opt.branching() == BRANCH_AFC) {
333 for (
int i = 0;
i<
n*
n*
n*
n;
i++) {
334 for (
int j=0; j<
n*
n; j++) {
335 if (
y[j].contains(
i+1)) {
339 os << (char)(j+1+
'A'-10) <<
" ";
344 os << std::endl <<
'\t';
365 SetVar dummySet0(*
this, is0, is0);
366 IntVar dummyInt0(*
this, 0, 0);
369 for (
int i=0;
i<nn;
i++)
373 for (
int i=0;
i<nn*nn;
i++)
379 for (
int i=0;
i<nn;
i++)
410 #ifdef GECODE_HAS_SET_VARS
415 "use both integer and set constraints");
419 "additional \"same\" constraint for integer model");
428 if (
opt.size() >= n_examples) {
429 std::cerr <<
"Error: size must be between 0 and "
430 << n_examples-1 << std::endl;
433 #ifdef GECODE_HAS_SET_VARS
436 Script::run<SudokuInt,DFS,SizeOptions>(
opt);
439 Script::run<SudokuSet,DFS,SizeOptions>(
opt);
442 Script::run<SudokuMixed,DFS,SizeOptions>(
opt);
446 Script::run<SudokuInt,DFS,SizeOptions>(
opt);
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl)
Post constraint .
SudokuSet(SudokuSet &s)
Constructor for cloning s.
@ MODEL_INT
Use integer constraints.
virtual void print(std::ostream &os) const
Print solution.
Post propagator for SetVar x
Post propagator for SetVar SetOpType SetVar y
@ PROP_SAME
Use "same" constraint with integer model.
void propagation(int v)
Set default propagation value.
const int n
The size of the problem.
@ MODEL_SET
Use set constraints.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
SetVarArray y
The fields occupied by a certain number.
Passing integer variables.
unsigned int size(I &i)
Size of all ranges of range iterator i.
static const IntSet empty
Empty set.
Slice< A > row(int r) const
Access row r.
bool assigned(View x, int v)
Whether x is assigned to value v.
SetVarBranch SET_VAR_DEGREE_SIZE_MAX(BranchTbl tbl)
void ipl(IntPropLevel i)
Set default integer propagation level.
Example: Solving Sudoku puzzles using set constraints
SudokuMixed(const SizeOptions &opt)
Constructor.
Example: Solving Sudoku puzzles using integer constraints
void 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.
SudokuMixed(SudokuMixed &s)
Constructor for cloning s.
SetVarBranch SET_VAR_NONE(void)
int main(int argc, char *argv[])
Main-function.
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
SetVarBranch SET_VAR_AFC_MAX(double d, BranchTbl tbl)
@ BRANCH_SIZE_AFC
Use minimum size over afc.
virtual Space * copy(void)
Perform copying during cloning.
Gecode toplevel namespace
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Parametric base-class for scripts.
void branching(int v)
Set default branching value.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Post propagator for SetVar SetOpType SetVar SetRelType r
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
SetValBranch SET_VAL_MIN_INC(void)
Base class for Sudoku puzzles.
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Slice< A > slice(int fc, int tc, int fr, int tr) const
Access slice of the matrix.
IntVarBranch INT_VAR_DEGREE_SIZE_MAX(BranchTbl tbl)
Select variable with largest degree divided by domain size.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Matrix-interface for arrays.
virtual Space * copy(void)
Perform copying during cloning.
@ SOT_DUNION
Disjoint union.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Slice< A > col(int c) const
Access column c.
@ BRANCH_SIZE_DEGREE
Use minimum size over degree.
@ BRANCH_SIZE
Use minimum size.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Example: Solving Sudoku puzzles using both set and integer constraints
virtual void print(std::ostream &os) const
Print solution.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
@ BRANCH_AFC
Use maximum afc.
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
void solutions(unsigned int n)
Set default number of solutions to search for.
Sudoku(const SizeOptions &opt)
Constructor.
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl)
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
@ BRANCH_NONE
Use lexicographic ordering.
virtual Space * copy(void)
Perform copying during cloning.
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
IntVarArray x
Values for the fields.
void model(int v)
Set default model value.
int n
Number of negative literals for node type.
Passing integer arguments.
@ PROP_NONE
No additional constraints.
Gecode::IntArgs i({1, 2, 3, 4})
SudokuInt(SudokuInt &s)
Constructor for cloning s.
virtual void print(std::ostream &os) const
Print solution.
Sudoku(Sudoku &s)
Constructor for cloning s.
@ MODEL_MIXED
Use both integer and set constraints.
SudokuSet(const SizeOptions &opt)
Constructor.
Options for scripts with additional size parameter
IntVarBranch INT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.