66 int xy(
int x,
int y)
const {
80 for (
int i=0;
i<
n;
i++)
81 for (
int j=0; j<
n; j++)
91 : n(opt.
size()), b(*this,n*n,0,n*n-1), q(*this,1,n) {
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);
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;
164 opt.
parse(argc,argv);
165 IntMinimizeScript::run<DominatingQueens,BAB,SizeOptions>(
opt);
void size(unsigned int s)
Set default size.
DominatingQueens(const SizeOptions &opt)
The actual problem.
Options for scripts with additional size parameter
int x(int xy) const
Compute x coordinate from pair xy.
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 .
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
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.
Parametric base-class for scripts.
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.
bool assigned(void) const
Test if all variables are assigned.
Passing integer arguments.
IntSet attacked(int xy)
Compute set of fields that can be attacked by xy.
int y(int xy) const
Compute y coordinate from pair xy.
IntValBranch INT_VAL_MAX(void)
Select largest value.
Node * x
Pointer to corresponding Boolean expression node.
int xy(int x, int y) const
Compute coordinate pair from x and y.
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.
struct Gecode::@512::NNF::@54::@56 a
For atomic nodes.
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntConLevel)
Post propagator for .