Go to the documentation of this file.
93 for (
int i =
n*
n;
i--; ) {
95 rel(*
this, w[
i] == (U || A[
i]));
97 rel(*
this, !w[
i] || !
b[
i]);
108 rel(*
this, q <= unknowns);
111 if (
opt.branching() == BRANCH_NAIVE) {
125 b.update(*
this, s.
b);
141 for (
int i = 0;
i <
n*
n; ++
i) {
146 if ((
i+1)%
n == 0) os << std::endl << (
i!=(
n*
n-1)?
"\t":
"");
148 os <<
"Number of white queens: " << q << std::endl << std::endl;
172 Choice(
const Brancher&
b,
int pos0,
bool val0)
175 virtual void archive(
Archive& e)
const {
191 const QueenArmies& q = static_cast<const QueenArmies&>(home);
192 for (
int i = start;
i < q.
n*q.
n; ++
i)
202 const QueenArmies& q = static_cast<const QueenArmies&>(home);
206 for (
int i = start;
i < q.
n*q.
n; ++
i) {
212 if (
size > maxsize) {
219 return new Choice(*
this,
pos,
true);
225 return new Choice(*
this,
pos, val);
233 const Choice&
c = static_cast<const Choice&>(
_c);
234 bool val = (
a == 0) ?
c.val : !
c.val;
242 std::ostream& o)
const {
243 const Choice&
c = static_cast<const Choice&>(
_c);
244 bool val = (
a == 0) ?
c.val : !
c.val;
245 o <<
"w[" <<
c.pos <<
"] = " << val;
257 return sizeof(*this);
289 for (
int i =
n;
i--; ) {
290 for (
int j =
n; j--; ) {
302 for (
int k = 8; k--; ) {
303 for (
int l = 0;
l <
n
304 && 0 <= (
i+
l*dir[k][0]) && (
i+
l*dir[k][0]) <
n
305 && 0 <= (j+
l*dir[k][1]) && (j+
l*dir[k][1]) <
n; ++
l) {
306 p[pn++] =
pos(
i+
l*dir[k][0], j+
l*dir[k][1],
n);
317 IntMaximizeScript::run<QueenArmies,BAB,SizeOptions>(
opt);
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
virtual Gecode::Choice * choice(Space &home)
Return choice.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
QueenArmies(const SizeOptions &opt)
Constructor.
unsigned int size(I &i)
Size of all ranges of range iterator i.
IntVar q
The number of white queens placed.
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
int main(int argc, char *argv[])
Main-function.
Choose variables left to right.
bool assigned(View x, int v)
Whether x is assigned to value v.
BoolVarArray w
The placement of the white queens.
static void post(QueenArmies &home)
Post brancher.
Multi _c(Gecode::IntArgs({1, 2, 3}))
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.
Base-class for both propagators and branchers.
Range iterator for integer sets.
SetVar W
Set of squares occupied by white queens.
SetExpr singleton(const LinIntExpr &e)
Singleton expression.
bool assigned(void) const
Test if all variables are assigned.
Choose variable with problem specific strategy.
Boolean view for Boolean variables.
Gecode toplevel namespace
int pos(int i, int j, int n)
Position of a piece in a square board.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Base-class for branchers.
BoolVar expr(Home home, const BoolExpr &e, const IntPropLevels &ipls)
Post Boolean expression and return its value.
SetVar U
Set of un-attacked squares.
Home class for posting propagators
virtual IntVar cost(void) const
Return solution cost.
Parametric base-class for scripts.
Range iterator for computing intersection (binary)
void branching(int v)
Set default branching value.
Post propagator for SetVar SetOpType SetVar SetRelType r
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
virtual void print(std::ostream &os) const
Print solution.
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with variable selection vars and value selection vals.
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
IntSet * A
Position of a piece in a square board.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
virtual void print(const Space &, const Gecode::Choice &_c, unsigned int a, std::ostream &o) const
Print explanation.
virtual ExecStatus commit(Space &home, const Gecode::Choice &_c, unsigned int a)
Perform commit for choice _c and alternative a.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
virtual size_t dispose(Space &)
Delete brancher and return its size.
virtual Space * copy(void)
Return copy during cloning.
Custom brancher for Peacable queens.
QueenArmies(QueenArmies &s)
Constructor for cloning.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
BoolVarArray b
The placement of the black queens.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
virtual Actor * copy(Space &home)
Copy brancher during cloning.
Iterator for the unknown ranges of a set variable.
void solutions(unsigned int n)
Set default number of solutions to search for.
Gecode::FloatVal c(-8, 8)
int n
Number of negative literals for node type.
Choice for performing commit
Execution has resulted in failure.
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
Example: Peaceable co-existing armies of queens
Gecode::IntArgs i({1, 2, 3, 4})
bool pos(const View &x)
Test whether x is postive.
int p
Number of positive literals for node type.
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
virtual void archive(Archive &e) const
Archive into e.
const FloatNum max
Largest allowed float value.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Options for scripts with additional size parameter