Esempio n. 1
0
bool SatBuilder::doEndProgram() {
	bool ok = ctx()->ok();
	if (!softClauses_.empty() && ok) {
		ctx()->setPreserveModels(true);
		ctx()->resizeVars(vars_+1);
		ctx()->startAddConstraints();
		LitVec cc; 
		for (LitVec::const_iterator it = softClauses_.begin(), end = softClauses_.end(); it != end && ok; ++it) {
			weight_t w     = (weight_t)it->asUint();
			Literal  relax = *++it;
			if (!relax.watched()) { 
				cc.assign(1, relax);
				do { cc.push_back(*++it); } while (!cc.back().watched());
				cc.back().clearWatch();
				ok = ClauseCreator::create(*ctx()->master(), cc, Constraint_t::static_constraint).ok();
			}
			relax.clearWatch();
			addMinLit(WeightLiteral(relax, w));
		}
		LitVec().swap(softClauses_);
	}
	if (ok && !ctx()->preserveModels()) {
		uint32 p    = 12;
		for (Var v  = 1; v != (Var)varState_.size() && ok; ++v) {
			uint32 m  = varState_[v];
			if ( (m & p) != p ) { ok = ctx()->addUnary(Literal(v, ((m>>2) & 1u) != 1)); }
		}
Esempio n. 2
0
bool Lookahead::propagateFixpoint(Solver& s) {
	if ((empty() || top_ == s.numAssignedVars()) && !score.deps.empty()) {
		// nothing to lookahead
		return true;
	}
	bool ok = true;
	uint32 dl;
	for (dl = s.decisionLevel(); !propagate(s); dl = s.decisionLevel()) {
		// some literal failed
		// resolve and propagate conflict
		assert(s.decisionLevel() >= dl);
		if (!s.resolveConflict() || !s.propagateUntil(this)) {
			ok = false;
			score.clearDeps();
			break;
		}
	}
	if (dl == 0 && ok) {
		// remember top-level size - no need to redo lookahead
		// on level 0 unless we learn a new implication
		assert(s.queueSize() == 0);
		top_ = s.numAssignedVars();
		LitVec().swap(imps_);
	}
	return ok;
}
Esempio n. 3
0
/////////////////////////////////////////////////////////////////////////////////////////
// solve
/////////////////////////////////////////////////////////////////////////////////////////
bool solve(SharedContext& ctx, const SolveParams& p, const SolveLimits& lim) {
	return SimpleSolve(lim).solve(ctx, p, LitVec());
}