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;
}
Exemple #2
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;
}