mirror of
https://github.com/Z3Prover/z3
synced 2025-04-06 17:44:08 +00:00
move sls core functionality to be independent of tactic
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
606a9a7409
commit
e321643bf5
|
@ -40,6 +40,7 @@ def init_project_def():
|
||||||
add_lib('model', ['macros'])
|
add_lib('model', ['macros'])
|
||||||
add_lib('converters', ['model'], 'ast/converters')
|
add_lib('converters', ['model'], 'ast/converters')
|
||||||
add_lib('simplifiers', ['euf', 'normal_forms', 'bit_blaster', 'converters', 'substitution'], 'ast/simplifiers')
|
add_lib('simplifiers', ['euf', 'normal_forms', 'bit_blaster', 'converters', 'substitution'], 'ast/simplifiers')
|
||||||
|
add_lib('ast_sls', ['ast'], 'ast/sls')
|
||||||
add_lib('tactic', ['simplifiers'])
|
add_lib('tactic', ['simplifiers'])
|
||||||
add_lib('mbp', ['model', 'simplex'], 'qe/mbp')
|
add_lib('mbp', ['model', 'simplex'], 'qe/mbp')
|
||||||
add_lib('qe_lite', ['tactic', 'mbp'], 'qe/lite')
|
add_lib('qe_lite', ['tactic', 'mbp'], 'qe/lite')
|
||||||
|
@ -64,7 +65,7 @@ def init_project_def():
|
||||||
add_lib('bv_tactics', ['tactic', 'bit_blaster', 'core_tactics'], 'tactic/bv')
|
add_lib('bv_tactics', ['tactic', 'bit_blaster', 'core_tactics'], 'tactic/bv')
|
||||||
add_lib('fuzzing', ['ast'], 'test/fuzzing')
|
add_lib('fuzzing', ['ast'], 'test/fuzzing')
|
||||||
add_lib('smt_tactic', ['smt'], 'smt/tactic')
|
add_lib('smt_tactic', ['smt'], 'smt/tactic')
|
||||||
add_lib('sls_tactic', ['tactic', 'normal_forms', 'core_tactics', 'bv_tactics'], 'tactic/sls')
|
add_lib('sls_tactic', ['tactic', 'normal_forms', 'core_tactics', 'bv_tactics', 'ast_sls'], 'tactic/sls')
|
||||||
add_lib('qe', ['smt', 'mbp', 'qe_lite', 'nlsat', 'tactic', 'nlsat_tactic'], 'qe')
|
add_lib('qe', ['smt', 'mbp', 'qe_lite', 'nlsat', 'tactic', 'nlsat_tactic'], 'qe')
|
||||||
add_lib('sat_solver', ['solver', 'core_tactics', 'aig_tactic', 'bv_tactics', 'arith_tactics', 'sat_tactic'], 'sat/sat_solver')
|
add_lib('sat_solver', ['solver', 'core_tactics', 'aig_tactic', 'bv_tactics', 'arith_tactics', 'sat_tactic'], 'sat/sat_solver')
|
||||||
add_lib('fd_solver', ['core_tactics', 'arith_tactics', 'sat_solver', 'smt'], 'tactic/fd_solver')
|
add_lib('fd_solver', ['core_tactics', 'arith_tactics', 'sat_solver', 'smt'], 'tactic/fd_solver')
|
||||||
|
|
|
@ -54,6 +54,7 @@ add_subdirectory(ast/euf)
|
||||||
add_subdirectory(ast/converters)
|
add_subdirectory(ast/converters)
|
||||||
add_subdirectory(ast/substitution)
|
add_subdirectory(ast/substitution)
|
||||||
add_subdirectory(ast/simplifiers)
|
add_subdirectory(ast/simplifiers)
|
||||||
|
add_subdirectory(ast/sls)
|
||||||
add_subdirectory(tactic)
|
add_subdirectory(tactic)
|
||||||
add_subdirectory(qe/mbp)
|
add_subdirectory(qe/mbp)
|
||||||
add_subdirectory(qe/lite)
|
add_subdirectory(qe/lite)
|
||||||
|
|
|
@ -17,7 +17,7 @@ Notes:
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
#include "ast/normal_forms/nnf.h"
|
#include "ast/normal_forms/nnf.h"
|
||||||
#include "tactic/sls/bvsls_opt_engine.h"
|
#include "ast/sls/bvsls_opt_engine.h"
|
||||||
|
|
||||||
bvsls_opt_engine::bvsls_opt_engine(ast_manager & m, params_ref const & p) :
|
bvsls_opt_engine::bvsls_opt_engine(ast_manager & m, params_ref const & p) :
|
||||||
sls_engine(m, p),
|
sls_engine(m, p),
|
|
@ -18,7 +18,7 @@ Notes:
|
||||||
--*/
|
--*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "tactic/sls/sls_engine.h"
|
#include "ast/sls/sls_engine.h"
|
||||||
|
|
||||||
class bvsls_opt_engine : public sls_engine {
|
class bvsls_opt_engine : public sls_engine {
|
||||||
sls_tracker & m_hard_tracker;
|
sls_tracker & m_hard_tracker;
|
|
@ -26,8 +26,8 @@ Notes:
|
||||||
#include "tactic/tactic.h"
|
#include "tactic/tactic.h"
|
||||||
#include "util/luby.h"
|
#include "util/luby.h"
|
||||||
|
|
||||||
#include "tactic/sls/sls_params.hpp"
|
#include "params/sls_params.hpp"
|
||||||
#include "tactic/sls/sls_engine.h"
|
#include "ast/sls/sls_engine.h"
|
||||||
|
|
||||||
|
|
||||||
sls_engine::sls_engine(ast_manager & m, params_ref const & p) :
|
sls_engine::sls_engine(ast_manager & m, params_ref const & p) :
|
||||||
|
@ -52,7 +52,6 @@ sls_engine::~sls_engine() {
|
||||||
|
|
||||||
void sls_engine::updt_params(params_ref const & _p) {
|
void sls_engine::updt_params(params_ref const & _p) {
|
||||||
sls_params p(_p);
|
sls_params p(_p);
|
||||||
m_produce_models = _p.get_bool("model", false);
|
|
||||||
m_max_restarts = p.max_restarts();
|
m_max_restarts = p.max_restarts();
|
||||||
m_tracker.set_random_seed(p.random_seed());
|
m_tracker.set_random_seed(p.random_seed());
|
||||||
m_walksat = p.walksat();
|
m_walksat = p.walksat();
|
||||||
|
@ -523,38 +522,6 @@ bailout:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sls_engine::operator()(goal_ref const & g, model_converter_ref & mc) {
|
|
||||||
if (g->inconsistent()) {
|
|
||||||
mc = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_produce_models = g->models_enabled();
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < g->size(); i++)
|
|
||||||
assert_expr(g->form(i));
|
|
||||||
|
|
||||||
lbool res = operator()();
|
|
||||||
|
|
||||||
if (res == l_true) {
|
|
||||||
report_tactic_progress("Number of flips:", m_stats.m_moves);
|
|
||||||
for (unsigned i = 0; i < g->size(); i++)
|
|
||||||
if (!m_mpz_manager.is_one(m_tracker.get_value(g->form(i))))
|
|
||||||
{
|
|
||||||
verbose_stream() << "Terminated before all assertions were SAT!" << std::endl;
|
|
||||||
NOT_IMPLEMENTED_YET();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_produce_models) {
|
|
||||||
model_ref mdl = m_tracker.get_model();
|
|
||||||
mc = model2model_converter(mdl.get());
|
|
||||||
TRACE("sls_model", mc->display(tout););
|
|
||||||
}
|
|
||||||
g->reset();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mc = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
lbool sls_engine::operator()() {
|
lbool sls_engine::operator()() {
|
||||||
m_tracker.initialize(m_assertions);
|
m_tracker.initialize(m_assertions);
|
||||||
|
@ -567,7 +534,7 @@ lbool sls_engine::operator()() {
|
||||||
do {
|
do {
|
||||||
checkpoint();
|
checkpoint();
|
||||||
|
|
||||||
report_tactic_progress("Searching... restarts left:", m_max_restarts - m_stats.m_restarts);
|
// report_tactic_progress("Searching... restarts left:", m_max_restarts - m_stats.m_restarts);
|
||||||
res = search();
|
res = search();
|
||||||
|
|
||||||
if (res == l_undef)
|
if (res == l_undef)
|
|
@ -21,10 +21,9 @@ Notes:
|
||||||
#include "util/stopwatch.h"
|
#include "util/stopwatch.h"
|
||||||
#include "util/lbool.h"
|
#include "util/lbool.h"
|
||||||
#include "ast/converters/model_converter.h"
|
#include "ast/converters/model_converter.h"
|
||||||
#include "tactic/goal.h"
|
|
||||||
|
|
||||||
#include "tactic/sls/sls_tracker.h"
|
#include "ast/sls/sls_tracker.h"
|
||||||
#include "tactic/sls/sls_evaluator.h"
|
#include "ast/sls/sls_evaluator.h"
|
||||||
#include "util/statistics.h"
|
#include "util/statistics.h"
|
||||||
|
|
||||||
class sls_engine {
|
class sls_engine {
|
||||||
|
@ -62,7 +61,6 @@ protected:
|
||||||
unsynch_mpz_manager m_mpz_manager;
|
unsynch_mpz_manager m_mpz_manager;
|
||||||
powers m_powers;
|
powers m_powers;
|
||||||
mpz m_zero, m_one, m_two;
|
mpz m_zero, m_one, m_two;
|
||||||
bool m_produce_models;
|
|
||||||
bv_util m_bv_util;
|
bv_util m_bv_util;
|
||||||
sls_tracker m_tracker;
|
sls_tracker m_tracker;
|
||||||
sls_evaluator m_evaluator;
|
sls_evaluator m_evaluator;
|
||||||
|
@ -96,7 +94,7 @@ public:
|
||||||
|
|
||||||
void assert_expr(expr * e) { m_assertions.push_back(e); }
|
void assert_expr(expr * e) { m_assertions.push_back(e); }
|
||||||
|
|
||||||
// stats const & get_stats(void) { return m_stats; }
|
stats const & get_stats(void) { return m_stats; }
|
||||||
void collect_statistics(statistics & st) const;
|
void collect_statistics(statistics & st) const;
|
||||||
void reset_statistics() { m_stats.reset(); }
|
void reset_statistics() { m_stats.reset(); }
|
||||||
|
|
||||||
|
@ -111,7 +109,12 @@ public:
|
||||||
lbool search();
|
lbool search();
|
||||||
|
|
||||||
lbool operator()();
|
lbool operator()();
|
||||||
void operator()(goal_ref const & g, model_converter_ref & mc);
|
|
||||||
|
mpz & get_value(expr * n) { return m_tracker.get_value(n); }
|
||||||
|
|
||||||
|
model_ref get_model() { return m_tracker.get_model(); }
|
||||||
|
|
||||||
|
unsynch_mpz_manager& get_mpz_manager() { return m_mpz_manager; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void checkpoint();
|
void checkpoint();
|
||||||
|
@ -135,5 +138,7 @@ protected:
|
||||||
|
|
||||||
//double get_restart_armin(unsigned cnt_restarts);
|
//double get_restart_armin(unsigned cnt_restarts);
|
||||||
unsigned check_restart(unsigned curr_value);
|
unsigned check_restart(unsigned curr_value);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,8 +21,8 @@ Notes:
|
||||||
|
|
||||||
#include "model/model_evaluator.h"
|
#include "model/model_evaluator.h"
|
||||||
|
|
||||||
#include "tactic/sls/sls_powers.h"
|
#include "ast/sls/sls_powers.h"
|
||||||
#include "tactic/sls/sls_tracker.h"
|
#include "ast/sls/sls_tracker.h"
|
||||||
|
|
||||||
class sls_evaluator {
|
class sls_evaluator {
|
||||||
ast_manager & m_manager;
|
ast_manager & m_manager;
|
|
@ -25,8 +25,8 @@ Notes:
|
||||||
#include "ast/bv_decl_plugin.h"
|
#include "ast/bv_decl_plugin.h"
|
||||||
#include "model/model.h"
|
#include "model/model.h"
|
||||||
|
|
||||||
#include "tactic/sls/sls_params.hpp"
|
#include "params/sls_params.hpp"
|
||||||
#include "tactic/sls/sls_powers.h"
|
#include "ast/sls/sls_powers.h"
|
||||||
|
|
||||||
class sls_tracker {
|
class sls_tracker {
|
||||||
ast_manager & m_manager;
|
ast_manager & m_manager;
|
|
@ -15,6 +15,7 @@ z3_add_component(params
|
||||||
poly_rewriter_params.pyg
|
poly_rewriter_params.pyg
|
||||||
rewriter_params.pyg
|
rewriter_params.pyg
|
||||||
seq_rewriter_params.pyg
|
seq_rewriter_params.pyg
|
||||||
|
sls_params.pyg
|
||||||
solver_params.pyg
|
solver_params.pyg
|
||||||
tactic_params.pyg
|
tactic_params.pyg
|
||||||
EXTRA_REGISTER_MODULE_HEADERS
|
EXTRA_REGISTER_MODULE_HEADERS
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
z3_add_component(sls_tactic
|
z3_add_component(sls_tactic
|
||||||
SOURCES
|
SOURCES
|
||||||
bvsls_opt_engine.cpp
|
|
||||||
sls_engine.cpp
|
|
||||||
sls_tactic.cpp
|
sls_tactic.cpp
|
||||||
COMPONENT_DEPENDENCIES
|
COMPONENT_DEPENDENCIES
|
||||||
bv_tactics
|
bv_tactics
|
||||||
core_tactics
|
core_tactics
|
||||||
normal_forms
|
normal_forms
|
||||||
tactic
|
tactic
|
||||||
PYG_FILES
|
ast_sls
|
||||||
sls_params.pyg
|
|
||||||
TACTIC_HEADERS
|
TACTIC_HEADERS
|
||||||
sls_tactic.h
|
sls_tactic.h
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,8 +27,8 @@ Notes:
|
||||||
#include "tactic/core/nnf_tactic.h"
|
#include "tactic/core/nnf_tactic.h"
|
||||||
#include "util/stopwatch.h"
|
#include "util/stopwatch.h"
|
||||||
#include "tactic/sls/sls_tactic.h"
|
#include "tactic/sls/sls_tactic.h"
|
||||||
#include "tactic/sls/sls_params.hpp"
|
#include "params/sls_params.hpp"
|
||||||
#include "tactic/sls/sls_engine.h"
|
#include "ast/sls/sls_engine.h"
|
||||||
|
|
||||||
class sls_tactic : public tactic {
|
class sls_tactic : public tactic {
|
||||||
ast_manager & m;
|
ast_manager & m;
|
||||||
|
@ -61,6 +61,38 @@ public:
|
||||||
sls_params::collect_param_descrs(r);
|
sls_params::collect_param_descrs(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run(goal_ref const& g, model_converter_ref& mc) {
|
||||||
|
if (g->inconsistent()) {
|
||||||
|
mc = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < g->size(); i++)
|
||||||
|
m_engine->assert_expr(g->form(i));
|
||||||
|
|
||||||
|
lbool res = m_engine->operator()();
|
||||||
|
auto const& stats = m_engine->get_stats();
|
||||||
|
if (res == l_true) {
|
||||||
|
report_tactic_progress("Number of flips:", stats.m_moves);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < g->size(); i++)
|
||||||
|
if (!m_engine->get_mpz_manager().is_one(m_engine->get_value(g->form(i)))) {
|
||||||
|
verbose_stream() << "Terminated before all assertions were SAT!" << std::endl;
|
||||||
|
NOT_IMPLEMENTED_YET();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g->models_enabled()) {
|
||||||
|
model_ref mdl = m_engine->get_model();
|
||||||
|
mc = model2model_converter(mdl.get());
|
||||||
|
TRACE("sls_model", mc->display(tout););
|
||||||
|
}
|
||||||
|
g->reset();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mc = nullptr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void operator()(goal_ref const & g,
|
void operator()(goal_ref const & g,
|
||||||
goal_ref_buffer & result) override {
|
goal_ref_buffer & result) override {
|
||||||
result.reset();
|
result.reset();
|
||||||
|
@ -69,7 +101,7 @@ public:
|
||||||
tactic_report report("sls", *g);
|
tactic_report report("sls", *g);
|
||||||
|
|
||||||
model_converter_ref mc;
|
model_converter_ref mc;
|
||||||
m_engine->operator()(g, mc);
|
run(g, mc);
|
||||||
g->add(mc.get());
|
g->add(mc.get());
|
||||||
g->inc_depth();
|
g->inc_depth();
|
||||||
result.push_back(g.get());
|
result.push_back(g.get());
|
||||||
|
|
Loading…
Reference in a new issue