38 using namespace Gecode;
62 int xy(
int x,
int y)
const {
76 for (
int i=0;
i<
n;
i++)
77 for (
int j=0; j<
n; j++)
91 for (
int i=0;
i<
n*
n;
i++)
92 dom(*
this,
b[
i], attacked(
i));
104 dom(*
this, q, (
n+1)/2, (
n+1)/2 + 1);
119 b.update(*
this, s.
b);
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;
162 IntMinimizeScript::run<DominatingQueens,BAB,SizeOptions>(
opt);
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
Node * x
Pointer to corresponding Boolean expression node.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Example: Dominating Queens
IntVar q
Number of queens.
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.
virtual Space * copy(void)
Perform copying during cloning.
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)
Parametric base-class for scripts.
Passing integer arguments.
void solutions(unsigned int n)
Set default number of solutions to search for.
Options for scripts with additional size parameter
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
@ IRT_LQ
Less or equal ( )
IntValBranch INT_VAL_MAX(void)
Select largest value.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::IntArgs i({1, 2, 3, 4})