44 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
46 #if QT_VERSION >= 0x050000
51 using namespace Gecode;
79 : Gecode::
Choice(b,2),
pos(pos0), val(val0) {}
81 virtual size_t size(
void)
const {
96 :
Brancher(home, share, b), start(b.start) {
97 x.update(home, share, b.
x);
103 for (
int n=
x.size();
n--; ) {
107 start =
x[start].val();
115 unsigned int min =
x[
n].size();
119 if (
x[iv.
val()].size() <
min) {
125 return new Choice(*
this, start, n);
131 return new Choice(*
this, pos, val);
145 std::ostream& o)
const {
147 o <<
"x[" << c.
pos <<
"] "
148 << ((a == 0) ?
"=" :
"!=")
153 return new (home)
Warnsdorff(home, share, *
this);
162 return sizeof(*this);
185 int f(
int x,
int y)
const {
198 static const int moves[8][2] = {
199 {-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}
201 int nbs[8];
int n_nbs = 0;
202 for (
int m=0; m<8; m++) {
203 int nx =
x(i) + moves[m][0], ny = y(i) + moves[m][1];
204 if ((nx >= 0) && (nx <
n) && (ny >= 0) && (ny <
n))
205 nbs[n_nbs++] = f(nx,ny);
211 :
n(opt.
size()), succ(*this,
n*
n,0,
n*
n-1) {
216 case BRANCH_WARNSDORFF:
223 succ.update(*
this, share, s.
succ);
228 int* jump =
new int[
n*
n];
231 for (
int i=0;
i<
n*
n;
i++) {
232 jump[j]=
i; j=succ[j].min();
236 for (
int i = 0;
i <
n;
i++) {
237 for (
int j = 0; j <
n; j++) {
239 os << jump[f(
i,j)] <<
" ";
241 os << std::endl <<
"\t";
267 for (
int i = nn;
i--; ) {
269 IntVar j(*
this,0,nn-1); jump[
i]=j;
279 for (
int f = 0; f < nn; f++) {
283 expr(*
this, (jump[
i.val()]-jump[f] == 1)),
285 expr(*
this, (jump[
i.val()]-jump[f] == 1-nn)),
286 expr(*
this, (succ[f] ==
i.val())));
287 dom(*
this, pred[f], ds);
288 dom(*
this, succ[f], ds);
319 for (
int f = 0; f <
n*
n; f++)
320 dom(*
this, succ[f], neighbors(f));
337 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
342 QGraphicsScene* scene;
346 static const int unit = 30;
349 KnightsInspector(
void) : scene(NULL), mw(NULL) {}
351 virtual void inspect(
const Space& s) {
356 QList <QGraphicsItem*> itemList = scene->items();
357 foreach (QGraphicsItem*
i, scene->items()) {
358 scene->removeItem(i);
362 for (
int i=0; i<k.
n; i++) {
363 for (
int j=0; j<k.
n; j++) {
364 scene->addRect(i*unit,j*unit,unit,unit);
366 QPen pen(Qt::black, 2);
368 pen.setColor(Qt::red);
369 pen.setStyle(Qt::DotLine);
373 int ky = xv.val() % k.
n;
374 int kx = xv.val() / k.
n;
375 scene->addLine(i*unit+unit/2,j*unit+unit/2,
376 kx*unit+unit/2,ky*unit+unit/2,
386 void initialize(
void) {
387 mw =
new QMainWindow();
388 scene =
new QGraphicsScene();
389 QGraphicsView* view =
new QGraphicsView(scene);
390 view->setRenderHints(QPainter::Antialiasing);
391 mw->setCentralWidget(view);
392 mw->setAttribute(Qt::WA_QuitOnClose,
false);
393 mw->setAttribute(Qt::WA_DeleteOnClose,
false);
394 QAction* closeWindow =
new QAction(
"Close window", mw);
395 closeWindow->setShortcut(QKeySequence(
"Ctrl+W"));
396 mw->connect(closeWindow, SIGNAL(triggered()),
398 mw->addAction(closeWindow);
402 virtual std::string name(
void) {
return "Board"; }
404 virtual void finalize(
void) {
426 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
428 opt.inspect.click(&ki);
431 opt.
parse(argc,argv);
434 Script::run<KnightsReified,DFS,SizeOptions>(
opt);
436 Script::run<KnightsCircuit,DFS,SizeOptions>(
opt);