mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 01:25:31 +00:00
Expose objective indices to .NET API
This commit is contained in:
parent
5fc429c501
commit
d38e2b9b78
5 changed files with 90 additions and 44 deletions
|
@ -42,21 +42,25 @@ namespace opt {
|
|||
}
|
||||
}
|
||||
|
||||
void context::add_soft_constraint(expr* f, rational const& w, symbol const& id) {
|
||||
unsigned context::add_soft_constraint(expr* f, rational const& w, symbol const& id) {
|
||||
maxsmt* ms;
|
||||
if (!m_maxsmts.find(id, ms)) {
|
||||
ms = alloc(maxsmt, m);
|
||||
m_maxsmts.insert(id, ms);
|
||||
m_objectives.push_back(objective(m, id));
|
||||
m_indices.insert(id, m_objectives.size() - 1);
|
||||
}
|
||||
ms->add(f, w);
|
||||
ms->add(f, w);
|
||||
SASSERT(m_indices.contains(id));
|
||||
return m_indices[id];
|
||||
}
|
||||
|
||||
void context::add_objective(app* t, bool is_max) {
|
||||
unsigned context::add_objective(app* t, bool is_max) {
|
||||
app_ref tr(t, m);
|
||||
unsigned index = m_optsmt.get_num_objectives();
|
||||
m_optsmt.add(t, is_max);
|
||||
m_objectives.push_back(objective(is_max, tr, index));
|
||||
return index;
|
||||
}
|
||||
|
||||
lbool context::optimize() {
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace opt {
|
|||
|
||||
class context {
|
||||
typedef map<symbol, maxsmt*, symbol_hash_proc, symbol_eq_proc> map_t;
|
||||
typedef map<symbol, unsigned, symbol_hash_proc, symbol_eq_proc> map_id;
|
||||
enum objective_t {
|
||||
O_MAXIMIZE,
|
||||
O_MINIMIZE,
|
||||
|
@ -65,13 +66,14 @@ namespace opt {
|
|||
params_ref m_params;
|
||||
optsmt m_optsmt;
|
||||
map_t m_maxsmts;
|
||||
map_id m_indices;
|
||||
vector<objective> m_objectives;
|
||||
model_ref m_model;
|
||||
public:
|
||||
context(ast_manager& m);
|
||||
~context();
|
||||
void add_soft_constraint(expr* f, rational const& w, symbol const& id);
|
||||
void add_objective(app* t, bool is_max);
|
||||
unsigned add_soft_constraint(expr* f, rational const& w, symbol const& id);
|
||||
unsigned add_objective(app* t, bool is_max);
|
||||
void add_hard_constraint(expr* f) { m_hard_constraints.push_back(f); }
|
||||
|
||||
lbool optimize();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue