Skip to content

Commit cf72a91

Browse files
bugfixes, adding plugin solver
1 parent 659e384 commit cf72a91

File tree

7 files changed

+146
-14
lines changed

7 files changed

+146
-14
lines changed

src/ast/sls/bv_sls.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace bv {
9191

9292
lbool sls::search() {
9393
// init and init_eval were invoked
94-
unsigned n = 0;
94+
unsigned n = 0;
9595
for (; n++ < m_config.m_max_repairs && m.inc(); ) {
9696
++m_stats.m_moves;
9797
auto [down, e] = next_to_repair();
@@ -164,7 +164,7 @@ namespace bv {
164164
return was_repaired;
165165
}
166166

167-
void sls::try_repair_up(app* e) {
167+
void sls::try_repair_up(app* e) {
168168
m_repair_up.remove(e->get_id());
169169
if (m_terms.is_assertion(e) || !m_eval.repair_up(e))
170170
m_repair_down.insert(e->get_id());

src/ast/sls/bv_sls_eval.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ namespace bv {
130130
void sls_eval::init_eval_bv(app* e) {
131131
if (bv.is_bv(e)) {
132132
auto& v = wval0(e);
133-
v.set(wval1(e));
133+
v.set(wval1(e).bits);
134134
}
135135
else if (m.is_bool(e))
136136
m_eval.setx(e->get_id(), bval1_bv(e), false);
@@ -299,10 +299,10 @@ namespace bv {
299299
return bval0(e);
300300
}
301301

302-
svector<digit_t>& sls_eval::wval1(app* e) const {
302+
sls_valuation& sls_eval::wval1(app* e) const {
303303
auto& val = *m_values1[e->get_id()];
304304
wval1(e, val);
305-
return val.bits;
305+
return val;
306306
}
307307

308308
void sls_eval::wval1(app* e, sls_valuation& val) const {
@@ -429,8 +429,6 @@ namespace bv {
429429
break;
430430
}
431431
case OP_CONCAT: {
432-
if (e->get_num_args() != 2)
433-
verbose_stream() << mk_bounded_pp(e, m) << "\n";
434432
SASSERT(e->get_num_args() == 2);
435433
auto const& a = wval0(e->get_arg(0));
436434
auto const& b = wval0(e->get_arg(1));
@@ -1005,8 +1003,8 @@ namespace bv {
10051003
}
10061004
else {
10071005
// b := a - e
1008-
a.set_sub(m_tmp, a.bits, e.bits);
1009-
a.set_repair(random_bool(), m_tmp);
1006+
b.set_sub(m_tmp, a.bits, e.bits);
1007+
b.set_repair(random_bool(), m_tmp);
10101008
}
10111009
return true;
10121010
}
@@ -1186,7 +1184,6 @@ namespace bv {
11861184
if (a.is_zero(m_tmp2))
11871185
return false;
11881186
if (!a.get_at_least(m_tmp2, m_tmp)) {
1189-
verbose_stream() << "could not get at least\n";
11901187
return false;
11911188
}
11921189
}
@@ -1571,7 +1568,7 @@ namespace bv {
15711568
return true;
15721569
}
15731570
if (bv.is_bv(e))
1574-
return wval0(e).try_set(wval1(to_app(e)));
1571+
return wval0(e).try_set(wval1(to_app(e)).bits);
15751572
return false;
15761573
}
15771574
}

src/ast/sls/bv_sls_eval.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ namespace bv {
136136
*/
137137
bool bval1(app* e) const;
138138
bool can_eval1(app* e) const;
139-
140-
svector<digit_t>& wval1(app* e) const;
139+
140+
sls_valuation& wval1(app* e) const;
141141

142142
/**
143143
* Override evaluaton.

src/ast/sls/sls_valuation.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ namespace bv {
202202
}
203203

204204
std::ostream& display(std::ostream& out) const {
205+
out << "V:";
205206
out << std::hex;
206207
auto print_bits = [&](svector<digit_t> const& v) {
207208
bool nz = false;
@@ -215,7 +216,7 @@ namespace bv {
215216
};
216217

217218
print_bits(bits);
218-
out << " ";
219+
out << " fix:";
219220
print_bits(fixed);
220221

221222
if (!eq(lo, hi)) {

src/sat/smt/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ z3_add_component(sat_smt
4646
q_solver.cpp
4747
recfun_solver.cpp
4848
sat_th.cpp
49+
sls_solver.cpp
4950
specrel_solver.cpp
5051
tseitin_theory_checker.cpp
5152
user_solver.cpp

src/sat/smt/sls_solver.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*++
2+
Copyright (c) 2020 Microsoft Corporation
3+
4+
Module Name:
5+
6+
sls_solver
7+
8+
Abstract:
9+
10+
Interface to Concurrent SLS solver
11+
12+
Author:
13+
14+
Nikolaj Bjorner (nbjorner) 2024-02-21
15+
16+
--*/
17+
18+
#include "sat/smt/sls_solver.h"
19+
#include "sat/smt/euf_solver.h"
20+
#include "ast/sls/bv_sls.h"
21+
22+
23+
namespace sls {
24+
25+
solver::solver(euf::solver& ctx):
26+
th_euf_solver(ctx, symbol("sls"), ctx.get_manager().mk_family_id("sls")) {}
27+
28+
solver::~solver() {
29+
if (m_rlimit) {
30+
m_rlimit->cancel();
31+
m_thread.join();
32+
}
33+
}
34+
35+
void solver::push_core() {
36+
if (s().scope_lvl() == s().search_lvl() + 1)
37+
init_local_search();
38+
}
39+
40+
void solver::pop_core(unsigned n) {
41+
if (s().scope_lvl() - n <= s().search_lvl())
42+
sample_local_search();
43+
}
44+
45+
void solver::simplify() {
46+
47+
}
48+
49+
50+
void solver::init_local_search() {
51+
if (m_rlimit) {
52+
m_rlimit->cancel();
53+
m_thread.join();
54+
}
55+
// set up state for local search solver here
56+
auto* bvsls = alloc(bv::sls, m);
57+
// walk clauses, add them
58+
// walk trail stack until search level, add units
59+
// encapsulate bvsls within the arguments of run-local-search.
60+
// ensure bvsls does not touch ast-manager.
61+
m_thread = std::thread([this]() { run_local_search(*this); });
62+
m_rlimit = alloc(reslimit);
63+
m_rlimit->push_child(&s().rlimit());
64+
}
65+
66+
void solver::sample_local_search() {
67+
68+
}
69+
70+
void solver::run_local_search(solver& s) {
71+
72+
}
73+
74+
}

src/sat/smt/sls_solver.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*++
2+
Copyright (c) 2020 Microsoft Corporation
3+
4+
Module Name:
5+
6+
sls_solver
7+
8+
Abstract:
9+
10+
Interface to Concurrent SLS solver
11+
12+
Author:
13+
14+
Nikolaj Bjorner (nbjorner) 2024-02-21
15+
16+
--*/
17+
#pragma once
18+
19+
#include "sat/smt/sat_th.h"
20+
#include "util/rlimit.h"
21+
22+
namespace euf {
23+
class solver;
24+
}
25+
26+
namespace sls {
27+
28+
class solver : public euf::th_euf_solver {
29+
std::atomic<lbool> m_result;
30+
std::atomic<bool> m_completed;
31+
std::thread m_thread;
32+
scoped_ptr<reslimit> m_rlimit;
33+
34+
void run_local_search(solver& s);
35+
void init_local_search();
36+
void sample_local_search();
37+
public:
38+
solver(euf::solver& ctx);
39+
~solver();
40+
41+
void push_core() override;
42+
void pop_core(unsigned n) override;
43+
void simplify() override;
44+
45+
sat::literal internalize(expr* e, bool sign, bool root) override { UNREACHABLE(); return sat::null_literal; }
46+
void internalize(expr* e) override { UNREACHABLE(); }
47+
th_solver* clone(euf::solver& ctx) override { return alloc(solver, ctx); }
48+
49+
50+
bool unit_propagate() override { return false; }
51+
void get_antecedents(sat::literal l, sat::ext_justification_idx idx, sat::literal_vector & r, bool probing) override { UNREACHABLE(); }
52+
sat::check_result check() override { return sat::check_result::CR_DONE; }
53+
std::ostream & display(std::ostream & out) const override { return out; }
54+
std::ostream & display_justification(std::ostream & out, sat::ext_justification_idx idx) const override { UNREACHABLE(); return out; }
55+
std::ostream & display_constraint(std::ostream & out, sat::ext_constraint_idx idx) const override { UNREACHABLE(); return out; }
56+
57+
};
58+
59+
}

0 commit comments

Comments
 (0)