Constructor
| 81 | |
| 82 | /// Constructor |
| 83 | QueenArmies(const SizeOptions& opt) : |
| 84 | IntMaximizeScript(opt), |
| 85 | n(opt.size()), |
| 86 | U(*this, IntSet::empty, IntSet(0, n*n)), |
| 87 | W(*this, IntSet::empty, IntSet(0, n*n)), |
| 88 | w(*this, n*n, 0, 1), |
| 89 | b(*this, n*n, 0, 1), |
| 90 | q(*this, 0, n*n) |
| 91 | { |
| 92 | // Basic rules of the model |
| 93 | for (int i = n*n; i--; ) { |
| 94 | // w[i] means that no blacks are allowed on A[i] |
| 95 | rel(*this, w[i] == (U || A[i])); |
| 96 | // Make sure blacks and whites are disjoint. |
| 97 | rel(*this, !w[i] || !b[i]); |
| 98 | // If i in U, then b[i] has a piece. |
| 99 | rel(*this, b[i] == (singleton(i) <= U)); |
| 100 | } |
| 101 | |
| 102 | // Connect optimization variable to number of pieces |
| 103 | linear(*this, w, IRT_EQ, q); |
| 104 | linear(*this, b, IRT_GQ, q); |
| 105 | |
| 106 | // Connect cardinality of U to the number of black pieces. |
| 107 | IntVar unknowns = expr(*this, cardinality(U)); |
| 108 | rel(*this, q <= unknowns); |
| 109 | linear(*this, b, IRT_EQ, unknowns); |
| 110 | |
| 111 | if (opt.branching() == BRANCH_NAIVE) { |
| 112 | branch(*this, w, BOOL_VAR_NONE(), BOOL_VAL_MAX()); |
| 113 | branch(*this, b, BOOL_VAR_NONE(), BOOL_VAL_MAX()); |
| 114 | } else { |
| 115 | QueenBranch::post(*this); |
| 116 | assign(*this, b, BOOL_ASSIGN_MAX()); |
| 117 | } |
| 118 | } |
| 119 | /// Constructor for cloning |
| 120 | QueenArmies(QueenArmies& s) |
| 121 | : IntMaximizeScript(s), n(s.n) { |
nothing calls this directly
no test coverage detected