%Test whether \a x is solution
| 242 | : SetTest(t,5,ds_12,false) {} |
| 243 | /// %Test whether \a x is solution |
| 244 | virtual bool solution(const SetAssignment& x) const { |
| 245 | int selected = 0; |
| 246 | for (CountableSetValues sel2(x.lub, x[3]); sel2(); |
| 247 | ++sel2, selected++) { |
| 248 | if (sel2.val() < 0) |
| 249 | return false; |
| 250 | } |
| 251 | CountableSetValues x4v(x.lub, x[4]); |
| 252 | if (selected == 0) |
| 253 | return !x4v(); |
| 254 | CountableSetRanges* sel = new CountableSetRanges[selected]; |
| 255 | CountableSetValues selector(x.lub, x[3]); |
| 256 | unsigned int cardsum = 0; |
| 257 | for (int i=selected; i--;++selector) { |
| 258 | if (selector.val()>=3 || selector.val()<0) { |
| 259 | delete[] sel; |
| 260 | return false; |
| 261 | } |
| 262 | sel[i].init(x.lub, x[selector.val()]); |
| 263 | CountableSetRanges xicard(x.lub, x[selector.val()]); |
| 264 | cardsum += Iter::Ranges::size(xicard); |
| 265 | } |
| 266 | |
| 267 | bool ret; |
| 268 | { |
| 269 | Region r; |
| 270 | Iter::Ranges::NaryUnion u(r, sel, selected); |
| 271 | ret = Iter::Ranges::size(u) == cardsum; |
| 272 | u.reset(); |
| 273 | CountableSetRanges z(x.lub, x[4]); |
| 274 | ret &= Iter::Ranges::equal(u, z); |
| 275 | } |
| 276 | delete[] sel; |
| 277 | return ret; |
| 278 | } |
| 279 | /// Post constraint on \a x |
| 280 | virtual void post(Space& home, SetVarArray& x, IntVarArray&) { |
| 281 | SetVarArgs xs(x.size()-2); |