-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
opt_pareto.cpp
113 lines (94 loc) · 3.23 KB
/
opt_pareto.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*++
Copyright (c) 2014 Microsoft Corporation
Module Name:
opt_pareto.cpp
Abstract:
Pareto front utilities
Author:
Nikolaj Bjorner (nbjorner) 2014-4-24
Notes:
--*/
#include "opt/opt_pareto.h"
#include "ast/ast_pp.h"
#include "ast/ast_util.h"
#include "model/model_smt2_pp.h"
namespace opt {
// ---------------------
// GIA pareto algorithm
lbool gia_pareto::operator()() {
expr_ref fml(m);
lbool is_sat = m_solver->check_sat(0, nullptr);
if (is_sat == l_true) {
{
m_solver->get_model(m_model);
solver::scoped_push _s(*m_solver.get());
while (is_sat == l_true) {
if (!m.inc()) {
return l_undef;
}
if (!m_model)
return l_undef;
m_solver->get_labels(m_labels);
m_model->set_model_completion(true);
IF_VERBOSE(1,
model_ref mdl(m_model);
cb.fix_model(mdl);
model_smt2_pp(verbose_stream() << "new model:\n", m, *mdl, 0););
// TBD: we can also use local search to tune solution coordinate-wise.
mk_dominates();
is_sat = m_solver->check_sat(0, nullptr);
if (is_sat == l_true) m_solver->get_model(m_model);
}
}
if (is_sat == l_undef) {
return l_undef;
}
SASSERT(is_sat == l_false);
is_sat = l_true;
mk_not_dominated_by();
}
return is_sat;
}
void pareto_base::mk_dominates() {
unsigned sz = cb.num_objectives();
expr_ref fml(m);
expr_ref_vector gt(m), fmls(m);
for (unsigned i = 0; i < sz; ++i) {
fmls.push_back(cb.mk_ge(i, m_model));
gt.push_back(cb.mk_gt(i, m_model));
}
fmls.push_back(mk_or(gt));
fml = mk_and(fmls);
IF_VERBOSE(10, verbose_stream() << "dominates: " << fml << "\n";);
TRACE("opt", model_smt2_pp(tout << fml << "\n", m, *m_model, 0););
m_solver->assert_expr(fml);
}
void pareto_base::mk_not_dominated_by() {
unsigned sz = cb.num_objectives();
expr_ref fml(m);
expr_ref_vector le(m);
for (unsigned i = 0; i < sz; ++i) {
le.push_back(cb.mk_le(i, m_model));
}
fml = m.mk_not(mk_and(le));
IF_VERBOSE(10, verbose_stream() << "not dominated by: " << fml << "\n";);
TRACE("opt", tout << fml << "\n";);
m_solver->assert_expr(fml);
}
// ---------------------------------
// OIA algorithm (without filtering)
lbool oia_pareto::operator()() {
solver::scoped_push _s(*m_solver.get());
lbool is_sat = m_solver->check_sat(0, nullptr);
if (!m.inc()) {
is_sat = l_undef;
}
if (is_sat == l_true) {
m_solver->get_model(m_model);
m_solver->get_labels(m_labels);
m_model->set_model_completion(true);
mk_not_dominated_by();
}
return is_sat;
}
}