mirror of
https://github.com/Z3Prover/z3
synced 2025-06-27 08:28:44 +00:00
Add push/pop to box optimization
This commit is contained in:
parent
4aa9c742ab
commit
5ed8a48ac2
4 changed files with 29 additions and 9 deletions
|
@ -249,8 +249,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
static expr* sexpr2expr(cmd_context & ctx, sexpr * s) {
|
static expr* sexpr2expr(cmd_context & ctx, sexpr * s) {
|
||||||
NOT_IMPLEMENTED_YET();
|
NOT_IMPLEMENTED_YET();
|
||||||
return 0;
|
return ctx.m().mk_true();
|
||||||
}
|
}
|
||||||
|
|
||||||
static opt::objective* sexpr2objective(cmd_context & ctx, sexpr * s) {
|
static opt::objective* sexpr2objective(cmd_context & ctx, sexpr * s) {
|
||||||
|
|
|
@ -90,20 +90,24 @@ namespace opt {
|
||||||
|
|
||||||
lbool context::execute_lex(compound_objective & obj) {
|
lbool context::execute_lex(compound_objective & obj) {
|
||||||
ptr_vector<objective> children(obj.num_children(), obj.children());
|
ptr_vector<objective> children(obj.num_children(), obj.children());
|
||||||
|
lbool result = l_true;
|
||||||
for (unsigned i = 0; i < children.size(); ++i) {
|
for (unsigned i = 0; i < children.size(); ++i) {
|
||||||
lbool result = execute(*children[i], true);
|
result = execute(*children[i], true);
|
||||||
if (result != l_true) return result;
|
if (result != l_true) break;
|
||||||
}
|
}
|
||||||
return l_true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool context::execute_box(compound_objective & obj) {
|
lbool context::execute_box(compound_objective & obj) {
|
||||||
ptr_vector<objective> children(obj.num_children(), obj.children());
|
ptr_vector<objective> children(obj.num_children(), obj.children());
|
||||||
|
lbool result = l_true;
|
||||||
for (unsigned i = 0; i < children.size(); ++i) {
|
for (unsigned i = 0; i < children.size(); ++i) {
|
||||||
lbool result = execute(*children[i], false);
|
push();
|
||||||
if (result != l_true) return result;
|
result = execute(*children[i], false);
|
||||||
|
pop(1);
|
||||||
|
if (result != l_true) break;
|
||||||
}
|
}
|
||||||
return l_true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool context::execute_pareto(compound_objective & obj) {
|
lbool context::execute_pareto(compound_objective & obj) {
|
||||||
|
@ -111,6 +115,16 @@ namespace opt {
|
||||||
return execute_lex(obj);
|
return execute_lex(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void context::push() {
|
||||||
|
opt_solver& s = *m_solver.get();
|
||||||
|
s.push();
|
||||||
|
}
|
||||||
|
|
||||||
|
void context::pop(unsigned sz) {
|
||||||
|
opt_solver& s = *m_solver.get();
|
||||||
|
s.pop(sz);
|
||||||
|
}
|
||||||
|
|
||||||
lbool context::optimize(objective & objective) {
|
lbool context::optimize(objective & objective) {
|
||||||
opt_solver& s = *m_solver.get();
|
opt_solver& s = *m_solver.get();
|
||||||
solver::scoped_push _sp(s);
|
solver::scoped_push _sp(s);
|
||||||
|
|
|
@ -59,6 +59,9 @@ namespace opt {
|
||||||
lbool execute_box(compound_objective & obj);
|
lbool execute_box(compound_objective & obj);
|
||||||
lbool execute_pareto(compound_objective & obj);
|
lbool execute_pareto(compound_objective & obj);
|
||||||
|
|
||||||
|
void push();
|
||||||
|
void pop(unsigned sz);
|
||||||
|
|
||||||
lbool optimize(objective & objective);
|
lbool optimize(objective & objective);
|
||||||
lbool optimize();
|
lbool optimize();
|
||||||
|
|
||||||
|
|
|
@ -1028,6 +1028,7 @@ inf_eps_rational<inf_rational> theory_diff_logic<Ext>::maximize(theory_var v) {
|
||||||
|
|
||||||
network_flow<GExt> net_flow(m_graph, balances);
|
network_flow<GExt> net_flow(m_graph, balances);
|
||||||
min_flow_result result = net_flow.min_cost();
|
min_flow_result result = net_flow.min_cost();
|
||||||
|
SASSERT(result != UNBOUNDED);
|
||||||
if (result == OPTIMAL) {
|
if (result == OPTIMAL) {
|
||||||
numeral objective_value = net_flow.get_optimal_solution(m_objective_assignments[v], true) + numeral(m_objective_consts[v]);
|
numeral objective_value = net_flow.get_optimal_solution(m_objective_assignments[v], true) + numeral(m_objective_consts[v]);
|
||||||
IF_VERBOSE(1, verbose_stream() << "Optimal value of objective " << v << ": " << objective_value << std::endl;);
|
IF_VERBOSE(1, verbose_stream() << "Optimal value of objective " << v << ": " << objective_value << std::endl;);
|
||||||
|
@ -1059,6 +1060,8 @@ inf_eps_rational<inf_rational> theory_diff_logic<Ext>::maximize(theory_var v) {
|
||||||
return inf_eps_rational<inf_rational>(inf_rational(r, i));
|
return inf_eps_rational<inf_rational>(inf_rational(r, i));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Dual problem is infeasible, primal problem is unbounded
|
||||||
|
SASSERT(result == INFEASIBLE);
|
||||||
IF_VERBOSE(1, verbose_stream() << "Unbounded objective" << std::endl;);
|
IF_VERBOSE(1, verbose_stream() << "Unbounded objective" << std::endl;);
|
||||||
return inf_eps_rational<inf_rational>::infinity();
|
return inf_eps_rational<inf_rational>::infinity();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue