Skip to content

Commit ccce599

Browse files
fix #4143
1 parent fa1197a commit ccce599

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

src/smt/diff_logic.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class dl_graph {
263263

264264
public:
265265
// An assignment is feasible if all edges are feasible.
266-
bool is_feasible() const {
266+
bool is_feasible_dbg() const {
267267
for (unsigned i = 0; i < m_edges.size(); ++i) {
268268
if (!is_feasible(m_edges[i])) {
269269
return false;
@@ -422,7 +422,7 @@ class dl_graph {
422422
}
423423

424424
if (m_heap.empty()) {
425-
SASSERT(is_feasible());
425+
SASSERT(is_feasible_dbg());
426426
reset_marks();
427427
m_assignment_stack.reset();
428428
return true;
@@ -498,7 +498,7 @@ class dl_graph {
498498

499499
// Add an new weighted edge "source --weight--> target" with explanation ex.
500500
edge_id add_edge(dl_var source, dl_var target, const numeral & weight, const explanation & ex) {
501-
// SASSERT(is_feasible());
501+
// SASSERT(is_feasible_dbg());
502502
edge_id new_id = m_edges.size();
503503
m_edges.push_back(edge(source, target, weight, m_timestamp, ex));
504504
m_activity.push_back(0);
@@ -513,7 +513,7 @@ class dl_graph {
513513
// The method assumes the graph is feasible before the invocation.
514514
bool enable_edge(edge_id id) {
515515
edge& e = m_edges[id];
516-
SASSERT(is_feasible());
516+
SASSERT(is_feasible_dbg());
517517
bool r = true;
518518
if (!e.is_enabled()) {
519519
e.enable(m_timestamp);
@@ -523,7 +523,7 @@ class dl_graph {
523523
r = make_feasible(id);
524524
}
525525
SASSERT(check_invariant());
526-
SASSERT(!r || is_feasible());
526+
SASSERT(!r || is_feasible_dbg());
527527
m_enabled_edges.push_back(id);
528528
}
529529
return r;
@@ -862,7 +862,7 @@ class dl_graph {
862862
// Create a new scope.
863863
// That is, save the number of edges in the graph.
864864
void push() {
865-
// SASSERT(is_feasible()); <<< I relaxed this condition
865+
// SASSERT(is_feasible_dbg()); <<< I relaxed this condition
866866
m_trail_stack.push_back(scope(m_edges.size(), m_enabled_edges.size(), m_timestamp));
867867
}
868868

@@ -896,20 +896,20 @@ class dl_graph {
896896
}
897897
m_trail_stack.shrink(new_lvl);
898898
SASSERT(check_invariant());
899-
// SASSERT(is_feasible()); <<< I relaxed the condition in push(), so this assertion is not valid anymore.
899+
// SASSERT(is_feasible_dbg()); <<< I relaxed the condition in push(), so this assertion is not valid anymore.
900900
}
901901

902902
// Make m_assignment[v] == zero
903903
// The whole assignment is adjusted in a way feasibility is preserved.
904904
// This method should only be invoked if the current assignment if feasible.
905905
void set_to_zero(dl_var v) {
906-
SASSERT(is_feasible());
906+
SASSERT(is_feasible_dbg());
907907
if (!m_assignment[v].is_zero()) {
908908
numeral k = m_assignment[v];
909909
for (auto& a : m_assignment) {
910910
a -= k;
911911
}
912-
SASSERT(is_feasible());
912+
SASSERT(is_feasible_dbg());
913913
}
914914
}
915915

@@ -929,7 +929,7 @@ class dl_graph {
929929
if (!m_assignment[w].is_zero()) {
930930
enable_edge(add_edge(v, w, numeral(0), explanation()));
931931
enable_edge(add_edge(w, v, numeral(0), explanation()));
932-
SASSERT(is_feasible());
932+
SASSERT(is_feasible_dbg());
933933
}
934934
}
935935
return;
@@ -947,7 +947,7 @@ class dl_graph {
947947
if (!m_assignment[v].is_zero() || !m_assignment[w].is_zero()) {
948948
enable_edge(add_edge(v, w, numeral(0), explanation()));
949949
enable_edge(add_edge(w, v, numeral(0), explanation()));
950-
SASSERT(is_feasible());
950+
SASSERT(is_feasible_dbg());
951951
}
952952
}
953953

src/smt/theory_diff_logic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ namespace smt {
171171
arith_eq_adapter m_arith_eq_adapter;
172172
theory_diff_logic_statistics m_stats;
173173
Graph m_graph;
174+
bool m_consistent;
174175
theory_var m_izero, m_rzero; // cache the variable representing the zero variable.
175176
int_vector m_scc_id; // Cheap equality propagation
176177
eq_prop_info_set m_eq_prop_info_set; // set of existing equality prop infos
@@ -230,6 +231,7 @@ namespace smt {
230231
m_params(params),
231232
m_util(m),
232233
m_arith_eq_adapter(*this, params, m_util),
234+
m_consistent(true),
233235
m_izero(null_theory_var),
234236
m_rzero(null_theory_var),
235237
m_terms(m),

src/smt/theory_diff_logic_def.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void theory_diff_logic<Ext>::init(context * ctx) {
7272

7373
template<typename Ext>
7474
bool theory_diff_logic<Ext>::internalize_term(app * term) {
75+
if (!m_consistent)
76+
return false;
7577
bool result = null_theory_var != mk_term(term);
7678
CTRACE("arith", !result, tout << "Did not internalize " << mk_pp(term, get_manager()) << "\n";);
7779
if (!result) {
@@ -161,6 +163,8 @@ void theory_diff_logic<Ext>::found_non_diff_logic_expr(expr * n) {
161163

162164
template<typename Ext>
163165
bool theory_diff_logic<Ext>::internalize_atom(app * n, bool gate_ctx) {
166+
if (!m_consistent)
167+
return false;
164168
context & ctx = get_context();
165169
if (!m_util.is_le(n) && !m_util.is_ge(n)) {
166170
found_non_diff_logic_expr(n);
@@ -341,7 +345,7 @@ void theory_diff_logic<Ext>::pop_scope_eh(unsigned num_scopes) {
341345
m_scopes.shrink(new_lvl);
342346
unsigned num_edges = m_graph.get_num_edges();
343347
m_graph.pop(num_scopes);
344-
CTRACE("arith", !m_graph.is_feasible(), m_graph.display(tout););
348+
CTRACE("arith", !m_graph.is_feasible_dbg(), m_graph.display(tout););
345349
if (num_edges != m_graph.get_num_edges() && m_num_simplex_edges > 0) {
346350
m_S.reset();
347351
m_num_simplex_edges = 0;
@@ -540,11 +544,13 @@ void theory_diff_logic<Ext>::propagate() {
540544

541545
template<typename Ext>
542546
void theory_diff_logic<Ext>::inc_conflicts() {
543-
m_stats.m_num_conflicts++;
544-
if (m_params.m_arith_adaptive) {
545-
double g = m_params.m_arith_adaptive_propagation_threshold;
546-
m_agility = m_agility*g + 1 - g;
547-
}
547+
get_context().push_trail(value_trail<context, bool>(m_consistent));
548+
m_consistent = false;
549+
m_stats.m_num_conflicts++;
550+
if (m_params.m_arith_adaptive) {
551+
double g = m_params.m_arith_adaptive_propagation_threshold;
552+
m_agility = m_agility*g + 1 - g;
553+
}
548554
}
549555

550556
template<typename Ext>
@@ -568,6 +574,7 @@ bool theory_diff_logic<Ext>::propagate_atom(atom* a) {
568574
if (!m_graph.enable_edge(edge_id)) {
569575
TRACE("arith", display(tout););
570576
set_neg_cycle_conflict();
577+
571578
return false;
572579
}
573580
return true;
@@ -741,7 +748,6 @@ theory_var theory_diff_logic<Ext>::mk_term(app* n) {
741748

742749
TRACE("arith", tout << mk_pp(n, get_manager()) << "\n";);
743750

744-
745751
rational r;
746752
if (m_util.is_numeral(n, r)) {
747753
return mk_num(n, r);
@@ -944,10 +950,10 @@ void theory_diff_logic<Ext>::display(std::ostream & out) const {
944950
}
945951

946952
template<typename Ext>
947-
bool theory_diff_logic<Ext>::is_consistent() const {
953+
bool theory_diff_logic<Ext>::is_consistent() const {
948954
DEBUG_CODE(
949955
context& ctx = get_context();
950-
for (unsigned i = 0; m_graph.is_feasible() && i < m_atoms.size(); ++i) {
956+
for (unsigned i = 0; m_graph.is_feasible_dbg() && i < m_atoms.size(); ++i) {
951957
atom* a = m_atoms[i];
952958
bool_var bv = a->get_bool_var();
953959
lbool asgn = ctx.get_assignment(bv);
@@ -958,7 +964,7 @@ bool theory_diff_logic<Ext>::is_consistent() const {
958964
SASSERT(m_graph.is_feasible(edge_id));
959965
}
960966
});
961-
return m_graph.is_feasible();
967+
return m_consistent;
962968
}
963969

964970

@@ -1230,8 +1236,8 @@ theory_diff_logic<Ext>::maximize(theory_var v, expr_ref& blocker, bool& has_shar
12301236
Simplex& S = m_S;
12311237
ast_manager& m = get_manager();
12321238

1233-
CTRACE("arith",!m_graph.is_feasible(), m_graph.display(tout););
1234-
SASSERT(m_graph.is_feasible());
1239+
CTRACE("arith",!m_graph.is_feasible_dbg(), m_graph.display(tout););
1240+
SASSERT(m_graph.is_feasible_dbg());
12351241

12361242
update_simplex(S);
12371243

@@ -1294,8 +1300,8 @@ theory_diff_logic<Ext>::maximize(theory_var v, expr_ref& blocker, bool& has_shar
12941300
rational r = rational(val.first);
12951301
m_graph.set_assignment(i, numeral(r));
12961302
}
1297-
CTRACE("arith",!m_graph.is_feasible(), m_graph.display(tout););
1298-
SASSERT(m_graph.is_feasible());
1303+
CTRACE("arith",!m_graph.is_feasible_dbg(), m_graph.display(tout););
1304+
SASSERT(m_graph.is_feasible_dbg());
12991305
inf_eps r1(rational(0), r);
13001306
blocker = mk_gt(v, r1);
13011307
return inf_eps(rational(0), r + m_objective_consts[v]);

src/smt/theory_utvpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ namespace smt {
138138
smt_params m_params;
139139
arith_util a;
140140
arith_eq_adapter m_arith_eq_adapter;
141+
bool m_consistent;
141142
th_var m_izero, m_rzero; //cache the variable representing the zero variable.
142143

143144
dl_graph<GExt> m_graph;

src/smt/theory_utvpi_def.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace smt {
6161
theory(m.mk_family_id("arith")),
6262
a(m),
6363
m_arith_eq_adapter(*this, m_params, a),
64+
m_consistent(true),
6465
m_izero(null_theory_var),
6566
m_rzero(null_theory_var),
6667
m_nc_functor(*this),
@@ -192,6 +193,8 @@ namespace smt {
192193

193194
template<typename Ext>
194195
void theory_utvpi<Ext>::inc_conflicts() {
196+
get_context().push_trail(value_trail<context, bool>(m_consistent));
197+
m_consistent = false;
195198
m_stats.m_num_conflicts++;
196199
if (m_params.m_arith_adaptive) {
197200
double g = m_params.m_arith_adaptive_propagation_threshold;
@@ -312,6 +315,8 @@ namespace smt {
312315

313316
template<typename Ext>
314317
bool theory_utvpi<Ext>::internalize_atom(app * n, bool) {
318+
if (!m_consistent)
319+
return false;
315320
context & ctx = get_context();
316321
if (!a.is_le(n) && !a.is_ge(n) && !a.is_lt(n) && !a.is_gt(n)) {
317322
found_non_utvpi_expr(n);
@@ -362,6 +367,8 @@ namespace smt {
362367

363368
template<typename Ext>
364369
bool theory_utvpi<Ext>::internalize_term(app * term) {
370+
if (!m_consistent)
371+
return false;
365372
bool result = !get_context().inconsistent() && null_theory_var != mk_term(term);
366373
CTRACE("utvpi", !result, tout << "Did not internalize " << mk_pp(term, get_manager()) << "\n";);
367374
return result;
@@ -698,8 +705,8 @@ namespace smt {
698705
}
699706

700707
template<typename Ext>
701-
bool theory_utvpi<Ext>::is_consistent() const {
702-
return m_graph.is_feasible();
708+
bool theory_utvpi<Ext>::is_consistent() const {
709+
return m_consistent;
703710
}
704711

705712

@@ -743,7 +750,7 @@ namespace smt {
743750
*/
744751
template<typename Ext>
745752
void theory_utvpi<Ext>::enforce_parity() {
746-
SASSERT(m_graph.is_feasible());
753+
SASSERT(m_graph.is_feasible_dbg());
747754
unsigned_vector todo;
748755
unsigned sz = get_num_vars();
749756
for (unsigned i = 0; i < sz; ++i) {
@@ -788,7 +795,7 @@ namespace smt {
788795
}
789796
}
790797
TRACE("utvpi", display(tout););
791-
SASSERT(m_graph.is_feasible());
798+
SASSERT(m_graph.is_feasible_dbg());
792799
}
793800
DEBUG_CODE(
794801
for (unsigned i = 0; i < sz; ++i) {
@@ -798,7 +805,7 @@ namespace smt {
798805
UNREACHABLE();
799806
}
800807
});
801-
SASSERT(m_graph.is_feasible());
808+
SASSERT(m_graph.is_feasible_dbg());
802809
}
803810

804811

0 commit comments

Comments
 (0)