| 244 | |
| 245 | template<class View> |
| 246 | ExecStatus |
| 247 | Weights<View>::propagate(Space& home, const ModEventDelta&) { |
| 248 | ModEvent me = ME_SET_NONE; |
| 249 | |
| 250 | if (!x.assigned()) { |
| 251 | // Collect the weights of the elements in the unknown set in an array |
| 252 | int size = elements.size(); |
| 253 | Region r; |
| 254 | int* minWeights = r.alloc<int>(size); |
| 255 | int* maxWeights = r.alloc<int>(size); |
| 256 | |
| 257 | UnknownRanges<View> ur(x); |
| 258 | Iter::Ranges::ToValues<UnknownRanges<View> > urv(ur); |
| 259 | for (int i=0; i<size; i++) { |
| 260 | if (!urv() || elements[i]<urv.val()) { |
| 261 | minWeights[i] = INT_MAX; |
| 262 | maxWeights[i] = INT_MIN; |
| 263 | } else { |
| 264 | assert(elements[i] == urv.val()); |
| 265 | minWeights[i] = weights[i]; |
| 266 | maxWeights[i] = weights[i]; |
| 267 | ++urv; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Sort the weights of the unknown elements |
| 272 | IntLess il; |
| 273 | Support::quicksort<int>(minWeights, size, il); |
| 274 | Support::quicksort<int>(maxWeights, size, il); |
| 275 | |
| 276 | // The maximum number of elements that can still be added to x |
| 277 | int delta = static_cast<int>(std::min(x.unknownSize(), x.cardMax() - x.glbSize())); |
| 278 | |
| 279 | // The weight of the elements already in x |
| 280 | GlbRanges<View> glb(x); |
| 281 | int glbWeight = weightI<GlbRanges<View> >(elements, weights, glb); |
| 282 | |
| 283 | // Compute the weight of the current lower bound of x, plus at most |
| 284 | // delta-1 further elements with smallest negative weights. This weight |
| 285 | // determines which elements in the upper bound cannot possibly be |
| 286 | // added to x (those whose weight would exceed the capacity even if |
| 287 | // all other elements are minimal) |
| 288 | int lowWeight = glbWeight; |
| 289 | for (int i=0; i<delta-1; i++) { |
| 290 | if (minWeights[i] >= 0) |
| 291 | break; |
| 292 | lowWeight+=minWeights[i]; |
| 293 | } |
| 294 | |
| 295 | // Compute the lowest possible weight of x. If there is another element |
| 296 | // with negative weight left, then add its weight to lowWeight. |
| 297 | // Otherwise lowWeight is already the lowest possible weight. |
| 298 | int lowestWeight = lowWeight; |
| 299 | if (delta>0 && minWeights[delta-1]<0) |
| 300 | lowestWeight+=minWeights[delta-1]; |
| 301 | |
| 302 | // If after including the minimal number of required elements, |
| 303 | // no more element with negative weight is available, then |
nothing calls this directly
no test coverage detected