3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-17 16:52:15 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-01-13 16:15:51 -08:00
commit 7e0920e362
8 changed files with 119 additions and 27 deletions

View file

@ -286,13 +286,13 @@ public:
m_last_index = 0;
bool first = index > 0;
SASSERT(index < asms.size() || asms.empty());
IF_VERBOSE(1, verbose_stream() << "start hill climb " << index << " asms: " << asms.size() << "\n";);
IF_VERBOSE(10, verbose_stream() << "start hill climb " << index << " asms: " << asms.size() << "\n";);
while (index < asms.size() && is_sat == l_true) {
while (!first && asms.size() > 20*(index - m_last_index) && index < asms.size()) {
index = next_index(asms, index);
}
IF_VERBOSE(1, verbose_stream() << "hill climb " << index << "\n";);
first = false;
IF_VERBOSE(3, verbose_stream() << "hill climb " << index << "\n";);
// IF_VERBOSE(3, verbose_stream() << "weight: " << get_weight(asms[0].get()) << " " << get_weight(asms[index-1].get()) << " num soft: " << index << "\n";);
m_last_index = index;
is_sat = check_sat(index, asms.c_ptr());

View file

@ -353,12 +353,26 @@ namespace opt {
m_upper += w;
}
struct cmp_first {
bool operator()(std::pair<unsigned, rational> const& x, std::pair<unsigned, rational> const& y) const {
return x.first < y.first;
}
};
void maxsmt::display_answer(std::ostream& out) const {
for (unsigned i = 0; i < m_soft_constraints.size(); ++i) {
expr* e = m_soft_constraints[i];
vector<std::pair<unsigned, rational>> sorted_weights;
unsigned n = m_weights.size();
for (unsigned i = 0; i < n; ++i) {
sorted_weights.push_back(std::make_pair(i, m_weights[i]));
}
std::sort(sorted_weights.begin(), sorted_weights.end(), cmp_first());
sorted_weights.reverse();
for (unsigned i = 0; i < n; ++i) {
unsigned idx = sorted_weights[i].first;
expr* e = m_soft_constraints[idx];
bool is_not = m.is_not(e, e);
out << m_weights[i] << ": " << mk_pp(e, m)
<< ((is_not != get_assignment(i))?" |-> true ":" |-> false ")
out << m_weights[idx] << ": " << mk_pp(e, m)
<< ((is_not != get_assignment(idx))?" |-> true ":" |-> false ")
<< "\n";
}

View file

@ -166,7 +166,9 @@ public:
}
virtual void execute(cmd_context & ctx) {
get_opt(ctx, m_opt).display_assignment(ctx.regular_stream());
if (!ctx.ignore_check()) {
get_opt(ctx, m_opt).display_assignment(ctx.regular_stream());
}
}
};