44 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
48 using namespace Gecode;
76 : Gecode::
Choice(b,2),
pos(pos0), val(val0) {}
78 virtual size_t size(
void)
const {
93 :
Brancher(home, share, b), start(b.start) {
94 x.update(home, share, b.
x);
100 for (
int n=x.size(); n--; ) {
104 start = x[start].val();
112 unsigned int min = x[n].size();
116 if (x[iv.
val()].size() <
min) {
122 return new Choice(*
this, start, n);
128 return new Choice(*
this, pos, val);
141 return new (home)
Warnsdorff(home, share, *
this);
150 return sizeof(*this);
173 int f(
int x,
int y)
const {
186 static const int moves[8][2] = {
187 {-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}
189 int nbs[8];
int n_nbs = 0;
190 for (
int m=0;
m<8;
m++) {
191 int nx = x(i) + moves[
m][0], ny = y(i) + moves[
m][1];
192 if ((nx >= 0) && (nx < n) && (ny >= 0) && (ny < n))
193 nbs[n_nbs++] = f(nx,ny);
199 : n(opt.
size()), succ(*this,n*n,0,n*n-1) {
204 case BRANCH_WARNSDORFF:
211 succ.update(*
this, share, s.
succ);
216 int* jump =
new int[n*n];
219 for (
int i=0;
i<n*n;
i++) {
220 jump[j]=
i; j=succ[j].min();
224 for (
int i = 0;
i < n;
i++) {
225 for (
int j = 0; j < n; j++) {
227 os << jump[f(
i,j)] <<
" ";
229 os << std::endl <<
"\t";
255 for (
int i = nn;
i--; ) {
256 IntVar p(*
this,0,nn-1); pred[
i]=p;
257 IntVar j(*
this,0,nn-1); jump[
i]=j;
267 for (
int f = 0; f < nn; f++) {
271 expr(*
this, (jump[
i.val()]-jump[f] == 1)),
273 expr(*
this, (jump[
i.val()]-jump[f] == 1-nn)),
274 expr(*
this, (succ[f] ==
i.val())));
275 dom(*
this, pred[f], ds);
276 dom(*
this, succ[f], ds);
307 for (
int f = 0; f < n*n; f++)
308 dom(*
this, succ[f], neighbors(f));
325 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
330 QGraphicsScene* scene;
334 static const int unit = 30;
337 KnightsInspector(
void) : scene(NULL), mw(NULL) {}
339 virtual void inspect(
const Space& s) {
344 QList <QGraphicsItem*> itemList = scene->items();
345 foreach (QGraphicsItem*
i, scene->items()) {
346 scene->removeItem(i);
350 for (
int i=0; i<k.
n; i++) {
351 for (
int j=0; j<k.
n; j++) {
352 scene->addRect(i*unit,j*unit,unit,unit);
354 QPen pen(Qt::black, 2);
356 pen.setColor(Qt::red);
357 pen.setStyle(Qt::DotLine);
361 int ky = xv.val() % k.
n;
362 int kx = xv.val() / k.
n;
363 scene->addLine(i*unit+unit/2,j*unit+unit/2,
364 kx*unit+unit/2,ky*unit+unit/2,
374 void initialize(
void) {
375 mw =
new QMainWindow();
376 scene =
new QGraphicsScene();
377 QGraphicsView* view =
new QGraphicsView(scene);
378 view->setRenderHints(QPainter::Antialiasing);
379 mw->setCentralWidget(view);
380 mw->setAttribute(Qt::WA_QuitOnClose,
false);
381 mw->setAttribute(Qt::WA_DeleteOnClose,
false);
382 QAction* closeWindow =
new QAction(
"Close window", mw);
383 closeWindow->setShortcut(QKeySequence(
"Ctrl+W"));
384 mw->connect(closeWindow, SIGNAL(triggered()),
386 mw->addAction(closeWindow);
390 virtual std::string name(
void) {
return "Board"; }
392 virtual void finalize(
void) {
414 #if defined(GECODE_HAS_QT) && defined(GECODE_HAS_GIST)
416 opt.inspect.click(&ki);
419 opt.
parse(argc,argv);
422 Script::run<KnightsReified,DFS,SizeOptions>(
opt);
424 Script::run<KnightsCircuit,DFS,SizeOptions>(
opt);