Ejemplo n.º 1
0
    virtual bool addPost(Clasp::Solver& s)
    {
        if (conf_.dlprop==2)
            if (!addDLProp(s,n_.constraints()))
                return false;

        std::vector<order::ReifiedLinearConstraint> constraints;
        if (conf_.dlprop==1)
        {
            constraints = n_.constraints();
        }
        
        ///solver takes ownership of propagator
        clingcon::ClingconOrderPropagator* cp = new clingcon::ClingconOrderPropagator(s, n_.getVariableCreator(), conf_,
                                                                                      std::move(n_.constraints()),n_.getEqualities(),
                                                                                      &(to_.names_));
        to_.props_[s.id()]=cp;
        if (!s.addPost(cp))
            return false;
        
        if (conf_.dlprop==1)
            if (!addDLProp(s, constraints))
                return false;
        return true;
    }
	bool onModel(const Clasp::Solver& s, const Clasp::Model& m) {
		printModel(s.symbolTable(), m);
		// exclude this model
		Clasp::LitVec clause;
		for (uint32 i = 1; i <= s.decisionLevel(); ++i) {
			clause.push_back( ~s.decision(i) );
		}
		return m.ctx->commitClause(clause);
	}
Ejemplo n.º 3
0
bool ExternalKnowledge::PostPropagator::propagate(Clasp::Solver &s) {
	if(ext_->poll()) {
		std::cerr << "Stopping solver..." << std::endl;
		s.setStopConflict();
	}

	if(s.hasConflict())	{
		assert(s.hasConflict());
		return false;
	}
	return true;
}
Ejemplo n.º 4
0
void AspOutPrinter::reportModel(const Clasp::Solver& s, const Clasp::Enumerator& e) {
	std::cout << "Model " << e.enumerated << ": \n";
	// get the symbol table from the solver
	const Clasp::SymbolTable& symTab = s.sharedContext()->symTab();
	for (Clasp::SymbolTable::const_iterator it = symTab.begin(); it != symTab.end(); ++it) {
		// print each named atom that is true w.r.t the current assignment
		if (s.isTrue(it->second.lit) && !it->second.name.empty()) {
			std::cout << it->second.name.c_str() << " ";
		}
	}
	std::cout << std::endl;
}
Ejemplo n.º 5
0
bool ClingoPropagator::propagateFixpoint(Clasp::Solver& s, Clasp::PostPropagator*) {
	POTASSCO_REQUIRE(prop_ <= trail_.size(), "Invalid propagate");
	for (Control ctrl(*this, s, state_prop); prop_ != trail_.size() || front_ < (int32)s.numAssignedVars();) {
		if (prop_ != trail_.size()) {
			// create copy because trail might change during call to user propagation
			temp_.assign(trail_.begin() + prop_, trail_.end());
			prop_ = static_cast<uint32>(trail_.size());
			ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->propagate(ctrl, Potassco::toSpan(temp_));
		}
		else {
			registerUndo(s);
			front_ = (int32)s.numAssignedVars();
			ScopedLock(call_->lock(), call_->propagator(), Inc(epoch_))->check(ctrl);
		}
		if (!addClause(s, state_prop) || (s.queueSize() && !s.propagateUntil(this))) {
			return false;
		}
	}
	return true;
}
Ejemplo n.º 6
0
 bool addDLProp(Clasp::Solver& s, const std::vector<order::ReifiedLinearConstraint>& constraints)
 {
     clingcon::ClingconDLPropagator* dlp = new clingcon::ClingconDLPropagator(s, conf_);
     for (const auto&i : constraints)
     {
         if (dlp->isValidConstraint(i))
             dlp->addValidConstraint(i);
     }
     if (!s.addPost(dlp))
         return false;
     return true;        
 }
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
bool ClaspCallback::onModel(const Clasp::Solver& s, const Clasp::Model& m)
{
	if(app.getPrinter().listensForSolverEvents()) {
		Clasp::SymbolTable& symbolTable = s.sharedContext()->symbolTable();
		std::ostringstream msg;
		msg << "Model: ";
		for(Clasp::SymbolTable::const_iterator it = symbolTable.begin(); it != symbolTable.end(); ++it) {
			if(m.isTrue(it->second.lit) && !it->second.name.empty())
				msg << it->second.name.c_str() << ' ';
		}
		app.getPrinter().solverEvent(msg.str());
	}
	return true;
}
Ejemplo n.º 9
0
void ExternalKnowledge::removePostPropagator(Clasp::Solver& solver) {
	solver.removePost(post_);
	my_post_ = true;
}
Ejemplo n.º 10
0
void ExternalKnowledge::addPostPropagator(Clasp::Solver& solver) {
	my_post_ = false;
	solver.addPost(post_);
}
Ejemplo n.º 11
0
	bool onModel(const Clasp::Solver& s, const Clasp::Model& m) {
		printModel(s.symbolTable(), m);
		return true;
	}
Ejemplo n.º 12
0
bool TheoryPropagator::attach(Clasp::Solver& s) { 
	return s.addPost(new PP(*this)); 
}
Ejemplo n.º 13
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;
}