| 43 | } |
| 44 | |
| 45 | int |
| 46 | IntVarImp::med(void) const { |
| 47 | // Computes the median |
| 48 | if (fst() == nullptr) |
| 49 | return (dom.min()+dom.max())/2 - ((dom.min()+dom.max())%2 < 0 ? 1 : 0); |
| 50 | unsigned int i = size() / 2; |
| 51 | if (size() % 2 == 0) |
| 52 | i--; |
| 53 | const RangeList* p = nullptr; |
| 54 | const RangeList* c = fst(); |
| 55 | while (i >= c->width()) { |
| 56 | i -= c->width(); |
| 57 | const RangeList* n=c->next(p); p=c; c=n; |
| 58 | } |
| 59 | return c->min() + static_cast<int>(i); |
| 60 | } |
| 61 | |
| 62 | bool |
| 63 | IntVarImp::in_full(int m) const { |