Exemplo n.º 1
0
bool TheoryPropagator::PP::addClause(const Potassco::LitSpan& clause) {
	CLASP_FAIL_IF(solver_->hasConflict(), "invalid addClause()!");
	clause_.clear();
	for (const Potassco::Lit_t* it = Potassco::begin(clause); it != Potassco::end(clause); ++it) {
		clause_.push_back(decodeLit(*it));
	}
	ClauseRep rep = ClauseCreator::prepare(*solver_, clause_, Clasp::ClauseCreator::clause_force_simplify, Constraint_t::Other);
	if (clause_.size() < 2) { clause_.resize(2, lit_false()); }
	status_ = ClauseCreator::status(*solver_, rep);
	uint32 impLevel = (status_ & ClauseCreator::status_asserting) != 0 ? solver_->level(clause_[1].var()) : UINT32_MAX;
	if (!inProp_ || impLevel >= solver_->decisionLevel()) {
		status_ = ClauseCreator::status_open;
		return ClauseCreator::create(*solver_, rep, ccFlags_s);
	}
	return false;
}
Exemplo n.º 2
0
void ClingoPropagator::Control::addWatch(Lit_t lit) {
	ScopedUnlock unlocked(lock(), ctx_);
	POTASSCO_REQUIRE(assignment_.hasLit(lit), "Invalid literal");
	Literal p = decodeLit(lit);
	Solver& s = solver();
	if (!s.hasWatch(p, ctx_)) {
		s.addWatch(p, ctx_);
		if ((state_ & state_init) != 0u && s.isTrue(p)) {
			// are we too late?
			bool inQ = std::find(s.trail().begin() + s.assignment().front, s.trail().end(), p) != s.trail().end();
			if (!inQ && !ctx_->inTrail(p)) {
				uint32 ignore = 0;
				ctx_->propagate(s, p, ignore);
			}
		}
	}
}
Exemplo n.º 3
0
void ClingoPropagator::undoLevel(Solver& s) {
	POTASSCO_REQUIRE(s.decisionLevel() == level_, "Invalid undo");
	uint32 beg = undo_.back();
	undo_.pop_back();
	if (prop_ > beg) {
		Potassco::LitSpan change = Potassco::toSpan(&trail_[0] + beg, prop_ - beg);
		ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->undo(Control(*this, s), change);
		prop_ = beg;
	}
	trail_.resize(beg);
	if (front_ != INT32_MAX) {
		front_ = -1;
		--level_;
	}
	else {
		level_ = !trail_.empty() ? s.level(decodeLit(trail_.back()).var()) : 0;
	}
}
Exemplo n.º 4
0
void ClingoPropagator::toClause(Solver& s, const Potassco::LitSpan& clause, Potassco::Clause_t prop) {
	POTASSCO_REQUIRE(todo_.empty(), "Assignment not propagated");
	Literal max;
	LitVec& mem = todo_.mem;
	for (const Potassco::Lit_t* it = Potassco::begin(clause); it != Potassco::end(clause); ++it) {
		Literal p = decodeLit(*it);
		if (max < p) { max = p; }
		mem.push_back(p);
	}
	if (aux_ < max) { aux_ = max; }
	if ((Potassco::Clause_t::isVolatile(prop) || s.auxVar(max.var())) && !isSentinel(s.sharedContext()->stepLiteral())) {
		mem.push_back(~s.sharedContext()->stepLiteral());
	}
	todo_.clause = ClauseCreator::prepare(s, mem, Clasp::ClauseCreator::clause_force_simplify, Constraint_t::Other);
	todo_.flags  = ccFlags_s[int(Potassco::Clause_t::isStatic(prop))];
	if (mem.empty()) {
		mem.push_back(lit_false());
	}
}
Exemplo n.º 5
0
void ClingoPropagator::Control::removeWatch(Lit_t lit) {
	ScopedUnlock unlocked(lock(), ctx_);
	if (assignment_.hasLit(lit)) {
		solver().removeWatch(decodeLit(lit), ctx_);
	}
}
Exemplo n.º 6
0
bool ClingoPropagator::Control::hasWatch(Lit_t lit) const {
	ScopedUnlock unlocked(lock(), ctx_);
	return assignment_.hasLit(lit) && solver().hasWatch(decodeLit(lit), ctx_);
}