Exemplo n.º 1
0
	bool propagate() {

		// make a less than or equal to min(max(x_i))
		setDom(y, setMax, min_max, x[min_max_var].getMaxLit());

		if (lower_change) {

			// make a greater than or equal to min(min(b_i))
			int64_t m = INT64_MAX; 
			for (int i = 0; i < sz; i++) {
				int64_t t = x[i].getMin();
				if (t < m) m = t;
			}
			if (y.setMinNotR(m)) {
				Clause *r = NULL;
				if (so.lazy) {
					r = Reason_new(sz+1);
					// Finesse lower bounds
					// Add reason ![y <= m-1] \/ [x_1 <= m-1] \/ ... \/ [x_n <= m-1] 
					for (int i = 0; i < sz; i++) (*r)[i+1] = x[i].getFMinLit(m);
//					for (int i = 0; i < sz; i++) (*r)[i+1] = x[i].getLit(m-1, 3);
				}
				if (!y.setMin(m, r)) return false;
			}

			// make b_i greater than or equal to min(a)
			m = y.getMin();
			Clause *r = NULL;
			if (so.lazy) {
				r = Reason_new(2);
				(*r)[1] = y.getMinLit();
			}				
			for (int i = 0; i < sz; i++) {
				if (x[i].setMinNotR(m)) if (!x[i].setMin(m, r)) return false;
			}
		}

		// Necessary and sufficient conditions for redundancy

		if (y.getMin() == min_max) satisfied = true;

		return true;
	}
Exemplo n.º 2
0
	bool propagate() {

		// y = a[fixed_index]
		if (fixed_index >= 0) {
			assert(x.getVal() == fixed_index);
			IntView<W>& f = a[fixed_index];
			setDom(y, setMin, f.getMin(), f.getMinLit(), x.getValLit());
			setDom(f, setMin, y.getMin(), y.getMinLit(), x.getValLit());
			setDom(y, setMax, f.getMax(), f.getMaxLit(), x.getValLit());
			setDom(f, setMax, y.getMax(), y.getMaxLit(), x.getValLit());
			if (y.isFixed() && f.isFixed()) satisfied = true;
			return true;
		}

		for (int i = 0; i < a.size(); i++) {
			if (!x.indomain(i)) continue;
			if (y.getMax() < a[i].getMin()) setDom(x, remVal, i, y.getMaxLit(), a[i].getMinLit());
			if (y.getMin() > a[i].getMax()) setDom(x, remVal, i, y.getMinLit(), a[i].getMaxLit());
		}

		if (no_min_support) {
			int64_t old_m = y.getMin();
			int64_t new_m = INT64_MAX;
			int best = -1;
			for (int i = 0; i < a.size(); i++) {
				if (!x.indomain(i)) continue;
				int64_t cur_m = a[i].getMin();
				if (cur_m < new_m) {
					best = i;
					new_m = cur_m;
					if (cur_m <= old_m) break;
				}
			}
			min_support = best;
			if (y.setMinNotR(new_m)) {
				Clause *r = NULL;
				if (so.lazy) {
					r = Reason_new(a.size()+1);
					// Finesse lower bounds
					for (int i = 0; i < a.size(); i++) {
						(*r)[i+1] = x.indomain(i) ? a[i].getFMinLit(new_m) : x.getLit(i, 1);
					}
				}
				if (!y.setMin(new_m, r)) return false;
			}
			no_min_support = false;
		}

		if (no_max_support) {
			int64_t old_m = y.getMax();
			int64_t new_m = INT_MIN;
			int best = -1;
			for (int i = 0; i < a.size(); i++) {
				if (!x.indomain(i)) continue;
				int64_t cur_m = a[i].getMax();
				if (cur_m > new_m) {
					best = i;
					new_m = cur_m;
					if (cur_m >= old_m) break;
				}
			}
			max_support = best;
			if (y.setMaxNotR(new_m)) {
				Clause *r = NULL;
				if (so.lazy) {
					r = Reason_new(a.size()+1);
					// Finesse upper bounds
					for (int i = 0; i < a.size(); i++) {
						(*r)[i+1] = x.indomain(i) ? a[i].getFMaxLit(new_m) : x.getLit(i, 1);
					}
				}
				if (!y.setMax(new_m, r)) return false;
			}
			no_max_support = false;
		}

		return true;
	}