96 for (
int i = n*n;
i--; ) {
98 rel(*
this, w[
i] == (U || A[
i]));
100 rel(*
this, !w[i] || !b[i]);
111 rel(*
this, q <= unknowns);
144 for (
int i = 0;
i < n*
n; ++
i) {
146 else if (b[
i].
assigned() && b[
i].val()) os <<
"B";
149 if ((
i+1)%n == 0) os << std::endl << (
i!=(n*n-1)?
"\t":
"");
151 os <<
"Number of white queens: " << q << std::endl << std::endl;
175 Choice(
const Brancher& b,
int pos0,
bool val0)
178 virtual size_t size(
void)
const {
179 return sizeof(Choice);
182 virtual void archive(
Archive& e)
const {
193 :
Brancher(home, share, b), start(b.start) {}
199 for (
int i = start;
i < q.
n*q.
n; ++
i)
213 for (
int i = start;
i < q.
n*q.
n; ++
i) {
219 if (size > maxsize) {
226 return new Choice(*
this, pos,
true);
232 return new Choice(*
this, pos, val);
240 const Choice&
c =
static_cast<const Choice&
>(
_c);
241 bool val = (a == 0) ? c.val : !c.val;
249 std::ostream& o)
const {
250 const Choice&
c =
static_cast<const Choice&
>(
_c);
251 bool val = (a == 0) ? c.val : !c.val;
252 o <<
"w[" << c.pos <<
"] = " << val;
264 return sizeof(*this);
288 opt.
parse(argc,argv);
296 for (
int i = n;
i--; ) {
297 for (
int j = n; j--; ) {
308 p[pn++] =
pos(
i, j, n);
309 for (
int k = 8; k--; ) {
310 for (
int l = 0;
l < n
311 && 0 <= (
i+
l*dir[k][0]) && (
i+
l*dir[k][0]) < n
312 && 0 <= (j+
l*dir[k][1]) && (j+
l*dir[k][1]) <
n; ++
l) {
313 p[pn++] =
pos(
i+
l*dir[k][0], j+
l*dir[k][1], n);
324 IntMaximizeScript::run<QueenArmies,BAB,SizeOptions>(
opt);
virtual Gecode::Choice * choice(Space &home)
Return choice.
void size(unsigned int s)
Set default size.
SetExpr singleton(const LinIntExpr &e)
Singleton expression.
Options for scripts with additional size parameter
Choose variables left to right.
virtual void print(const Space &, const Gecode::Choice &_c, unsigned int a, std::ostream &o) const
Print explanation.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatNum c)
Post propagator for .
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Range iterator for integer sets.
const FloatNum max
Largest allowed float value.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
IntVar q
The number of white queens placed.
void update(Space &home, bool share, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
int main(int argc, char *argv[])
Main-function.
SetVar W
Set of squares occupied by white queens.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
bool pos(const View &x)
Test whether x is postive.
virtual ExecStatus commit(Space &home, const Gecode::Choice &_c, unsigned int a)
Perform commit for choice _c and alternative a.
QueenArmies(bool share, QueenArmies &s)
Constructor for cloning.
virtual Space * copy(bool share)
Return copy during cloning.
int pos(int i, int j, int n)
Position of a piece in a square board.
BoolVarArray w
The placement of the white queens.
QueenArmies(const SizeOptions &opt)
Constructor.
Parametric base-class for scripts.
Base-class for both propagators and branchers.
static BrancherHandle post(QueenArmies &home)
Post brancher.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Iterator for the unknown ranges of a set variable.
virtual size_t dispose(Space &)
Delete brancher and return its size.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
Base-class for branchers.
int n
Number of negative literals for node type.
Execution has resulted in failure.
Example: Peaceable co-existing armies of queens
Range iterator for computing intersection (binary)
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
IntSet * A
Position of a piece in a square board.
virtual void archive(Archive &e) const
Archive into e.
unsigned int size(I &i)
Size of all ranges of range iterator i.
void branching(int v)
Set default branching value.
virtual Actor * copy(Space &home, bool share)
Copy brancher during cloning.
SetVar U
Set of un-attacked squares.
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
IntValBranch INT_VAL_MAX(void)
Select largest value.
BoolVar expr(Home home, const BoolExpr &e, IntConLevel icl)
Post Boolean expression and return its value.
BrancherHandle assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Choice for performing commit
virtual void print(std::ostream &os) const
Print solution.
BoolVarArray b
The placement of the black queens.
bool assigned(View x, int v)
Whether x is assigned to value v.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
void solutions(unsigned int n)
Set default number of solutions to search for.
Custom brancher for Peacable queens.
Choose variable with problem specific strategy.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
bool assigned(void) const
Test if all variables are assigned.
BrancherHandle 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.
Home class for posting propagators
virtual IntVar cost(void) const
Return solution cost.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Multi _c(Gecode::IntArgs(3, 1, 2, 3))
Boolean view for Boolean variables.