示例#1
0
void Definition::addRule(uint id, bool onlyif, int defID, bool conj, Atom head, const litlist& ps) {
	auto& def = rules[defID];
	auto it = def.find(head);
	if (it == def.cend()) {
		def[head] = new TempRule(id, onlyif, head, conj, ps);
		return;
	}

	auto prevrule = it->second;
	if(prevrule->onlyif != prevrule->onlyif){
		throw idpexception("Rules on the same head in the same definition need to have the same semantics.");
	}
	if (prevrule->conjunctive) { // introduce new var (we need disjunctive root anyway)
		auto newvar = solver->newAtom();
		def[newvar] = new TempRule(id, onlyif, newvar, prevrule->conjunctive, prevrule->body);
		prevrule->conjunctive = false;
		prevrule->body = {mkLit(newvar)};
	}
	if (conj) { // Create a new var and rule first
		auto newvar = solver->newAtom();
		def[newvar] = new TempRule(id, onlyif, newvar, conj, ps);
		prevrule->body.push_back(mkPosLit(newvar));
	} else { // Disjunctive, so can add directly
		prevrule->body.insert(prevrule->body.end(), ps.cbegin(), ps.cend());
	}
}
std::string ExternalConstraintVisitor::toString(const litlist& literals) const {
	std::stringstream ss;
	bool begin = true;
	for (auto i = literals.cbegin(); i < literals.cend(); ++i) {
		if (not begin) {
			ss << " | ";
		}
		begin = false;
		ss << toString(*i);
	}
	return ss.str();
}