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);
141 for (
int i = 0; i <
n*
n; ++i) {
142 if (
w[i].assigned() &&
w[i].val()) os <<
"W";
143 else if (
b[i].assigned() &&
b[i].val()) os <<
"B";
144 else if (!
w[i].assigned() && !
b[i].assigned()) os <<
" ";
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;
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) {
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);
281 opt.
parse(argc,argv);
287 int *
p =
new int[std::max(
n*
n, 25)];
289 for (
int i =
n; i--; ) {
290 for (
int j =
n; j--; ) {
301 p[pn++] = pos(i, j,
n);
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);
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Base-class for both propagators and branchers.
Base-class for branchers.
Choice for performing commit
virtual void archive(Archive &e) const
Archive into e.
Parametric base-class for scripts.
static void run(const Options &opt, Script *s=NULL)
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)
Iterator for the unknown ranges of a set variable.
Options for scripts with additional size parameter
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.
bool assigned(void) const
Test whether view is assigned.
Custom brancher for Peacable queens.
virtual Gecode::Choice * choice(Space &home)
Return choice.
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.
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.
static void post(QueenArmies &home)
Post brancher.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
virtual Actor * copy(Space &home)
Copy brancher during cloning.
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.
void parse(int argc, char *argv[])
Parse commandline arguments.
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=nullptr, FloatVarValPrint vvp=nullptr)
Assign all x with variable selection vars and value selection vals.
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.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
@ IRT_GQ
Greater or equal ( )
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode toplevel namespace
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
Post propagator for SetVar SetOpType SetVar SetRelType r
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
SetExpr singleton(const LinIntExpr &)
Singleton expression.
@ ES_OK
Execution is okay.
@ ES_FAILED
Execution has resulted in failure.
LinIntExpr cardinality(const SetExpr &)
Cardinality of set expression.