Add constraint for next better solution
| 210 | } |
| 211 | /// Add constraint for next better solution |
| 212 | virtual void constrain(const Space& _s) { |
| 213 | const HasSolutions& s = static_cast<const HasSolutions&>(_s); |
| 214 | switch (htc) { |
| 215 | case HTC_NONE: |
| 216 | break; |
| 217 | case HTC_LEX_LE: |
| 218 | case HTC_LEX_GR: |
| 219 | { |
| 220 | IntVarArgs y(6); |
| 221 | for (int i=0; i<6; i++) |
| 222 | y[i] = IntVar(*this, s.x[i].val(), s.x[i].val()); |
| 223 | lex(*this, x, (htc == HTC_LEX_LE) ? IRT_LE : IRT_GR, y); |
| 224 | break; |
| 225 | } |
| 226 | case HTC_BAL_LE: |
| 227 | case HTC_BAL_GR: |
| 228 | { |
| 229 | IntVarArgs y(6); |
| 230 | for (int i=0; i<6; i++) |
| 231 | y[i] = IntVar(*this, s.x[i].val(), s.x[i].val()); |
| 232 | IntVar xs(*this, -18, 18); |
| 233 | IntVar ys(*this, -18, 18); |
| 234 | rel(*this, x[0]+x[1]+x[2]-x[3]-x[4]-x[5] == xs); |
| 235 | rel(*this, y[0]+y[1]+y[2]-y[3]-y[4]-y[5] == ys); |
| 236 | rel(*this, |
| 237 | expr(*this,abs(xs)), |
| 238 | (htc == HTC_BAL_LE) ? IRT_LE : IRT_GR, |
| 239 | expr(*this,abs(ys))); |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | /// Return number of solutions |
| 245 | virtual int solutions(void) const { |
| 246 | if (htb1 == HTB_NONE) { |