Skip to content

Commit

Permalink
move sls core functionality to be independent of tactic
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Dec 22, 2023
1 parent 606a9a7 commit e321643
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 56 deletions.
3 changes: 2 additions & 1 deletion scripts/mk_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Module Name:
--*/
#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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Module Name:
--*/
#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;
Expand Down
39 changes: 3 additions & 36 deletions src/tactic/sls/sls_engine.cpp → src/ast/sls/sls_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Module Name:
#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) :
Expand All @@ -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();
Expand Down Expand Up @@ -523,38 +522,6 @@ lbool sls_engine::search() {
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);
Expand All @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions src/tactic/sls/sls_engine.h → src/ast/sls/sls_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Module Name:
#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 {
Expand Down Expand Up @@ -62,7 +61,6 @@ class sls_engine {
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;
Expand Down Expand Up @@ -96,7 +94,7 @@ class sls_engine {

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(); }

Expand All @@ -111,7 +109,12 @@ class sls_engine {
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();
Expand All @@ -135,5 +138,7 @@ class sls_engine {

//double get_restart_armin(unsigned cnt_restarts);
unsigned check_restart(unsigned curr_value);


};

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Module Name:

#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;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/tactic/sls/sls_tracker.h → src/ast/sls/sls_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Module Name:
#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;
Expand Down
1 change: 1 addition & 0 deletions src/params/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions src/tactic/sls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
38 changes: 35 additions & 3 deletions src/tactic/sls/sls_tactic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Module Name:
#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;
Expand Down Expand Up @@ -60,6 +60,38 @@ class sls_tactic : public tactic {
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 {
Expand All @@ -69,7 +101,7 @@ class sls_tactic : public tactic {
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());
Expand Down

0 comments on commit e321643

Please sign in to comment.