Skip to content

Commit e321643

Browse files
move sls core functionality to be independent of tactic
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
1 parent 606a9a7 commit e321643

13 files changed

+60
-56
lines changed

scripts/mk_project.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def init_project_def():
4040
add_lib('model', ['macros'])
4141
add_lib('converters', ['model'], 'ast/converters')
4242
add_lib('simplifiers', ['euf', 'normal_forms', 'bit_blaster', 'converters', 'substitution'], 'ast/simplifiers')
43+
add_lib('ast_sls', ['ast'], 'ast/sls')
4344
add_lib('tactic', ['simplifiers'])
4445
add_lib('mbp', ['model', 'simplex'], 'qe/mbp')
4546
add_lib('qe_lite', ['tactic', 'mbp'], 'qe/lite')
@@ -64,7 +65,7 @@ def init_project_def():
6465
add_lib('bv_tactics', ['tactic', 'bit_blaster', 'core_tactics'], 'tactic/bv')
6566
add_lib('fuzzing', ['ast'], 'test/fuzzing')
6667
add_lib('smt_tactic', ['smt'], 'smt/tactic')
67-
add_lib('sls_tactic', ['tactic', 'normal_forms', 'core_tactics', 'bv_tactics'], 'tactic/sls')
68+
add_lib('sls_tactic', ['tactic', 'normal_forms', 'core_tactics', 'bv_tactics', 'ast_sls'], 'tactic/sls')
6869
add_lib('qe', ['smt', 'mbp', 'qe_lite', 'nlsat', 'tactic', 'nlsat_tactic'], 'qe')
6970
add_lib('sat_solver', ['solver', 'core_tactics', 'aig_tactic', 'bv_tactics', 'arith_tactics', 'sat_tactic'], 'sat/sat_solver')
7071
add_lib('fd_solver', ['core_tactics', 'arith_tactics', 'sat_solver', 'smt'], 'tactic/fd_solver')

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ add_subdirectory(ast/euf)
5454
add_subdirectory(ast/converters)
5555
add_subdirectory(ast/substitution)
5656
add_subdirectory(ast/simplifiers)
57+
add_subdirectory(ast/sls)
5758
add_subdirectory(tactic)
5859
add_subdirectory(qe/mbp)
5960
add_subdirectory(qe/lite)

src/tactic/sls/bvsls_opt_engine.cpp renamed to src/ast/sls/bvsls_opt_engine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Module Name:
1717
1818
--*/
1919
#include "ast/normal_forms/nnf.h"
20-
#include "tactic/sls/bvsls_opt_engine.h"
20+
#include "ast/sls/bvsls_opt_engine.h"
2121

2222
bvsls_opt_engine::bvsls_opt_engine(ast_manager & m, params_ref const & p) :
2323
sls_engine(m, p),

src/tactic/sls/bvsls_opt_engine.h renamed to src/ast/sls/bvsls_opt_engine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Module Name:
1818
--*/
1919
#pragma once
2020

21-
#include "tactic/sls/sls_engine.h"
21+
#include "ast/sls/sls_engine.h"
2222

2323
class bvsls_opt_engine : public sls_engine {
2424
sls_tracker & m_hard_tracker;

src/tactic/sls/sls_engine.cpp renamed to src/ast/sls/sls_engine.cpp

+3-36
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Module Name:
2626
#include "tactic/tactic.h"
2727
#include "util/luby.h"
2828

29-
#include "tactic/sls/sls_params.hpp"
30-
#include "tactic/sls/sls_engine.h"
29+
#include "params/sls_params.hpp"
30+
#include "ast/sls/sls_engine.h"
3131

3232

3333
sls_engine::sls_engine(ast_manager & m, params_ref const & p) :
@@ -52,7 +52,6 @@ sls_engine::~sls_engine() {
5252

5353
void sls_engine::updt_params(params_ref const & _p) {
5454
sls_params p(_p);
55-
m_produce_models = _p.get_bool("model", false);
5655
m_max_restarts = p.max_restarts();
5756
m_tracker.set_random_seed(p.random_seed());
5857
m_walksat = p.walksat();
@@ -523,38 +522,6 @@ lbool sls_engine::search() {
523522
return res;
524523
}
525524

526-
void sls_engine::operator()(goal_ref const & g, model_converter_ref & mc) {
527-
if (g->inconsistent()) {
528-
mc = nullptr;
529-
return;
530-
}
531-
532-
m_produce_models = g->models_enabled();
533-
534-
for (unsigned i = 0; i < g->size(); i++)
535-
assert_expr(g->form(i));
536-
537-
lbool res = operator()();
538-
539-
if (res == l_true) {
540-
report_tactic_progress("Number of flips:", m_stats.m_moves);
541-
for (unsigned i = 0; i < g->size(); i++)
542-
if (!m_mpz_manager.is_one(m_tracker.get_value(g->form(i))))
543-
{
544-
verbose_stream() << "Terminated before all assertions were SAT!" << std::endl;
545-
NOT_IMPLEMENTED_YET();
546-
}
547-
548-
if (m_produce_models) {
549-
model_ref mdl = m_tracker.get_model();
550-
mc = model2model_converter(mdl.get());
551-
TRACE("sls_model", mc->display(tout););
552-
}
553-
g->reset();
554-
}
555-
else
556-
mc = nullptr;
557-
}
558525

559526
lbool sls_engine::operator()() {
560527
m_tracker.initialize(m_assertions);
@@ -567,7 +534,7 @@ lbool sls_engine::operator()() {
567534
do {
568535
checkpoint();
569536

570-
report_tactic_progress("Searching... restarts left:", m_max_restarts - m_stats.m_restarts);
537+
// report_tactic_progress("Searching... restarts left:", m_max_restarts - m_stats.m_restarts);
571538
res = search();
572539

573540
if (res == l_undef)

src/tactic/sls/sls_engine.h renamed to src/ast/sls/sls_engine.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ Module Name:
2121
#include "util/stopwatch.h"
2222
#include "util/lbool.h"
2323
#include "ast/converters/model_converter.h"
24-
#include "tactic/goal.h"
2524

26-
#include "tactic/sls/sls_tracker.h"
27-
#include "tactic/sls/sls_evaluator.h"
25+
#include "ast/sls/sls_tracker.h"
26+
#include "ast/sls/sls_evaluator.h"
2827
#include "util/statistics.h"
2928

3029
class sls_engine {
@@ -62,7 +61,6 @@ class sls_engine {
6261
unsynch_mpz_manager m_mpz_manager;
6362
powers m_powers;
6463
mpz m_zero, m_one, m_two;
65-
bool m_produce_models;
6664
bv_util m_bv_util;
6765
sls_tracker m_tracker;
6866
sls_evaluator m_evaluator;
@@ -96,7 +94,7 @@ class sls_engine {
9694

9795
void assert_expr(expr * e) { m_assertions.push_back(e); }
9896

99-
// stats const & get_stats(void) { return m_stats; }
97+
stats const & get_stats(void) { return m_stats; }
10098
void collect_statistics(statistics & st) const;
10199
void reset_statistics() { m_stats.reset(); }
102100

@@ -111,7 +109,12 @@ class sls_engine {
111109
lbool search();
112110

113111
lbool operator()();
114-
void operator()(goal_ref const & g, model_converter_ref & mc);
112+
113+
mpz & get_value(expr * n) { return m_tracker.get_value(n); }
114+
115+
model_ref get_model() { return m_tracker.get_model(); }
116+
117+
unsynch_mpz_manager& get_mpz_manager() { return m_mpz_manager; }
115118

116119
protected:
117120
void checkpoint();
@@ -135,5 +138,7 @@ class sls_engine {
135138

136139
//double get_restart_armin(unsigned cnt_restarts);
137140
unsigned check_restart(unsigned curr_value);
141+
142+
138143
};
139144

src/tactic/sls/sls_evaluator.h renamed to src/ast/sls/sls_evaluator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Module Name:
2121

2222
#include "model/model_evaluator.h"
2323

24-
#include "tactic/sls/sls_powers.h"
25-
#include "tactic/sls/sls_tracker.h"
24+
#include "ast/sls/sls_powers.h"
25+
#include "ast/sls/sls_tracker.h"
2626

2727
class sls_evaluator {
2828
ast_manager & m_manager;
File renamed without changes.

src/tactic/sls/sls_tracker.h renamed to src/ast/sls/sls_tracker.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Module Name:
2525
#include "ast/bv_decl_plugin.h"
2626
#include "model/model.h"
2727

28-
#include "tactic/sls/sls_params.hpp"
29-
#include "tactic/sls/sls_powers.h"
28+
#include "params/sls_params.hpp"
29+
#include "ast/sls/sls_powers.h"
3030

3131
class sls_tracker {
3232
ast_manager & m_manager;

src/params/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ z3_add_component(params
1515
poly_rewriter_params.pyg
1616
rewriter_params.pyg
1717
seq_rewriter_params.pyg
18+
sls_params.pyg
1819
solver_params.pyg
1920
tactic_params.pyg
2021
EXTRA_REGISTER_MODULE_HEADERS
File renamed without changes.

src/tactic/sls/CMakeLists.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
z3_add_component(sls_tactic
22
SOURCES
3-
bvsls_opt_engine.cpp
4-
sls_engine.cpp
53
sls_tactic.cpp
64
COMPONENT_DEPENDENCIES
75
bv_tactics
86
core_tactics
97
normal_forms
108
tactic
11-
PYG_FILES
12-
sls_params.pyg
9+
ast_sls
1310
TACTIC_HEADERS
1411
sls_tactic.h
1512
)

src/tactic/sls/sls_tactic.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Module Name:
2727
#include "tactic/core/nnf_tactic.h"
2828
#include "util/stopwatch.h"
2929
#include "tactic/sls/sls_tactic.h"
30-
#include "tactic/sls/sls_params.hpp"
31-
#include "tactic/sls/sls_engine.h"
30+
#include "params/sls_params.hpp"
31+
#include "ast/sls/sls_engine.h"
3232

3333
class sls_tactic : public tactic {
3434
ast_manager & m;
@@ -60,6 +60,38 @@ class sls_tactic : public tactic {
6060
void collect_param_descrs(param_descrs & r) override {
6161
sls_params::collect_param_descrs(r);
6262
}
63+
64+
void run(goal_ref const& g, model_converter_ref& mc) {
65+
if (g->inconsistent()) {
66+
mc = nullptr;
67+
return;
68+
}
69+
70+
for (unsigned i = 0; i < g->size(); i++)
71+
m_engine->assert_expr(g->form(i));
72+
73+
lbool res = m_engine->operator()();
74+
auto const& stats = m_engine->get_stats();
75+
if (res == l_true) {
76+
report_tactic_progress("Number of flips:", stats.m_moves);
77+
78+
for (unsigned i = 0; i < g->size(); i++)
79+
if (!m_engine->get_mpz_manager().is_one(m_engine->get_value(g->form(i)))) {
80+
verbose_stream() << "Terminated before all assertions were SAT!" << std::endl;
81+
NOT_IMPLEMENTED_YET();
82+
}
83+
84+
if (g->models_enabled()) {
85+
model_ref mdl = m_engine->get_model();
86+
mc = model2model_converter(mdl.get());
87+
TRACE("sls_model", mc->display(tout););
88+
}
89+
g->reset();
90+
}
91+
else
92+
mc = nullptr;
93+
94+
}
6395

6496
void operator()(goal_ref const & g,
6597
goal_ref_buffer & result) override {
@@ -69,7 +101,7 @@ class sls_tactic : public tactic {
69101
tactic_report report("sls", *g);
70102

71103
model_converter_ref mc;
72-
m_engine->operator()(g, mc);
104+
run(g, mc);
73105
g->add(mc.get());
74106
g->inc_depth();
75107
result.push_back(g.get());

0 commit comments

Comments
 (0)