Example #1
0
	bool propagate() {

		// propagate holes in y
		for (int v = y.getMin(); v <= y.getMax(); v++) {
			if (!y.indomain(v)) continue;
			assert(num_support[v] > 0);
			int *s = support[v];
			if (x.indomain(s[0]) && a[s[0]].indomain(v)) continue;
			int f = 0;
			while (!(x.indomain(s[f]) && a[s[f]].indomain(v)) && ++f < num_support[v]);
			if (f == num_support[v]) {
				// v has no support, remove from y
				Clause* r = NULL;
				if (so.lazy) {
					r = Reason_new(x.getMax() + 4 - x.getMin());
					(*r)[1] = x.getMinLit();
					(*r)[2] = x.getMaxLit();
					for (int i = x.getMin(); i <= x.getMax(); i++) {
						//(*r)[3 + i - x.getMin()] = x.indomain(i) ? ~a[i].getLit(v, 0) : ~x.getLit(i, 0);
						int reasonIndex = 3 + i - x.getMin();
						if(x.indomain(i))
						{
							Lit l = ~a[i].getLit(v, 0);
							(*r)[reasonIndex] = l;
						}
						else
						{
							Lit l = ~x.getLit(i, 0);
						 	(*r)[reasonIndex] = l;
						}
					}
				}
				if (!y.remVal(v, r)) return false;
			} else {
				// shift bad supports to back
				for (int i = 0; i < f; i++) temp_sup[i] = s[i];
				for (int i = f; i < num_support[v]; i++) {
					s[i-f] = s[i];
				}
				s += num_support[v] - f;
				for (int i = 0; i < f; i++) s[i] = temp_sup[i];
				num_support[v] -= f;
			}
		}

		// propagate holes in x
		// just ignore

		// propagate holes in a_i
		if (x.isFixed()) {
			int v = x.getVal();
			IntView<W>& f = a[v];
			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());
			for (typename IntView<W>::iterator i = a[v].begin(); i != a[v].end(); ) {
				int w = *i++;
				if (!y.indomain(w) && !a[v].remVal(w, so.lazy ? Reason(~y.getLit(w, 0), ~x.getLit(v, 1)) : Reason()))
					return false;
			}
		}

		return true;
	}
Example #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;
	}