bool ilp_solution_t::contains(const literal_t &target) const { std::set<literal_t> literals; std::set<literal_t> non_eqs; std::list< hash_set<term_t> > terms; enumerate_unified_terms_sets(&terms); get_reduced_sol(&literals, &non_eqs, terms); for(auto l: literals) { bool fSatisfied(true); // Does the arity of l match? if(target.predicate != l.predicate || target.terms.size() != l.terms.size()) { continue; } for(auto i = 0; i<l.terms.size(); i++) { if(target.terms[i] == "_") continue; if(target.terms[i] != l.terms[i]) fSatisfied = false; } if(fSatisfied) return true; } return false; }
void ilp_solution_t::print_human_readable_hypothesis(std::ostream *os) const { const ilp_problem_t *prob = problem(); const pg::proof_graph_t *graph = prob->proof_graph(); std::set<literal_t> literals; std::set<literal_t> non_eqs; std::list< hash_set<term_t> > terms; auto reguralized = [](const std::list<hash_set<term_t> > &terms, const literal_t &lit) -> literal_t { literal_t out(lit); for (term_idx_t i = 0; i < out.terms.size(); ++i) { for (auto set : terms) if (set.count(out.terms.at(i)) > 0) { out.terms[i] = *set.begin(); break; } } return out; }; enumerate_unified_terms_sets(&terms); // ENUMERATE ELEMENTS OF literals AND non_eqs for (auto n : graph->nodes()) if (not n.is_equality_node()) if (n.type() == pg::NODE_HYPOTHESIS or n.type() == pg::NODE_OBSERVABLE) { variable_idx_t v = problem()->find_variable_with_node(n.index()); if (prob->node_is_active(*this, n.index())) { if (n.is_non_equality_node()) literals.insert(reguralized(terms, n.literal())); else non_eqs.insert(reguralized(terms, n.literal())); } } (*os) << "<hypothesis>" << std::endl; (*os) << "(^ " << util::join_f(literals, [](const literal_t &l){ return l.to_string(); }, " ") << (non_eqs.empty() ? "" : " ") << util::join_f(non_eqs, [](const literal_t &l){ return l.to_string(); }, " "); auto term2str = [](const term_t &t){ return t.string(); }; for (auto set : terms) (*os) << " (= " << util::join_f(set, term2str, " ") << ")"; (*os) << ")" << std::endl; (*os) << "</hypothesis>" << std::endl; }
void ilp_solution_t::print_human_readable_hypothesis(std::ostream *os) const { std::set<literal_t> literals; std::set<literal_t> non_eqs; std::list< hash_set<term_t> > terms; enumerate_unified_terms_sets(&terms); get_reduced_sol(&literals, &non_eqs, terms); (*os) << "<hypothesis>" << std::endl; (*os) << "(^ " << util::join_f(literals, [](const literal_t &l){ return l.to_string(); }, " ") << (non_eqs.empty() ? "" : " ") << util::join_f(non_eqs, [](const literal_t &l){ return l.to_string(); }, " "); auto term2str = [](const term_t &t){ return t.string(); }; for (auto set : terms) (*os) << " (= " << util::join_f(set, term2str, " ") << ")"; (*os) << ")" << std::endl; (*os) << "</hypothesis>" << std::endl; }