| 43 | |
| 44 | template<class VY> |
| 45 | inline ExecStatus |
| 46 | GqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) { |
| 47 | if (x.size() == 0) { |
| 48 | GECODE_ME_CHECK(y.lq(home,0)); |
| 49 | return ES_OK; |
| 50 | } |
| 51 | |
| 52 | x.unique(); |
| 53 | |
| 54 | if (x.size() == 1) { |
| 55 | GECODE_ME_CHECK(y.lq(home,1)); |
| 56 | return ES_OK; |
| 57 | } |
| 58 | |
| 59 | GECODE_ME_CHECK(y.lq(home,x.size())); |
| 60 | |
| 61 | if (y.max() <= 1) |
| 62 | return ES_OK; |
| 63 | |
| 64 | if (y.min() == x.size()) { |
| 65 | assert(y.assigned()); |
| 66 | return Distinct::Dom<IntView>::post(home,x); |
| 67 | } |
| 68 | |
| 69 | // Eliminate assigned views and store them into the value set |
| 70 | ValSet vs; |
| 71 | int n = x.size(); |
| 72 | for (int i=n; i--; ) |
| 73 | if (x[i].assigned()) { |
| 74 | vs.add(home, x[i].val()); |
| 75 | x[i] = x[--n]; |
| 76 | } |
| 77 | |
| 78 | GECODE_ME_CHECK(y.lq(home,n + vs.size())); |
| 79 | |
| 80 | if (n == 0) { |
| 81 | assert(vs.size() >= y.max()); |
| 82 | return ES_OK; |
| 83 | } |
| 84 | |
| 85 | x.size(n); |
| 86 | |
| 87 | (void) new (home) GqInt<VY>(home, vs, x, y); |
| 88 | return ES_OK; |
| 89 | } |
| 90 | |
| 91 | template<class VY> |
| 92 | forceinline |