66 int xy(
int x,
int y)
const {
80 for (
int i=0;
i<
n;
i++)
81 for (
int j=0; j<
n; j++)
92 n(opt.
size()), b(*this,n*n,0,n*n-1), q(*this,1,n) {
95 for (
int i=0;
i<n*
n;
i++)
96 dom(*
this, b[
i], attacked(i));
108 dom(*
this, q, (n+1)/2, (n+1)/2 + 1);
136 os <<
"\tNumber of Queens: " << q << std::endl;
137 os <<
"\tBoard: " << b << std::endl;
140 bool* placed =
new bool[n*
n];
141 for (
int i=0;
i<n*
n;
i++)
143 for (
int i=0;
i<n*
n;
i++)
144 placed[b[
i].val()] =
true;
145 for (
int j=0; j<
n; j++) {
147 for (
int i=0;
i<
n;
i++)
148 std::cout << (placed[xy(
i,j)] ?
'Q' :
'.') <<
' ';
149 std::cout << std::endl;
165 opt.
parse(argc,argv);
166 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
virtual IntVar cost(void) const
Return cost.
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.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
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)
bool assigned(void) const
Test if all variables are assigned.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
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.
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel)
Post propagator for .
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Example: Dominating Queens
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
virtual void print(std::ostream &os) const
Print solution.
Passing integer arguments.
int y(int xy) const
Compute y coordinate from pair xy.
virtual Space * copy(void)
Perform copying during cloning.
IntSet attacked(int xy)
Compute set of fields that can be attacked by xy.
IntValBranch INT_VAL_MAX(void)
Select largest value.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Post propagator for SetVar SetOpType SetVar y
DominatingQueens(DominatingQueens &s)
Constructor for cloning s.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
void solutions(unsigned int n)
Set default number of solutions to search for.
Post propagator for SetVar x
int main(int argc, char *argv[])
Main-function.
Gecode toplevel namespace