70 void parse(
int& argc,
char* argv[]) {
76 if (_size.
value() == 0U)
77 return static_cast<int>(_height.
value());
79 return static_cast<int>(_size.
value());
83 if (_size.
value() == 0U)
84 return static_cast<int>(_width.
value());
86 return static_cast<int>(_size.
value());
89 int colors(
void)
const {
return static_cast<int>(_colors.
value()); }
98 return _no_monochrome_rectangle.
value();
211 return IntVar(*
this, 0, 0);
221 for (
int i =
v.size();
i--; ) {
223 for (
int j =
i; j--; ) {
224 rel(*
this, viIsZero || (
v[
i] !=
v[j]));
254 for (
int i =
v.size();
i--; )
255 for (
int j =
i; j--; )
256 disequalities <<
expr(*
this,
v[
i] !=
v[j]);
263 for (
int i = 0;
i <
v.size()-1; ++
i)
264 equalities <<
expr(*
this,
v[
i] ==
v[
i+1]);
288 const int length =
v1.
size();
292 for (
int i = 0;
i < length; ++
i) {
301 for (
int i = length;
i--; ) {
372 for (
int c1 = 0; c1 <
width; ++c1) {
373 for (
int c2 = c1+1; c2 <
width; ++c2) {
374 for (
int r1 = 0; r1 <
height; ++r1) {
375 for (
int r2 = r1+1; r2 <
height; ++r2) {
387 for (
int r1 = 0; r1 <
height; ++r1) {
388 for (
int r2 = r1+1; r2 <
height; ++r2) {
394 for (
int c1 = 0; c1 <
width; ++c1) {
395 for (
int c2 = c1+1; c2 <
width; ++c2) {
434 os << m(
c,
r) <<
" ";
439 os <<
"\tmax color: " <<
max_color << std::endl;
459 _height(
"height",
"Height of matrix", 8),
460 _width(
"width",
"Width of matrix", 8),
461 _size(
"size",
"If different from 0, used as both width and height", 0),
462 _colors(
"colors",
"Maximum number of colors", 4),
463 _not_all_equal(
"not-all-equal",
"How to implement the not all equals constraint (used in corners model)",
465 _same_or_0(
"same-or-0",
"How to implement the same or 0 constraint (used in the decomposed no monochrome rectangle constraint)",
467 _distinct_except_0(
"distinct-except-0",
"How to implement the distinct except 0 constraint (used in the decomposed no monochrome rectangle constraint)",
469 _no_monochrome_rectangle(
"no-monochrome-rectangle",
"How to implement no monochrome rectangle (used in the rows model)",
478 add(_distinct_except_0);
479 add(_no_monochrome_rectangle);
491 "both",
"Order both rows/columns and values");
498 "both",
"Use both rows and corners model");
501 "matrix",
"Use both rows and columns model");
525 "Use decompositions into same_or_0 and distinct_except_0.");
528 "Use DFA as direct implementation.");
539 Script::run<ColoredMatrix,DFS,ColoredMatrixOptions>(
opt);
541 Script::run<ColoredMatrix,BAB,ColoredMatrixOptions>(
opt);
563 const int start_state = 0;
564 const int not_equal_state = 2*colors+1;
565 const int final_state = 2*colors+2;
567 int n_transitions = colors*colors + 2*colors + 2;
570 int current_transition = 0;
573 for (
int color = 1; color <= colors; ++color) {
574 trans[current_transition++] =
580 for (
int state = 1; state <= colors; ++state) {
581 for (
int color = 1; color <= colors; ++color) {
582 if (color == state) {
583 trans[current_transition++] =
586 trans[current_transition++] =
594 for (
int color = 1; color <= colors; ++color) {
595 trans[current_transition++] =
600 trans[current_transition++] =
604 trans[current_transition++] =
607 int final_states[] = {final_state, -1};
609 DFA result(start_state, trans, final_states,
true);
618 for (
int i = 1;
i <= colors; ++
i) {
619 for (
int j = 1; j <= colors; ++j) {
621 result.add({
i, j,
i});
623 result.add({
i, j, 0});
642 const int nstates = 1 << colors;
643 const int start_state = nstates-1;
647 int current_transition = 0;
649 for (
int state = nstates; state--; ) {
652 for (
int color = 1; color <= colors; ++color) {
653 const int color_bit = (1 << (color-1));
654 if (state & color_bit) {
655 trans[current_transition++] =
662 int* final_states =
new int[nstates+1];
663 final_states[nstates] = -1;
664 for (
int i = nstates;
i--; ) {
668 DFA result(start_state, trans, final_states);
671 delete[] final_states;
692 const int base_states = 1 << colors;
693 const int start_state = base_states-1;
694 const int nstates = base_states + colors*base_states;
697 int current_transition = 0;
699 for (
int state = base_states; state--; ) {
700 for (
int color = 1; color <= colors; ++color) {
701 const int color_bit = (1 << (color-1));
702 const int color_remembered_state = state + color*base_states;
704 trans[current_transition++] =
707 for (
int next_color = 1; next_color <= colors; ++next_color) {
708 if (next_color == color) {
710 if (state & color_bit) {
711 trans[current_transition++] =
715 trans[current_transition++] =
722 assert(current_transition <= nstates*colors+1);
724 int* final_states =
new int[base_states+1];
725 final_states[base_states] = -1;
726 for (
int i = base_states;
i--; ) {
730 DFA result(start_state, trans, final_states);
733 delete[] final_states;
744 for (
int i = 1;
i <= colors; ++
i) {
762 const int nstates = 1 + colors + 1;
763 const int start_state = 0;
764 const int final_state = nstates-1;
767 int current_transition = 0;
770 for (
int color = 1; color <= colors; ++color) {
771 trans[current_transition++] =
DFA::Transition(start_state, color, color);
775 for (
int state = 1; state <= colors; ++state) {
776 for (
int color = 1; color <= colors; ++color) {
777 if (state == color) {
780 trans[current_transition++] =
DFA::Transition(state, color, final_state);
786 for (
int color = 1; color <= colors; ++color) {
787 trans[current_transition++] =
DFA::Transition(final_state, color, final_state);
792 int final_states[] = {final_state, -1};
794 DFA result(start_state, trans, final_states);
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
int colors(void) const
Return number of colors.
int distinct_except_0(void) const
Return how to implement distinct except 0.
int same_or_0(void) const
Return how to implement same or 0.
int height(void) const
Return height.
int width(void) const
Return width.
int no_monochrome_rectangle(void) const
Return how to implement distinct except 0.
ColoredMatrixOptions(const char *n)
Initialize options for example with name n.
int not_all_equal(void) const
Return how to implement not all equals.
Example: Colored matrix example.
IntVar same_or_0(const IntVar &a, const IntVar &b)
int main(int argc, char *argv[])
Main-function.
void distinct_except_0(const IntVarArgs &v)
const ColoredMatrixOptions & opt
Options for model.
DFA not_all_equal_dfa(int colors)
DFA no_monochrome_rectangle_dfa(int colors)
IntSetArgs distinct_except_0_counts(int colors, int size)
virtual void print(std::ostream &os) const
Print solution.
const int colors
Number of colors to use.
void not_all_equal(const IntVarArgs &v)
ColoredMatrix(ColoredMatrix &s)
Constructor for cloning s.
void no_monochrome_rectangle(IntVarArgs v1, IntVarArgs v2)
@ NOT_ALL_EQUAL_NQ
Use direct constraint for implemeting not all equals.
@ NOT_ALL_EQUAL_REIFIED
Use reification for implemeting not all equals.
@ NOT_ALL_EQUAL_NVALUES
Use nvalues for implementing not all equals.
@ NOT_ALL_EQUAL_NAIVE
Use naive reification for implemeting not all equals.
@ NOT_ALL_EQUAL_COUNT
Use count for implementing not all equals.
@ NOT_ALL_EQUAL_DFA
Use dfa for implementing not all equals.
@ NO_MONOCHROME_DFA
Use dfa for no monochrome rectangle.
@ NO_MONOCHROME_DECOMPOSITION
Use decomposition for no monochrome rectangle.
virtual Space * copy(void)
Copy during cloning.
@ SEARCH_DFS
Find solution.
@ SEARCH_BAB
Find optimal solution.
@ SAME_OR_0_DFA
Use dfa for same or 0.
@ SAME_OR_0_TUPLE_SET
Use tuple set for same or 0.
@ SAME_OR_0_REIFIED
Use reification for same or 0.
DFA distinct_except_0_dfa(int colors)
@ SYMMETRY_MATRIX
Order rows and columns of matrix.
@ SYMMETRY_NONE
No symmetry breaking.
@ SYMMETRY_VALUES
Order value occurences.
TupleSet same_or_0_tuple_set(int colors)
@ MODEL_COLUMNS
Use model on pairs of columns.
@ MODEL_ROWS
Use model on pairs of rows.
@ MODEL_CORNERS
Use model on corner combinations.
virtual IntVar cost(void) const
Return cost.
IntVarArray x
Array for matrix variables.
ColoredMatrix(const ColoredMatrixOptions &opt0)
Actual model.
DFA same_or_0_dfa(int colors)
@ DISTINCT_EXCEPT_0_DFA
Use dfa for distinct except 0.
@ DISTINCT_EXCEPT_0_COUNT
Use count for distinct except 0.
@ DISTINCT_EXCEPT_0_REIFIED
Use reification for distinct except 0.
const int width
Width of matrix.
IntVar max_color
Maximum color used.
const int height
Height of matrix.
int size(void) const
Return size of array (number of elements)
void add(Driver::BaseOption &o)
Add new option o.
Passing Boolean variables.
Boolean integer variables.
Specification of a DFA transition.
Deterministic finite automaton (DFA)
Parametric base-class for scripts.
String-valued option (integer value defined by strings)
void value(int v)
Set default value to v.
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
void value(unsigned int v)
Set default value to v.
Passing integer variables.
Matrix-interface for arrays.
Slice< A > col(int c) const
Access column c.
Slice< A > row(int r) const
Access row r.
Driver::StringOption _model
General model options.
void symmetry(int v)
Set default symmetry value.
Driver::StringOption _search
Search options.
void ipl(IntPropLevel i)
Set default integer propagation level.
void model(int v)
Set default model value.
Driver::StringOption _symmetry
General symmetry options.
Class represeting a set of tuples.
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.
void parse(int argc, char *argv[])
Parse commandline arguments.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
void extensional(Home home, const IntVarArgs &x, DFA d, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for extensional constraint described by a DFA.
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel=IPL_DEF)
Post propagator that s precedes t in x.
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
const FloatNum max
Largest allowed float value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode toplevel namespace
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel ipl=IPL_DEF)
Post propagator for .
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
IntValBranch INT_VAL_MIN(void)
Select smallest value.
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel ipl=IPL_DEF)
Post propagator for .
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::IntArgs v2({Gecode::Int::Limits::min, 0, 1, Gecode::Int::Limits::max-4})
Gecode::IntArgs v1({Gecode::Int::Limits::min+4, 0, 1, Gecode::Int::Limits::max})
LDSB< TieBreak > tiebreak("TieBreak")
#define GECODE_NEVER
Assert that this command is never executed.