Skip to content

Commit db5af30

Browse files
logging for #2450
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 1d488d0 commit db5af30

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

src/nlsat/nlsat_interval_set.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ namespace nlsat {
743743
m_am.set(w, s->m_intervals[irrational_i].m_upper);
744744
}
745745

746-
void interval_set_manager::display(std::ostream & out, interval_set const * s) const {
746+
std::ostream& interval_set_manager::display(std::ostream & out, interval_set const * s) const {
747747
if (s == nullptr) {
748748
out << "{}";
749-
return;
749+
return out;
750750
}
751751
out << "{";
752752
for (unsigned i = 0; i < s->m_num_intervals; i++) {
@@ -757,6 +757,7 @@ namespace nlsat {
757757
out << "}";
758758
if (s->m_full)
759759
out << "*";
760+
return out;
760761
}
761762

762763
};

src/nlsat/nlsat_interval_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace nlsat {
9393
*/
9494
void get_justifications(interval_set const * s, literal_vector & js);
9595

96-
void display(std::ostream & out, interval_set const * s) const;
96+
std::ostream& display(std::ostream & out, interval_set const * s) const;
9797

9898
unsigned num_intervals(interval_set const * s) const;
9999

src/nlsat/nlsat_solver.cpp

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,33 @@ namespace nlsat {
122122
};
123123
perm_display_var_proc m_display_var;
124124

125+
display_assumption_proc const* m_display_assumption;
126+
struct display_literal_assumption : public display_assumption_proc {
127+
imp& i;
128+
literal_vector const& lits;
129+
display_literal_assumption(imp& i, literal_vector const& lits): i(i), lits(lits) {}
130+
std::ostream& operator()(std::ostream& out, assumption a) const override {
131+
if (lits.begin() <= a && a < lits.end()) {
132+
out << *((literal const*)a);
133+
}
134+
else if (i.m_display_assumption) {
135+
(*i.m_display_assumption)(out, a);
136+
}
137+
return out;
138+
}
139+
140+
};
141+
struct scoped_display_assumptions {
142+
imp& i;
143+
display_assumption_proc const* m_save;
144+
scoped_display_assumptions(imp& i, display_assumption_proc const& p): i(i), m_save(i.m_display_assumption) {
145+
i.m_display_assumption = &p;
146+
}
147+
~scoped_display_assumptions() {
148+
i.m_display_assumption = m_save;
149+
}
150+
};
151+
125152
explain m_explain;
126153

127154
bool_var m_bk; // current Boolean variable we are processing
@@ -179,6 +206,7 @@ namespace nlsat {
179206
m_patch_denom(m_pm),
180207
m_num_bool_vars(0),
181208
m_display_var(m_perm),
209+
m_display_assumption(nullptr),
182210
m_explain(s, m_assignment, m_cache, m_atoms, m_var2eq, m_evaluator),
183211
m_scope_lvl(0),
184212
m_lemma(s),
@@ -1035,9 +1063,9 @@ namespace nlsat {
10351063
interval_set * xk_set = m_infeasible[m_xk];
10361064
save_set_updt_trail(xk_set);
10371065
interval_set_ref new_set(m_ism);
1038-
TRACE("nlsat_inf_set", tout << "updating infeasible set\n"; m_ism.display(tout, xk_set); tout << "\n"; m_ism.display(tout, s); tout << "\n";);
1066+
TRACE("nlsat_inf_set", tout << "updating infeasible set\n"; m_ism.display(tout, xk_set) << "\n"; m_ism.display(tout, s) << "\n";);
10391067
new_set = m_ism.mk_union(s, xk_set);
1040-
TRACE("nlsat_inf_set", tout << "new infeasible set:\n"; m_ism.display(tout, new_set); tout << "\n";);
1068+
TRACE("nlsat_inf_set", tout << "new infeasible set:\n"; m_ism.display(tout, new_set) << "\n";);
10411069
SASSERT(!m_ism.is_full(new_set));
10421070
m_ism.inc_ref(new_set);
10431071
m_infeasible[m_xk] = new_set;
@@ -1060,7 +1088,7 @@ namespace nlsat {
10601088
if (m_var2eq[x] != 0 && degree(m_var2eq[x]) <= degree(a))
10611089
return; // we only update m_var2eq if the new equality has smaller degree
10621090
TRACE("simplify_core", tout << "Saving equality for "; m_display_var(tout, x) << " (x" << x << ") ";
1063-
tout << "scope-lvl: " << scope_lvl() << "\n"; display(tout, literal(b, false)); tout << "\n";);
1091+
tout << "scope-lvl: " << scope_lvl() << "\n"; display(tout, literal(b, false)) << "\n";);
10641092
save_updt_eq_trail(m_var2eq[x]);
10651093
m_var2eq[x] = a;
10661094
}
@@ -1094,7 +1122,8 @@ namespace nlsat {
10941122
SASSERT(a != nullptr);
10951123
interval_set_ref curr_set(m_ism);
10961124
curr_set = m_evaluator.infeasible_intervals(a, l.sign());
1097-
TRACE("nlsat_inf_set", tout << "infeasible set for literal: "; display(tout, l); tout << "\n"; m_ism.display(tout, curr_set); tout << "\n";);
1125+
TRACE("nlsat_inf_set", tout << "infeasible set for literal: "; display(tout, l); tout << "\n"; m_ism.display(tout, curr_set); tout << "\n";
1126+
display(tout, cls) << "\n";);
10981127
if (m_ism.is_empty(curr_set)) {
10991128
TRACE("nlsat_inf_set", tout << "infeasible set is empty, found literal\n";);
11001129
R_propagate(l, nullptr);
@@ -1114,7 +1143,8 @@ namespace nlsat {
11141143
interval_set_ref tmp(m_ism);
11151144
tmp = m_ism.mk_union(curr_set, xk_set);
11161145
if (m_ism.is_full(tmp)) {
1117-
TRACE("nlsat_inf_set", tout << "infeasible set + current set = R, skip literal\n";);
1146+
TRACE("nlsat_inf_set", tout << "infeasible set + current set = R, skip literal\n";
1147+
display(tout, cls) << "\n";);
11181148
R_propagate(~l, tmp, false);
11191149
continue;
11201150
}
@@ -1382,6 +1412,8 @@ namespace nlsat {
13821412
for (unsigned i = 0; i < sz; ++i) {
13831413
mk_clause(1, ptr+i, (assumption)(ptr+i));
13841414
}
1415+
display_literal_assumption dla(*this, assumptions);
1416+
scoped_display_assumptions _scoped_display(*this, dla);
13851417
lbool r = check();
13861418

13871419
if (r == l_false) {
@@ -1393,9 +1425,6 @@ namespace nlsat {
13931425
if (ptr <= lp && lp < ptr + sz) {
13941426
result.push_back(*lp);
13951427
}
1396-
else {
1397-
std::cout << "pointer out of bounds\n";
1398-
}
13991428
}
14001429
}
14011430
collect(assumptions, m_clauses);
@@ -1506,7 +1535,7 @@ namespace nlsat {
15061535
}
15071536

15081537
void resolve_clause(bool_var b, unsigned sz, literal const * c) {
1509-
TRACE("nlsat_proof", tout << "resolving "; if (b != null_bool_var) display_atom(tout, b); tout << "\n"; display(tout, sz, c); tout << "\n";);
1538+
TRACE("nlsat_proof", tout << "resolving "; if (b != null_bool_var) display_atom(tout, b) << "\n"; display(tout, sz, c); tout << "\n";);
15101539
TRACE("nlsat_proof_sk", tout << "resolving "; if (b != null_bool_var) tout << "b" << b; tout << "\n"; display_abst(tout, sz, c); tout << "\n";);
15111540

15121541
bool found_decision = false;
@@ -1703,7 +1732,7 @@ namespace nlsat {
17031732
if (t.m_kind == trail::BVAR_ASSIGNMENT) {
17041733
bool_var b = t.m_b;
17051734
if (is_marked(b)) {
1706-
TRACE("nlsat_resolve", tout << "found marked bool_var: " << b << "\n"; display_atom(tout, b); tout << "\n";);
1735+
TRACE("nlsat_resolve", tout << "found marked bool_var: " << b << "\n"; display_atom(tout, b) << "\n";);
17071736
m_num_marks--;
17081737
reset_mark(b);
17091738
justification jst = m_justifications[b];
@@ -1812,13 +1841,7 @@ namespace nlsat {
18121841
undo_until_level(new_lvl);
18131842
}
18141843

1815-
bool same = (sz == conflict_clause->size());
1816-
if (same) {
1817-
for (unsigned i = 0; same && i < sz; ++i) {
1818-
same = m_lemma[i] == (*conflict_clause)[i];
1819-
}
1820-
}
1821-
if (same) {
1844+
if (lemma_is_clause(*conflict_clause)) {
18221845
TRACE("nlsat", tout << "found decision literal in conflict clause\n";);
18231846
VERIFY(process_clause(*conflict_clause, true));
18241847
return true;
@@ -1839,6 +1862,14 @@ namespace nlsat {
18391862
return true;
18401863
}
18411864

1865+
bool lemma_is_clause(clause const& cls) const {
1866+
bool same = (m_lemma.size() == cls.size());
1867+
for (unsigned i = 0; same && i < m_lemma.size(); ++i) {
1868+
same = m_lemma[i] == cls[i];
1869+
}
1870+
return same;
1871+
}
1872+
18421873

18431874
// -----------------------
18441875
//
@@ -2883,10 +2914,11 @@ namespace nlsat {
28832914
std::ostream& display_assumptions(std::ostream & out, _assumption_set s) const {
28842915
vector<assumption, false> deps;
28852916
m_asm.linearize(s, deps);
2917+
bool first = true;
28862918
for (auto dep : deps) {
2887-
out << *((literal const*)(dep)) << " ";
2919+
if (first) first = false; else out << " ";
2920+
if (m_display_assumption) (*m_display_assumption)(out, dep);
28882921
}
2889-
28902922
return out;
28912923
}
28922924

@@ -3154,6 +3186,11 @@ namespace nlsat {
31543186
m_imp->m_display_var.m_proc = &proc;
31553187
}
31563188

3189+
void solver::set_display_assumption(display_assumption_proc const& proc) {
3190+
m_imp->m_display_assumption = &proc;
3191+
}
3192+
3193+
31573194
unsigned solver::num_vars() const {
31583195
return m_imp->num_vars();
31593196
}

src/nlsat/nlsat_solver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ namespace nlsat {
3131
class evaluator;
3232
class explain;
3333

34+
class display_assumption_proc {
35+
public:
36+
virtual std::ostream& operator()(std::ostream& out, assumption a) const = 0;
37+
};
38+
3439
class solver {
3540
struct imp;
3641
imp * m_imp;
@@ -55,6 +60,8 @@ namespace nlsat {
5560

5661
void set_display_var(display_var_proc const & proc);
5762

63+
void set_display_assumption(display_assumption_proc const& proc);
64+
5865
// -----------------------
5966
//
6067
// Variable, Atoms, Clauses & Assumption creation

0 commit comments

Comments
 (0)