Exemplo n.º 1
0
bool ClingconDLPropagator::init(Clasp::Solver& s)
{
    for (unsigned int i = 0; i != literals_.size(); ++i)
    {
        if (!s.isFalse(literals_[i]) || !s.isTrue(literals_[i]))
        {
            s.addWatch(literals_[i],this,Clasp::Literal(i+1,false).rep());
            s.addWatch(~literals_[i],this,Clasp::Literal(i+1,true).rep());
        }
    }
    for (unsigned int i = 0; i != literals_.size(); ++i)
    {
        std::vector<difflogic::DLPropagator::EdgeId> consequences;
        if (s.isFalse(literals_[i]))
            consequences = p_.deactivate(i+1);
        else
        if (s.isTrue(literals_[i]))
            consequences = p_.activate(i+1);
            
        for (const auto& j : consequences)
        {
            Clasp::Literal l = edgeid2lit(j);
            if (!s_.isTrue(l))
            {
                if (!s.force(l))
                    return false;
                //std::cout << "initially propagated " << l.var() << "," << l.sign() << " to pending: " << j << std::endl;
                propagated_.push_back(l);
            }
        }
    }
    return true;
}
Exemplo n.º 2
0
bool TheoryPropagator::PP::propagateFixpoint(Clasp::Solver& s, Clasp::PostPropagator*) {
	typedef Potassco::AbstractPropagator::ChangeList ChangeList;
	while (delta_ != trail_.size()) {
		uint32 dl = s.decisionLevel();
		if (undo_.back().level != dl) {
			s.addUndoWatch(dl, this);
			undo_.push_back(Undo(dl, delta_));
		}
		ChangeList change = Potassco::toSpan(&trail_[0] + delta_, trail_.size() - delta_);
		delta_  = trail_.size();
		status_ = ClauseCreator::status_open;
		solver_ = &s;
		inProp_ = true;
		bool ok = wrapper_->prop_->propagate(*this, change);
		inProp_ = false;
		if (!ok && !s.hasConflict() && (status_ & ClauseCreator::status_asserting) != 0) {
			if (s.level(clause_[1].var()) < dl && dl != s.backtrackLevel()) {
				TheoryPropagator::PP::reset();
				for (PostPropagator* n = this->next; n; n = n->next) { n->reset(); }
				dl = s.undoUntil(s.level(clause_[1].var()));
			}
			if (!s.isFalse(clause_[0])) {
				ok = ClauseCreator::create(*solver_, clause_, ccFlags_s | ClauseCreator::clause_no_prepare, Constraint_t::Other);
			}
			else {
				return s.force(clause_[0], this);
			}
		}
		if (s.hasConflict() || !ok || (s.queueSize() && !s.propagateUntil(this))) {
			if (!s.hasConflict()) { s.setStopConflict(); }
			return false;
		}
		CLASP_FAIL_IF(dl < s.decisionLevel(), "invalid operation in propagation");
	}
	return true;
}