bool LinearPropagator::propagate_true(const LinearConstraint& l) { assert(l.getRelation()==LinearConstraint::Relation::LE); auto minmax = computeMinMax(l); if (minmax.second <= l.getRhs()) return true; for (auto i : l.getViews()) { auto r = vs_.getCurrentRestrictor(i); auto wholeRange = vs_.getRestrictor(i); std::pair<int64,int64> mm; mm.first = minmax.first - r.lower(); mm.second = minmax.second - r.upper(); int64 up = l.getRhs() - mm.first; if (up < r.lower()) { //std::cout << "Constrain Variable " << i.first << " with new upper bound " << up << std::endl; return false; } if (up < r.upper()) { //std::cout << "Constrain Variable " << i.first << " with new upper bound " << up << std::endl; //auto newUpper = std::lower_bound(wholeRange.begin(), wholeRange.end(), up); auto newUpper = std::upper_bound(wholeRange.begin(), wholeRange.end(), up); if (!constrainUpperBound(newUpper)) // +1 is needed, as it is in iterator pointing after the element return false; minmax.first = mm.first + r.lower(); minmax.second = mm.second + *(newUpper-1); } } return true; }
std::pair<int64,int64> LinearPropagator::computeMinMax(const LinearConstraint& l) { auto views = l.getViews(); std::pair<int64,int64> minmax(0,0); for (auto i : views) { auto r = vs_.getCurrentRestrictor(i); minmax.first += r.lower(); minmax.second += r.upper(); } return minmax; }
int64 LinearLiteralPropagator::computeMin(const LinearConstraint& l, itervec& clause) { auto& views = l.getViews(); int64 min(0); for (auto& i : views) { auto r = vs_.getVariableStorage().getCurrentRestrictor(i); assert(!r.isEmpty()); min += r.lower(); clause.emplace_back(r.begin()); } return min; }
std::pair<int64,int64> LinearLiteralPropagator::computeMinMax(const LinearConstraint& l, LinearConstraintClause::itervec& clause) { auto views = l.getViews(); std::pair<int64,int64> minmax(0,0); for (auto i : views) { auto r = vs_.getVariableStorage().getCurrentRestrictor(i); assert(!r.isEmpty()); minmax.first += r.lower(); minmax.second += r.upper(); clause.emplace_back(r.begin()); } return minmax; }