62 int xy(
int x,
int y)
const {
76 for (
int i=0; i<
n; i++)
77 for (
int j=0; j<
n; j++)
88 n(opt.size()),
b(*this,
n*
n,0,
n*
n-1),
q(*this,1,
n) {
91 for (
int i=0; i<
n*
n; i++)
104 dom(*
this,
q, (
n+1)/2, (
n+1)/2 + 1);
119 b.update(*
this, s.
b);
120 q.update(*
this, s.
q);
132 os <<
"\tNumber of Queens: " <<
q << std::endl;
133 os <<
"\tBoard: " <<
b << std::endl;
136 bool* placed =
new bool[
n*
n];
137 for (
int i=0; i<
n*
n; i++)
139 for (
int i=0; i<
n*
n; i++)
140 placed[
b[i].val()] =
true;
141 for (
int j=0; j<
n; j++) {
143 for (
int i=0; i<
n; i++)
144 std::cout << (placed[
xy(i,j)] ?
'Q' :
'.') <<
' ';
145 std::cout << std::endl;
161 opt.
parse(argc,argv);
IntVar q
Number of queens.
virtual Space * copy(void)
Perform copying during cloning.
int main(int argc, char *argv[])
Main-function.
int y(int xy) const
Compute y coordinate from pair xy.
DominatingQueens(const SizeOptions &opt)
The actual problem.
IntVarArray b
Fields on the board.
const int n
Size of the board.
int x(int xy) const
Compute x coordinate from pair xy.
DominatingQueens(DominatingQueens &s)
Constructor for cloning s.
virtual void print(std::ostream &os) const
Print solution.
int xy(int x, int y) const
Compute coordinate pair from x and y.
virtual IntVar cost(void) const
Return cost.
IntSet attacked(int xy)
Compute set of fields that can be attacked by xy.
static void run(const Options &opt, Script *s=NULL)
Passing integer arguments.
Options for scripts with additional size parameter
void parse(int argc, char *argv[])
Parse commandline arguments.
Driver::ScriptBase< Driver::IgnoreStepOption< IntMinimizeSpace > > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
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.
@ IRT_LQ
Less or equal ( )
Gecode toplevel namespace
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
IntValBranch INT_VAL_MAX(void)
Select largest value.
Post propagator for SetVar SetOpType SetVar y
IntValBranch INT_VAL_MIN(void)
Select smallest value.
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel ipl=IPL_DEF)
Post propagator for .
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Post propagator for SetVar x