| 113 | |
| 114 | template<class Card> |
| 115 | ExecStatus |
| 116 | Dom<Card>::propagate(Space& home, const ModEventDelta&) { |
| 117 | Region r; |
| 118 | |
| 119 | int* count = r.alloc<int>(k.size()); |
| 120 | for (int i = k.size(); i--; ) |
| 121 | count[i] = 0; |
| 122 | |
| 123 | // total number of assigned views |
| 124 | int noa = 0; |
| 125 | for (int i = y.size(); i--; ) |
| 126 | if (y[i].assigned()) { |
| 127 | noa++; |
| 128 | int idx; |
| 129 | if (!lookupValue(k,y[i].val(),idx)) |
| 130 | return ES_FAILED; |
| 131 | count[idx]++; |
| 132 | if (Card::propagate && (k[idx].max() == 0)) |
| 133 | return ES_FAILED; |
| 134 | } |
| 135 | |
| 136 | if (noa == y.size()) { |
| 137 | // All views are assigned |
| 138 | for (int i = k.size(); i--; ) { |
| 139 | if ((k[i].min() > count[i]) || (count[i] > k[i].max())) |
| 140 | return ES_FAILED; |
| 141 | // the solution contains ci occurrences of value k[i].card(); |
| 142 | if (Card::propagate) |
| 143 | GECODE_ME_CHECK(k[i].eq(home, count[i])); |
| 144 | } |
| 145 | return home.ES_SUBSUMED(*this); |
| 146 | } |
| 147 | |
| 148 | // before propagation performs inferences on cardinality variables: |
| 149 | if (Card::propagate) { |
| 150 | if (noa > 0) |
| 151 | for (int i = k.size(); i--; ) |
| 152 | if (!k[i].assigned()) { |
| 153 | GECODE_ME_CHECK(k[i].lq(home, y.size() - (noa - count[i]))); |
| 154 | GECODE_ME_CHECK(k[i].gq(home, count[i])); |
| 155 | } |
| 156 | |
| 157 | GECODE_ES_CHECK(prop_card<Card>(home,y,k)); |
| 158 | if (!card_consistent<Card>(y,k)) |
| 159 | return ES_FAILED; |
| 160 | } |
| 161 | |
| 162 | if (x.size() == 0) { |
| 163 | for (int j = k.size(); j--; ) |
| 164 | if ((k[j].min() > k[j].counter()) || (k[j].max() < k[j].counter())) |
| 165 | return ES_FAILED; |
| 166 | return home.ES_SUBSUMED(*this); |
| 167 | } else if ((x.size() == 1) && (x[0].assigned())) { |
| 168 | int idx; |
| 169 | if (!lookupValue(k,x[0].val(),idx)) |
| 170 | return ES_FAILED; |
| 171 | GECODE_ME_CHECK(k[idx].inc()); |
| 172 | for (int j = k.size(); j--; ) |
nothing calls this directly
no test coverage detected