40 using namespace Gecode;
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) {
123 W.update(*
this, s.
W);
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 {
192 for (
int i = start;
i < q.
n*q.
n; ++
i)
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)
int p
Number of positive literals for node type.
BoolVar expr(Home home, const BoolExpr &e, const IntPropLevels &ipls)
Post Boolean expression and return its value.
int n
Number of negative literals for node type.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Base-class for both propagators and branchers.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Base-class for branchers.
Choice for performing commit
virtual void archive(Archive &e) const
Archive into e.
Parametric base-class for scripts.
Home class for posting propagators
Range iterator for integer sets.
Boolean view for Boolean variables.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Range iterator for computing intersection (binary)
void branching(int v)
Set default branching value.
void solutions(unsigned int n)
Set default number of solutions to search for.
Iterator for the unknown ranges of a set variable.
Options for scripts with additional size parameter
bool assigned(void) const
Test if all variables are assigned.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Custom brancher for Peacable queens.
virtual void print(const Space &, const Gecode::Choice &_c, unsigned int a, std::ostream &o) const
Print explanation.
virtual Gecode::Choice * choice(Space &home)
Return choice.
virtual ExecStatus commit(Space &home, const Gecode::Choice &_c, unsigned int a)
Perform commit for choice _c and alternative a.
virtual size_t dispose(Space &)
Delete brancher and return its size.
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
virtual Actor * copy(Space &home)
Copy brancher during cloning.
static void post(QueenArmies &home)
Post brancher.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
Example: Peaceable co-existing armies of queens
QueenArmies(const SizeOptions &opt)
Constructor.
int main(int argc, char *argv[])
Main-function.
int pos(int i, int j, int n)
Position of a piece in a square board.
virtual void print(std::ostream &os) const
Print solution.
BoolVarArray w
The placement of the white queens.
BoolVarArray b
The placement of the black queens.
@ BRANCH_NAIVE
Choose variables left to right.
@ BRANCH_SPECIFIC
Choose variable with problem specific strategy.
QueenArmies(QueenArmies &s)
Constructor for cloning.
virtual IntVar cost(void) const
Return solution cost.
IntVar q
The number of white queens placed.
SetVar W
Set of squares occupied by white queens.
virtual Space * copy(void)
Return copy during cloning.
SetVar U
Set of un-attacked squares.
IntSet * A
Position of a piece in a square board.
@ ES_OK
Execution is okay.
@ ES_FAILED
Execution has resulted in failure.
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
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.
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 .
@ IRT_GQ
Greater or equal ( )
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
bool pos(const View &x)
Test whether x is postive.
const FloatNum max
Largest allowed float value.
bool assigned(View x, int v)
Whether x is assigned to value v.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})
Multi _c(Gecode::IntArgs({1, 2, 3}))
SetExpr singleton(const LinIntExpr &e)
Singleton expression.
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.