#include #include class BoolArgMax : public Propagator { public: int const sz; BoolView * const x; IntView<> const y; int offset; BoolArgMax(vec _x, int _offset, IntView<> _y) : sz(_x.size()), x(_x.release()), y(_y), offset(_offset) { priority = 1; for (int i = 0; i < sz; i++) x[i].attach(this, i, EVENT_LU); y.attach(this, sz, EVENT_C); } bool propagate() { // l = index of first x that can be true // y >= l because not x[i] forall i toFix; for (typename IntView<>::iterator yi = y.begin(); yi != y.end(); ++yi) { int i = *yi - offset; if (l==sz && (!x[i].isFixed() || x[i].isTrue())) { l = i; } if (x[i].isFixed() && x[i].isFalse()) { if (y.remValNotR(i+offset)) { toFix.push(i); } } u = i; if (x[i].isFixed() && x[i].isTrue()) { break; } } for (int i=0; i& x, int offset, IntVar* y) { vec w; for (int i = 0; i < x.size(); i++) w.push(BoolView(x[i])); new BoolArgMax(w, offset, IntView<>(y)); }