bool simplify(goal_ref const& g, pb_preproc_model_converter& mc) { reset(); normalize(g); if (g->inconsistent()) { return false; } for (unsigned i = 0; i < g->size(); ++i) { process_vars(i, g); } if (m_ge.empty()) { return false; } for (unsigned i = 0; i < m_ge.size(); ++i) { classify_vars(i, to_app(g->form(m_ge[i]))); } declassifier dcl(m_vars); expr_mark visited; for (unsigned i = 0; !m_vars.empty() && i < m_other.size(); ++i) { for_each_expr(dcl, visited, g->form(m_other[i])); } if (m_vars.empty()) { return false; } // display_annotation(tout, g); m_progress = false; // first eliminate variables var_map::iterator it = next_resolvent(m_vars.begin()); while (it != m_vars.end()) { app * e = it->m_key; rec const& r = it->m_value; TRACE("pb", tout << mk_pp(e, m) << " " << r.pos.size() << " " << r.neg.size() << "\n";); if (r.pos.empty()) { replace(r.neg, e, m.mk_false(), g); mc.set_value(e, false); } else if (r.neg.empty()) { replace(r.pos, e, m.mk_true(), g); mc.set_value(e, true); } if (g->inconsistent()) return false; ++it; it = next_resolvent(it); }
inline bool process_vars(buffer::ptr_c const& buff, int ttl, std::string& string) { if (ttl < 0) { return false; } std::string::size_type pos = 0, p1, p2; std::string name, val; for (;find_next_var(string, pos, p1, p2, name);) { if (find_val_by_name(buff, name, val)) { if (process_vars(buff, ttl-1, val)) { string.replace(p1, p2 - p1, val); pos = p1 + val.length(); continue; } } pos = p2; } return true; }