cadical 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +26 -0
- data/README.md +101 -0
- data/ext/cadical/cadical/LICENSE +28 -0
- data/ext/cadical/cadical/README.md +65 -0
- data/ext/cadical/cadical/VERSION +1 -0
- data/ext/cadical/cadical/src/analyze.cpp +1360 -0
- data/ext/cadical/cadical/src/arena.cpp +30 -0
- data/ext/cadical/cadical/src/arena.hpp +105 -0
- data/ext/cadical/cadical/src/assume.cpp +616 -0
- data/ext/cadical/cadical/src/averages.cpp +34 -0
- data/ext/cadical/cadical/src/averages.hpp +37 -0
- data/ext/cadical/cadical/src/backbone.cpp +631 -0
- data/ext/cadical/cadical/src/backtrack.cpp +177 -0
- data/ext/cadical/cadical/src/backward.cpp +231 -0
- data/ext/cadical/cadical/src/bins.cpp +22 -0
- data/ext/cadical/cadical/src/bins.hpp +22 -0
- data/ext/cadical/cadical/src/block.cpp +824 -0
- data/ext/cadical/cadical/src/block.hpp +37 -0
- data/ext/cadical/cadical/src/cadical.cpp +1026 -0
- data/ext/cadical/cadical/src/cadical.hpp +1419 -0
- data/ext/cadical/cadical/src/ccadical.cpp +208 -0
- data/ext/cadical/cadical/src/ccadical.h +74 -0
- data/ext/cadical/cadical/src/checker.cpp +649 -0
- data/ext/cadical/cadical/src/checker.hpp +173 -0
- data/ext/cadical/cadical/src/clause.cpp +689 -0
- data/ext/cadical/cadical/src/clause.hpp +190 -0
- data/ext/cadical/cadical/src/collect.cpp +545 -0
- data/ext/cadical/cadical/src/compact.cpp +550 -0
- data/ext/cadical/cadical/src/condition.cpp +940 -0
- data/ext/cadical/cadical/src/config.cpp +101 -0
- data/ext/cadical/cadical/src/config.hpp +20 -0
- data/ext/cadical/cadical/src/congruence.cpp +7880 -0
- data/ext/cadical/cadical/src/congruence.hpp +757 -0
- data/ext/cadical/cadical/src/constrain.cpp +64 -0
- data/ext/cadical/cadical/src/contract.cpp +27 -0
- data/ext/cadical/cadical/src/contract.hpp +139 -0
- data/ext/cadical/cadical/src/cover.cpp +704 -0
- data/ext/cadical/cadical/src/cover.hpp +34 -0
- data/ext/cadical/cadical/src/decide.cpp +347 -0
- data/ext/cadical/cadical/src/decompose.cpp +738 -0
- data/ext/cadical/cadical/src/decompose.hpp +23 -0
- data/ext/cadical/cadical/src/deduplicate.cpp +275 -0
- data/ext/cadical/cadical/src/definition.cpp +283 -0
- data/ext/cadical/cadical/src/delay.hpp +38 -0
- data/ext/cadical/cadical/src/drattracer.cpp +153 -0
- data/ext/cadical/cadical/src/drattracer.hpp +55 -0
- data/ext/cadical/cadical/src/elim.cpp +1171 -0
- data/ext/cadical/cadical/src/elim.hpp +53 -0
- data/ext/cadical/cadical/src/elimfast.cpp +570 -0
- data/ext/cadical/cadical/src/ema.cpp +95 -0
- data/ext/cadical/cadical/src/ema.hpp +68 -0
- data/ext/cadical/cadical/src/extend.cpp +289 -0
- data/ext/cadical/cadical/src/external.cpp +1034 -0
- data/ext/cadical/cadical/src/external.hpp +487 -0
- data/ext/cadical/cadical/src/external_propagate.cpp +1316 -0
- data/ext/cadical/cadical/src/factor.cpp +1011 -0
- data/ext/cadical/cadical/src/factor.hpp +54 -0
- data/ext/cadical/cadical/src/file.cpp +506 -0
- data/ext/cadical/cadical/src/file.hpp +210 -0
- data/ext/cadical/cadical/src/flags.cpp +135 -0
- data/ext/cadical/cadical/src/flags.hpp +93 -0
- data/ext/cadical/cadical/src/flip.cpp +269 -0
- data/ext/cadical/cadical/src/format.cpp +89 -0
- data/ext/cadical/cadical/src/format.hpp +36 -0
- data/ext/cadical/cadical/src/frattracer.cpp +277 -0
- data/ext/cadical/cadical/src/frattracer.hpp +67 -0
- data/ext/cadical/cadical/src/gates.cpp +766 -0
- data/ext/cadical/cadical/src/heap.hpp +212 -0
- data/ext/cadical/cadical/src/idruptracer.cpp +566 -0
- data/ext/cadical/cadical/src/idruptracer.hpp +112 -0
- data/ext/cadical/cadical/src/instantiate.cpp +365 -0
- data/ext/cadical/cadical/src/instantiate.hpp +45 -0
- data/ext/cadical/cadical/src/internal.cpp +1265 -0
- data/ext/cadical/cadical/src/internal.hpp +1941 -0
- data/ext/cadical/cadical/src/inttypes.hpp +34 -0
- data/ext/cadical/cadical/src/ipasir.cpp +47 -0
- data/ext/cadical/cadical/src/ipasir.h +37 -0
- data/ext/cadical/cadical/src/kitten.c +2599 -0
- data/ext/cadical/cadical/src/kitten.h +97 -0
- data/ext/cadical/cadical/src/level.hpp +33 -0
- data/ext/cadical/cadical/src/lidruptracer.cpp +657 -0
- data/ext/cadical/cadical/src/lidruptracer.hpp +122 -0
- data/ext/cadical/cadical/src/limit.cpp +146 -0
- data/ext/cadical/cadical/src/limit.hpp +168 -0
- data/ext/cadical/cadical/src/logging.cpp +214 -0
- data/ext/cadical/cadical/src/logging.hpp +98 -0
- data/ext/cadical/cadical/src/lookahead.cpp +520 -0
- data/ext/cadical/cadical/src/lratchecker.cpp +833 -0
- data/ext/cadical/cadical/src/lratchecker.hpp +168 -0
- data/ext/cadical/cadical/src/lrattracer.cpp +200 -0
- data/ext/cadical/cadical/src/lrattracer.hpp +61 -0
- data/ext/cadical/cadical/src/lucky.cpp +506 -0
- data/ext/cadical/cadical/src/message.cpp +218 -0
- data/ext/cadical/cadical/src/message.hpp +65 -0
- data/ext/cadical/cadical/src/minimize.cpp +224 -0
- data/ext/cadical/cadical/src/mobical.cpp +5588 -0
- data/ext/cadical/cadical/src/occs.cpp +52 -0
- data/ext/cadical/cadical/src/occs.hpp +36 -0
- data/ext/cadical/cadical/src/options.cpp +359 -0
- data/ext/cadical/cadical/src/options.hpp +442 -0
- data/ext/cadical/cadical/src/parse.cpp +471 -0
- data/ext/cadical/cadical/src/parse.hpp +75 -0
- data/ext/cadical/cadical/src/phases.cpp +56 -0
- data/ext/cadical/cadical/src/phases.hpp +19 -0
- data/ext/cadical/cadical/src/probe.cpp +990 -0
- data/ext/cadical/cadical/src/profile.cpp +107 -0
- data/ext/cadical/cadical/src/profile.hpp +283 -0
- data/ext/cadical/cadical/src/proof.cpp +691 -0
- data/ext/cadical/cadical/src/proof.hpp +125 -0
- data/ext/cadical/cadical/src/propagate.cpp +584 -0
- data/ext/cadical/cadical/src/queue.cpp +90 -0
- data/ext/cadical/cadical/src/queue.hpp +74 -0
- data/ext/cadical/cadical/src/radix.hpp +180 -0
- data/ext/cadical/cadical/src/random.cpp +207 -0
- data/ext/cadical/cadical/src/random.h +44 -0
- data/ext/cadical/cadical/src/random.hpp +98 -0
- data/ext/cadical/cadical/src/range.hpp +125 -0
- data/ext/cadical/cadical/src/reap.cpp +127 -0
- data/ext/cadical/cadical/src/reap.hpp +28 -0
- data/ext/cadical/cadical/src/reduce.cpp +278 -0
- data/ext/cadical/cadical/src/reluctant.hpp +82 -0
- data/ext/cadical/cadical/src/rephase.cpp +402 -0
- data/ext/cadical/cadical/src/report.cpp +313 -0
- data/ext/cadical/cadical/src/resources.cpp +160 -0
- data/ext/cadical/cadical/src/resources.hpp +16 -0
- data/ext/cadical/cadical/src/restart.cpp +178 -0
- data/ext/cadical/cadical/src/restore.cpp +267 -0
- data/ext/cadical/cadical/src/score.cpp +51 -0
- data/ext/cadical/cadical/src/score.hpp +16 -0
- data/ext/cadical/cadical/src/shrink.cpp +507 -0
- data/ext/cadical/cadical/src/signal.cpp +136 -0
- data/ext/cadical/cadical/src/signal.hpp +33 -0
- data/ext/cadical/cadical/src/solution.cpp +50 -0
- data/ext/cadical/cadical/src/solver.cpp +1871 -0
- data/ext/cadical/cadical/src/stable.cpp +31 -0
- data/ext/cadical/cadical/src/stack.h +110 -0
- data/ext/cadical/cadical/src/stats.cpp +920 -0
- data/ext/cadical/cadical/src/stats.hpp +418 -0
- data/ext/cadical/cadical/src/subsume.cpp +645 -0
- data/ext/cadical/cadical/src/sweep.cpp +1960 -0
- data/ext/cadical/cadical/src/sweep.hpp +61 -0
- data/ext/cadical/cadical/src/terminal.cpp +38 -0
- data/ext/cadical/cadical/src/terminal.hpp +96 -0
- data/ext/cadical/cadical/src/ternary.cpp +450 -0
- data/ext/cadical/cadical/src/testing.hpp +24 -0
- data/ext/cadical/cadical/src/tier.cpp +189 -0
- data/ext/cadical/cadical/src/tracer.hpp +186 -0
- data/ext/cadical/cadical/src/transred.cpp +253 -0
- data/ext/cadical/cadical/src/unstable.cpp +29 -0
- data/ext/cadical/cadical/src/util.cpp +129 -0
- data/ext/cadical/cadical/src/util.hpp +181 -0
- data/ext/cadical/cadical/src/var.cpp +39 -0
- data/ext/cadical/cadical/src/var.hpp +22 -0
- data/ext/cadical/cadical/src/veripbtracer.cpp +427 -0
- data/ext/cadical/cadical/src/veripbtracer.hpp +106 -0
- data/ext/cadical/cadical/src/version.cpp +107 -0
- data/ext/cadical/cadical/src/version.hpp +13 -0
- data/ext/cadical/cadical/src/vivify.cpp +1893 -0
- data/ext/cadical/cadical/src/vivify.hpp +50 -0
- data/ext/cadical/cadical/src/walk.cpp +1088 -0
- data/ext/cadical/cadical/src/walk.hpp +91 -0
- data/ext/cadical/cadical/src/walk_full_occs.cpp +966 -0
- data/ext/cadical/cadical/src/warmup.cpp +403 -0
- data/ext/cadical/cadical/src/watch.cpp +126 -0
- data/ext/cadical/cadical/src/watch.hpp +77 -0
- data/ext/cadical/cadical_ext.c +778 -0
- data/ext/cadical/extconf.rb +26 -0
- data/lib/cadical/version.rb +3 -0
- data/lib/cadical.rb +12 -0
- metadata +218 -0
|
@@ -0,0 +1,1360 @@
|
|
|
1
|
+
#include "internal.hpp"
|
|
2
|
+
|
|
3
|
+
namespace CaDiCaL {
|
|
4
|
+
|
|
5
|
+
/*------------------------------------------------------------------------*/
|
|
6
|
+
|
|
7
|
+
// Code for conflict analysis, i.e., to generate the first UIP clause. The
|
|
8
|
+
// main function is 'analyze' below. It further uses 'minimize' to minimize
|
|
9
|
+
// the first UIP clause, which is in 'minimize.cpp'. An important side
|
|
10
|
+
// effect of conflict analysis is to update the decision queue by bumping
|
|
11
|
+
// variables. Similarly analyzed clauses are bumped to mark them as active.
|
|
12
|
+
|
|
13
|
+
/*------------------------------------------------------------------------*/
|
|
14
|
+
|
|
15
|
+
void Internal::learn_empty_clause () {
|
|
16
|
+
assert (!unsat);
|
|
17
|
+
build_chain_for_empty ();
|
|
18
|
+
LOG ("learned empty clause");
|
|
19
|
+
external->check_learned_empty_clause ();
|
|
20
|
+
int64_t id = ++clause_id;
|
|
21
|
+
if (proof) {
|
|
22
|
+
proof->add_derived_empty_clause (id, lrat_chain);
|
|
23
|
+
}
|
|
24
|
+
unsat = true;
|
|
25
|
+
conflict_id = id;
|
|
26
|
+
marked_failed = true;
|
|
27
|
+
conclusion.push_back (id);
|
|
28
|
+
lrat_chain.clear ();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void Internal::learn_unit_clause (int lit) {
|
|
32
|
+
assert (!unsat);
|
|
33
|
+
LOG ("learned unit clause %d, stored at position %d", lit, vlit (lit));
|
|
34
|
+
external->check_learned_unit_clause (lit);
|
|
35
|
+
int64_t id = ++clause_id;
|
|
36
|
+
if (lrat || frat) {
|
|
37
|
+
const unsigned uidx = vlit (lit);
|
|
38
|
+
unit_clauses (uidx) = id;
|
|
39
|
+
}
|
|
40
|
+
if (proof) {
|
|
41
|
+
proof->add_derived_unit_clause (id, lit, lrat_chain);
|
|
42
|
+
}
|
|
43
|
+
mark_fixed (lit);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*------------------------------------------------------------------------*/
|
|
47
|
+
|
|
48
|
+
// Move bumped variables to the front of the (VMTF) decision queue. The
|
|
49
|
+
// 'bumped' time stamp is updated accordingly. It is used to determine
|
|
50
|
+
// whether the 'queue.assigned' pointer has to be moved in 'unassign'.
|
|
51
|
+
|
|
52
|
+
void Internal::bump_queue (int lit) {
|
|
53
|
+
assert (opts.bump);
|
|
54
|
+
const int idx = vidx (lit);
|
|
55
|
+
if (!links[idx].next)
|
|
56
|
+
return;
|
|
57
|
+
queue.dequeue (links, idx);
|
|
58
|
+
queue.enqueue (links, idx);
|
|
59
|
+
assert (stats.bumped != INT64_MAX);
|
|
60
|
+
btab[idx] = ++stats.bumped;
|
|
61
|
+
LOG ("moved to front variable %d and bumped to %" PRId64 "", idx,
|
|
62
|
+
btab[idx]);
|
|
63
|
+
if (!vals[idx])
|
|
64
|
+
update_queue_unassigned (idx);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*------------------------------------------------------------------------*/
|
|
68
|
+
|
|
69
|
+
// It would be better to use 'isinf' but there are some historical issues
|
|
70
|
+
// with this function. On some platforms it is a macro and even for C++ it
|
|
71
|
+
// changed the scope (in pre 5.0 gcc) from '::isinf' to 'std::isinf'. I do
|
|
72
|
+
// not want to worry about these strange incompatibilities and thus use the
|
|
73
|
+
// same trick as in older solvers (since the MiniSAT team invented EVSIDS)
|
|
74
|
+
// and simply put a hard limit here. It is less elegant but easy to port.
|
|
75
|
+
|
|
76
|
+
static inline bool evsids_limit_hit (double score) {
|
|
77
|
+
assert (sizeof (score) == 8); // assume IEEE 754 64-bit double
|
|
78
|
+
return score > 1e150; // MAX_DOUBLE is around 1.8e308
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/*------------------------------------------------------------------------*/
|
|
82
|
+
|
|
83
|
+
// Classical exponential VSIDS as pioneered by MiniSAT.
|
|
84
|
+
|
|
85
|
+
void Internal::rescale_variable_scores () {
|
|
86
|
+
stats.rescored++;
|
|
87
|
+
double divider = score_inc;
|
|
88
|
+
for (auto idx : vars) {
|
|
89
|
+
const double tmp = stab[idx];
|
|
90
|
+
if (tmp > divider)
|
|
91
|
+
divider = tmp;
|
|
92
|
+
}
|
|
93
|
+
PHASE ("rescore", stats.rescored, "rescoring %d variable scores by 1/%g",
|
|
94
|
+
max_var, divider);
|
|
95
|
+
assert (divider > 0);
|
|
96
|
+
double factor = 1.0 / divider;
|
|
97
|
+
for (auto idx : vars)
|
|
98
|
+
stab[idx] *= factor;
|
|
99
|
+
score_inc *= factor;
|
|
100
|
+
PHASE ("rescore", stats.rescored,
|
|
101
|
+
"new score increment %g after %" PRId64 " conflicts", score_inc,
|
|
102
|
+
stats.conflicts);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void Internal::bump_variable_score (int lit) {
|
|
106
|
+
assert (opts.bump);
|
|
107
|
+
int idx = vidx (lit);
|
|
108
|
+
double old_score = score (idx);
|
|
109
|
+
assert (!evsids_limit_hit (old_score));
|
|
110
|
+
double new_score = old_score + score_inc;
|
|
111
|
+
if (evsids_limit_hit (new_score)) {
|
|
112
|
+
LOG ("bumping %g score of %d hits EVSIDS score limit", old_score, idx);
|
|
113
|
+
rescale_variable_scores ();
|
|
114
|
+
old_score = score (idx);
|
|
115
|
+
assert (!evsids_limit_hit (old_score));
|
|
116
|
+
new_score = old_score + score_inc;
|
|
117
|
+
}
|
|
118
|
+
assert (!evsids_limit_hit (new_score));
|
|
119
|
+
LOG ("new %g score of %d", new_score, idx);
|
|
120
|
+
score (idx) = new_score;
|
|
121
|
+
if (scores.contains (idx))
|
|
122
|
+
scores.update (idx);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Important variables recently used in conflict analysis are 'bumped',
|
|
126
|
+
|
|
127
|
+
void Internal::bump_variable (int lit) {
|
|
128
|
+
if (use_scores ())
|
|
129
|
+
bump_variable_score (lit);
|
|
130
|
+
else
|
|
131
|
+
bump_queue (lit);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// After every conflict the variable score increment is increased by a
|
|
135
|
+
// factor (if we are currently using scores).
|
|
136
|
+
|
|
137
|
+
void Internal::bump_variable_score_inc () {
|
|
138
|
+
assert (use_scores ());
|
|
139
|
+
assert (!evsids_limit_hit (score_inc));
|
|
140
|
+
double f = 1e3 / opts.scorefactor;
|
|
141
|
+
double new_score_inc = score_inc * f;
|
|
142
|
+
if (evsids_limit_hit (new_score_inc)) {
|
|
143
|
+
LOG ("bumping %g increment by %g hits EVSIDS score limit", score_inc,
|
|
144
|
+
f);
|
|
145
|
+
rescale_variable_scores ();
|
|
146
|
+
new_score_inc = score_inc * f;
|
|
147
|
+
}
|
|
148
|
+
assert (!evsids_limit_hit (new_score_inc));
|
|
149
|
+
LOG ("bumped score increment from %g to %g with factor %g", score_inc,
|
|
150
|
+
new_score_inc, f);
|
|
151
|
+
score_inc = new_score_inc;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/*------------------------------------------------------------------------*/
|
|
155
|
+
|
|
156
|
+
struct analyze_bumped_rank {
|
|
157
|
+
Internal *internal;
|
|
158
|
+
analyze_bumped_rank (Internal *i) : internal (i) {}
|
|
159
|
+
typedef uint64_t Type;
|
|
160
|
+
Type operator() (const int &a) const { return internal->bumped (a); }
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
struct analyze_bumped_smaller {
|
|
164
|
+
Internal *internal;
|
|
165
|
+
analyze_bumped_smaller (Internal *i) : internal (i) {}
|
|
166
|
+
bool operator() (const int &a, const int &b) const {
|
|
167
|
+
const auto s = analyze_bumped_rank (internal) (a);
|
|
168
|
+
const auto t = analyze_bumped_rank (internal) (b);
|
|
169
|
+
return s < t;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/*------------------------------------------------------------------------*/
|
|
174
|
+
|
|
175
|
+
void Internal::bump_variables () {
|
|
176
|
+
|
|
177
|
+
assert (opts.bump);
|
|
178
|
+
|
|
179
|
+
START (bump);
|
|
180
|
+
|
|
181
|
+
if (!use_scores ()) {
|
|
182
|
+
|
|
183
|
+
// Variables are bumped in the order they are in the current decision
|
|
184
|
+
// queue. This maintains relative order between bumped variables in
|
|
185
|
+
// the queue and seems to work best. We also experimented with
|
|
186
|
+
// focusing on variables of the last decision level, but results were
|
|
187
|
+
// mixed.
|
|
188
|
+
|
|
189
|
+
MSORT (opts.radixsortlim, analyzed.begin (), analyzed.end (),
|
|
190
|
+
analyze_bumped_rank (this), analyze_bumped_smaller (this));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (const auto &lit : analyzed)
|
|
194
|
+
bump_variable (lit);
|
|
195
|
+
|
|
196
|
+
if (use_scores ())
|
|
197
|
+
bump_variable_score_inc ();
|
|
198
|
+
|
|
199
|
+
STOP (bump);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*------------------------------------------------------------------------*/
|
|
203
|
+
|
|
204
|
+
// We use the glue time stamp table 'gtab' for fast glue computation.
|
|
205
|
+
|
|
206
|
+
int Internal::recompute_glue (Clause *c) {
|
|
207
|
+
int res = 0;
|
|
208
|
+
const int64_t stamp = ++stats.recomputed;
|
|
209
|
+
for (const auto &lit : *c) {
|
|
210
|
+
assert (val (lit));
|
|
211
|
+
int level = var (lit).level;
|
|
212
|
+
assert (gtab[level] <= stamp);
|
|
213
|
+
if (gtab[level] == stamp)
|
|
214
|
+
continue;
|
|
215
|
+
gtab[level] = stamp;
|
|
216
|
+
res++;
|
|
217
|
+
}
|
|
218
|
+
return res;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Clauses resolved since the last reduction are marked as 'used', their
|
|
222
|
+
// glue is recomputed and they are promoted if the glue shrinks. Note that
|
|
223
|
+
// promotion from 'tier3' to 'tier2' will set 'used' to '2'.
|
|
224
|
+
|
|
225
|
+
inline void Internal::bump_clause (Clause *c) {
|
|
226
|
+
LOG (c, "bumping");
|
|
227
|
+
c->used = max_used;
|
|
228
|
+
if (c->hyper)
|
|
229
|
+
return;
|
|
230
|
+
if (!c->redundant)
|
|
231
|
+
return;
|
|
232
|
+
int new_glue = recompute_glue (c);
|
|
233
|
+
if (new_glue < c->glue)
|
|
234
|
+
promote_clause (c, new_glue);
|
|
235
|
+
|
|
236
|
+
const size_t glue =
|
|
237
|
+
std::min ((size_t) c->glue, stats.used[stable].size () - 1);
|
|
238
|
+
++stats.used[stable][glue];
|
|
239
|
+
++stats.bump_used[stable];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
void Internal::bump_clause2 (Clause *c) { bump_clause (c); }
|
|
243
|
+
/*------------------------------------------------------------------------*/
|
|
244
|
+
|
|
245
|
+
// During conflict analysis literals not seen yet either become part of the
|
|
246
|
+
// first unique implication point (UIP) clause (if on lower decision level),
|
|
247
|
+
// are dropped (if fixed), or are resolved away (if on the current decision
|
|
248
|
+
// level and different from the first UIP). At the same time we update the
|
|
249
|
+
// number of seen literals on a decision level. This helps conflict clause
|
|
250
|
+
// minimization. The number of seen levels is the glucose level (also
|
|
251
|
+
// called 'glue', or 'LBD').
|
|
252
|
+
|
|
253
|
+
inline void Internal::analyze_literal (int lit, int &open,
|
|
254
|
+
int &resolvent_size,
|
|
255
|
+
int &antecedent_size) {
|
|
256
|
+
assert (lit);
|
|
257
|
+
Var &v = var (lit);
|
|
258
|
+
Flags &f = flags (lit);
|
|
259
|
+
|
|
260
|
+
if (!v.level) {
|
|
261
|
+
if (f.seen || !lrat)
|
|
262
|
+
return;
|
|
263
|
+
f.seen = true;
|
|
264
|
+
unit_analyzed.push_back (lit);
|
|
265
|
+
assert (val (lit) < 0);
|
|
266
|
+
int64_t id = unit_id (-lit);
|
|
267
|
+
unit_chain.push_back (id);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
++antecedent_size;
|
|
271
|
+
if (f.seen)
|
|
272
|
+
return;
|
|
273
|
+
|
|
274
|
+
// before marking as seen, get reason and check for missed unit
|
|
275
|
+
|
|
276
|
+
assert (val (lit) < 0);
|
|
277
|
+
assert (v.level <= level);
|
|
278
|
+
if (v.reason == external_reason) {
|
|
279
|
+
assert (!opts.exteagerreasons);
|
|
280
|
+
v.reason = learn_external_reason_clause (-lit, 0, true);
|
|
281
|
+
if (!v.reason) { // actually a unit
|
|
282
|
+
--antecedent_size;
|
|
283
|
+
LOG ("%d unit after explanation", -lit);
|
|
284
|
+
if (f.seen || !lrat)
|
|
285
|
+
return;
|
|
286
|
+
f.seen = true;
|
|
287
|
+
unit_analyzed.push_back (lit);
|
|
288
|
+
assert (val (lit) < 0);
|
|
289
|
+
const unsigned uidx = vlit (-lit);
|
|
290
|
+
int64_t id = unit_clauses (uidx);
|
|
291
|
+
assert (id);
|
|
292
|
+
unit_chain.push_back (id);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
f.seen = true;
|
|
298
|
+
analyzed.push_back (lit);
|
|
299
|
+
|
|
300
|
+
assert (v.reason != external_reason);
|
|
301
|
+
if (v.level < level)
|
|
302
|
+
clause.push_back (lit);
|
|
303
|
+
Level &l = control[v.level];
|
|
304
|
+
if (!l.seen.count++) {
|
|
305
|
+
LOG ("found new level %d contributing to conflict", v.level);
|
|
306
|
+
levels.push_back (v.level);
|
|
307
|
+
}
|
|
308
|
+
if (v.trail < l.seen.trail)
|
|
309
|
+
l.seen.trail = v.trail;
|
|
310
|
+
++resolvent_size;
|
|
311
|
+
LOG ("analyzed literal %d assigned at level %d", lit, v.level);
|
|
312
|
+
if (v.level == level)
|
|
313
|
+
open++;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
inline void Internal::analyze_reason (int lit, Clause *reason, int &open,
|
|
317
|
+
int &resolvent_size,
|
|
318
|
+
int &antecedent_size) {
|
|
319
|
+
assert (reason);
|
|
320
|
+
assert (reason != external_reason);
|
|
321
|
+
bump_clause (reason);
|
|
322
|
+
if (lrat)
|
|
323
|
+
lrat_chain.push_back (reason->id);
|
|
324
|
+
for (const auto &other : *reason)
|
|
325
|
+
if (other != lit)
|
|
326
|
+
analyze_literal (other, open, resolvent_size, antecedent_size);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/*------------------------------------------------------------------------*/
|
|
330
|
+
|
|
331
|
+
// This is an idea which was implicit in MapleCOMSPS 2016 for 'limit = 1'.
|
|
332
|
+
// See also the paragraph on 'bumping reason side literals' in their SAT'16
|
|
333
|
+
// paper [LiangGaneshPoupartCzarnecki-SAT'16]. Reason side bumping was
|
|
334
|
+
// performed exactly when 'LRB' based decision heuristics was used, which in
|
|
335
|
+
// the original version was enabled after 10000 conflicts until a time limit
|
|
336
|
+
// of 2500 seconds was reached (half of the competition time limit). The
|
|
337
|
+
// Maple / Glucose / MiniSAT evolution winning the SAT race in 2019 made
|
|
338
|
+
// the schedule of reason side bumping deterministic, i.e., avoiding a time
|
|
339
|
+
// limit, by switching between 'LRB' and 'VSIDS' in an interval of initially
|
|
340
|
+
// 30 million propagations, which then is increased geometrically by 10%.
|
|
341
|
+
|
|
342
|
+
inline bool Internal::bump_also_reason_literal (int lit) {
|
|
343
|
+
assert (lit);
|
|
344
|
+
assert (val (lit) < 0);
|
|
345
|
+
Flags &f = flags (lit);
|
|
346
|
+
if (f.seen)
|
|
347
|
+
return false;
|
|
348
|
+
const Var &v = var (lit);
|
|
349
|
+
if (!v.level)
|
|
350
|
+
return false;
|
|
351
|
+
f.seen = true;
|
|
352
|
+
analyzed.push_back (lit);
|
|
353
|
+
LOG ("bumping also reason literal %d assigned at level %d", lit, v.level);
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// We experimented with deeper reason bumping without much success though.
|
|
358
|
+
|
|
359
|
+
inline void Internal::bump_also_reason_literals (int lit, int depth_limit,
|
|
360
|
+
size_t analyzed_limit) {
|
|
361
|
+
assert (lit);
|
|
362
|
+
assert (depth_limit > 0);
|
|
363
|
+
const Var &v = var (lit);
|
|
364
|
+
assert (val (lit));
|
|
365
|
+
if (!v.level)
|
|
366
|
+
return;
|
|
367
|
+
Clause *reason = v.reason;
|
|
368
|
+
if (!reason || reason == external_reason)
|
|
369
|
+
return;
|
|
370
|
+
stats.ticks.search[stable]++;
|
|
371
|
+
for (const auto &other : *reason) {
|
|
372
|
+
if (other == lit)
|
|
373
|
+
continue;
|
|
374
|
+
if (!bump_also_reason_literal (other))
|
|
375
|
+
continue;
|
|
376
|
+
if (depth_limit < 2)
|
|
377
|
+
continue;
|
|
378
|
+
bump_also_reason_literals (-other, depth_limit - 1, analyzed_limit);
|
|
379
|
+
if (analyzed.size () > analyzed_limit)
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
inline void Internal::bump_also_all_reason_literals () {
|
|
385
|
+
assert (opts.bump);
|
|
386
|
+
if (!opts.bumpreason)
|
|
387
|
+
return;
|
|
388
|
+
if (averages.current.decisions > opts.bumpreasonrate) {
|
|
389
|
+
LOG ("decisions per conflict rate %g > limit %d",
|
|
390
|
+
(double) averages.current.decisions, opts.bumpreasonrate);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (delay[stable].bumpreasons.limit) {
|
|
394
|
+
LOG ("delaying reason bumping %" PRId64 " more times",
|
|
395
|
+
delay[stable].bumpreasons.limit);
|
|
396
|
+
delay[stable].bumpreasons.limit--;
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
assert (opts.bumpreasondepth > 0);
|
|
400
|
+
const int depth_limit = opts.bumpreasondepth + stable;
|
|
401
|
+
size_t saved_analyzed = analyzed.size ();
|
|
402
|
+
size_t analyzed_limit = saved_analyzed * opts.bumpreasonlimit;
|
|
403
|
+
for (const auto &lit : clause)
|
|
404
|
+
if (analyzed.size () <= analyzed_limit)
|
|
405
|
+
bump_also_reason_literals (-lit, depth_limit, analyzed_limit);
|
|
406
|
+
else
|
|
407
|
+
break;
|
|
408
|
+
if (analyzed.size () > analyzed_limit) {
|
|
409
|
+
LOG ("not bumping reason side literals as limit exhausted");
|
|
410
|
+
for (size_t i = saved_analyzed; i != analyzed.size (); i++) {
|
|
411
|
+
const int lit = analyzed[i];
|
|
412
|
+
Flags &f = flags (lit);
|
|
413
|
+
assert (f.seen);
|
|
414
|
+
f.seen = false;
|
|
415
|
+
}
|
|
416
|
+
delay[stable].bumpreasons.interval++;
|
|
417
|
+
analyzed.resize (saved_analyzed);
|
|
418
|
+
} else {
|
|
419
|
+
LOG ("bumping reasons up to depth %d", opts.bumpreasondepth);
|
|
420
|
+
delay[stable].bumpreasons.interval /= 2;
|
|
421
|
+
}
|
|
422
|
+
LOG ("delay internal %" PRId64, delay[stable].bumpreasons.interval);
|
|
423
|
+
delay[stable].bumpreasons.limit = delay[stable].bumpreasons.interval;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/*------------------------------------------------------------------------*/
|
|
427
|
+
|
|
428
|
+
void Internal::clear_unit_analyzed_literals () {
|
|
429
|
+
LOG ("clearing %zd unit analyzed literals", unit_analyzed.size ());
|
|
430
|
+
for (const auto &lit : unit_analyzed) {
|
|
431
|
+
Flags &f = flags (lit);
|
|
432
|
+
assert (f.seen);
|
|
433
|
+
assert (!var (lit).level);
|
|
434
|
+
f.seen = false;
|
|
435
|
+
assert (!f.keep);
|
|
436
|
+
assert (!f.poison);
|
|
437
|
+
assert (!f.removable);
|
|
438
|
+
}
|
|
439
|
+
unit_analyzed.clear ();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
void Internal::clear_analyzed_literals () {
|
|
443
|
+
LOG ("clearing %zd analyzed literals", analyzed.size ());
|
|
444
|
+
for (const auto &lit : analyzed) {
|
|
445
|
+
Flags &f = flags (lit);
|
|
446
|
+
assert (f.seen);
|
|
447
|
+
f.seen = false;
|
|
448
|
+
assert (!f.keep);
|
|
449
|
+
assert (!f.poison);
|
|
450
|
+
assert (!f.removable);
|
|
451
|
+
}
|
|
452
|
+
analyzed.clear ();
|
|
453
|
+
#if 0 // to expensive, even for debugging mode
|
|
454
|
+
if (unit_analyzed.size ())
|
|
455
|
+
return;
|
|
456
|
+
for (auto idx : vars) {
|
|
457
|
+
Flags &f = flags (idx);
|
|
458
|
+
assert (!f.seen);
|
|
459
|
+
}
|
|
460
|
+
#endif
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
void Internal::clear_analyzed_levels () {
|
|
464
|
+
LOG ("clearing %zd analyzed levels", levels.size ());
|
|
465
|
+
for (const auto &l : levels)
|
|
466
|
+
if (l < (int) control.size ())
|
|
467
|
+
control[l].reset ();
|
|
468
|
+
levels.clear ();
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/*------------------------------------------------------------------------*/
|
|
472
|
+
|
|
473
|
+
// Smaller level and trail. Comparing literals on their level is necessary
|
|
474
|
+
// for chronological backtracking, since trail order might in this case not
|
|
475
|
+
// respect level order.
|
|
476
|
+
|
|
477
|
+
struct analyze_trail_negative_rank {
|
|
478
|
+
Internal *internal;
|
|
479
|
+
analyze_trail_negative_rank (Internal *s) : internal (s) {}
|
|
480
|
+
typedef uint64_t Type;
|
|
481
|
+
Type operator() (int a) {
|
|
482
|
+
Var &v = internal->var (a);
|
|
483
|
+
uint64_t res = v.level;
|
|
484
|
+
res <<= 32;
|
|
485
|
+
res |= v.trail;
|
|
486
|
+
return ~res;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
struct analyze_trail_larger {
|
|
491
|
+
Internal *internal;
|
|
492
|
+
analyze_trail_larger (Internal *s) : internal (s) {}
|
|
493
|
+
bool operator() (const int &a, const int &b) const {
|
|
494
|
+
return analyze_trail_negative_rank (internal) (a) <
|
|
495
|
+
analyze_trail_negative_rank (internal) (b);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/*------------------------------------------------------------------------*/
|
|
500
|
+
|
|
501
|
+
// Generate new driving clause and compute jump level.
|
|
502
|
+
|
|
503
|
+
Clause *Internal::new_driving_clause (const int glue, int &jump) {
|
|
504
|
+
|
|
505
|
+
const size_t size = clause.size ();
|
|
506
|
+
Clause *res;
|
|
507
|
+
|
|
508
|
+
if (!size) {
|
|
509
|
+
|
|
510
|
+
jump = 0;
|
|
511
|
+
res = 0;
|
|
512
|
+
|
|
513
|
+
} else if (size == 1) {
|
|
514
|
+
|
|
515
|
+
iterating = true;
|
|
516
|
+
jump = 0;
|
|
517
|
+
res = 0;
|
|
518
|
+
|
|
519
|
+
} else {
|
|
520
|
+
|
|
521
|
+
assert (clause.size () > 1);
|
|
522
|
+
|
|
523
|
+
// We have to get the last assigned literals into the watch position.
|
|
524
|
+
// Sorting all literals with respect to reverse assignment order is
|
|
525
|
+
// overkill but seems to get slightly faster run-time. For 'minimize'
|
|
526
|
+
// we sort the literals too heuristically along the trail order (so in
|
|
527
|
+
// the opposite order) with the hope to hit the recursion limit less
|
|
528
|
+
// frequently. Thus sorting effort is doubled here.
|
|
529
|
+
//
|
|
530
|
+
MSORT (opts.radixsortlim, clause.begin (), clause.end (),
|
|
531
|
+
analyze_trail_negative_rank (this), analyze_trail_larger (this));
|
|
532
|
+
|
|
533
|
+
jump = var (clause[1]).level;
|
|
534
|
+
res = new_learned_redundant_clause (glue);
|
|
535
|
+
res->used = max_used;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
LOG ("jump level %d", jump);
|
|
539
|
+
|
|
540
|
+
return res;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/*------------------------------------------------------------------------*/
|
|
544
|
+
|
|
545
|
+
// determine the OTFS level for OTFS. Unlike the find_conflict_level, we do
|
|
546
|
+
// not have to fix the clause
|
|
547
|
+
|
|
548
|
+
inline int Internal::otfs_find_backtrack_level (int &forced) {
|
|
549
|
+
assert (opts.otfs);
|
|
550
|
+
int res = 0;
|
|
551
|
+
|
|
552
|
+
for (const auto &lit : *conflict) {
|
|
553
|
+
const int tmp = var (lit).level;
|
|
554
|
+
if (tmp == level) {
|
|
555
|
+
forced = lit;
|
|
556
|
+
} else if (tmp > res) {
|
|
557
|
+
res = tmp;
|
|
558
|
+
LOG ("bt level is now %d due to %d", res, lit);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return res;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/*------------------------------------------------------------------------*/
|
|
565
|
+
|
|
566
|
+
// If chronological backtracking is enabled we need to find the actual
|
|
567
|
+
// conflict level and then potentially can also reuse the conflict clause
|
|
568
|
+
// as driving clause instead of deriving a redundant new driving clause
|
|
569
|
+
// (forcing 'forced') if the number 'count' of literals in conflict assigned
|
|
570
|
+
// at the conflict level is exactly one.
|
|
571
|
+
|
|
572
|
+
inline int Internal::find_conflict_level (int &forced) {
|
|
573
|
+
|
|
574
|
+
assert (conflict);
|
|
575
|
+
assert (opts.chrono || opts.otfs || external_prop);
|
|
576
|
+
|
|
577
|
+
int res = 0, count = 0;
|
|
578
|
+
|
|
579
|
+
forced = 0;
|
|
580
|
+
|
|
581
|
+
for (const auto &lit : *conflict) {
|
|
582
|
+
const int tmp = var (lit).level;
|
|
583
|
+
if (tmp > res) {
|
|
584
|
+
res = tmp;
|
|
585
|
+
forced = lit;
|
|
586
|
+
count = 1;
|
|
587
|
+
} else if (tmp == res) {
|
|
588
|
+
count++;
|
|
589
|
+
if (res == level && count > 1)
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
LOG ("%d literals on actual conflict level %d", count, res);
|
|
595
|
+
|
|
596
|
+
const int size = conflict->size;
|
|
597
|
+
int *lits = conflict->literals;
|
|
598
|
+
|
|
599
|
+
// Move the two highest level literals to the front.
|
|
600
|
+
//
|
|
601
|
+
for (int i = 0; i < 2; i++) {
|
|
602
|
+
|
|
603
|
+
const int lit = lits[i];
|
|
604
|
+
|
|
605
|
+
int highest_position = i;
|
|
606
|
+
int highest_literal = lit;
|
|
607
|
+
int highest_level = var (highest_literal).level;
|
|
608
|
+
|
|
609
|
+
for (int j = i + 1; j < size; j++) {
|
|
610
|
+
const int other = lits[j];
|
|
611
|
+
const int tmp = var (other).level;
|
|
612
|
+
if (highest_level >= tmp)
|
|
613
|
+
continue;
|
|
614
|
+
highest_literal = other;
|
|
615
|
+
highest_position = j;
|
|
616
|
+
highest_level = tmp;
|
|
617
|
+
if (highest_level == res)
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// No unwatched higher assignment level literal.
|
|
622
|
+
//
|
|
623
|
+
if (highest_position == i)
|
|
624
|
+
continue;
|
|
625
|
+
|
|
626
|
+
if (highest_position > 1) {
|
|
627
|
+
LOG (conflict, "unwatch %d in", lit);
|
|
628
|
+
remove_watch (watches (lit), conflict);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
lits[highest_position] = lit;
|
|
632
|
+
lits[i] = highest_literal;
|
|
633
|
+
|
|
634
|
+
if (highest_position > 1)
|
|
635
|
+
watch_literal (highest_literal, lits[!i], conflict);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Only if the number of highest level literals in the conflict is one
|
|
639
|
+
// then we can reuse the conflict clause as driving clause for 'forced'.
|
|
640
|
+
//
|
|
641
|
+
if (count != 1)
|
|
642
|
+
forced = 0;
|
|
643
|
+
|
|
644
|
+
return res;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/*------------------------------------------------------------------------*/
|
|
648
|
+
|
|
649
|
+
inline int Internal::determine_actual_backtrack_level (int jump) {
|
|
650
|
+
|
|
651
|
+
int res;
|
|
652
|
+
|
|
653
|
+
assert (level > jump);
|
|
654
|
+
|
|
655
|
+
if (!opts.chrono) {
|
|
656
|
+
res = jump;
|
|
657
|
+
LOG ("chronological backtracking disabled using jump level %d", res);
|
|
658
|
+
} else if (opts.chronoalways) {
|
|
659
|
+
stats.chrono++;
|
|
660
|
+
res = level - 1;
|
|
661
|
+
LOG ("forced chronological backtracking to level %d", res);
|
|
662
|
+
} else if (jump >= level - 1) {
|
|
663
|
+
res = jump;
|
|
664
|
+
LOG ("jump level identical to chronological backtrack level %d", res);
|
|
665
|
+
} else if ((size_t) jump < assumptions.size ()) {
|
|
666
|
+
res = jump;
|
|
667
|
+
LOG ("using jump level %d since it is lower than assumption level %zd",
|
|
668
|
+
res, assumptions.size ());
|
|
669
|
+
} else if (level - jump > opts.chronolevelim) {
|
|
670
|
+
stats.chrono++;
|
|
671
|
+
res = level - 1;
|
|
672
|
+
LOG ("back-jumping over %d > %d levels prohibited"
|
|
673
|
+
"thus backtracking chronologically to level %d",
|
|
674
|
+
level - jump, opts.chronolevelim, res);
|
|
675
|
+
} else if (opts.chronoreusetrail) {
|
|
676
|
+
int best_idx = 0, best_pos = 0;
|
|
677
|
+
|
|
678
|
+
if (use_scores ()) {
|
|
679
|
+
for (size_t i = control[jump + 1].trail; i < trail.size (); i++) {
|
|
680
|
+
const int idx = abs (trail[i]);
|
|
681
|
+
if (best_idx && !score_smaller (this) (best_idx, idx))
|
|
682
|
+
continue;
|
|
683
|
+
best_idx = idx;
|
|
684
|
+
best_pos = i;
|
|
685
|
+
}
|
|
686
|
+
LOG ("best variable score %g", score (best_idx));
|
|
687
|
+
} else {
|
|
688
|
+
for (size_t i = control[jump + 1].trail; i < trail.size (); i++) {
|
|
689
|
+
const int idx = abs (trail[i]);
|
|
690
|
+
if (best_idx && bumped (best_idx) >= bumped (idx))
|
|
691
|
+
continue;
|
|
692
|
+
best_idx = idx;
|
|
693
|
+
best_pos = i;
|
|
694
|
+
}
|
|
695
|
+
LOG ("best variable bumped %" PRId64 "", bumped (best_idx));
|
|
696
|
+
}
|
|
697
|
+
assert (best_idx);
|
|
698
|
+
LOG ("best variable %d at trail position %d", best_idx, best_pos);
|
|
699
|
+
|
|
700
|
+
// Now find the frame and decision level in the control stack of that
|
|
701
|
+
// best variable index. Note that, as in 'reuse_trail', the frame
|
|
702
|
+
// 'control[i]' for decision level 'i' contains the trail before that
|
|
703
|
+
// decision level, i.e., the decision 'control[i].decision' sits at
|
|
704
|
+
// 'control[i].trail' in the trail and we thus have to check the level
|
|
705
|
+
// of the control frame one higher than at the result level.
|
|
706
|
+
//
|
|
707
|
+
res = jump;
|
|
708
|
+
while (res < level - 1 && control[res + 1].trail <= best_pos)
|
|
709
|
+
res++;
|
|
710
|
+
|
|
711
|
+
if (res == jump)
|
|
712
|
+
LOG ("default non-chronological back-jumping to level %d", res);
|
|
713
|
+
else {
|
|
714
|
+
stats.chrono++;
|
|
715
|
+
LOG ("chronological backtracking to level %d to reuse trail", res);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
} else {
|
|
719
|
+
res = jump;
|
|
720
|
+
LOG ("non-chronological back-jumping to level %d", res);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return res;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/*------------------------------------------------------------------------*/
|
|
727
|
+
|
|
728
|
+
void Internal::eagerly_subsume_recently_learned_clauses (Clause *c) {
|
|
729
|
+
assert (opts.eagersubsume);
|
|
730
|
+
LOG (c, "trying eager subsumption with");
|
|
731
|
+
mark (c);
|
|
732
|
+
int64_t lim = stats.eagertried + opts.eagersubsumelim;
|
|
733
|
+
const auto begin = clauses.begin ();
|
|
734
|
+
auto it = clauses.end ();
|
|
735
|
+
#ifdef LOGGING
|
|
736
|
+
int64_t before = stats.eagersub;
|
|
737
|
+
#endif
|
|
738
|
+
while (it != begin && stats.eagertried++ <= lim) {
|
|
739
|
+
Clause *d = *--it;
|
|
740
|
+
if (c == d)
|
|
741
|
+
continue;
|
|
742
|
+
if (d->garbage)
|
|
743
|
+
continue;
|
|
744
|
+
if (!d->redundant)
|
|
745
|
+
continue;
|
|
746
|
+
int needed = c->size;
|
|
747
|
+
for (auto &lit : *d) {
|
|
748
|
+
if (marked (lit) <= 0)
|
|
749
|
+
continue;
|
|
750
|
+
if (!--needed)
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
if (needed)
|
|
754
|
+
continue;
|
|
755
|
+
LOG (d, "eager subsumed");
|
|
756
|
+
stats.eagersub++;
|
|
757
|
+
stats.subsumed++;
|
|
758
|
+
mark_garbage (d);
|
|
759
|
+
}
|
|
760
|
+
unmark (c);
|
|
761
|
+
#ifdef LOGGING
|
|
762
|
+
uint64_t subsumed = stats.eagersub - before;
|
|
763
|
+
if (subsumed)
|
|
764
|
+
LOG ("eagerly subsumed %" PRIu64 " clauses", subsumed);
|
|
765
|
+
#endif
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/*------------------------------------------------------------------------*/
|
|
769
|
+
|
|
770
|
+
Clause *Internal::on_the_fly_strengthen (Clause *new_conflict, int uip) {
|
|
771
|
+
assert (new_conflict);
|
|
772
|
+
assert (new_conflict->size > 2);
|
|
773
|
+
LOG (new_conflict, "applying OTFS on lit %d", uip);
|
|
774
|
+
auto sorted = std::vector<int> ();
|
|
775
|
+
sorted.reserve (new_conflict->size);
|
|
776
|
+
assert (sorted.empty ());
|
|
777
|
+
++stats.otfs.strengthened;
|
|
778
|
+
|
|
779
|
+
int *lits = new_conflict->literals;
|
|
780
|
+
|
|
781
|
+
assert (lits[0] == uip || lits[1] == uip);
|
|
782
|
+
const int other_init = lits[0] ^ lits[1] ^ uip;
|
|
783
|
+
|
|
784
|
+
assert (mini_chain.empty ());
|
|
785
|
+
|
|
786
|
+
const int old_size = new_conflict->size;
|
|
787
|
+
int new_size = 0;
|
|
788
|
+
for (int i = 0; i < old_size; ++i) {
|
|
789
|
+
const int other = lits[i];
|
|
790
|
+
sorted.push_back (other);
|
|
791
|
+
if (var (other).level)
|
|
792
|
+
lits[new_size++] = other;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
LOG (new_conflict, "removing all units in");
|
|
796
|
+
|
|
797
|
+
assert (lits[0] == uip || lits[1] == uip);
|
|
798
|
+
const int other = lits[0] ^ lits[1] ^ uip;
|
|
799
|
+
lits[0] = other;
|
|
800
|
+
lits[1] = lits[--new_size];
|
|
801
|
+
LOG (new_conflict, "putting uip at pos 1");
|
|
802
|
+
|
|
803
|
+
if (other_init != other)
|
|
804
|
+
remove_watch (watches (other_init), new_conflict);
|
|
805
|
+
remove_watch (watches (uip), new_conflict);
|
|
806
|
+
|
|
807
|
+
assert (!lrat || lrat_chain.back () == new_conflict->id);
|
|
808
|
+
if (lrat) {
|
|
809
|
+
assert (!lrat_chain.empty ());
|
|
810
|
+
for (const auto &id : unit_chain) {
|
|
811
|
+
mini_chain.push_back (id);
|
|
812
|
+
}
|
|
813
|
+
const auto end = lrat_chain.rend ();
|
|
814
|
+
const auto begin = lrat_chain.rbegin ();
|
|
815
|
+
for (auto i = begin; i != end; i++) {
|
|
816
|
+
const auto id = *i;
|
|
817
|
+
mini_chain.push_back (id);
|
|
818
|
+
}
|
|
819
|
+
lrat_chain.clear ();
|
|
820
|
+
clear_unit_analyzed_literals ();
|
|
821
|
+
unit_chain.clear ();
|
|
822
|
+
}
|
|
823
|
+
assert (unit_analyzed.empty ());
|
|
824
|
+
// sort the clause
|
|
825
|
+
{
|
|
826
|
+
int highest_pos = 0;
|
|
827
|
+
int highest_level = 0;
|
|
828
|
+
for (int i = 1; i < new_size; i++) {
|
|
829
|
+
const unsigned other = lits[i];
|
|
830
|
+
assert (val (other) < 0);
|
|
831
|
+
const int level = var (other).level;
|
|
832
|
+
assert (level);
|
|
833
|
+
LOG ("checking %d", other);
|
|
834
|
+
if (level <= highest_level)
|
|
835
|
+
continue;
|
|
836
|
+
highest_pos = i;
|
|
837
|
+
highest_level = level;
|
|
838
|
+
}
|
|
839
|
+
LOG ("highest lit is %d", lits[highest_pos]);
|
|
840
|
+
if (highest_pos != 1)
|
|
841
|
+
swap (lits[1], lits[highest_pos]);
|
|
842
|
+
LOG ("removing %d literals", new_conflict->size - new_size);
|
|
843
|
+
|
|
844
|
+
if (new_size == 1) {
|
|
845
|
+
LOG (new_conflict, "new size = 1, so interrupting");
|
|
846
|
+
assert (!opts.exteagerreasons);
|
|
847
|
+
return 0;
|
|
848
|
+
} else {
|
|
849
|
+
otfs_strengthen_clause (new_conflict, uip, new_size, sorted);
|
|
850
|
+
assert (new_size == new_conflict->size);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
if (other_init != other)
|
|
855
|
+
watch_literal (other, lits[1], new_conflict);
|
|
856
|
+
else {
|
|
857
|
+
update_watch_size (watches (other), lits[1], new_conflict);
|
|
858
|
+
}
|
|
859
|
+
watch_literal (lits[1], other, new_conflict);
|
|
860
|
+
|
|
861
|
+
LOG (new_conflict, "strengthened clause by OTFS");
|
|
862
|
+
sorted.clear ();
|
|
863
|
+
|
|
864
|
+
return new_conflict;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/*------------------------------------------------------------------------*/
|
|
868
|
+
inline void Internal::otfs_subsume_clause (Clause *subsuming,
|
|
869
|
+
Clause *subsumed) {
|
|
870
|
+
stats.subsumed++;
|
|
871
|
+
assert (subsuming->size <= subsumed->size);
|
|
872
|
+
LOG (subsumed, "subsumed");
|
|
873
|
+
if (subsumed->redundant)
|
|
874
|
+
stats.subred++;
|
|
875
|
+
else
|
|
876
|
+
stats.subirr++;
|
|
877
|
+
if (subsumed->redundant || !subsuming->redundant) {
|
|
878
|
+
mark_garbage (subsumed);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
LOG ("turning redundant subsuming clause into irredundant clause");
|
|
882
|
+
subsuming->redundant = false;
|
|
883
|
+
if (proof)
|
|
884
|
+
proof->strengthen (subsuming->id);
|
|
885
|
+
mark_garbage (subsumed);
|
|
886
|
+
stats.current.irredundant++;
|
|
887
|
+
stats.added.irredundant++;
|
|
888
|
+
stats.irrlits += subsuming->size;
|
|
889
|
+
assert (stats.current.redundant > 0);
|
|
890
|
+
stats.current.redundant--;
|
|
891
|
+
assert (stats.added.redundant > 0);
|
|
892
|
+
stats.added.redundant--;
|
|
893
|
+
// ... and keep 'stats.added.total'.
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/*------------------------------------------------------------------------*/
|
|
897
|
+
|
|
898
|
+
// Candidate clause 'c' is strengthened by removing 'lit' and units.
|
|
899
|
+
//
|
|
900
|
+
void Internal::otfs_strengthen_clause (Clause *c, int lit, int new_size,
|
|
901
|
+
const std::vector<int> &old) {
|
|
902
|
+
stats.strengthened++;
|
|
903
|
+
assert (c->size > 2);
|
|
904
|
+
(void) shrink_clause (c, new_size);
|
|
905
|
+
if (proof) {
|
|
906
|
+
proof->otfs_strengthen_clause (c, old, mini_chain);
|
|
907
|
+
}
|
|
908
|
+
if (!c->redundant) {
|
|
909
|
+
mark_removed (lit);
|
|
910
|
+
}
|
|
911
|
+
mini_chain.clear ();
|
|
912
|
+
c->used = max_used;
|
|
913
|
+
LOG (c, "strengthened");
|
|
914
|
+
external->check_shrunken_clause (c);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/*------------------------------------------------------------------------*/
|
|
918
|
+
|
|
919
|
+
// If the average number of decisions per conflict (analysis actually so not
|
|
920
|
+
// taking OTFS conflicts into account) is high we do not bump reasons. This
|
|
921
|
+
// is the function which updates the exponential moving decision rate
|
|
922
|
+
// average.
|
|
923
|
+
|
|
924
|
+
void Internal::update_decision_rate_average () {
|
|
925
|
+
int64_t current = stats.decisions;
|
|
926
|
+
int64_t decisions = current - saved_decisions;
|
|
927
|
+
UPDATE_AVERAGE (averages.current.decisions, decisions);
|
|
928
|
+
saved_decisions = current;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/*------------------------------------------------------------------------*/
|
|
932
|
+
|
|
933
|
+
// This is the main conflict analysis routine. It assumes that a conflict
|
|
934
|
+
// was found. Then we derive the 1st UIP clause, optionally minimize it,
|
|
935
|
+
// add it as learned clause, and then uses the clause for conflict directed
|
|
936
|
+
// back-jumping and flipping the 1st UIP literal. In combination with
|
|
937
|
+
// chronological backtracking (see discussion above) the algorithm becomes
|
|
938
|
+
// slightly more involved.
|
|
939
|
+
|
|
940
|
+
void Internal::analyze () {
|
|
941
|
+
|
|
942
|
+
START (analyze);
|
|
943
|
+
|
|
944
|
+
assert (conflict);
|
|
945
|
+
assert (lrat_chain.empty ());
|
|
946
|
+
assert (unit_chain.empty ());
|
|
947
|
+
assert (unit_analyzed.empty ());
|
|
948
|
+
assert (clause.empty ());
|
|
949
|
+
|
|
950
|
+
// First update moving averages of trail height at conflict.
|
|
951
|
+
//
|
|
952
|
+
UPDATE_AVERAGE (averages.current.trail.fast, num_assigned);
|
|
953
|
+
UPDATE_AVERAGE (averages.current.trail.slow, num_assigned);
|
|
954
|
+
update_decision_rate_average ();
|
|
955
|
+
|
|
956
|
+
/*----------------------------------------------------------------------*/
|
|
957
|
+
|
|
958
|
+
if (external_prop && !external_prop_is_lazy && opts.exteagerreasons) {
|
|
959
|
+
explain_external_propagations ();
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
if (opts.chrono || external_prop) {
|
|
963
|
+
|
|
964
|
+
int forced;
|
|
965
|
+
|
|
966
|
+
const int conflict_level = find_conflict_level (forced);
|
|
967
|
+
|
|
968
|
+
// In principle we can perform conflict analysis as in non-chronological
|
|
969
|
+
// backtracking except if there is only one literal with the maximum
|
|
970
|
+
// assignment level in the clause. Then standard conflict analysis is
|
|
971
|
+
// unnecessary and we can use the conflict as a driving clause. In the
|
|
972
|
+
// pseudo code of the SAT'18 paper on chronological backtracking this
|
|
973
|
+
// corresponds to the situation handled in line 4-6 in Alg. 1, except
|
|
974
|
+
// that the pseudo code in the paper only backtracks while we eagerly
|
|
975
|
+
// assign the single literal on the highest decision level.
|
|
976
|
+
|
|
977
|
+
if (forced) {
|
|
978
|
+
|
|
979
|
+
assert (forced);
|
|
980
|
+
assert (conflict_level > 0);
|
|
981
|
+
LOG ("single highest level literal %d", forced);
|
|
982
|
+
|
|
983
|
+
// The pseudo code in the SAT'18 paper actually backtracks to the
|
|
984
|
+
// 'second highest decision' level, while their code backtracks
|
|
985
|
+
// to 'conflict_level-1', which is more in the spirit of chronological
|
|
986
|
+
// backtracking anyhow and thus we also do the latter.
|
|
987
|
+
//
|
|
988
|
+
backtrack (conflict_level - 1);
|
|
989
|
+
|
|
990
|
+
// if we are on decision level 0 search assign will learn unit
|
|
991
|
+
// so we need a valid chain here (of course if we are not on decision
|
|
992
|
+
// level 0 this will not result in a valid chain).
|
|
993
|
+
// we can just use build_chain_for_units in propagate
|
|
994
|
+
//
|
|
995
|
+
build_chain_for_units (forced, conflict, 0);
|
|
996
|
+
|
|
997
|
+
LOG ("forcing %d", forced);
|
|
998
|
+
search_assign_driving (forced, conflict);
|
|
999
|
+
|
|
1000
|
+
conflict = 0;
|
|
1001
|
+
if (!opts.chrono)
|
|
1002
|
+
did_external_prop = true;
|
|
1003
|
+
STOP (analyze);
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Backtracking to the conflict level is in the pseudo code in the
|
|
1008
|
+
// SAT'18 chronological backtracking paper, but not in their actual
|
|
1009
|
+
// implementation. In principle we do not need to backtrack here.
|
|
1010
|
+
// However, as a side effect of backtracking to the conflict level we
|
|
1011
|
+
// set 'level' to the conflict level which then allows us to reuse the
|
|
1012
|
+
// old 'analyze' code as is. The alternative (which we also tried but
|
|
1013
|
+
// then abandoned) is to use 'conflict_level' instead of 'level' in the
|
|
1014
|
+
// analysis, which however requires to pass it to the 'analyze_reason'
|
|
1015
|
+
// and 'analyze_literal' functions.
|
|
1016
|
+
//
|
|
1017
|
+
backtrack (conflict_level);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// Actual conflict on root level, thus formula unsatisfiable.
|
|
1021
|
+
//
|
|
1022
|
+
if (!level) {
|
|
1023
|
+
learn_empty_clause ();
|
|
1024
|
+
if (external->learner)
|
|
1025
|
+
external->export_learned_empty_clause ();
|
|
1026
|
+
STOP (analyze);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/*----------------------------------------------------------------------*/
|
|
1031
|
+
|
|
1032
|
+
// First derive the 1st UIP clause by going over literals assigned on the
|
|
1033
|
+
// current decision level. Literals in the conflict are marked as 'seen'
|
|
1034
|
+
// as well as all literals in reason clauses of already 'seen' literals on
|
|
1035
|
+
// the current decision level. Thus the outer loop starts with the
|
|
1036
|
+
// conflict clause as 'reason' and then uses the 'reason' of the next
|
|
1037
|
+
// seen literal on the trail assigned on the current decision level.
|
|
1038
|
+
// During this process maintain the number 'open' of seen literals on the
|
|
1039
|
+
// current decision level with not yet processed 'reason'. As soon 'open'
|
|
1040
|
+
// drops to one, we have found the first unique implication point. This
|
|
1041
|
+
// is sound because the topological order in which literals are processed
|
|
1042
|
+
// follows the assignment order and a more complex algorithm to find
|
|
1043
|
+
// articulation points is not necessary.
|
|
1044
|
+
//
|
|
1045
|
+
Clause *reason = conflict;
|
|
1046
|
+
LOG (reason, "analyzing conflict");
|
|
1047
|
+
|
|
1048
|
+
assert (clause.empty ());
|
|
1049
|
+
assert (lrat_chain.empty ());
|
|
1050
|
+
|
|
1051
|
+
const auto &t = &trail;
|
|
1052
|
+
int i = t->size (); // Start at end-of-trail.
|
|
1053
|
+
int open = 0; // Seen but not processed on this level.
|
|
1054
|
+
int uip = 0; // The first UIP literal.
|
|
1055
|
+
int resolvent_size = 0; // without the uip
|
|
1056
|
+
int antecedent_size = 1; // with the uip and without unit literals
|
|
1057
|
+
int conflict_size = 0; // without the uip and without unit literals
|
|
1058
|
+
int resolved = 0; // number of resolution (0 = clause in CNF)
|
|
1059
|
+
const bool otfs = opts.otfs;
|
|
1060
|
+
|
|
1061
|
+
for (;;) {
|
|
1062
|
+
antecedent_size = 1; // for uip
|
|
1063
|
+
analyze_reason (uip, reason, open, resolvent_size, antecedent_size);
|
|
1064
|
+
if (resolved == 0)
|
|
1065
|
+
conflict_size = antecedent_size - 1;
|
|
1066
|
+
assert (resolvent_size == open + (int) clause.size ());
|
|
1067
|
+
|
|
1068
|
+
if (otfs && resolved > 0 && antecedent_size > 2 &&
|
|
1069
|
+
resolvent_size < antecedent_size) {
|
|
1070
|
+
assert (reason != conflict);
|
|
1071
|
+
LOG (analyzed, "found candidate for OTFS conflict");
|
|
1072
|
+
LOG (clause, "found candidate for OTFS conflict");
|
|
1073
|
+
LOG (reason, "found candidate (size %d) for OTFS resolvent",
|
|
1074
|
+
antecedent_size);
|
|
1075
|
+
const int other = reason->literals[0] ^ reason->literals[1] ^ uip;
|
|
1076
|
+
assert (other != uip);
|
|
1077
|
+
reason = on_the_fly_strengthen (reason, uip);
|
|
1078
|
+
if (opts.bump)
|
|
1079
|
+
bump_variables ();
|
|
1080
|
+
|
|
1081
|
+
assert (conflict_size);
|
|
1082
|
+
if (!reason) {
|
|
1083
|
+
uip = -other;
|
|
1084
|
+
assert (open == 1);
|
|
1085
|
+
LOG ("clause is actually unit %d, stopping", -uip);
|
|
1086
|
+
reverse (begin (mini_chain), end (mini_chain));
|
|
1087
|
+
for (auto id : mini_chain)
|
|
1088
|
+
lrat_chain.push_back (id);
|
|
1089
|
+
mini_chain.clear ();
|
|
1090
|
+
clear_analyzed_levels ();
|
|
1091
|
+
assert (!opts.exteagerreasons);
|
|
1092
|
+
clause.clear ();
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
assert (conflict_size >= 2);
|
|
1096
|
+
|
|
1097
|
+
if (resolved == 1 && resolvent_size < conflict_size) {
|
|
1098
|
+
// here both clauses are part of the CNF, so one subsumes the other
|
|
1099
|
+
otfs_subsume_clause (reason, conflict);
|
|
1100
|
+
LOG (reason, "changing conflict to");
|
|
1101
|
+
--conflict_size;
|
|
1102
|
+
assert (conflict_size == reason->size);
|
|
1103
|
+
++stats.otfs.subsumed;
|
|
1104
|
+
++stats.subsumed;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
LOG (reason, "changing conflict to");
|
|
1108
|
+
conflict = reason;
|
|
1109
|
+
if (open == 1) {
|
|
1110
|
+
int forced = 0;
|
|
1111
|
+
const int conflict_level = otfs_find_backtrack_level (forced);
|
|
1112
|
+
int new_level = determine_actual_backtrack_level (conflict_level);
|
|
1113
|
+
UPDATE_AVERAGE (averages.current.level, new_level);
|
|
1114
|
+
backtrack (new_level);
|
|
1115
|
+
|
|
1116
|
+
LOG ("forcing %d", forced);
|
|
1117
|
+
search_assign_driving (forced, conflict);
|
|
1118
|
+
|
|
1119
|
+
// Clean up.
|
|
1120
|
+
//
|
|
1121
|
+
conflict = 0;
|
|
1122
|
+
clear_analyzed_literals ();
|
|
1123
|
+
clear_analyzed_levels ();
|
|
1124
|
+
clause.clear ();
|
|
1125
|
+
STOP (analyze);
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
stats.conflicts++;
|
|
1130
|
+
|
|
1131
|
+
clear_analyzed_literals ();
|
|
1132
|
+
clear_analyzed_levels ();
|
|
1133
|
+
clause.clear ();
|
|
1134
|
+
resolvent_size = 0;
|
|
1135
|
+
antecedent_size = 1;
|
|
1136
|
+
resolved = 0;
|
|
1137
|
+
open = 0;
|
|
1138
|
+
analyze_reason (0, reason, open, resolvent_size, antecedent_size);
|
|
1139
|
+
conflict_size = antecedent_size - 1;
|
|
1140
|
+
assert (open > 1);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
++resolved;
|
|
1144
|
+
|
|
1145
|
+
uip = 0;
|
|
1146
|
+
while (!uip) {
|
|
1147
|
+
if (!i) {
|
|
1148
|
+
lazy_external_propagator_out_of_order_clause (uip);
|
|
1149
|
+
if (unsat)
|
|
1150
|
+
return;
|
|
1151
|
+
else if (uip) {
|
|
1152
|
+
open = 1;
|
|
1153
|
+
break;
|
|
1154
|
+
} else {
|
|
1155
|
+
LOG (reason, "restarting the analysis on the new conflict");
|
|
1156
|
+
++stats.conflicts;
|
|
1157
|
+
reason = conflict;
|
|
1158
|
+
resolvent_size = 0;
|
|
1159
|
+
antecedent_size = 1;
|
|
1160
|
+
resolved = 0;
|
|
1161
|
+
open = 0;
|
|
1162
|
+
analyze_reason (0, reason, open, resolvent_size, antecedent_size);
|
|
1163
|
+
conflict_size = antecedent_size - 1;
|
|
1164
|
+
assert (open > 1);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
assert (i > 0);
|
|
1168
|
+
const int lit = (*t)[--i];
|
|
1169
|
+
if (!flags (lit).seen)
|
|
1170
|
+
continue;
|
|
1171
|
+
if (var (lit).level == level)
|
|
1172
|
+
uip = lit;
|
|
1173
|
+
}
|
|
1174
|
+
if (!--open)
|
|
1175
|
+
break;
|
|
1176
|
+
reason = var (uip).reason;
|
|
1177
|
+
if (reason == external_reason) {
|
|
1178
|
+
assert (!opts.exteagerreasons);
|
|
1179
|
+
reason = learn_external_reason_clause (-uip, 0, true);
|
|
1180
|
+
var (uip).reason = reason;
|
|
1181
|
+
}
|
|
1182
|
+
assert (reason != external_reason);
|
|
1183
|
+
LOG (reason, "analyzing %d reason", uip);
|
|
1184
|
+
assert (resolvent_size);
|
|
1185
|
+
--resolvent_size;
|
|
1186
|
+
}
|
|
1187
|
+
LOG ("first UIP %d", uip);
|
|
1188
|
+
clause.push_back (-uip);
|
|
1189
|
+
|
|
1190
|
+
// Update glue and learned (1st UIP literals) statistics.
|
|
1191
|
+
//
|
|
1192
|
+
int size = (int) clause.size ();
|
|
1193
|
+
const int glue = (int) levels.size () - 1;
|
|
1194
|
+
LOG (clause, "1st UIP size %d and glue %d clause", size, glue);
|
|
1195
|
+
UPDATE_AVERAGE (averages.current.glue.fast, glue);
|
|
1196
|
+
UPDATE_AVERAGE (averages.current.glue.slow, glue);
|
|
1197
|
+
stats.learned.literals += size;
|
|
1198
|
+
stats.learned.clauses++;
|
|
1199
|
+
assert (glue < size);
|
|
1200
|
+
|
|
1201
|
+
// up to this point lrat_chain contains the proof for current clause in
|
|
1202
|
+
// reversed order. in minimize and shrink the clause is changed and
|
|
1203
|
+
// therefore lrat_chain has to be extended. Unfortunately we cannot create
|
|
1204
|
+
// the chain directly during minimization (or shrinking) but afterwards we
|
|
1205
|
+
// can calculate it pretty easily and even better the same algorithm works
|
|
1206
|
+
// for both shrinking and minimization.
|
|
1207
|
+
|
|
1208
|
+
// Minimize the 1st UIP clause as pioneered by Niklas Soerensson in
|
|
1209
|
+
// MiniSAT and described in our joint SAT'09 paper.
|
|
1210
|
+
//
|
|
1211
|
+
if (size > 1) {
|
|
1212
|
+
if (opts.shrink)
|
|
1213
|
+
shrink_and_minimize_clause ();
|
|
1214
|
+
else if (opts.minimize)
|
|
1215
|
+
minimize_clause ();
|
|
1216
|
+
|
|
1217
|
+
size = (int) clause.size ();
|
|
1218
|
+
|
|
1219
|
+
// Update decision heuristics.
|
|
1220
|
+
//
|
|
1221
|
+
if (opts.bump) {
|
|
1222
|
+
bump_also_all_reason_literals ();
|
|
1223
|
+
bump_variables ();
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
if (external->learner)
|
|
1227
|
+
external->export_learned_large_clause (clause);
|
|
1228
|
+
} else if (external->learner)
|
|
1229
|
+
external->export_learned_unit_clause (-uip);
|
|
1230
|
+
|
|
1231
|
+
// Update actual size statistics.
|
|
1232
|
+
//
|
|
1233
|
+
stats.units += (size == 1);
|
|
1234
|
+
stats.binaries += (size == 2);
|
|
1235
|
+
UPDATE_AVERAGE (averages.current.size, size);
|
|
1236
|
+
|
|
1237
|
+
// reverse lrat_chain. We could probably work with reversed iterators
|
|
1238
|
+
// (views) to be more efficient but we would have to distinguish in proof
|
|
1239
|
+
//
|
|
1240
|
+
if (lrat) {
|
|
1241
|
+
LOG (unit_chain, "unit chain: ");
|
|
1242
|
+
for (auto id : unit_chain)
|
|
1243
|
+
lrat_chain.push_back (id);
|
|
1244
|
+
unit_chain.clear ();
|
|
1245
|
+
reverse (lrat_chain.begin (), lrat_chain.end ());
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// Determine back-jump level, learn driving clause, backtrack and assign
|
|
1249
|
+
// flipped 1st UIP literal.
|
|
1250
|
+
//
|
|
1251
|
+
int jump;
|
|
1252
|
+
Clause *driving_clause = new_driving_clause (glue, jump);
|
|
1253
|
+
UPDATE_AVERAGE (averages.current.jump, jump);
|
|
1254
|
+
|
|
1255
|
+
int new_level = determine_actual_backtrack_level (jump);
|
|
1256
|
+
UPDATE_AVERAGE (averages.current.level, new_level);
|
|
1257
|
+
backtrack (new_level);
|
|
1258
|
+
|
|
1259
|
+
// It should hold that (!level <=> size == 1)
|
|
1260
|
+
// and (!uip <=> size == 0)
|
|
1261
|
+
// this means either we have already learned a clause => size >= 2
|
|
1262
|
+
// in this case we will not learn empty clause or unit here
|
|
1263
|
+
// or we haven't actually learned a clause in new_driving_clause
|
|
1264
|
+
// then lrat_chain is still valid and we will learn a unit or empty clause
|
|
1265
|
+
//
|
|
1266
|
+
if (uip) {
|
|
1267
|
+
search_assign_driving (-uip, driving_clause);
|
|
1268
|
+
} else
|
|
1269
|
+
learn_empty_clause ();
|
|
1270
|
+
|
|
1271
|
+
if (stable)
|
|
1272
|
+
reluctant.tick (); // Reluctant has its own 'conflict' counter.
|
|
1273
|
+
|
|
1274
|
+
// Clean up.
|
|
1275
|
+
//
|
|
1276
|
+
clear_analyzed_literals ();
|
|
1277
|
+
clear_unit_analyzed_literals ();
|
|
1278
|
+
clear_analyzed_levels ();
|
|
1279
|
+
clause.clear ();
|
|
1280
|
+
conflict = 0;
|
|
1281
|
+
|
|
1282
|
+
lrat_chain.clear ();
|
|
1283
|
+
STOP (analyze);
|
|
1284
|
+
|
|
1285
|
+
if (driving_clause && opts.eagersubsume)
|
|
1286
|
+
eagerly_subsume_recently_learned_clauses (driving_clause);
|
|
1287
|
+
|
|
1288
|
+
if (lim.recompute_tier <= stats.conflicts)
|
|
1289
|
+
recompute_tier ();
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// In the special case where the external propagator is lazy, the same
|
|
1293
|
+
// invariants as OTFS break (but even more complicated). There are three
|
|
1294
|
+
// possible cases:
|
|
1295
|
+
// - the clause becomes empty (unsat must be answered)
|
|
1296
|
+
// - the clause is a unit (backtrack and set the clause)
|
|
1297
|
+
// - the clause is a new conflict on lower level and we restart the
|
|
1298
|
+
// analysis
|
|
1299
|
+
//
|
|
1300
|
+
// TODO: we do not really need to keep the clause longer than the conflict
|
|
1301
|
+
// analysis.
|
|
1302
|
+
void Internal::lazy_external_propagator_out_of_order_clause (int &uip) {
|
|
1303
|
+
assert (!opts.exteagerreasons);
|
|
1304
|
+
assert (external_prop);
|
|
1305
|
+
LOG (clause, "out-of-order conflict");
|
|
1306
|
+
if (clause.empty ()) {
|
|
1307
|
+
LOG (lrat_chain, "lrat_chain:");
|
|
1308
|
+
LOG (clause, "clause:");
|
|
1309
|
+
LOG (unit_chain, "units:");
|
|
1310
|
+
if (lrat) {
|
|
1311
|
+
LOG (unit_chain, "unit chain: ");
|
|
1312
|
+
for (auto id : unit_chain)
|
|
1313
|
+
lrat_chain.push_back (id);
|
|
1314
|
+
unit_chain.clear ();
|
|
1315
|
+
reverse (lrat_chain.begin (), lrat_chain.end ());
|
|
1316
|
+
}
|
|
1317
|
+
LOG (lrat_chain, "lrat_chain:");
|
|
1318
|
+
learn_empty_clause ();
|
|
1319
|
+
if (external->learner)
|
|
1320
|
+
external->export_learned_empty_clause ();
|
|
1321
|
+
conflict = 0;
|
|
1322
|
+
} else if (clause.size () == 1) {
|
|
1323
|
+
LOG ("found out-of-order unit");
|
|
1324
|
+
uip = -clause[0];
|
|
1325
|
+
assert (uip);
|
|
1326
|
+
backtrack (var (uip).level);
|
|
1327
|
+
assert (val (uip) > 0);
|
|
1328
|
+
clause.clear ();
|
|
1329
|
+
} else {
|
|
1330
|
+
int jump;
|
|
1331
|
+
const int glue = clause.size () - 1;
|
|
1332
|
+
conflict = new_driving_clause (glue, jump);
|
|
1333
|
+
UPDATE_AVERAGE (averages.current.level, jump);
|
|
1334
|
+
backtrack (jump);
|
|
1335
|
+
LOG (conflict, "new conflict");
|
|
1336
|
+
}
|
|
1337
|
+
// Clean up.
|
|
1338
|
+
//
|
|
1339
|
+
clear_analyzed_literals ();
|
|
1340
|
+
clear_unit_analyzed_literals ();
|
|
1341
|
+
clear_analyzed_levels ();
|
|
1342
|
+
clause.clear ();
|
|
1343
|
+
|
|
1344
|
+
if (unsat) {
|
|
1345
|
+
lrat_chain.clear ();
|
|
1346
|
+
STOP (analyze);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// We wait reporting a learned unit until propagation of that unit is
|
|
1351
|
+
// completed. Otherwise the 'i' report gives the number of remaining
|
|
1352
|
+
// variables before propagating the unit (and hides the actual remaining
|
|
1353
|
+
// variables after propagating it).
|
|
1354
|
+
|
|
1355
|
+
void Internal::iterate () {
|
|
1356
|
+
iterating = false;
|
|
1357
|
+
report ('i');
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
} // namespace CaDiCaL
|