Skip to content

Commit e550424

Browse files
use propagation filter
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 423e084 commit e550424

File tree

5 files changed

+217
-29
lines changed

5 files changed

+217
-29
lines changed

src/ast/for_each_expr.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,67 @@ bool subterms::iterator::operator!=(iterator const& other) const {
109109
return !(*this == other);
110110
}
111111

112+
113+
subterms_postorder::subterms_postorder(expr_ref_vector const& es): m_es(es) {}
114+
subterms_postorder::subterms_postorder(expr_ref& e) : m_es(e.m()) { m_es.push_back(e); }
115+
subterms_postorder::iterator subterms_postorder::begin() { return iterator(*this, true); }
116+
subterms_postorder::iterator subterms_postorder::end() { return iterator(*this, false); }
117+
subterms_postorder::iterator::iterator(subterms_postorder& f, bool start): m_es(f.m_es) {
118+
if (!start) m_es.reset();
119+
next();
120+
}
121+
expr* subterms_postorder::iterator::operator*() {
122+
return m_es.back();
123+
}
124+
subterms_postorder::iterator subterms_postorder::iterator::operator++(int) {
125+
iterator tmp = *this;
126+
++*this;
127+
return tmp;
128+
}
129+
130+
void subterms_postorder::iterator::next() {
131+
while (!m_es.empty()) {
132+
expr* e = m_es.back();
133+
if (m_visited.is_marked(e)) {
134+
m_es.pop_back();
135+
continue;
136+
}
137+
bool all_visited = true;
138+
if (is_app(e)) {
139+
for (expr* arg : *to_app(e)) {
140+
if (!m_visited.is_marked(arg)) {
141+
m_es.push_back(arg);
142+
all_visited = false;
143+
}
144+
}
145+
}
146+
if (all_visited) {
147+
m_visited.mark(e, true);
148+
break;
149+
}
150+
}
151+
152+
}
153+
154+
subterms_postorder::iterator& subterms_postorder::iterator::operator++() {
155+
expr* e = m_es.back();
156+
next();
157+
return *this;
158+
}
159+
160+
bool subterms_postorder::iterator::operator==(iterator const& other) const {
161+
// ignore state of visited
162+
if (other.m_es.size() != m_es.size()) {
163+
return false;
164+
}
165+
for (unsigned i = m_es.size(); i-- > 0; ) {
166+
if (m_es.get(i) != other.m_es.get(i))
167+
return false;
168+
}
169+
return true;
170+
}
171+
172+
bool subterms_postorder::iterator::operator!=(iterator const& other) const {
173+
return !(*this == other);
174+
}
175+

src/ast/for_each_expr.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ unsigned get_num_exprs(expr * n, expr_fast_mark1 & visited);
167167

168168
bool has_skolem_functions(expr * n);
169169

170+
// pre-order traversal of subterms
170171
class subterms {
171172
expr_ref_vector m_es;
172173
public:
@@ -187,5 +188,26 @@ class subterms {
187188
iterator end();
188189
};
189190

191+
class subterms_postorder {
192+
expr_ref_vector m_es;
193+
public:
194+
class iterator {
195+
expr_ref_vector m_es;
196+
expr_mark m_visited, m_seen;
197+
void next();
198+
public:
199+
iterator(subterms_postorder& f, bool start);
200+
expr* operator*();
201+
iterator operator++(int);
202+
iterator& operator++();
203+
bool operator==(iterator const& other) const;
204+
bool operator!=(iterator const& other) const;
205+
};
206+
subterms_postorder(expr_ref_vector const& es);
207+
subterms_postorder(expr_ref& e);
208+
iterator begin();
209+
iterator end();
210+
};
211+
190212
#endif /* FOR_EACH_EXPR_H_ */
191213

src/sat/sat_solver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ namespace sat {
388388
m_touched[l1.var()] = m_touch_index;
389389
m_touched[l2.var()] = m_touch_index;
390390

391-
if (find_binary_watch(get_wlist(~l1), ~l2) && value(l1) == l_undef) {
391+
if (learned && find_binary_watch(get_wlist(~l1), ~l2) && value(l1) == l_undef) {
392392
assign_unit(l1);
393393
return;
394394
}
395-
if (find_binary_watch(get_wlist(~l2), ~l1) && value(l2) == l_undef) {
395+
if (learned && find_binary_watch(get_wlist(~l2), ~l1) && value(l2) == l_undef) {
396396
assign_unit(l2);
397397
return;
398398
}
399-
watched* w0 = find_binary_watch(get_wlist(~l1), l2);
399+
watched* w0 = learned ? find_binary_watch(get_wlist(~l1), l2) : nullptr;
400400
if (w0) {
401401
TRACE("sat", tout << "found binary " << l1 << " " << l2 << "\n";);
402402
if (w0->is_learned() && !learned) {

src/smt/smt_model_finder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ namespace smt {
483483
}
484484

485485
void set_context(context * ctx) {
486-
SASSERT(m_context==0);
486+
SASSERT(m_context== nullptr);
487487
m_context = ctx;
488488
}
489489

@@ -1065,12 +1065,14 @@ namespace smt {
10651065

10661066
void mk_inverse(node * n) {
10671067
SASSERT(n->is_root());
1068-
instantiation_set * s = n->get_instantiation_set();
1068+
instantiation_set * s = n->get_instantiation_set();
10691069
s->mk_inverse(*this);
10701070
}
10711071

10721072
void mk_inverses() {
1073-
for (node * n : m_root_nodes) {
1073+
unsigned offset = m_context->get_random_value();
1074+
for (unsigned i = m_root_nodes.size(); i-- > 0; ) {
1075+
node* n = m_root_nodes[(i + offset) % m_root_nodes.size()];
10741076
SASSERT(n->is_root());
10751077
mk_inverse(n);
10761078
}
@@ -1838,7 +1840,7 @@ namespace smt {
18381840
for (qinfo* qi : m_qinfo_vect)
18391841
qi->populate_inst_sets(m_flat_q, m_the_one, *m_uvar_inst_sets, ctx);
18401842
for (instantiation_set * s : *m_uvar_inst_sets) {
1841-
if (s != nullptr)
1843+
if (s != nullptr)
18421844
s->mk_inverse(ev);
18431845
}
18441846
}

0 commit comments

Comments
 (0)