42 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
44 #if QT_VERSION >= 0x050000
72 : q(*this,opt.
size(),0,opt.
size()-1) {
73 const int n = q.
size();
76 for (
int i = 0;
i<
n;
i++)
77 for (
int j =
i+1; j<
n; j++) {
78 rel(*
this, q[
i] != q[j]);
79 rel(*
this, q[
i]+
i != q[j]+j);
80 rel(*
this, q[
i]-
i != q[j]-j);
84 for (
int i = 0;
i<
n;
i++)
85 for (
int j =
i+1; j<
n; j++) {
86 rel(*
this, q[
i]+
i != q[j]+j);
87 rel(*
this, q[
i]-
i != q[j]-j);
108 return new Queens(share,*
this);
115 for (
int i = 0;
i < q.
size();
i++) {
118 os << std::endl <<
"\t";
124 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
129 QGraphicsScene* scene;
133 static const int unit = 20;
136 QueensInspector(
void) : scene(NULL), mw(NULL) {}
138 virtual void inspect(
const Space& s) {
143 QList <QGraphicsItem*> itemList = scene->items();
144 foreach (QGraphicsItem*
i, scene->items()) {
145 scene->removeItem(i);
149 for (
int i=0; i<q.
q.
size(); i++) {
150 for (
int j=0; j<q.
q.
size(); j++) {
151 scene->addRect(i*unit,j*unit,unit,unit);
153 QBrush
b(q.
q[i].
assigned() ? Qt::black : Qt::red);
154 QPen
p(q.
q[i].
assigned() ? Qt::black : Qt::white);
156 scene->addEllipse(QRectF(i*unit+unit/4,xv.val()*unit+unit/4,
157 unit/2,unit/2),
p,
b);
164 void initialize(
void) {
165 mw =
new QMainWindow();
166 scene =
new QGraphicsScene();
167 QGraphicsView* view =
new QGraphicsView(scene);
168 view->setRenderHints(QPainter::Antialiasing);
169 mw->setCentralWidget(view);
170 mw->setAttribute(Qt::WA_QuitOnClose,
false);
171 mw->setAttribute(Qt::WA_DeleteOnClose,
false);
172 QAction* closeWindow =
new QAction(
"Close window", mw);
173 closeWindow->setShortcut(QKeySequence(
"Ctrl+W"));
174 mw->connect(closeWindow, SIGNAL(triggered()),
176 mw->addAction(closeWindow);
180 virtual std::string name(
void) {
return "Board"; }
182 virtual void finalize(
void) {
200 "only binary disequality constraints");
202 "single distinct and binary disequality constraints");
204 "three distinct constraints");
206 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
208 opt.inspect.click(&ki);
211 opt.
parse(argc,argv);
212 Script::run<Queens,DFS,SizeOptions>(
opt);
Value iterator for integer variables.
void size(unsigned int s)
Set default size.
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Options for scripts with additional size parameter
void propagation(int v)
Set default propagation value.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
IntVarArray q
Position of queens on boards.
Use only binary disequality constraints.
Abstract base class for inspectors.
Parametric base-class for scripts.
void iterations(unsigned int i)
Set default number of iterations.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
int p
Number of positive literals for node type.
Use three distinct constraints.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
int main(int argc, char *argv[])
Main-function.
virtual void print(std::ostream &os) const
Print solution.
Use single distinct and binary disequality constraints.
virtual Space * copy(bool share)
Perform copying during cloning.
Queens(bool share, Queens &s)
Constructor for cloning s.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Queens(const SizeOptions &opt)
The actual problem.
void distinct(Home home, const IntVarArgs &x, IntConLevel icl)
Post propagator for for all .
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
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.
int size(void) const
Return size of array (number of elements)
void icl(IntConLevel i)
Set default integer consistency level.