diff --git a/scripts/mk_project.py b/scripts/mk_project.py index 77bb1b680..534e597ef 100644 --- a/scripts/mk_project.py +++ b/scripts/mk_project.py @@ -40,6 +40,7 @@ def init_project_def(): add_lib('model', ['macros']) add_lib('converters', ['model'], 'ast/converters') 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('mbp', ['model', 'simplex'], 'qe/mbp') 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('fuzzing', ['ast'], 'test/fuzzing') 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('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') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a12571f35..4c09f31aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ add_subdirectory(ast/euf) add_subdirectory(ast/converters) add_subdirectory(ast/substitution) add_subdirectory(ast/simplifiers) +add_subdirectory(ast/sls) add_subdirectory(tactic) add_subdirectory(qe/mbp) add_subdirectory(qe/lite) diff --git a/src/tactic/sls/bvsls_opt_engine.cpp b/src/ast/sls/bvsls_opt_engine.cpp similarity index 99% rename from src/tactic/sls/bvsls_opt_engine.cpp rename to src/ast/sls/bvsls_opt_engine.cpp index 37454ca72..e4c96d735 100644 --- a/src/tactic/sls/bvsls_opt_engine.cpp +++ b/src/ast/sls/bvsls_opt_engine.cpp @@ -17,7 +17,7 @@ Notes: --*/ #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) : sls_engine(m, p), diff --git a/src/tactic/sls/bvsls_opt_engine.h b/src/ast/sls/bvsls_opt_engine.h similarity index 98% rename from src/tactic/sls/bvsls_opt_engine.h rename to src/ast/sls/bvsls_opt_engine.h index c6b3857af..435fa3af4 100644 --- a/src/tactic/sls/bvsls_opt_engine.h +++ b/src/ast/sls/bvsls_opt_engine.h @@ -18,7 +18,7 @@ Notes: --*/ #pragma once -#include "tactic/sls/sls_engine.h" +#include "ast/sls/sls_engine.h" class bvsls_opt_engine : public sls_engine { sls_tracker & m_hard_tracker; diff --git a/src/tactic/sls/sls_engine.cpp b/src/ast/sls/sls_engine.cpp similarity index 94% rename from src/tactic/sls/sls_engine.cpp rename to src/ast/sls/sls_engine.cpp index 58676edfb..8b4253747 100644 --- a/src/tactic/sls/sls_engine.cpp +++ b/src/ast/sls/sls_engine.cpp @@ -26,8 +26,8 @@ Notes: #include "tactic/tactic.h" #include "util/luby.h" -#include "tactic/sls/sls_params.hpp" -#include "tactic/sls/sls_engine.h" +#include "params/sls_params.hpp" +#include "ast/sls/sls_engine.h" 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) { sls_params p(_p); - m_produce_models = _p.get_bool("model", false); m_max_restarts = p.max_restarts(); m_tracker.set_random_seed(p.random_seed()); m_walksat = p.walksat(); @@ -523,38 +522,6 @@ bailout: 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()() { m_tracker.initialize(m_assertions); @@ -567,7 +534,7 @@ lbool sls_engine::operator()() { do { 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(); if (res == l_undef) diff --git a/src/tactic/sls/sls_engine.h b/src/ast/sls/sls_engine.h similarity index 92% rename from src/tactic/sls/sls_engine.h rename to src/ast/sls/sls_engine.h index 5f290c626..88ebb98b8 100644 --- a/src/tactic/sls/sls_engine.h +++ b/src/ast/sls/sls_engine.h @@ -21,10 +21,9 @@ Notes: #include "util/stopwatch.h" #include "util/lbool.h" #include "ast/converters/model_converter.h" -#include "tactic/goal.h" -#include "tactic/sls/sls_tracker.h" -#include "tactic/sls/sls_evaluator.h" +#include "ast/sls/sls_tracker.h" +#include "ast/sls/sls_evaluator.h" #include "util/statistics.h" class sls_engine { @@ -62,7 +61,6 @@ protected: unsynch_mpz_manager m_mpz_manager; powers m_powers; mpz m_zero, m_one, m_two; - bool m_produce_models; bv_util m_bv_util; sls_tracker m_tracker; sls_evaluator m_evaluator; @@ -96,7 +94,7 @@ public: 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 reset_statistics() { m_stats.reset(); } @@ -111,7 +109,12 @@ public: lbool search(); 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: void checkpoint(); @@ -135,5 +138,7 @@ protected: //double get_restart_armin(unsigned cnt_restarts); unsigned check_restart(unsigned curr_value); + + }; diff --git a/src/tactic/sls/sls_evaluator.h b/src/ast/sls/sls_evaluator.h similarity index 99% rename from src/tactic/sls/sls_evaluator.h rename to src/ast/sls/sls_evaluator.h index d386ece15..2ee03c928 100644 --- a/src/tactic/sls/sls_evaluator.h +++ b/src/ast/sls/sls_evaluator.h @@ -21,8 +21,8 @@ Notes: #include "model/model_evaluator.h" -#include "tactic/sls/sls_powers.h" -#include "tactic/sls/sls_tracker.h" +#include "ast/sls/sls_powers.h" +#include "ast/sls/sls_tracker.h" class sls_evaluator { ast_manager & m_manager; diff --git a/src/tactic/sls/sls_powers.h b/src/ast/sls/sls_powers.h similarity index 100% rename from src/tactic/sls/sls_powers.h rename to src/ast/sls/sls_powers.h diff --git a/src/tactic/sls/sls_tracker.h b/src/ast/sls/sls_tracker.h similarity index 99% rename from src/tactic/sls/sls_tracker.h rename to src/ast/sls/sls_tracker.h index 951153a5c..67723828f 100644 --- a/src/tactic/sls/sls_tracker.h +++ b/src/ast/sls/sls_tracker.h @@ -25,8 +25,8 @@ Notes: #include "ast/bv_decl_plugin.h" #include "model/model.h" -#include "tactic/sls/sls_params.hpp" -#include "tactic/sls/sls_powers.h" +#include "params/sls_params.hpp" +#include "ast/sls/sls_powers.h" class sls_tracker { ast_manager & m_manager; diff --git a/src/params/CMakeLists.txt b/src/params/CMakeLists.txt index cdc21da97..763702caf 100644 --- a/src/params/CMakeLists.txt +++ b/src/params/CMakeLists.txt @@ -15,6 +15,7 @@ z3_add_component(params poly_rewriter_params.pyg rewriter_params.pyg seq_rewriter_params.pyg + sls_params.pyg solver_params.pyg tactic_params.pyg EXTRA_REGISTER_MODULE_HEADERS diff --git a/src/tactic/sls/sls_params.pyg b/src/params/sls_params.pyg similarity index 100% rename from src/tactic/sls/sls_params.pyg rename to src/params/sls_params.pyg diff --git a/src/tactic/sls/CMakeLists.txt b/src/tactic/sls/CMakeLists.txt index 436b1742f..83599b827 100644 --- a/src/tactic/sls/CMakeLists.txt +++ b/src/tactic/sls/CMakeLists.txt @@ -1,15 +1,12 @@ z3_add_component(sls_tactic SOURCES - bvsls_opt_engine.cpp - sls_engine.cpp sls_tactic.cpp COMPONENT_DEPENDENCIES bv_tactics core_tactics normal_forms tactic - PYG_FILES - sls_params.pyg + ast_sls TACTIC_HEADERS sls_tactic.h ) diff --git a/src/tactic/sls/sls_tactic.cpp b/src/tactic/sls/sls_tactic.cpp index e631c23e9..6daadc83b 100644 --- a/src/tactic/sls/sls_tactic.cpp +++ b/src/tactic/sls/sls_tactic.cpp @@ -27,8 +27,8 @@ Notes: #include "tactic/core/nnf_tactic.h" #include "util/stopwatch.h" #include "tactic/sls/sls_tactic.h" -#include "tactic/sls/sls_params.hpp" -#include "tactic/sls/sls_engine.h" +#include "params/sls_params.hpp" +#include "ast/sls/sls_engine.h" class sls_tactic : public tactic { ast_manager & m; @@ -60,6 +60,38 @@ public: void collect_param_descrs(param_descrs & r) override { 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, goal_ref_buffer & result) override { @@ -69,7 +101,7 @@ public: tactic_report report("sls", *g); model_converter_ref mc; - m_engine->operator()(g, mc); + run(g, mc); g->add(mc.get()); g->inc_depth(); result.push_back(g.get());