Hello Gecoders, I'd like to perform a depth first search with a specific static variable ordering. I have a matrix of integer variables and I want to label the top row first, then the left column, then the rest of the matrix in standard top-to-bottom, left-to-right order.
The naive search shown here gives a standard top-to-bottom, left-to-right ordering: class Problem : public Space { IntVarArray cells; Problem(int n) { Matrix<IntVarArray> m(cells, n, n); // ... // set up constraints on cells via m // ... branch(*this, cells, INT_VAR_NONE, INT_VAR_MIN); } } I have managed to achieve the ordering I want, like this (with the new bits marked with comments): class Problem : public Space { IntVarArray cells; IntVarArray ordering; // *** added this array *** Problem(int n) { Matrix<IntVarArray> m(cells, n, n); // ... // set up constraints on cells via m // ... // *** added this block *** int index = 0; for (int c = 0 ; c < n ; c++) ordering[index++] = m(c,0); for (int r = 1 ; r < n ; r++) ordering[index++] = m(0,r); for (int r = 1 ; r < n ; r++) for (int c = 1 ; c < n ; c++) ordering[index++] = m(c,r); // *** search on "ordering" instead of "cells" *** branch(*this, cells, INT_VAR_NONE, INT_VAR_MIN); } } This seems to work. My question: is this the best way to do it? (It just occurred to me that maybe it could be done using Slices -- is that right?) Thanks, Chris _______________________________________________ Gecode users mailing list us...@gecode.org https://www.gecode.org/mailman/listinfo/gecode-users