66 int xy(
int x,
int y)
const {
80 for (
int i=0;
i<
n;
i++)
81 for (
int j=0; j<
n; j++)
94 for (
int i=0;
i<
n*
n;
i++)
95 dom(*
this,
b[
i], attacked(
i));
107 dom(*
this, q, (
n+1)/2, (
n+1)/2 + 1);
122 b.update(*
this, share, s.
b);
135 os <<
"\tNumber of Queens: " << q << std::endl;
136 os <<
"\tBoard: " <<
b << std::endl;
139 bool* placed =
new bool[
n*
n];
140 for (
int i=0;
i<
n*
n;
i++)
142 for (
int i=0;
i<
n*
n;
i++)
143 placed[
b[
i].val()] =
true;
144 for (
int j=0; j<
n; j++) {
146 for (
int i=0;
i<
n;
i++)
147 std::cout << (placed[xy(
i,j)] ?
'Q' :
'.') <<
' ';
148 std::cout << std::endl;
165 IntMinimizeScript::run<DominatingQueens,BAB,SizeOptions>(
opt);
DominatingQueens(const SizeOptions &opt)
The actual problem.
Options for scripts with additional size parameter
virtual IntVar cost(void) const
Return cost.
void update(Space &home, bool share, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
IntVar q
Number of queens.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
struct Gecode::@511::NNF::@54::@55 b
For binary nodes (and, or, eqv)
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
const int n
Size of the board.
int xy(int x, int y) const
Compute coordinate pair from x and y.
Parametric base-class for scripts.
int x(int xy) const
Compute x coordinate from pair xy.
IntVarArray b
Fields on the board.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
virtual Space * copy(bool share)
Perform copying during cloning.
DominatingQueens(bool share, DominatingQueens &s)
Constructor for cloning s.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Example: Dominating Queens
virtual void print(std::ostream &os) const
Print solution.
Passing integer arguments.
int y(int xy) const
Compute y coordinate from pair xy.
struct Gecode::@511::NNF::@54::@56 a
For atomic nodes.
IntSet attacked(int xy)
Compute set of fields that can be attacked by xy.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
IntValBranch INT_VAL_MAX(void)
Select largest value.
Node * x
Pointer to corresponding Boolean expression node.
void solutions(unsigned int n)
Set default number of solutions to search for.
int main(int argc, char *argv[])
Main-function.
Gecode toplevel namespace
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 nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntConLevel)
Post propagator for .