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,1316 @@
|
|
|
1
|
+
#include "internal.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
|
|
5
|
+
namespace CaDiCaL {
|
|
6
|
+
|
|
7
|
+
/*----------------------------------------------------------------------------*/
|
|
8
|
+
//
|
|
9
|
+
// Mark a variable as an observed one. It can be a new variable. It is
|
|
10
|
+
// assumed to be clean (not eliminated by previous simplifications).
|
|
11
|
+
//
|
|
12
|
+
void Internal::add_observed_var (int ilit) {
|
|
13
|
+
int idx = vidx (ilit);
|
|
14
|
+
if (idx >= (int64_t) relevanttab.size ())
|
|
15
|
+
relevanttab.resize (1 + (size_t) idx, 0);
|
|
16
|
+
unsigned &ref = relevanttab[idx];
|
|
17
|
+
if (ref < UINT_MAX) {
|
|
18
|
+
ref++;
|
|
19
|
+
LOG ("variable %d is observed %u times", idx, ref);
|
|
20
|
+
} else
|
|
21
|
+
LOG ("variable %d remains observed forever", idx);
|
|
22
|
+
// TODO: instead of actually backtracking, it would be enough to notify
|
|
23
|
+
// backtrack and re-play again every levels' notification to the
|
|
24
|
+
// propagator
|
|
25
|
+
if (val (ilit) && level && !fixed (ilit)) {
|
|
26
|
+
// The variable is already assigned, but we can not send a notification
|
|
27
|
+
// about it because it happened on an earlier decision level.
|
|
28
|
+
// To not break the stack-like view of the trail, we simply backtrack to
|
|
29
|
+
// undo this unnotifiable assignment.
|
|
30
|
+
REQUIRE (!conflict,
|
|
31
|
+
"can not observe assigned variable during conflict analysis");
|
|
32
|
+
const int assignment_level = var (ilit).level;
|
|
33
|
+
backtrack (assignment_level - 1);
|
|
34
|
+
} else if (level && fixed (ilit)) {
|
|
35
|
+
backtrack (0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*----------------------------------------------------------------------------*/
|
|
40
|
+
//
|
|
41
|
+
// Removing an observed variable should happen only once it is ensured
|
|
42
|
+
// that there is no unexplained propagation in the implication
|
|
43
|
+
// graph involving this variable. To ensure that, the solver might
|
|
44
|
+
// need to backtrack so that the variable becomes unassigned.
|
|
45
|
+
//
|
|
46
|
+
void Internal::remove_observed_var (int ilit) {
|
|
47
|
+
if (!fixed (ilit) && level && val (ilit)) {
|
|
48
|
+
REQUIRE (
|
|
49
|
+
!conflict,
|
|
50
|
+
"can not unobserve assigned variable during conflict analysis");
|
|
51
|
+
const int assignment_level = var (ilit).level;
|
|
52
|
+
backtrack (assignment_level - 1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
assert (fixed (ilit) || !val (ilit));
|
|
56
|
+
|
|
57
|
+
const int idx = vidx (ilit);
|
|
58
|
+
assert ((size_t) idx < relevanttab.size ());
|
|
59
|
+
unsigned &ref = relevanttab[idx];
|
|
60
|
+
assert (fixed (ilit) || ref > 0);
|
|
61
|
+
if (fixed (ilit))
|
|
62
|
+
ref = 0;
|
|
63
|
+
else if (ref < UINT_MAX) {
|
|
64
|
+
if (!--ref) {
|
|
65
|
+
LOG ("variable %d is not observed anymore", idx);
|
|
66
|
+
} else
|
|
67
|
+
LOG ("variable %d is unobserved once but remains observed %u times",
|
|
68
|
+
ilit, ref);
|
|
69
|
+
} else
|
|
70
|
+
LOG ("variable %d remains observed forever", idx);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/*----------------------------------------------------------------------------*/
|
|
74
|
+
//
|
|
75
|
+
// Supposed to be used only by mobical.
|
|
76
|
+
//
|
|
77
|
+
bool Internal::observed (int ilit) const {
|
|
78
|
+
assert ((size_t) vidx (ilit) < relevanttab.size ());
|
|
79
|
+
return relevanttab[vidx (ilit)] > 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/*----------------------------------------------------------------------------*/
|
|
83
|
+
//
|
|
84
|
+
// Check for unexplained propagations upon disconnecting external propagator
|
|
85
|
+
//
|
|
86
|
+
void Internal::set_changed_val () {
|
|
87
|
+
if (!opts.ilb) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
for (auto idx : vars) {
|
|
91
|
+
if (!val (idx))
|
|
92
|
+
continue;
|
|
93
|
+
if (var (idx).reason != external_reason)
|
|
94
|
+
continue;
|
|
95
|
+
if (!changed_val) {
|
|
96
|
+
changed_val = idx;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
assert (val (changed_val));
|
|
100
|
+
if (var (idx).level < var (changed_val).level) {
|
|
101
|
+
changed_val = idx;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void Internal::renotify_trail_after_ilb () {
|
|
107
|
+
assert (opts.ilb);
|
|
108
|
+
if (!external_prop || external_prop_is_lazy || !trail.size () ||
|
|
109
|
+
!opts.ilb) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
LOG ("notify external propagator about new assignments (after ilb)");
|
|
113
|
+
#ifndef NDEBUG
|
|
114
|
+
LOG ("(decision level: %d, trail size: %zd, notified %zd)", level,
|
|
115
|
+
trail.size (), notified);
|
|
116
|
+
#endif
|
|
117
|
+
renotify_full_trail ();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
void Internal::renotify_trail_after_local_search () {
|
|
121
|
+
if (!external_prop || external_prop_is_lazy || !trail.size ()) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
LOG ("notify external propagator about new assignments (after local "
|
|
125
|
+
"search)");
|
|
126
|
+
#ifndef NDEBUG
|
|
127
|
+
LOG ("(decision level: %d, trail size: %zd, notified %zd)", level,
|
|
128
|
+
trail.size (), notified);
|
|
129
|
+
#endif
|
|
130
|
+
renotify_full_trail ();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void Internal::renotify_full_trail_between_trail_pos (
|
|
134
|
+
int start_level, int end_level, int propagator_level,
|
|
135
|
+
std::vector<int> &assigned, bool start_new_level) {
|
|
136
|
+
assert (assigned.empty ());
|
|
137
|
+
int j = start_level;
|
|
138
|
+
#ifdef LOGGING
|
|
139
|
+
LOG ("starting notification of level %d from trail %d .. %d",
|
|
140
|
+
propagator_level, start_level, end_level);
|
|
141
|
+
#else
|
|
142
|
+
(void) propagator_level;
|
|
143
|
+
#endif
|
|
144
|
+
if (start_new_level) {
|
|
145
|
+
if (assigned.size ())
|
|
146
|
+
external->propagator->notify_assignment (assigned);
|
|
147
|
+
assigned.clear ();
|
|
148
|
+
external->propagator->notify_new_decision_level ();
|
|
149
|
+
}
|
|
150
|
+
for (; j < end_level; ++j) {
|
|
151
|
+
int ilit = trail[j];
|
|
152
|
+
// In theory, 0 ilit can happen due to pseudo-decision levels
|
|
153
|
+
if (!ilit)
|
|
154
|
+
continue;
|
|
155
|
+
|
|
156
|
+
if (!observed (ilit))
|
|
157
|
+
continue;
|
|
158
|
+
|
|
159
|
+
int elit = externalize (ilit); // TODO: double-check tainting
|
|
160
|
+
|
|
161
|
+
LOG ("notifying elit %d @ %d aka %s", propagator_level, elit,
|
|
162
|
+
LOGLIT (ilit));
|
|
163
|
+
assert (elit);
|
|
164
|
+
// Fixed variables might get mapped (during compact) to another
|
|
165
|
+
// non-observed but fixed variable.
|
|
166
|
+
// This happens on root level, so notification about their assignment
|
|
167
|
+
// is already done.
|
|
168
|
+
assert (external->observed (elit) || fixed (ilit));
|
|
169
|
+
if (!external->ervars[abs (elit)])
|
|
170
|
+
assigned.push_back (elit);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (assigned.size ())
|
|
174
|
+
external->propagator->notify_assignment (assigned);
|
|
175
|
+
assigned.clear ();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// It repeats ALL assignments of the trail, so the already notified
|
|
179
|
+
// root-level assignments will be notified multiple times.
|
|
180
|
+
//
|
|
181
|
+
// As CaDiCaL is missing some '0' seperators, it is important to go
|
|
182
|
+
// over slices from the control stack instead of going over the trail
|
|
183
|
+
// directly.
|
|
184
|
+
void Internal::renotify_full_trail () {
|
|
185
|
+
const size_t end_of_trail = trail.size ();
|
|
186
|
+
if (level) {
|
|
187
|
+
notified = 0; // TODO: save the last notified root-level position
|
|
188
|
+
// somewhere and use it here
|
|
189
|
+
notify_backtrack (0);
|
|
190
|
+
}
|
|
191
|
+
std::vector<int> assigned;
|
|
192
|
+
|
|
193
|
+
int propagator_level = 0;
|
|
194
|
+
|
|
195
|
+
const int c_size = control.size ();
|
|
196
|
+
{ // first all root-level literals
|
|
197
|
+
const int start_level = 0;
|
|
198
|
+
const int end_level =
|
|
199
|
+
(control.size () > 1 ? control[1].trail : end_of_trail);
|
|
200
|
+
renotify_full_trail_between_trail_pos (
|
|
201
|
+
start_level, end_level, propagator_level, assigned, false);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// notify all intermediate levels
|
|
205
|
+
for (int i = 2; i < c_size; ++i) {
|
|
206
|
+
const int start_level = control[i - 1].trail;
|
|
207
|
+
const int end_level = control[i].trail;
|
|
208
|
+
propagator_level++;
|
|
209
|
+
LOG ("notification of %d", propagator_level);
|
|
210
|
+
|
|
211
|
+
renotify_full_trail_between_trail_pos (
|
|
212
|
+
start_level, end_level, propagator_level, assigned, true);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// and the current level if there is non-root level one
|
|
216
|
+
if (level) {
|
|
217
|
+
const int start_level = control.back ().trail;
|
|
218
|
+
propagator_level++;
|
|
219
|
+
renotify_full_trail_between_trail_pos (
|
|
220
|
+
start_level, end_of_trail, propagator_level, assigned, true);
|
|
221
|
+
}
|
|
222
|
+
assert (propagator_level == level);
|
|
223
|
+
notified = trail.size ();
|
|
224
|
+
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/*----------------------------------------------------------------------------*/
|
|
229
|
+
//
|
|
230
|
+
// Check if the variable is assigned by decision.
|
|
231
|
+
//
|
|
232
|
+
bool Internal::is_decision (int ilit) {
|
|
233
|
+
if (!level || fixed (ilit) || !val (ilit))
|
|
234
|
+
return false;
|
|
235
|
+
|
|
236
|
+
const int idx = vidx (ilit);
|
|
237
|
+
Var &v = var (idx);
|
|
238
|
+
#ifndef NDEBUG
|
|
239
|
+
LOG (v.reason,
|
|
240
|
+
"is_decision: i%d (current level: %d, is_fixed: %d, v.level: %d, "
|
|
241
|
+
"is_external_reason: %d, v.reason: )",
|
|
242
|
+
ilit, level, fixed (ilit), v.level, v.reason == external_reason);
|
|
243
|
+
#endif
|
|
244
|
+
if (!v.level || v.reason)
|
|
245
|
+
return false;
|
|
246
|
+
assert (!v.reason);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void Internal::force_backtrack (int new_level) {
|
|
251
|
+
REQUIRE (forced_backt_allowed,
|
|
252
|
+
"not allowed to force backtrack in that state of the solver.");
|
|
253
|
+
REQUIRE (new_level >= 0,
|
|
254
|
+
"the target level of a forced backtrack must be non-negative.");
|
|
255
|
+
REQUIRE (level > 0 && new_level < level,
|
|
256
|
+
"the target level of a forced backtrack must be smaller than "
|
|
257
|
+
"the current decision level.");
|
|
258
|
+
|
|
259
|
+
#ifndef NDEBUG
|
|
260
|
+
LOG ("external propagator forces backtrack to decision level"
|
|
261
|
+
"%d (from level %d)",
|
|
262
|
+
new_level, level);
|
|
263
|
+
#endif
|
|
264
|
+
backtrack (new_level);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/*----------------------------------------------------------------------------*/
|
|
268
|
+
//
|
|
269
|
+
// Call external propagator to check if there is a literal to be propagated.
|
|
270
|
+
// The reason of the propagation is not necessarily asked at that point.
|
|
271
|
+
//
|
|
272
|
+
// In case the externally propagated literal is already falsified, the
|
|
273
|
+
// reason is asked and conflict analysis starts. In case the externally
|
|
274
|
+
// propagated literal is already satisfied, nothing happens.
|
|
275
|
+
//
|
|
276
|
+
bool Internal::external_propagate () {
|
|
277
|
+
if (level)
|
|
278
|
+
require_mode (SEARCH);
|
|
279
|
+
assert (!unsat);
|
|
280
|
+
|
|
281
|
+
size_t before = num_assigned;
|
|
282
|
+
bool cb_repropagate_needed = true;
|
|
283
|
+
while (cb_repropagate_needed && !conflict && external_prop &&
|
|
284
|
+
!external_prop_is_lazy && !private_steps) {
|
|
285
|
+
#ifndef NDEBUG
|
|
286
|
+
LOG ("external propagation starts (decision level: %d, trail size: "
|
|
287
|
+
"%zd, notified %zd)",
|
|
288
|
+
level, trail.size (), notified);
|
|
289
|
+
#endif
|
|
290
|
+
cb_repropagate_needed = false;
|
|
291
|
+
// external->reset_extended (); //TODO for inprocessing
|
|
292
|
+
|
|
293
|
+
notify_assignments ();
|
|
294
|
+
|
|
295
|
+
int elit = external->propagator->cb_propagate ();
|
|
296
|
+
|
|
297
|
+
REQUIRE (
|
|
298
|
+
!elit || ((size_t) abs (elit) < external->is_observed.size () &&
|
|
299
|
+
external->is_observed[abs (elit)]),
|
|
300
|
+
"external propagations are only allowed over observed variables.");
|
|
301
|
+
|
|
302
|
+
stats.ext_prop.ext_cb++;
|
|
303
|
+
stats.ext_prop.eprop_call++;
|
|
304
|
+
while (elit) {
|
|
305
|
+
assert (external->is_observed[abs (elit)]);
|
|
306
|
+
int ilit = external->e2i[abs (elit)];
|
|
307
|
+
if (elit < 0)
|
|
308
|
+
ilit = -ilit;
|
|
309
|
+
int tmp = val (ilit);
|
|
310
|
+
#ifndef NDEBUG
|
|
311
|
+
assert (fixed (ilit) || observed (ilit));
|
|
312
|
+
LOG ("External propagation of e%d (i%d val: %d)", elit, ilit, tmp);
|
|
313
|
+
#endif
|
|
314
|
+
if (!tmp) {
|
|
315
|
+
// variable is not assigned, it can be propagated
|
|
316
|
+
if (!level) {
|
|
317
|
+
Clause *res = learn_external_reason_clause (ilit, elit);
|
|
318
|
+
#ifndef LOGGING
|
|
319
|
+
LOG (res, "reason clause of external propagation of %d:", elit);
|
|
320
|
+
#endif
|
|
321
|
+
(void) res;
|
|
322
|
+
} else
|
|
323
|
+
search_assign_external (ilit);
|
|
324
|
+
stats.ext_prop.eprop_prop++;
|
|
325
|
+
|
|
326
|
+
if (unsat || conflict)
|
|
327
|
+
break;
|
|
328
|
+
propagate ();
|
|
329
|
+
if (unsat || conflict)
|
|
330
|
+
break;
|
|
331
|
+
notify_assignments ();
|
|
332
|
+
} else if (tmp < 0) {
|
|
333
|
+
LOG ("External propgation of %d is falsified under current trail",
|
|
334
|
+
ilit);
|
|
335
|
+
stats.ext_prop.eprop_conf++;
|
|
336
|
+
int level_before = level;
|
|
337
|
+
size_t assigned = num_assigned;
|
|
338
|
+
Clause *res = learn_external_reason_clause (ilit, elit);
|
|
339
|
+
#ifndef LOGGING
|
|
340
|
+
LOG (res, "reason clause of external propagation of %d:", elit);
|
|
341
|
+
#endif
|
|
342
|
+
(void) res;
|
|
343
|
+
bool trail_changed =
|
|
344
|
+
(num_assigned != assigned || level != level_before ||
|
|
345
|
+
propagated < trail.size ());
|
|
346
|
+
|
|
347
|
+
if (unsat || conflict)
|
|
348
|
+
break;
|
|
349
|
+
|
|
350
|
+
if (trail_changed) {
|
|
351
|
+
propagate ();
|
|
352
|
+
if (unsat || conflict)
|
|
353
|
+
break;
|
|
354
|
+
notify_assignments ();
|
|
355
|
+
}
|
|
356
|
+
} // else (tmp > 0) -> the case of a satisfied literal is ignored
|
|
357
|
+
elit = external->propagator->cb_propagate ();
|
|
358
|
+
stats.ext_prop.ext_cb++;
|
|
359
|
+
stats.ext_prop.eprop_call++;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#ifndef NDEBUG
|
|
363
|
+
LOG ("External propagation ends (decision level: %d, trail size: %zd, "
|
|
364
|
+
"notified %zd)",
|
|
365
|
+
level, trail.size (), notified);
|
|
366
|
+
#endif
|
|
367
|
+
if (!unsat && !conflict) {
|
|
368
|
+
int level_before = level;
|
|
369
|
+
size_t assigned = num_assigned;
|
|
370
|
+
bool has_external_clause = ask_external_clause ();
|
|
371
|
+
// New observed variable might have triggered a backtrack during this
|
|
372
|
+
// ask_external_clause call, so we need to propagate before continuing
|
|
373
|
+
stats.ext_prop.ext_cb++;
|
|
374
|
+
stats.ext_prop.elearn_call++;
|
|
375
|
+
|
|
376
|
+
bool trail_changed =
|
|
377
|
+
(num_assigned != assigned || level != level_before ||
|
|
378
|
+
propagated < trail.size ());
|
|
379
|
+
if (trail_changed) {
|
|
380
|
+
propagate (); // unsat or conflict will be caught later
|
|
381
|
+
if (!unsat || !conflict)
|
|
382
|
+
notify_assignments ();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#ifndef NDEBUG
|
|
386
|
+
if (has_external_clause)
|
|
387
|
+
LOG ("New external clauses are to be added.");
|
|
388
|
+
else
|
|
389
|
+
LOG ("No external clauses to be added.");
|
|
390
|
+
#endif
|
|
391
|
+
|
|
392
|
+
while (has_external_clause) {
|
|
393
|
+
level_before = level;
|
|
394
|
+
assigned = num_assigned;
|
|
395
|
+
|
|
396
|
+
add_external_clause (0);
|
|
397
|
+
trail_changed =
|
|
398
|
+
(num_assigned != assigned || level != level_before ||
|
|
399
|
+
propagated < trail.size ());
|
|
400
|
+
cb_repropagate_needed = true;
|
|
401
|
+
|
|
402
|
+
if (unsat || conflict) {
|
|
403
|
+
cb_repropagate_needed = false;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (trail_changed) {
|
|
408
|
+
propagate ();
|
|
409
|
+
if (unsat || conflict) {
|
|
410
|
+
cb_repropagate_needed = false;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
notify_assignments ();
|
|
415
|
+
}
|
|
416
|
+
has_external_clause = ask_external_clause ();
|
|
417
|
+
stats.ext_prop.ext_cb++;
|
|
418
|
+
stats.ext_prop.elearn_call++;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
#ifndef NDEBUG
|
|
422
|
+
LOG ("External clause addition ends on decision level %d at trail "
|
|
423
|
+
"size "
|
|
424
|
+
"%zd (notified %zd)",
|
|
425
|
+
level, trail.size (), notified);
|
|
426
|
+
#endif
|
|
427
|
+
}
|
|
428
|
+
if (before < num_assigned)
|
|
429
|
+
did_external_prop = true;
|
|
430
|
+
return !conflict;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/*----------------------------------------------------------------------------*/
|
|
434
|
+
//
|
|
435
|
+
// Helper function, calls 'cb_has_external_clause', while maintains the
|
|
436
|
+
// related redundancy type of the clause.
|
|
437
|
+
//
|
|
438
|
+
|
|
439
|
+
bool Internal::ask_external_clause () {
|
|
440
|
+
ext_clause_forgettable = false;
|
|
441
|
+
bool res =
|
|
442
|
+
external->propagator->cb_has_external_clause (ext_clause_forgettable);
|
|
443
|
+
|
|
444
|
+
return res;
|
|
445
|
+
}
|
|
446
|
+
/*----------------------------------------------------------------------------*/
|
|
447
|
+
//
|
|
448
|
+
// Literals of the externally learned clause must be reordered based on the
|
|
449
|
+
// assignment levels of the literals.
|
|
450
|
+
//
|
|
451
|
+
void Internal::move_literals_to_watch () {
|
|
452
|
+
if (clause.size () < 2)
|
|
453
|
+
return;
|
|
454
|
+
if (!level)
|
|
455
|
+
return;
|
|
456
|
+
|
|
457
|
+
for (int i = 0; i < 2; i++) {
|
|
458
|
+
int highest_position = i;
|
|
459
|
+
int highest_literal = clause[i];
|
|
460
|
+
|
|
461
|
+
int highest_level = var (highest_literal).level;
|
|
462
|
+
int highest_value = val (highest_literal);
|
|
463
|
+
|
|
464
|
+
for (size_t j = i + 1; j < clause.size (); j++) {
|
|
465
|
+
const int other = clause[j];
|
|
466
|
+
const int other_level = var (other).level;
|
|
467
|
+
const int other_value = val (other);
|
|
468
|
+
|
|
469
|
+
if (other_value < 0) {
|
|
470
|
+
if (highest_value >= 0)
|
|
471
|
+
continue;
|
|
472
|
+
if (other_level <= highest_level)
|
|
473
|
+
continue;
|
|
474
|
+
} else if (other_value > 0) {
|
|
475
|
+
if (highest_value > 0 && other_level >= highest_level)
|
|
476
|
+
continue;
|
|
477
|
+
} else {
|
|
478
|
+
if (highest_value >= 0)
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
highest_position = j;
|
|
483
|
+
highest_literal = other;
|
|
484
|
+
highest_level = other_level;
|
|
485
|
+
highest_value = other_value;
|
|
486
|
+
}
|
|
487
|
+
#ifndef NDEBUG
|
|
488
|
+
LOG ("highest position: %d highest level: %d highest value: %d",
|
|
489
|
+
highest_position, highest_level, highest_value);
|
|
490
|
+
#endif
|
|
491
|
+
|
|
492
|
+
if (highest_position == i)
|
|
493
|
+
continue;
|
|
494
|
+
if (highest_position > i) {
|
|
495
|
+
std::swap (clause[i], clause[highest_position]);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/*----------------------------------------------------------------------------*/
|
|
501
|
+
//
|
|
502
|
+
// Reads out from the external propagator the lemma/proapgation reason
|
|
503
|
+
// clause literal by literal. In case propagated_elit is 0, it is about an
|
|
504
|
+
// external clause via 'cb_add_external_clause_lit'. Otherwise, it is about
|
|
505
|
+
// learning the reason of 'propagated_elit' via 'cb_add_reason_clause_lit'.
|
|
506
|
+
// The learned clause is simplified by the current root-level assignment
|
|
507
|
+
// (i.e. root-level falsified literals are removed, root satisfied clauses
|
|
508
|
+
// are skipped). Duplicate literals are removed, tauotologies are detected
|
|
509
|
+
// and skipped. It always adds the original (un-simplified) external clause
|
|
510
|
+
// to the proof as an input clause and
|
|
511
|
+
// the simplified version of it (except exceptions below) as a derived
|
|
512
|
+
// clause.
|
|
513
|
+
//
|
|
514
|
+
// In case the external clause, after simplifications, is satisfied, no
|
|
515
|
+
// clause is constructed, and the function returns 0. In case the external
|
|
516
|
+
// clause, after simplifications, is empty, no clause is constructed, unsat
|
|
517
|
+
// is set true and the function returns 0. In case the external clause,
|
|
518
|
+
// after simplifications, is unit, no clause is constructed,
|
|
519
|
+
// 'Internal::clause' has the unit literal (without 0) and the function
|
|
520
|
+
// returns 0.
|
|
521
|
+
//
|
|
522
|
+
// In every other cases a new clause is constructed and the pointer is in
|
|
523
|
+
// newest_clause
|
|
524
|
+
//
|
|
525
|
+
void Internal::add_external_clause (int propagated_elit,
|
|
526
|
+
bool no_backtrack) {
|
|
527
|
+
assert (original.empty ());
|
|
528
|
+
int elit = 0;
|
|
529
|
+
bool propagated_lit_found = false;
|
|
530
|
+
|
|
531
|
+
if (propagated_elit) {
|
|
532
|
+
// Propagation reason clauses are by default assumed to be forgettable
|
|
533
|
+
// irredundant. In case they would be unforgettably important, the
|
|
534
|
+
// propagator can add them as an explicit unforgettable external clause
|
|
535
|
+
// or set 'are_reasons_forgettable' to false.
|
|
536
|
+
ext_clause_forgettable = external->propagator->are_reasons_forgettable;
|
|
537
|
+
#ifndef NDEBUG
|
|
538
|
+
LOG ("add external reason of propagated lit: %d", propagated_elit);
|
|
539
|
+
#endif
|
|
540
|
+
elit = external->propagator->cb_add_reason_clause_lit (propagated_elit);
|
|
541
|
+
if (elit == propagated_elit)
|
|
542
|
+
propagated_lit_found = true;
|
|
543
|
+
} else
|
|
544
|
+
elit = external->propagator->cb_add_external_clause_lit ();
|
|
545
|
+
|
|
546
|
+
REQUIRE (
|
|
547
|
+
!elit || ((size_t) abs (elit) < external->is_observed.size () &&
|
|
548
|
+
external->is_observed[abs (elit)]),
|
|
549
|
+
"external (reason) clause must contain only observed variables.");
|
|
550
|
+
|
|
551
|
+
// we need to be build a new LRAT chain if we are already in the middle of
|
|
552
|
+
// the analysis (like during failed assumptions)
|
|
553
|
+
LOG (lrat_chain, "lrat chain before");
|
|
554
|
+
std::vector<int64_t> lrat_chain_ext = std::move (lrat_chain);
|
|
555
|
+
lrat_chain.clear ();
|
|
556
|
+
clause.clear ();
|
|
557
|
+
|
|
558
|
+
// Read out the external lemma into original and simplify it into clause
|
|
559
|
+
assert (clause.empty ());
|
|
560
|
+
assert (original.empty ());
|
|
561
|
+
|
|
562
|
+
assert (!force_no_backtrack);
|
|
563
|
+
assert (!from_propagator);
|
|
564
|
+
force_no_backtrack = no_backtrack;
|
|
565
|
+
from_propagator = true;
|
|
566
|
+
while (elit) {
|
|
567
|
+
external->add (elit);
|
|
568
|
+
if (propagated_elit) {
|
|
569
|
+
elit =
|
|
570
|
+
external->propagator->cb_add_reason_clause_lit (propagated_elit);
|
|
571
|
+
if (elit == propagated_elit)
|
|
572
|
+
propagated_lit_found = true;
|
|
573
|
+
} else
|
|
574
|
+
elit = external->propagator->cb_add_external_clause_lit ();
|
|
575
|
+
|
|
576
|
+
REQUIRE (
|
|
577
|
+
!elit || ((size_t) abs (elit) < external->is_observed.size () &&
|
|
578
|
+
external->is_observed[abs (elit)]),
|
|
579
|
+
"external (reason) clause must contain only observed variables.");
|
|
580
|
+
}
|
|
581
|
+
external->add (elit);
|
|
582
|
+
|
|
583
|
+
REQUIRE (!propagated_elit || propagated_lit_found,
|
|
584
|
+
"external reason clause must contain the propagated literal.");
|
|
585
|
+
#ifdef NCONTRACTS
|
|
586
|
+
(void) propagated_lit_found;
|
|
587
|
+
#endif
|
|
588
|
+
|
|
589
|
+
assert (original.empty ());
|
|
590
|
+
assert (clause.empty ());
|
|
591
|
+
force_no_backtrack = false;
|
|
592
|
+
from_propagator = false;
|
|
593
|
+
lrat_chain = std::move (lrat_chain_ext);
|
|
594
|
+
LOG (lrat_chain, "lrat chain after");
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/*----------------------------------------------------------------------------*/
|
|
598
|
+
//
|
|
599
|
+
// Recursively calls 'learn_external_reason_clause' to explain every
|
|
600
|
+
// backward reachable externally propagated literal starting from 'ilit'.
|
|
601
|
+
//
|
|
602
|
+
void Internal::explain_reason (int ilit, Clause *reason, int &open) {
|
|
603
|
+
if (!opts.exteagerreasons)
|
|
604
|
+
return;
|
|
605
|
+
#ifndef NDEBUG
|
|
606
|
+
LOG (reason, "explain_reason of %d (open: %d)", ilit, open);
|
|
607
|
+
#endif
|
|
608
|
+
assert (reason);
|
|
609
|
+
assert (reason != external_reason);
|
|
610
|
+
for (const auto &other : *reason) {
|
|
611
|
+
if (other == ilit)
|
|
612
|
+
continue;
|
|
613
|
+
Flags &f = flags (other);
|
|
614
|
+
if (f.seen)
|
|
615
|
+
continue;
|
|
616
|
+
Var &v = var (other);
|
|
617
|
+
if (!v.level)
|
|
618
|
+
continue;
|
|
619
|
+
assert (val (other) < 0);
|
|
620
|
+
assert (v.level <= level);
|
|
621
|
+
if (v.reason == external_reason) {
|
|
622
|
+
v.reason = learn_external_reason_clause (-other, 0, true);
|
|
623
|
+
}
|
|
624
|
+
if (v.level && v.reason) {
|
|
625
|
+
f.seen = true;
|
|
626
|
+
open++;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/*----------------------------------------------------------------------------*/
|
|
632
|
+
//
|
|
633
|
+
// In case external propagation was used, the reason clauses of the relevant
|
|
634
|
+
// propagations must be learned lazily before/during conflict analysis.
|
|
635
|
+
// While conflict analysis needs to analyze only the current level, lazy
|
|
636
|
+
// clause learning must check every clause on every level that is backward
|
|
637
|
+
// reachable from the conflicting clause to guarantee that the assignment
|
|
638
|
+
// levels of the variables are accurate. So this explanation round is
|
|
639
|
+
// separated from the conflict analysis, thereby guranteeing that the flags
|
|
640
|
+
// and datastructures can be properly used later.
|
|
641
|
+
//
|
|
642
|
+
// This function must be called before the conflict analysis, in order to
|
|
643
|
+
// guarantee that every relevant reason clause is indeed learned already and
|
|
644
|
+
// to be sure that the levels of assignments are set correctly.
|
|
645
|
+
//
|
|
646
|
+
// Later TODO: experiment with bounded explanation (explain only those
|
|
647
|
+
// literals that are directly used during conflict analysis +
|
|
648
|
+
// minimizing/shrinking). The assignment levels are then only
|
|
649
|
+
// over-approximated.
|
|
650
|
+
//
|
|
651
|
+
void Internal::explain_external_propagations () {
|
|
652
|
+
assert (conflict);
|
|
653
|
+
assert (clause.empty ());
|
|
654
|
+
|
|
655
|
+
Clause *reason = conflict;
|
|
656
|
+
std::vector<int> seen_lits;
|
|
657
|
+
int open = 0; // Seen but not explained literal
|
|
658
|
+
|
|
659
|
+
explain_reason (0, reason, open); // marks conflict clause lits as seen
|
|
660
|
+
int i = trail.size (); // Start at end-of-trail
|
|
661
|
+
while (i > 0) {
|
|
662
|
+
const int lit = trail[--i];
|
|
663
|
+
if (!flags (lit).seen)
|
|
664
|
+
continue;
|
|
665
|
+
seen_lits.push_back (lit);
|
|
666
|
+
Var &v = var (lit);
|
|
667
|
+
if (!v.level)
|
|
668
|
+
continue;
|
|
669
|
+
if (v.reason) {
|
|
670
|
+
open--;
|
|
671
|
+
explain_reason (lit, v.reason, open);
|
|
672
|
+
}
|
|
673
|
+
if (!open)
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
assert (!open);
|
|
677
|
+
|
|
678
|
+
if (!opts.exteagerrecalc) {
|
|
679
|
+
for (auto lit : seen_lits) {
|
|
680
|
+
Flags &f = flags (lit);
|
|
681
|
+
f.seen = false;
|
|
682
|
+
}
|
|
683
|
+
#ifndef NDEBUG
|
|
684
|
+
for (auto idx : vars) {
|
|
685
|
+
assert (!flags (idx).seen);
|
|
686
|
+
}
|
|
687
|
+
#endif
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// Traverse now in the opposite direction (from lower to higher levels)
|
|
691
|
+
// and calculate the actual assignment level for the seen assignments.
|
|
692
|
+
for (auto it = seen_lits.rbegin (); it != seen_lits.rend (); ++it) {
|
|
693
|
+
const int lit = *it;
|
|
694
|
+
Flags &f = flags (lit);
|
|
695
|
+
Var &v = var (lit);
|
|
696
|
+
if (v.reason) {
|
|
697
|
+
int real_level = 0;
|
|
698
|
+
for (const auto &other : *v.reason) {
|
|
699
|
+
if (other == lit)
|
|
700
|
+
continue;
|
|
701
|
+
int tmp = var (other).level;
|
|
702
|
+
if (tmp > real_level)
|
|
703
|
+
real_level = tmp;
|
|
704
|
+
}
|
|
705
|
+
if (v.level && !real_level) {
|
|
706
|
+
build_chain_for_units (lit, v.reason, 1);
|
|
707
|
+
learn_unit_clause (lit);
|
|
708
|
+
lrat_chain.clear ();
|
|
709
|
+
v.reason = 0;
|
|
710
|
+
}
|
|
711
|
+
assert (v.level >= real_level);
|
|
712
|
+
if (v.level > real_level) {
|
|
713
|
+
v.level = real_level;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
f.seen = false;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
#if 0 // has been fuzzed extensively
|
|
720
|
+
for (auto idx : vars) {
|
|
721
|
+
assert (!flags (idx).seen);
|
|
722
|
+
}
|
|
723
|
+
#endif
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/*----------------------------------------------------------------------------*/
|
|
727
|
+
//
|
|
728
|
+
// Learns the reason clause of the propagation of ilit from the
|
|
729
|
+
// external propagator via 'add_external_clause'.
|
|
730
|
+
// In case of falsified propagation steps, if the propagated literal is
|
|
731
|
+
// already fixed to the opposite value, externalize will not necessarily
|
|
732
|
+
// give back the original elit (but an equivalent one). To avoid that, in
|
|
733
|
+
// falsified propagation cases the propagated elit is added as a second
|
|
734
|
+
// argument.
|
|
735
|
+
//
|
|
736
|
+
Clause *Internal::learn_external_reason_clause (int ilit,
|
|
737
|
+
int falsified_elit,
|
|
738
|
+
bool no_backtrack) {
|
|
739
|
+
assert (external->propagator); // REQ is defined by not allowing
|
|
740
|
+
// unobserving during conflict
|
|
741
|
+
// we cannot modify clause during analysis
|
|
742
|
+
auto clause_tmp = std::move (clause);
|
|
743
|
+
|
|
744
|
+
assert (clause.empty ());
|
|
745
|
+
assert (original.empty ());
|
|
746
|
+
|
|
747
|
+
stats.ext_prop.eprop_expl++;
|
|
748
|
+
|
|
749
|
+
int elit = 0;
|
|
750
|
+
if (!falsified_elit) {
|
|
751
|
+
assert (!fixed (ilit));
|
|
752
|
+
elit = externalize (ilit);
|
|
753
|
+
} else
|
|
754
|
+
elit = falsified_elit;
|
|
755
|
+
|
|
756
|
+
LOG ("ilit: %d, elit: %d", ilit, elit);
|
|
757
|
+
add_external_clause (elit, no_backtrack);
|
|
758
|
+
|
|
759
|
+
#ifndef NDEBUG
|
|
760
|
+
if (!falsified_elit && newest_clause) {
|
|
761
|
+
// Check if external propagation is correct wrt to the topological order
|
|
762
|
+
// defined by the trail. In case it is a falsified external propagation
|
|
763
|
+
// step, the order does not matter, the reason simply supposed to be a
|
|
764
|
+
// falsified clause.
|
|
765
|
+
const int propagated_ilit = ilit;
|
|
766
|
+
for (auto const reason_ilit : *newest_clause) {
|
|
767
|
+
assert (var (reason_ilit).trail <= var (propagated_ilit).trail);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
#endif
|
|
771
|
+
|
|
772
|
+
clause = std::move (clause_tmp);
|
|
773
|
+
return newest_clause;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/*----------------------------------------------------------------------------*/
|
|
777
|
+
//
|
|
778
|
+
// Helper function to be able to call learn_external_reason_clause when the
|
|
779
|
+
// internal clause is already used in the caller side (for example during
|
|
780
|
+
// proof checking). These calls are assumed to be without a falsified elit.
|
|
781
|
+
// Dont use it in general instead of learn_external_reason_clause because it
|
|
782
|
+
// does not support the corner cases where a literal remains in clause.
|
|
783
|
+
//
|
|
784
|
+
Clause *Internal::wrapped_learn_external_reason_clause (int ilit) {
|
|
785
|
+
Clause *res;
|
|
786
|
+
std::vector<int64_t> chain_tmp{std::move (lrat_chain)};
|
|
787
|
+
lrat_chain.clear ();
|
|
788
|
+
if (clause.empty ()) {
|
|
789
|
+
res = learn_external_reason_clause (ilit, 0, true);
|
|
790
|
+
} else {
|
|
791
|
+
std::vector<int> clause_tmp{std::move (clause)};
|
|
792
|
+
clause.clear ();
|
|
793
|
+
res = learn_external_reason_clause (ilit, 0, true);
|
|
794
|
+
// The learn_external_reason clause can leave a literal in clause when
|
|
795
|
+
// there is a falsified elit arg. Here it is not allowed to
|
|
796
|
+
// happen.
|
|
797
|
+
assert (clause.empty ());
|
|
798
|
+
|
|
799
|
+
clause = std::move (clause_tmp);
|
|
800
|
+
clause_tmp.clear ();
|
|
801
|
+
}
|
|
802
|
+
assert (lrat_chain.empty ());
|
|
803
|
+
lrat_chain = std::move (chain_tmp);
|
|
804
|
+
chain_tmp.clear ();
|
|
805
|
+
return res;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/*----------------------------------------------------------------------------*/
|
|
809
|
+
//
|
|
810
|
+
// Checks if the new clause forces backtracking, new assignments or conflict
|
|
811
|
+
// analysis
|
|
812
|
+
//
|
|
813
|
+
void Internal::handle_external_clause (Clause *res) {
|
|
814
|
+
if (from_propagator)
|
|
815
|
+
stats.ext_prop.elearned++;
|
|
816
|
+
// at level 0 we have to do nothing...
|
|
817
|
+
if (!level)
|
|
818
|
+
return;
|
|
819
|
+
if (!res) {
|
|
820
|
+
if (from_propagator)
|
|
821
|
+
stats.ext_prop.elearn_prop++;
|
|
822
|
+
// new unit clause. For now just backtrack.
|
|
823
|
+
assert (!force_no_backtrack);
|
|
824
|
+
assert (level);
|
|
825
|
+
// if (!opts.chrono) {
|
|
826
|
+
backtrack ();
|
|
827
|
+
// }
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (from_propagator)
|
|
831
|
+
stats.ext_prop.elearned++;
|
|
832
|
+
assert (res->size >= 2);
|
|
833
|
+
const int pos0 = res->literals[0];
|
|
834
|
+
const int pos1 = res->literals[1];
|
|
835
|
+
if (force_no_backtrack) {
|
|
836
|
+
assert (val (pos1) < 0);
|
|
837
|
+
assert (val (pos0) >= 0);
|
|
838
|
+
return;
|
|
839
|
+
// TODO: maybe fix levels
|
|
840
|
+
}
|
|
841
|
+
const int l1 = var (pos1).level;
|
|
842
|
+
if (val (pos0) < 0) { // conflicting or propagating clause
|
|
843
|
+
assert (0 < l1 && l1 <= var (pos0).level);
|
|
844
|
+
if (!opts.chrono) {
|
|
845
|
+
backtrack (l1);
|
|
846
|
+
}
|
|
847
|
+
if (val (pos0) < 0) {
|
|
848
|
+
conflict = res;
|
|
849
|
+
if (!from_propagator) {
|
|
850
|
+
// its better to backtrack instead of analyze
|
|
851
|
+
backtrack (l1 - 1);
|
|
852
|
+
conflict = 0;
|
|
853
|
+
assert (!val (pos0) && !val (pos1));
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
search_assign_driving (pos0, res);
|
|
857
|
+
}
|
|
858
|
+
if (from_propagator)
|
|
859
|
+
stats.ext_prop.elearn_conf++;
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
if (val (pos1) < 0 && !val (pos0)) { // propagating clause
|
|
863
|
+
if (!opts.chrono) {
|
|
864
|
+
backtrack (l1);
|
|
865
|
+
}
|
|
866
|
+
search_assign_driving (pos0, res);
|
|
867
|
+
if (from_propagator)
|
|
868
|
+
stats.ext_prop.elearn_conf++;
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/*----------------------------------------------------------------------------*/
|
|
874
|
+
//
|
|
875
|
+
// Asks the external propagator if the current solution is OK
|
|
876
|
+
// by calling 'cb_check_found_model (model)'.
|
|
877
|
+
//
|
|
878
|
+
// The checked model is built up after everything is restored
|
|
879
|
+
// from the reconstruction stack and every variable is reactivated
|
|
880
|
+
// and so it is not just simply the trail (i.e. it can be expensive).
|
|
881
|
+
//
|
|
882
|
+
// If the external propagator approves the model, the function
|
|
883
|
+
// returns true.
|
|
884
|
+
//
|
|
885
|
+
// If the propagator does not approve the model, the solver asks
|
|
886
|
+
// the propagator to add an external clause.
|
|
887
|
+
// This external clause, however, does NOT have to be falsified by
|
|
888
|
+
// the current model. The possible cases and reactions are described
|
|
889
|
+
// below in the function. The possible states after that function:
|
|
890
|
+
// - A solution was found and accepted by the external propagator
|
|
891
|
+
// - A conflicting clause was learned from the external propagator
|
|
892
|
+
// - The empty clause was learned due to something new learned from
|
|
893
|
+
// the external propagator.
|
|
894
|
+
//
|
|
895
|
+
// In case only new variables were introduced, but no new clauses were
|
|
896
|
+
// added, the function will return without a conflict to the outer CDCL
|
|
897
|
+
// loop, where the new (not yet satisfied) variables are recognized and
|
|
898
|
+
// the search continues.
|
|
899
|
+
bool Internal::external_check_solution () {
|
|
900
|
+
if (!external_prop)
|
|
901
|
+
return true;
|
|
902
|
+
|
|
903
|
+
bool trail_changed = true;
|
|
904
|
+
bool added_new_clauses = false;
|
|
905
|
+
while (trail_changed || added_new_clauses) {
|
|
906
|
+
notify_assignments ();
|
|
907
|
+
if (!satisfied ())
|
|
908
|
+
break;
|
|
909
|
+
trail_changed = false; // to be on the safe side
|
|
910
|
+
added_new_clauses = false;
|
|
911
|
+
LOG ("Final check by external propagator is invoked.");
|
|
912
|
+
stats.ext_prop.echeck_call++;
|
|
913
|
+
external->reset_extended ();
|
|
914
|
+
external->extend ();
|
|
915
|
+
|
|
916
|
+
std::vector<int> etrail;
|
|
917
|
+
|
|
918
|
+
// Here the variables must be filtered by external->is_observed,
|
|
919
|
+
// because fixed variables are internally not necessarily observed
|
|
920
|
+
// anymore.
|
|
921
|
+
for (int idx = 1;
|
|
922
|
+
idx <= std::min ((int) external->is_observed.size () - 1,
|
|
923
|
+
external->max_var);
|
|
924
|
+
idx++) {
|
|
925
|
+
if (!external->is_observed[idx])
|
|
926
|
+
continue;
|
|
927
|
+
const int lit = external->ival (idx);
|
|
928
|
+
etrail.push_back (lit);
|
|
929
|
+
#ifndef NDEBUG
|
|
930
|
+
#ifdef LOGGING
|
|
931
|
+
bool p = external->vals[idx];
|
|
932
|
+
LOG ("evals[%d]: %d ival(%d): %d", idx, p, idx, lit);
|
|
933
|
+
#endif
|
|
934
|
+
#endif
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
forced_backt_allowed = true;
|
|
938
|
+
size_t assigned = num_assigned;
|
|
939
|
+
int level_before = level;
|
|
940
|
+
bool is_consistent =
|
|
941
|
+
external->propagator->cb_check_found_model (etrail);
|
|
942
|
+
stats.ext_prop.ext_cb++;
|
|
943
|
+
forced_backt_allowed = false;
|
|
944
|
+
|
|
945
|
+
if (num_assigned != assigned || level != level_before ||
|
|
946
|
+
propagated < trail.size ()) {
|
|
947
|
+
// In case an external forced backtracking was performed, the CDCL
|
|
948
|
+
// loop needs to continue withouth further checks of the model.
|
|
949
|
+
trail_changed = true;
|
|
950
|
+
return !conflict;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
if (is_consistent) {
|
|
954
|
+
LOG ("Found solution is approved by external propagator.");
|
|
955
|
+
return true;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
bool has_external_clause = ask_external_clause ();
|
|
959
|
+
|
|
960
|
+
stats.ext_prop.ext_cb++;
|
|
961
|
+
stats.ext_prop.elearn_call++;
|
|
962
|
+
|
|
963
|
+
if (has_external_clause)
|
|
964
|
+
LOG (
|
|
965
|
+
"Found solution triggered new clauses from external propagator.");
|
|
966
|
+
|
|
967
|
+
while (has_external_clause) {
|
|
968
|
+
level_before = level;
|
|
969
|
+
assigned = num_assigned;
|
|
970
|
+
add_external_clause (0);
|
|
971
|
+
bool trail_changed =
|
|
972
|
+
(num_assigned != assigned || level != level_before ||
|
|
973
|
+
propagated < trail.size ());
|
|
974
|
+
added_new_clauses = true;
|
|
975
|
+
//
|
|
976
|
+
// There are many possible scenarios here:
|
|
977
|
+
// - Learned conflicting clause: return to CDCL loop (conflict true)
|
|
978
|
+
// - Learned conflicting unit clause that after backtrack+BCP leads to
|
|
979
|
+
// a new complete solution: force the outer loop to check the new
|
|
980
|
+
// model (trail_changed is true, but (conflict & unsat) is false)
|
|
981
|
+
// - Learned empty clause: return to CDCL loop (unsat true)
|
|
982
|
+
// - Learned a non-conflicting unit clause:
|
|
983
|
+
// Though it does not invalidate the current solution, the solver
|
|
984
|
+
// will backtrack to the root level and will repropagate it. The
|
|
985
|
+
// search will start again (saved phases hopefully make it quick),
|
|
986
|
+
// but it is needed in order to guarantee that every fixed variable
|
|
987
|
+
// is properly handled+notified (important for incremental use
|
|
988
|
+
// cases).
|
|
989
|
+
// - Otherwise: the solution is considered approved and the CDCL-loop
|
|
990
|
+
// can return with res = 10.
|
|
991
|
+
//
|
|
992
|
+
if (unsat || conflict || trail_changed)
|
|
993
|
+
break;
|
|
994
|
+
has_external_clause = ask_external_clause ();
|
|
995
|
+
stats.ext_prop.ext_cb++;
|
|
996
|
+
stats.ext_prop.elearn_call++;
|
|
997
|
+
}
|
|
998
|
+
LOG ("No more external clause to add.");
|
|
999
|
+
if (unsat || conflict)
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (!unsat && conflict) {
|
|
1004
|
+
const int conflict_level = var (conflict->literals[0]).level;
|
|
1005
|
+
if (conflict_level != level) {
|
|
1006
|
+
backtrack (conflict_level);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return !conflict;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/*----------------------------------------------------------------------------*/
|
|
1014
|
+
//
|
|
1015
|
+
// Notify the external propagator that an observed variable got assigned.
|
|
1016
|
+
//
|
|
1017
|
+
void Internal::notify_assignments () {
|
|
1018
|
+
if (!external_prop || external_prop_is_lazy || private_steps)
|
|
1019
|
+
return;
|
|
1020
|
+
|
|
1021
|
+
const size_t end_of_trail = trail.size ();
|
|
1022
|
+
|
|
1023
|
+
if (notified >= end_of_trail)
|
|
1024
|
+
return;
|
|
1025
|
+
|
|
1026
|
+
LOG ("notify external propagator about new assignments");
|
|
1027
|
+
std::vector<int> assigned;
|
|
1028
|
+
|
|
1029
|
+
while (notified < end_of_trail) {
|
|
1030
|
+
int ilit = trail[notified++];
|
|
1031
|
+
if (!observed (ilit))
|
|
1032
|
+
continue;
|
|
1033
|
+
|
|
1034
|
+
int elit = externalize (ilit); // TODO: double-check tainting
|
|
1035
|
+
assert (elit);
|
|
1036
|
+
if (external->ervars[abs (elit)])
|
|
1037
|
+
continue;
|
|
1038
|
+
// Fixed variables might get mapped (during compact) to another
|
|
1039
|
+
// non-observed but fixed variable.
|
|
1040
|
+
// This happens on root level, so notification about their assignment is
|
|
1041
|
+
// already done.
|
|
1042
|
+
assert (external->observed (elit) ||
|
|
1043
|
+
(fixed (ilit) && !external->ervars[abs (elit)]));
|
|
1044
|
+
assigned.push_back (elit);
|
|
1045
|
+
}
|
|
1046
|
+
if (assigned.size ())
|
|
1047
|
+
external->propagator->notify_assignment (assigned);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/*----------------------------------------------------------------------------*/
|
|
1052
|
+
|
|
1053
|
+
void Internal::connect_propagator () {
|
|
1054
|
+
if (level)
|
|
1055
|
+
backtrack ();
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/*----------------------------------------------------------------------------*/
|
|
1059
|
+
//
|
|
1060
|
+
// Notify the external propagator that a new decision level is started.
|
|
1061
|
+
//
|
|
1062
|
+
void Internal::notify_decision () {
|
|
1063
|
+
if (!external_prop || external_prop_is_lazy || private_steps)
|
|
1064
|
+
return;
|
|
1065
|
+
external->propagator->notify_new_decision_level ();
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/*----------------------------------------------------------------------------*/
|
|
1069
|
+
//
|
|
1070
|
+
// Notify the external propagator that backtrack to new_level.
|
|
1071
|
+
//
|
|
1072
|
+
void Internal::notify_backtrack (size_t new_level) {
|
|
1073
|
+
if (!external_prop || external_prop_is_lazy || private_steps)
|
|
1074
|
+
return;
|
|
1075
|
+
external->propagator->notify_backtrack (new_level);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/*----------------------------------------------------------------------------*/
|
|
1079
|
+
//
|
|
1080
|
+
// Ask the external propagator if there is a suggested literal as next
|
|
1081
|
+
// decision.
|
|
1082
|
+
//
|
|
1083
|
+
int Internal::ask_decision () {
|
|
1084
|
+
if (!external_prop || external_prop_is_lazy || private_steps)
|
|
1085
|
+
return 0;
|
|
1086
|
+
|
|
1087
|
+
assert (!unsat);
|
|
1088
|
+
assert (!conflict);
|
|
1089
|
+
notify_assignments ();
|
|
1090
|
+
int level_before = level;
|
|
1091
|
+
forced_backt_allowed = true;
|
|
1092
|
+
int elit = external->propagator->cb_decide ();
|
|
1093
|
+
forced_backt_allowed = false;
|
|
1094
|
+
stats.ext_prop.ext_cb++;
|
|
1095
|
+
|
|
1096
|
+
if (level_before != level) {
|
|
1097
|
+
|
|
1098
|
+
propagate ();
|
|
1099
|
+
assert (!unsat);
|
|
1100
|
+
assert (!conflict);
|
|
1101
|
+
notify_assignments ();
|
|
1102
|
+
|
|
1103
|
+
// In case the external propagator forced to backtrack below the
|
|
1104
|
+
// pseduo decision levels, we must go back to the CDCL loop instead of
|
|
1105
|
+
// making a decision.
|
|
1106
|
+
if ((size_t) level < assumptions.size () ||
|
|
1107
|
+
((size_t) level == assumptions.size () && constraint.size ())) {
|
|
1108
|
+
return 0;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
if (!elit)
|
|
1113
|
+
return 0;
|
|
1114
|
+
LOG ("external propagator proposes decision: %d", elit);
|
|
1115
|
+
|
|
1116
|
+
REQUIRE ((size_t) abs (elit) < external->is_observed.size () &&
|
|
1117
|
+
external->is_observed[abs (elit)],
|
|
1118
|
+
"external decisions are only allowed over observed variables.");
|
|
1119
|
+
|
|
1120
|
+
assert (external->is_observed[abs (elit)]);
|
|
1121
|
+
|
|
1122
|
+
int ilit = external->e2i[abs (elit)];
|
|
1123
|
+
if (elit < 0)
|
|
1124
|
+
ilit = -ilit;
|
|
1125
|
+
|
|
1126
|
+
assert (fixed (ilit) || observed (ilit));
|
|
1127
|
+
|
|
1128
|
+
LOG ("Asking external propagator for decision returned: %d (internal: "
|
|
1129
|
+
"%d, fixed: %d, val: %d)",
|
|
1130
|
+
elit, ilit, fixed (ilit), val (ilit));
|
|
1131
|
+
|
|
1132
|
+
REQUIRE (
|
|
1133
|
+
!fixed (ilit) && !val (ilit),
|
|
1134
|
+
"external decisions are only allowed over unassigned variables.");
|
|
1135
|
+
|
|
1136
|
+
return ilit;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
/*----------------------------------------------------------------------------*/
|
|
1140
|
+
//
|
|
1141
|
+
// Check if the clause is a forgettable clause coming from the external
|
|
1142
|
+
// propagator.
|
|
1143
|
+
//
|
|
1144
|
+
bool Internal::is_external_forgettable (int64_t id) {
|
|
1145
|
+
assert (opts.check);
|
|
1146
|
+
return (external->forgettable_original.find (id) !=
|
|
1147
|
+
external->forgettable_original.end ());
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/*----------------------------------------------------------------------------*/
|
|
1151
|
+
//
|
|
1152
|
+
// When an external forgettable clause is deleted, it is marked in the
|
|
1153
|
+
// 'forgettable_original' hash, so that the internal model checking can
|
|
1154
|
+
// ignore it.
|
|
1155
|
+
//
|
|
1156
|
+
void Internal::mark_garbage_external_forgettable (int64_t id) {
|
|
1157
|
+
assert (opts.check);
|
|
1158
|
+
assert (is_external_forgettable (id));
|
|
1159
|
+
|
|
1160
|
+
LOG (external->forgettable_original[id],
|
|
1161
|
+
"forgettable external lemma is deleted:");
|
|
1162
|
+
// Mark as removed by flipping the first flag to false.
|
|
1163
|
+
external->forgettable_original[id][0] = 0;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/*----------------------------------------------------------------------------*/
|
|
1167
|
+
//
|
|
1168
|
+
// Check that the literals in the clause are properly ordered. Used only
|
|
1169
|
+
// internally for debug purposes.
|
|
1170
|
+
//
|
|
1171
|
+
void Internal::check_watched_literal_invariants () {
|
|
1172
|
+
#ifndef NDEBUG
|
|
1173
|
+
int v0 = 0;
|
|
1174
|
+
int v1 = 0;
|
|
1175
|
+
|
|
1176
|
+
if (val (clause[0]) > 0)
|
|
1177
|
+
v0 = 1;
|
|
1178
|
+
else if (val (clause[0]) < 0)
|
|
1179
|
+
v0 = -1;
|
|
1180
|
+
|
|
1181
|
+
if (val (clause[1]) > 0)
|
|
1182
|
+
v1 = 1;
|
|
1183
|
+
else if (val (clause[1]) < 0)
|
|
1184
|
+
v1 = -1;
|
|
1185
|
+
assert (v0 >= v1);
|
|
1186
|
+
#endif
|
|
1187
|
+
if (val (clause[0]) > 0) {
|
|
1188
|
+
if (val (clause[1]) > 0) { // Case 1: Both literals are satisfied
|
|
1189
|
+
// They are ordered by lower to higher decision level
|
|
1190
|
+
assert (var (clause[0]).level <= var (clause[1]).level);
|
|
1191
|
+
|
|
1192
|
+
// Every other literal of the clause is either
|
|
1193
|
+
// - satisfied at higher level
|
|
1194
|
+
// - unassigned
|
|
1195
|
+
// - falsified
|
|
1196
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1197
|
+
assert (val (clause[i]) <= 0 ||
|
|
1198
|
+
(var (clause[1]).level <= var (clause[i]).level));
|
|
1199
|
+
|
|
1200
|
+
} else if (val (clause[1]) ==
|
|
1201
|
+
0) { // Case 2: First satisfied, next unassigned
|
|
1202
|
+
|
|
1203
|
+
// Every other literal of the clause is either
|
|
1204
|
+
// - unassigned
|
|
1205
|
+
// - falsified
|
|
1206
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1207
|
+
assert (val (clause[i]) <= 0);
|
|
1208
|
+
|
|
1209
|
+
} else { // Case 3: First satisfied, next falsified -> could have been a
|
|
1210
|
+
// reason of a previous propagation
|
|
1211
|
+
// Every other literal of the clause is falsified but at a lower
|
|
1212
|
+
// decision level
|
|
1213
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1214
|
+
assert (val (clause[i]) < 0 &&
|
|
1215
|
+
(var (clause[1]).level >= var (clause[i]).level));
|
|
1216
|
+
}
|
|
1217
|
+
} else if (val (clause[0]) == 0) {
|
|
1218
|
+
if (val (clause[1]) == 0) { // Case 4: Both literals are unassigned
|
|
1219
|
+
|
|
1220
|
+
// Every other literal of the clause is either
|
|
1221
|
+
// - unassigned
|
|
1222
|
+
// - falsified
|
|
1223
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1224
|
+
assert (val (clause[i]) <= 0);
|
|
1225
|
+
|
|
1226
|
+
} else { // Case 5: First unassigned, next falsified -> PROPAGATE
|
|
1227
|
+
// Every other literal of the clause is falsified but at a lower
|
|
1228
|
+
// decision level
|
|
1229
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1230
|
+
assert (val (clause[i]) < 0 &&
|
|
1231
|
+
(var (clause[1]).level >= var (clause[i]).level));
|
|
1232
|
+
}
|
|
1233
|
+
} else {
|
|
1234
|
+
assert (val (clause[0]) < 0 &&
|
|
1235
|
+
val (clause[1]) < 0); // Case 6: Both literals are falsified
|
|
1236
|
+
|
|
1237
|
+
// They are ordered by higher to lower decision level
|
|
1238
|
+
assert (var (clause[0]).level >= var (clause[1]).level);
|
|
1239
|
+
|
|
1240
|
+
// Every other literal of the clause is falsified, but at a lower level
|
|
1241
|
+
for (size_t i = 2; i < clause.size (); i++)
|
|
1242
|
+
assert (val (clause[i]) < 0 &&
|
|
1243
|
+
(var (clause[1]).level >= var (clause[i]).level));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
#ifndef NDEBUG
|
|
1248
|
+
|
|
1249
|
+
/*----------------------------------------------------------------------------*/
|
|
1250
|
+
//
|
|
1251
|
+
// An expensive function that can be used for deep-debug trail-related
|
|
1252
|
+
// issues in mobical. Do not use it unless it is really unavoidable.
|
|
1253
|
+
//
|
|
1254
|
+
// eq_class contains all the merged external literals that are currently
|
|
1255
|
+
// compacted to the internal literal of trail[0] and return true.
|
|
1256
|
+
//
|
|
1257
|
+
// In case trail[0] does not exists or is not on the root level, the
|
|
1258
|
+
// function returns false (indicating that there was no merger literal
|
|
1259
|
+
// found).
|
|
1260
|
+
//
|
|
1261
|
+
bool Internal::get_merged_literals (std::vector<int> &eq_class) {
|
|
1262
|
+
eq_class.clear ();
|
|
1263
|
+
|
|
1264
|
+
if (!trail.size ())
|
|
1265
|
+
return false;
|
|
1266
|
+
|
|
1267
|
+
int ilit = trail[0];
|
|
1268
|
+
size_t lit_level = var (ilit).level;
|
|
1269
|
+
|
|
1270
|
+
if (!lit_level) {
|
|
1271
|
+
// Collect all the variables that are merged and mapped to that ilit
|
|
1272
|
+
size_t e2i_size = external->e2i.size ();
|
|
1273
|
+
int ivar = abs (ilit);
|
|
1274
|
+
for (size_t i = 0; i < e2i_size; i++) {
|
|
1275
|
+
int other = abs (external->e2i[i]);
|
|
1276
|
+
if (other == ivar) {
|
|
1277
|
+
if (external->e2i[i] == ilit)
|
|
1278
|
+
eq_class.push_back (i);
|
|
1279
|
+
else
|
|
1280
|
+
eq_class.push_back (-1 * i);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
return true;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
return false;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/*----------------------------------------------------------------------------*/
|
|
1291
|
+
//
|
|
1292
|
+
// Collect all external variables that are FIXED internally. Again an
|
|
1293
|
+
// expensive function that should be called only for debugging in mobical.
|
|
1294
|
+
//
|
|
1295
|
+
// Do not use it unless it is really unavoidable.
|
|
1296
|
+
//
|
|
1297
|
+
void Internal::get_all_fixed_literals (std::vector<int> &fixed_lits) {
|
|
1298
|
+
fixed_lits.clear ();
|
|
1299
|
+
if (!trail.size ())
|
|
1300
|
+
return;
|
|
1301
|
+
|
|
1302
|
+
int e2i_size = external->e2i.size ();
|
|
1303
|
+
int ilit;
|
|
1304
|
+
for (int eidx = 1; eidx < e2i_size; eidx++) {
|
|
1305
|
+
ilit = external->e2i[eidx];
|
|
1306
|
+
if (ilit && !external->ervars[eidx]) {
|
|
1307
|
+
Flags &f = flags (ilit);
|
|
1308
|
+
if (f.status == Flags::FIXED) {
|
|
1309
|
+
fixed_lits.push_back (vals[abs (ilit)] * eidx);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
#endif
|
|
1315
|
+
|
|
1316
|
+
} // namespace CaDiCaL
|