mirror of
https://github.com/Z3Prover/z3
synced 2025-06-06 14:13:23 +00:00
fix memory smash
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
3757f337e5
commit
eb6d39ba46
6 changed files with 27 additions and 9 deletions
|
@ -92,12 +92,12 @@ namespace simplex {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const var_t null_var = UINT_MAX;
|
static const var_t null_var = UINT_MAX;
|
||||||
|
mutable manager m;
|
||||||
|
mutable eps_manager em;
|
||||||
mutable matrix M;
|
mutable matrix M;
|
||||||
unsigned m_max_iterations;
|
unsigned m_max_iterations;
|
||||||
volatile bool m_cancel;
|
volatile bool m_cancel;
|
||||||
var_heap m_to_patch;
|
var_heap m_to_patch;
|
||||||
mutable manager m;
|
|
||||||
mutable eps_manager em;
|
|
||||||
vector<var_info> m_vars;
|
vector<var_info> m_vars;
|
||||||
svector<var_t> m_row2base;
|
svector<var_t> m_row2base;
|
||||||
bool m_bland;
|
bool m_bland;
|
||||||
|
@ -110,6 +110,7 @@ namespace simplex {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
simplex():
|
simplex():
|
||||||
|
M(m),
|
||||||
m_max_iterations(UINT_MAX),
|
m_max_iterations(UINT_MAX),
|
||||||
m_cancel(false),
|
m_cancel(false),
|
||||||
m_to_patch(1024),
|
m_to_patch(1024),
|
||||||
|
|
|
@ -246,6 +246,9 @@ namespace simplex {
|
||||||
M.ensure_var(m_vars.size());
|
M.ensure_var(m_vars.size());
|
||||||
m_vars.push_back(var_info());
|
m_vars.push_back(var_info());
|
||||||
}
|
}
|
||||||
|
if (m_to_patch.get_bounds() <= v) {
|
||||||
|
m_to_patch.set_bounds(2*v+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ext>
|
template<typename Ext>
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace simplex {
|
||||||
void del_col_entry(unsigned idx);
|
void del_col_entry(unsigned idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
manager m;
|
manager& m;
|
||||||
vector<_row> m_rows;
|
vector<_row> m_rows;
|
||||||
svector<unsigned> m_dead_rows; // rows to recycle
|
svector<unsigned> m_dead_rows; // rows to recycle
|
||||||
vector<column> m_columns; // per var
|
vector<column> m_columns; // per var
|
||||||
|
@ -143,7 +143,7 @@ namespace simplex {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
sparse_matrix() {}
|
sparse_matrix(manager& m): m(m) {}
|
||||||
~sparse_matrix();
|
~sparse_matrix();
|
||||||
|
|
||||||
class row {
|
class row {
|
||||||
|
|
|
@ -29,6 +29,7 @@ Notes:
|
||||||
#include "pp_params.hpp"
|
#include "pp_params.hpp"
|
||||||
#include "opt_params.hpp"
|
#include "opt_params.hpp"
|
||||||
#include "model_smt2_pp.h"
|
#include "model_smt2_pp.h"
|
||||||
|
#include "stopwatch.h"
|
||||||
|
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
|
@ -113,14 +114,23 @@ namespace opt {
|
||||||
tout << mk_pp(m_context.get_formulas()[i], m_context.m()) << "\n";
|
tout << mk_pp(m_context.get_formulas()[i], m_context.m()) << "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
stopwatch w;
|
||||||
if (dump_benchmarks()) {
|
if (dump_benchmarks()) {
|
||||||
|
w.start();
|
||||||
std::stringstream file_name;
|
std::stringstream file_name;
|
||||||
file_name << "opt_solver" << ++m_dump_count << ".smt2";
|
file_name << "opt_solver" << ++m_dump_count << ".smt2";
|
||||||
std::ofstream buffer(file_name.str().c_str());
|
std::ofstream buffer(file_name.str().c_str());
|
||||||
to_smt2_benchmark(buffer, num_assumptions, assumptions, "opt_solver", "");
|
to_smt2_benchmark(buffer, num_assumptions, assumptions, "opt_solver", "");
|
||||||
buffer.close();
|
buffer.close();
|
||||||
|
IF_VERBOSE(1, verbose_stream() << "(created benchmark: " << file_name.str() << "...";
|
||||||
|
verbose_stream().flush(););
|
||||||
}
|
}
|
||||||
return m_context.check(num_assumptions, assumptions);
|
lbool r = m_context.check(num_assumptions, assumptions);
|
||||||
|
if (dump_benchmarks()) {
|
||||||
|
w.stop();
|
||||||
|
IF_VERBOSE(1, verbose_stream() << ".. " << r << " " << std::fixed << w.get_seconds() << ")\n";);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void opt_solver::maximize_objectives() {
|
void opt_solver::maximize_objectives() {
|
||||||
|
|
|
@ -518,6 +518,7 @@ namespace opt {
|
||||||
};
|
};
|
||||||
|
|
||||||
lbool incremental_solve() {
|
lbool incremental_solve() {
|
||||||
|
IF_VERBOSE(3, verbose_stream() << "(incremental solve)\n";);
|
||||||
TRACE("opt", tout << "weighted maxsat\n";);
|
TRACE("opt", tout << "weighted maxsat\n";);
|
||||||
scoped_ensure_theory wth(*this);
|
scoped_ensure_theory wth(*this);
|
||||||
solver::scoped_push _s(s);
|
solver::scoped_push _s(s);
|
||||||
|
@ -541,6 +542,7 @@ namespace opt {
|
||||||
s.assert_expr(fml);
|
s.assert_expr(fml);
|
||||||
was_sat = true;
|
was_sat = true;
|
||||||
}
|
}
|
||||||
|
IF_VERBOSE(3, verbose_stream() << "(incremental bound)\n";);
|
||||||
}
|
}
|
||||||
if (was_sat) {
|
if (was_sat) {
|
||||||
wth().get_assignment(m_assignment);
|
wth().get_assignment(m_assignment);
|
||||||
|
@ -605,6 +607,7 @@ namespace opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
lbool conditional_solve(expr* cond) {
|
lbool conditional_solve(expr* cond) {
|
||||||
|
IF_VERBOSE(3, verbose_stream() << "(conditional solve)\n";);
|
||||||
smt::theory_weighted_maxsat& wth = *get_theory();
|
smt::theory_weighted_maxsat& wth = *get_theory();
|
||||||
bool was_sat = false;
|
bool was_sat = false;
|
||||||
lbool is_sat = l_true;
|
lbool is_sat = l_true;
|
||||||
|
@ -1169,6 +1172,7 @@ namespace opt {
|
||||||
// cost becomes 0
|
// cost becomes 0
|
||||||
|
|
||||||
lbool bisection_solve() {
|
lbool bisection_solve() {
|
||||||
|
IF_VERBOSE(3, verbose_stream() << "(bisection solve)\n";);
|
||||||
TRACE("opt", tout << "weighted maxsat\n";);
|
TRACE("opt", tout << "weighted maxsat\n";);
|
||||||
scoped_ensure_theory wth(*this);
|
scoped_ensure_theory wth(*this);
|
||||||
solver::scoped_push _s(s);
|
solver::scoped_push _s(s);
|
||||||
|
|
|
@ -476,7 +476,7 @@ namespace smt {
|
||||||
ctx.mk_th_axiom(get_id(), lit, ~c->lit(i));
|
ctx.mk_th_axiom(get_id(), lit, ~c->lit(i));
|
||||||
}
|
}
|
||||||
ctx.mk_th_axiom(get_id(), lits.size(), lits.c_ptr());
|
ctx.mk_th_axiom(get_id(), lits.size(), lits.c_ptr());
|
||||||
return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// maximal coefficient:
|
// maximal coefficient:
|
||||||
|
@ -490,7 +490,7 @@ namespace smt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pre-compile threshold for cardinality
|
// pre-compile threshold for cardinality
|
||||||
bool enable_compile = m_enable_compilation && c->is_ge();
|
bool enable_compile = m_enable_compilation && c->is_ge() && !c->k().is_one();
|
||||||
for (unsigned i = 0; enable_compile && i < args.size(); ++i) {
|
for (unsigned i = 0; enable_compile && i < args.size(); ++i) {
|
||||||
enable_compile = (args[i].second <= m_max_compiled_coeff);
|
enable_compile = (args[i].second <= m_max_compiled_coeff);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue