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,940 @@
|
|
|
1
|
+
#include "internal.hpp"
|
|
2
|
+
|
|
3
|
+
namespace CaDiCaL {
|
|
4
|
+
|
|
5
|
+
/*------------------------------------------------------------------------*/
|
|
6
|
+
|
|
7
|
+
// Globally blocked clause elimination (which we call here 'conditioning')
|
|
8
|
+
// is described first in the PhD thesis of Benjamin Kiesl from 2019. An
|
|
9
|
+
// extended version, which in particular describes the algorithm implemented
|
|
10
|
+
// below is in our invited ATVA'19 paper [KieslHeuleBiere-ATVA'19]. This
|
|
11
|
+
// accordingly needs witnesses consisting potentially of more than one
|
|
12
|
+
// literal. It is the first technique implemented in CaDiCaL with this
|
|
13
|
+
// feature (PR clause elimination thus should work in principle too).
|
|
14
|
+
|
|
15
|
+
// Basically globally blocked clauses are like set blocked clauses, except
|
|
16
|
+
// that the witness cube (of literals to be flipped during reconstruction)
|
|
17
|
+
// can contain variables which are not in the blocked clause. This
|
|
18
|
+
// can simulate some interesting global optimizations like 'headlines' from
|
|
19
|
+
// the FAN algorithm for ATPG. The technique was actually motivated to
|
|
20
|
+
// simulate this optimization. It turns out that globally blocked clauses
|
|
21
|
+
// can be seen as 'conditional autarkies', where in essence the condition
|
|
22
|
+
// cube is the negation of the globally blocked redundant clause (it
|
|
23
|
+
// needs to contain one autarky literal though) and the autarky part
|
|
24
|
+
// represents the witness.
|
|
25
|
+
|
|
26
|
+
/*------------------------------------------------------------------------*/
|
|
27
|
+
|
|
28
|
+
// Elimination of globally blocked clauses is first tried in regular
|
|
29
|
+
// intervals in terms of the number of conflicts. Then the main heuristics
|
|
30
|
+
// is to trigger 'condition' if the decision level is above the current
|
|
31
|
+
// moving average of the back jump level.
|
|
32
|
+
|
|
33
|
+
// TODO We might need to consider less frequent conditioning.
|
|
34
|
+
|
|
35
|
+
bool Internal::conditioning () {
|
|
36
|
+
|
|
37
|
+
if (!opts.condition)
|
|
38
|
+
return false;
|
|
39
|
+
if (!preprocessing && !opts.inprocessing)
|
|
40
|
+
return false;
|
|
41
|
+
if (preprocessing)
|
|
42
|
+
assert (lim.preprocessing);
|
|
43
|
+
|
|
44
|
+
// Triggered in regular 'opts.conditionint' conflict intervals.
|
|
45
|
+
//
|
|
46
|
+
if (lim.condition > stats.conflicts)
|
|
47
|
+
return false;
|
|
48
|
+
|
|
49
|
+
if (!level)
|
|
50
|
+
return false; // One decision necessary.
|
|
51
|
+
|
|
52
|
+
if (level <= averages.current.jump)
|
|
53
|
+
return false; // Main heuristic.
|
|
54
|
+
|
|
55
|
+
if (!stats.current.irredundant)
|
|
56
|
+
return false;
|
|
57
|
+
double remain = active ();
|
|
58
|
+
if (!remain)
|
|
59
|
+
return false;
|
|
60
|
+
double ratio = stats.current.irredundant / remain;
|
|
61
|
+
return ratio <= opts.conditionmaxrat;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/*------------------------------------------------------------------------*/
|
|
65
|
+
|
|
66
|
+
// We start with the current assignment and then temporarily unassign
|
|
67
|
+
// literals. They are reassigned afterwards. The global state of the CDCL
|
|
68
|
+
// solver should not change though. Thus we copied from 'search_unassign'
|
|
69
|
+
// in 'backtrack.cpp' what is needed to unassign literals and then from
|
|
70
|
+
// 'search_assign' in 'propagate.cpp' what is needed for reassigning
|
|
71
|
+
// literals, but restricted the copied code to only updating the actual
|
|
72
|
+
// assignment (in 'vals') and not changing anything else.
|
|
73
|
+
|
|
74
|
+
// We use temporarily unassigning for two purposes. First, if a conditional
|
|
75
|
+
// literal does not occur negated in a candidate clause it is unassigned.
|
|
76
|
+
// Second, as a minor optimization, we first unassign all root-level
|
|
77
|
+
// assigned (fixed) literals, to avoid checking the decision level of
|
|
78
|
+
// literals during the procedure.
|
|
79
|
+
|
|
80
|
+
void Internal::condition_unassign (int lit) {
|
|
81
|
+
LOG ("condition unassign %d", lit);
|
|
82
|
+
assert (val (lit) > 0);
|
|
83
|
+
set_val (lit, 0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void Internal::condition_assign (int lit) {
|
|
87
|
+
LOG ("condition assign %d", lit);
|
|
88
|
+
assert (!val (lit));
|
|
89
|
+
set_val (lit, 1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*------------------------------------------------------------------------*/
|
|
93
|
+
|
|
94
|
+
// The current partition into conditional part and autarky part during
|
|
95
|
+
// refinement is represented through a conditional bit in 'marks'.
|
|
96
|
+
|
|
97
|
+
inline bool Internal::is_conditional_literal (int lit) const {
|
|
98
|
+
return val (lit) > 0 && getbit (lit, 0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
inline bool Internal::is_autarky_literal (int lit) const {
|
|
102
|
+
return val (lit) > 0 && !getbit (lit, 0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
inline void Internal::mark_as_conditional_literal (int lit) {
|
|
106
|
+
LOG ("marking %d as conditional literal", lit);
|
|
107
|
+
assert (val (lit) > 0);
|
|
108
|
+
setbit (lit, 0);
|
|
109
|
+
assert (is_conditional_literal (lit));
|
|
110
|
+
assert (!is_autarky_literal (lit));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
inline void Internal::unmark_as_conditional_literal (int lit) {
|
|
114
|
+
LOG ("unmarking %d as conditional literal", lit);
|
|
115
|
+
assert (is_conditional_literal (lit));
|
|
116
|
+
unsetbit (lit, 0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*------------------------------------------------------------------------*/
|
|
120
|
+
|
|
121
|
+
// We also need to know the literals which are in the current clause. These
|
|
122
|
+
// are just marked (also in 'marks' but with the (signed) upper two bits).
|
|
123
|
+
// We need a signed mark here, since we have to distinguish positive and
|
|
124
|
+
// negative occurrences of literals in the candidate clause.
|
|
125
|
+
|
|
126
|
+
inline bool Internal::is_in_candidate_clause (int lit) const {
|
|
127
|
+
return marked67 (lit) > 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
inline void Internal::mark_in_candidate_clause (int lit) {
|
|
131
|
+
LOG ("marking %d as literal of the candidate clause", lit);
|
|
132
|
+
mark67 (lit);
|
|
133
|
+
assert (is_in_candidate_clause (lit));
|
|
134
|
+
assert (!is_in_candidate_clause (-lit));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
inline void Internal::unmark_in_candidate_clause (int lit) {
|
|
138
|
+
LOG ("unmarking %d as literal of the candidate clause", lit);
|
|
139
|
+
assert (is_in_candidate_clause (lit));
|
|
140
|
+
unmark67 (lit);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*------------------------------------------------------------------------*/
|
|
144
|
+
|
|
145
|
+
struct less_conditioned {
|
|
146
|
+
bool operator() (Clause *a, Clause *b) {
|
|
147
|
+
return !a->conditioned && b->conditioned;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// This is the function for eliminating globally blocked clauses. It is
|
|
152
|
+
// triggered during CDCL search according to 'conditioning' above and uses
|
|
153
|
+
// the current assignment as basis to find globally blocked clauses.
|
|
154
|
+
|
|
155
|
+
long Internal::condition_round (long delta) {
|
|
156
|
+
|
|
157
|
+
long limit;
|
|
158
|
+
#ifndef QUIET
|
|
159
|
+
long props = 0;
|
|
160
|
+
#endif
|
|
161
|
+
if (LONG_MAX - delta < stats.condprops)
|
|
162
|
+
limit = LONG_MAX;
|
|
163
|
+
else
|
|
164
|
+
limit = stats.condprops + delta;
|
|
165
|
+
|
|
166
|
+
size_t initial_trail_level = trail.size ();
|
|
167
|
+
int initial_level = level;
|
|
168
|
+
|
|
169
|
+
LOG ("initial trail level %zd", initial_trail_level);
|
|
170
|
+
|
|
171
|
+
protect_reasons ();
|
|
172
|
+
|
|
173
|
+
#if defined(LOGGING) || !defined(NDEBUG)
|
|
174
|
+
int additionally_assigned = 0;
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
for (auto idx : vars) {
|
|
178
|
+
const signed char tmp = val (idx);
|
|
179
|
+
Var &v = var (idx);
|
|
180
|
+
if (tmp) {
|
|
181
|
+
if (v.level) {
|
|
182
|
+
const int lit = tmp < 0 ? -idx : idx;
|
|
183
|
+
if (!active (idx)) {
|
|
184
|
+
LOG ("temporarily unassigning inactive literal %d", lit);
|
|
185
|
+
condition_unassign (lit);
|
|
186
|
+
}
|
|
187
|
+
if (frozen (idx)) {
|
|
188
|
+
LOG ("temporarily unassigning frozen literal %d", lit);
|
|
189
|
+
condition_unassign (lit);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else if (frozen (idx)) {
|
|
193
|
+
LOG ("keeping frozen literal %d unassigned", idx);
|
|
194
|
+
} else if (!active (idx)) {
|
|
195
|
+
LOG ("keeping inactive literal %d unassigned", idx);
|
|
196
|
+
} else { // if (preprocessing) {
|
|
197
|
+
if (initial_level == level) {
|
|
198
|
+
level++;
|
|
199
|
+
LOG ("new condition decision level");
|
|
200
|
+
}
|
|
201
|
+
const int lit = decide_phase (idx, true);
|
|
202
|
+
condition_assign (lit);
|
|
203
|
+
v.level = level;
|
|
204
|
+
trail.push_back (lit);
|
|
205
|
+
#if defined(LOGGING) || !defined(NDEBUG)
|
|
206
|
+
additionally_assigned++;
|
|
207
|
+
#endif
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
LOG ("assigned %d additional literals", additionally_assigned);
|
|
211
|
+
|
|
212
|
+
// We compute statistics about the size of the assignments.
|
|
213
|
+
//
|
|
214
|
+
// The initial assignment consists of the non-root-level assigned literals
|
|
215
|
+
// split into a conditional and an autarky part. The conditional part
|
|
216
|
+
// consists of literals assigned true and occurring negated in a clause
|
|
217
|
+
// (touch the clause), which does not contain another literal assigned to
|
|
218
|
+
// true. This initial partition is the same for all refinements used in
|
|
219
|
+
// checking whether a candidate clause is globally blocked.
|
|
220
|
+
//
|
|
221
|
+
// For each candidate clause some of the conditional literals have to be
|
|
222
|
+
// unassigned, and the autarky is shrunken by turning some of the autarky
|
|
223
|
+
// literals into conditional literals (which might get unassigned in a
|
|
224
|
+
// later refinement though).
|
|
225
|
+
//
|
|
226
|
+
// The fix-point of this procedure produces a final assignment, which
|
|
227
|
+
// consists of the remaining assigned literals, again split into a
|
|
228
|
+
// conditional and an autarky part.
|
|
229
|
+
//
|
|
230
|
+
struct {
|
|
231
|
+
size_t assigned, conditional, autarky;
|
|
232
|
+
} initial, remain;
|
|
233
|
+
|
|
234
|
+
initial.assigned = 0;
|
|
235
|
+
for (auto idx : vars) {
|
|
236
|
+
const signed char tmp = val (idx);
|
|
237
|
+
if (!tmp)
|
|
238
|
+
continue;
|
|
239
|
+
if (!var (idx).level)
|
|
240
|
+
continue;
|
|
241
|
+
LOG ("initial assignment %ds", tmp < 0 ? -idx : idx);
|
|
242
|
+
initial.assigned++;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
PHASE ("condition", stats.conditionings, "initial assignment of size %zd",
|
|
246
|
+
initial.assigned);
|
|
247
|
+
|
|
248
|
+
// For each candidate clause we refine the assignment (monotonically),
|
|
249
|
+
// by unassigning some conditional literals and turning some autarky
|
|
250
|
+
// literals into conditionals.
|
|
251
|
+
//
|
|
252
|
+
// As the conditional part is usually smaller than the autarky part our
|
|
253
|
+
// implementation only explicitly maintains the initial conditional part,
|
|
254
|
+
// with conditional bit set to true through 'mark_as_conditional_literal'.
|
|
255
|
+
// The autarky part consists of all literals assigned true which do not
|
|
256
|
+
// have their conditional bit set to true. Since in both cases the
|
|
257
|
+
// literal has to be assigned true, we only need a single bit for both the
|
|
258
|
+
// literal as well as its negation (it does not have to be 'signed').
|
|
259
|
+
//
|
|
260
|
+
vector<int> conditional;
|
|
261
|
+
|
|
262
|
+
vector<Clause *> candidates; // Gather candidate clauses.
|
|
263
|
+
#ifndef QUIET
|
|
264
|
+
size_t watched = 0; // Number of watched clauses.
|
|
265
|
+
#endif
|
|
266
|
+
|
|
267
|
+
initial.autarky = initial.assigned; // Initially all are in autarky
|
|
268
|
+
initial.conditional = 0; // and none in conditional part.
|
|
269
|
+
|
|
270
|
+
// Upper bound on the number of watched clauses. In principle one could
|
|
271
|
+
// use 'SIZE_MAX' but this is not available by default (yet).
|
|
272
|
+
//
|
|
273
|
+
const size_t size_max = clauses.size () + 1;
|
|
274
|
+
|
|
275
|
+
// Initialize additional occurrence lists.
|
|
276
|
+
//
|
|
277
|
+
init_occs ();
|
|
278
|
+
|
|
279
|
+
// Number of previously conditioned and unconditioned candidates.
|
|
280
|
+
//
|
|
281
|
+
size_t conditioned = 0, unconditioned = 0;
|
|
282
|
+
|
|
283
|
+
// Now go over all (non-garbage) irredundant clauses and check whether
|
|
284
|
+
// they are candidates, have to be watched, or whether they force the
|
|
285
|
+
// negation of some of their literals to be conditional initially.
|
|
286
|
+
//
|
|
287
|
+
for (const auto &c : clauses) {
|
|
288
|
+
if (c->garbage)
|
|
289
|
+
continue; // Can already be ignored.
|
|
290
|
+
if (c->redundant)
|
|
291
|
+
continue; // Ignore redundant clauses too.
|
|
292
|
+
|
|
293
|
+
// First determine the following numbers for the candidate clause
|
|
294
|
+
// (restricted to non-root-level assignments).
|
|
295
|
+
//
|
|
296
|
+
int positive = 0; // Number true literals.
|
|
297
|
+
int negative = 0; // Number false literals.
|
|
298
|
+
int watch = 0; // True Literal to watch.
|
|
299
|
+
//
|
|
300
|
+
size_t minsize = size_max; // Number of occurrences of 'watch'.
|
|
301
|
+
//
|
|
302
|
+
// But also ignore root-level satisfied but not yet garbage clauses.
|
|
303
|
+
//
|
|
304
|
+
bool satisfied = false; // Root level satisfied.
|
|
305
|
+
//
|
|
306
|
+
for (const_literal_iterator l = c->begin ();
|
|
307
|
+
!satisfied && l != c->end (); l++) {
|
|
308
|
+
const int lit = *l;
|
|
309
|
+
const signed char tmp = val (lit);
|
|
310
|
+
if (tmp && !var (lit).level)
|
|
311
|
+
satisfied = (tmp > 0);
|
|
312
|
+
else if (tmp < 0)
|
|
313
|
+
negative++;
|
|
314
|
+
else if (tmp > 0) {
|
|
315
|
+
const size_t size = occs (lit).size ();
|
|
316
|
+
if (size < minsize)
|
|
317
|
+
watch = lit, minsize = size;
|
|
318
|
+
positive++;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (satisfied) { // Ignore root-level satisfied clauses.
|
|
322
|
+
mark_garbage (c); // But mark them as garbage already now.
|
|
323
|
+
continue; // ... with next clause 'c'.
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Candidates are clauses with at least a positive literal in it.
|
|
327
|
+
//
|
|
328
|
+
if (positive > 0) {
|
|
329
|
+
LOG (c, "found %d positive literals in candidate", positive);
|
|
330
|
+
candidates.push_back (c);
|
|
331
|
+
if (c->conditioned)
|
|
332
|
+
conditioned++;
|
|
333
|
+
else
|
|
334
|
+
unconditioned++;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Only one positive literal in each clauses with also at least one
|
|
338
|
+
// negative literal has to be watched in occurrence lists. These
|
|
339
|
+
// watched clauses will be checked to contain only negative literals as
|
|
340
|
+
// soon such a positive literal is unassigned. If this is the case
|
|
341
|
+
// these false literals have to be unassigned and potentially new
|
|
342
|
+
// conditional literals have to be determined.
|
|
343
|
+
//
|
|
344
|
+
// Note that only conditional literals are unassigned. However it does
|
|
345
|
+
// not matter that we might also watch autarky literals, because either
|
|
346
|
+
// such an autarky literal remains a witness that the clause is
|
|
347
|
+
// satisfied as long it remains an autarky literal. Otherwise at one
|
|
348
|
+
// point it becomes conditional and is unassigned, but then a
|
|
349
|
+
// replacement watch will be searched.
|
|
350
|
+
//
|
|
351
|
+
if (negative > 0 && positive > 0) {
|
|
352
|
+
LOG (c, "found %d negative literals in candidate", negative);
|
|
353
|
+
assert (watch);
|
|
354
|
+
assert (val (watch) > 0);
|
|
355
|
+
Occs &os = occs (watch);
|
|
356
|
+
assert (os.size () == minsize);
|
|
357
|
+
os.push_back (c);
|
|
358
|
+
#ifndef QUIET
|
|
359
|
+
watched++;
|
|
360
|
+
#endif
|
|
361
|
+
LOG (c, "watching %d with %zd occurrences in", watch, minsize);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// The initial global conditional part for the current assignment is
|
|
365
|
+
// extracted from clauses with only negative literals. It is the same
|
|
366
|
+
// for all considered candidate clauses. These negative literals make up
|
|
367
|
+
// the global conditional part, are marked here.
|
|
368
|
+
//
|
|
369
|
+
if (negative > 0 && !positive) {
|
|
370
|
+
|
|
371
|
+
size_t new_conditionals = 0;
|
|
372
|
+
|
|
373
|
+
for (const_literal_iterator l = c->begin (); l != c->end (); l++) {
|
|
374
|
+
const int lit = *l;
|
|
375
|
+
signed char tmp = val (lit);
|
|
376
|
+
if (!tmp)
|
|
377
|
+
continue;
|
|
378
|
+
assert (tmp < 0);
|
|
379
|
+
if (!var (lit).level)
|
|
380
|
+
continue; // Not unassigned yet!
|
|
381
|
+
if (is_conditional_literal (-lit))
|
|
382
|
+
continue;
|
|
383
|
+
mark_as_conditional_literal (-lit);
|
|
384
|
+
conditional.push_back (-lit);
|
|
385
|
+
new_conditionals++;
|
|
386
|
+
}
|
|
387
|
+
if (new_conditionals > 0)
|
|
388
|
+
LOG (c, "marked %zu negations of literals as conditional in",
|
|
389
|
+
new_conditionals);
|
|
390
|
+
|
|
391
|
+
initial.conditional += new_conditionals;
|
|
392
|
+
assert (initial.autarky >= new_conditionals);
|
|
393
|
+
initial.autarky -= new_conditionals;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
} // End of loop over all clauses to collect candidates etc.
|
|
397
|
+
|
|
398
|
+
PHASE ("condition", stats.conditionings, "found %zd candidate clauses",
|
|
399
|
+
candidates.size ());
|
|
400
|
+
PHASE ("condition", stats.conditionings,
|
|
401
|
+
"watching %zu literals and clauses", watched);
|
|
402
|
+
PHASE ("condition", stats.conditionings,
|
|
403
|
+
"initially %zd conditional literals %.0f%%", initial.conditional,
|
|
404
|
+
percent (initial.conditional, initial.assigned));
|
|
405
|
+
PHASE ("condition", stats.conditionings,
|
|
406
|
+
"initially %zd autarky literals %.0f%%", initial.autarky,
|
|
407
|
+
percent (initial.autarky, initial.assigned));
|
|
408
|
+
#ifdef LOGGING
|
|
409
|
+
for (size_t i = 0; i < conditional.size (); i++) {
|
|
410
|
+
LOG ("initial conditional %d", conditional[i]);
|
|
411
|
+
assert (is_conditional_literal (conditional[i]));
|
|
412
|
+
}
|
|
413
|
+
for (size_t i = 0; i < trail.size (); i++)
|
|
414
|
+
if (is_autarky_literal (trail[i]))
|
|
415
|
+
LOG ("initial autarky %d", trail[i]);
|
|
416
|
+
#endif
|
|
417
|
+
assert (initial.conditional == conditional.size ());
|
|
418
|
+
assert (initial.assigned == initial.conditional + initial.autarky);
|
|
419
|
+
|
|
420
|
+
stats.condassinit += initial.assigned;
|
|
421
|
+
stats.condcondinit += initial.conditional;
|
|
422
|
+
stats.condautinit += initial.autarky;
|
|
423
|
+
stats.condassvars += active ();
|
|
424
|
+
|
|
425
|
+
// To speed-up and particularly simplify the code we unassign all
|
|
426
|
+
// root-level variables temporarily, actually all inactive assigned
|
|
427
|
+
// variables. This allows us to avoid tests on whether an assigned
|
|
428
|
+
// literal is actually root-level assigned and thus should be ignored (not
|
|
429
|
+
// considered to be assigned). For this to work we have to ignore root
|
|
430
|
+
// level satisfied clauses as done above. These are neither candidates
|
|
431
|
+
// nor have to be watched. Remaining originally root-level assigned
|
|
432
|
+
// literals in clauses are only set to false.
|
|
433
|
+
//
|
|
434
|
+
for (const auto &lit : trail)
|
|
435
|
+
if (fixed (lit))
|
|
436
|
+
condition_unassign (lit);
|
|
437
|
+
|
|
438
|
+
// Stack to save temporarily unassigned (conditional) literals.
|
|
439
|
+
//
|
|
440
|
+
vector<int> unassigned;
|
|
441
|
+
|
|
442
|
+
// Make sure to focus on clauses not tried before by marking clauses which
|
|
443
|
+
// have been checked before using the 'conditioned' bit of clauses. If all
|
|
444
|
+
// candidates have their bit set, we have to reset it. Since the
|
|
445
|
+
// assignment might be completely different then last time and thus also
|
|
446
|
+
// the set of candidates this method does not really exactly lead to a
|
|
447
|
+
// round robin scheme of scheduling clauses.
|
|
448
|
+
//
|
|
449
|
+
// TODO consider computing conditioned and unconditioned over all clauses.
|
|
450
|
+
//
|
|
451
|
+
assert (conditioned + unconditioned == candidates.size ());
|
|
452
|
+
if (conditioned && unconditioned) {
|
|
453
|
+
stable_sort (candidates.begin (), candidates.end (),
|
|
454
|
+
less_conditioned ());
|
|
455
|
+
PHASE ("condition", stats.conditionings,
|
|
456
|
+
"focusing on %zd candidates %.0f%% not tried last time",
|
|
457
|
+
unconditioned, percent (unconditioned, candidates.size ()));
|
|
458
|
+
} else if (conditioned && !unconditioned) {
|
|
459
|
+
for (auto const &c : candidates) {
|
|
460
|
+
assert (c->conditioned);
|
|
461
|
+
c->conditioned = false; // Reset 'conditioned' bit.
|
|
462
|
+
}
|
|
463
|
+
PHASE ("condition", stats.conditionings,
|
|
464
|
+
"all %zd candidates tried before", conditioned);
|
|
465
|
+
} else {
|
|
466
|
+
assert (!conditioned);
|
|
467
|
+
PHASE ("condition", stats.conditionings, "all %zd candidates are fresh",
|
|
468
|
+
unconditioned);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// TODO prune assignments further!
|
|
472
|
+
// And thus might result in less watched clauses.
|
|
473
|
+
// So watching should be done here and not earlier.
|
|
474
|
+
// Also, see below, we might need to consider the negation of unassigned
|
|
475
|
+
// literals in candidate clauses as being watched.
|
|
476
|
+
|
|
477
|
+
// Now try to block all candidate clauses.
|
|
478
|
+
//
|
|
479
|
+
long blocked = 0; // Number of Successfully blocked clauses.
|
|
480
|
+
//
|
|
481
|
+
#ifndef QUIET
|
|
482
|
+
size_t untried = candidates.size ();
|
|
483
|
+
#endif
|
|
484
|
+
for (const auto &c : candidates) {
|
|
485
|
+
|
|
486
|
+
if (initial.autarky <= 0)
|
|
487
|
+
break;
|
|
488
|
+
|
|
489
|
+
if (c->reason)
|
|
490
|
+
continue;
|
|
491
|
+
|
|
492
|
+
bool terminated_or_limit_hit = true;
|
|
493
|
+
if (terminated_asynchronously ())
|
|
494
|
+
LOG ("asynchronous termination detected");
|
|
495
|
+
else if (stats.condprops >= limit)
|
|
496
|
+
LOG ("condition propagation limit %ld hit", limit);
|
|
497
|
+
else
|
|
498
|
+
terminated_or_limit_hit = false;
|
|
499
|
+
|
|
500
|
+
if (terminated_or_limit_hit) {
|
|
501
|
+
PHASE ("condition", stats.conditionings,
|
|
502
|
+
"%zd candidates %.0f%% not tried after %ld propagations",
|
|
503
|
+
untried, percent (untried, candidates.size ()), props);
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
#ifndef QUIET
|
|
507
|
+
untried--;
|
|
508
|
+
#endif
|
|
509
|
+
assert (!c->garbage);
|
|
510
|
+
assert (!c->redundant);
|
|
511
|
+
|
|
512
|
+
LOG (c, "candidate");
|
|
513
|
+
c->conditioned = 1; // Next time later.
|
|
514
|
+
|
|
515
|
+
// We watch an autarky literal in the clause, and can stop trying to
|
|
516
|
+
// globally block the clause as soon it turns into a conditional
|
|
517
|
+
// literal and we can not find another one. If the fix-point assignment
|
|
518
|
+
// is reached and we still have an autarky literal left the watched one
|
|
519
|
+
// is reported as witness for this clause being globally blocked.
|
|
520
|
+
//
|
|
521
|
+
int watched_autarky_literal = 0;
|
|
522
|
+
|
|
523
|
+
// First mark all true literals in the candidate clause and find an
|
|
524
|
+
// autarky literal which witnesses that this clause has still a chance
|
|
525
|
+
// to be globally blocked.
|
|
526
|
+
//
|
|
527
|
+
for (const_literal_iterator l = c->begin (); l != c->end (); l++) {
|
|
528
|
+
const int lit = *l;
|
|
529
|
+
mark_in_candidate_clause (lit);
|
|
530
|
+
if (watched_autarky_literal)
|
|
531
|
+
continue;
|
|
532
|
+
if (!is_autarky_literal (lit))
|
|
533
|
+
continue;
|
|
534
|
+
watched_autarky_literal = lit;
|
|
535
|
+
|
|
536
|
+
// TODO assign non-assigned literals to false?
|
|
537
|
+
// Which might need to trigger watching additional clauses.
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (!watched_autarky_literal) {
|
|
541
|
+
LOG ("no initial autarky literal found");
|
|
542
|
+
for (const_literal_iterator l = c->begin (); l != c->end (); l++)
|
|
543
|
+
unmark_in_candidate_clause (*l);
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
stats.condcands++; // Only now ...
|
|
548
|
+
|
|
549
|
+
LOG ("watching first autarky literal %d", watched_autarky_literal);
|
|
550
|
+
|
|
551
|
+
// Save assignment sizes for statistics, logging and checking.
|
|
552
|
+
//
|
|
553
|
+
remain = initial;
|
|
554
|
+
|
|
555
|
+
// Position of next conditional and unassigned literal to process in the
|
|
556
|
+
// 'conditional' and the 'unassigned' stack.
|
|
557
|
+
//
|
|
558
|
+
struct {
|
|
559
|
+
size_t conditional, unassigned;
|
|
560
|
+
} next = {0, 0};
|
|
561
|
+
|
|
562
|
+
assert (unassigned.empty ());
|
|
563
|
+
assert (conditional.size () == initial.conditional);
|
|
564
|
+
|
|
565
|
+
while (watched_autarky_literal && stats.condprops < limit &&
|
|
566
|
+
next.conditional < conditional.size ()) {
|
|
567
|
+
|
|
568
|
+
assert (next.unassigned == unassigned.size ());
|
|
569
|
+
|
|
570
|
+
const int conditional_lit = conditional[next.conditional++];
|
|
571
|
+
LOG ("processing next conditional %d", conditional_lit);
|
|
572
|
+
assert (is_conditional_literal (conditional_lit));
|
|
573
|
+
|
|
574
|
+
if (is_in_candidate_clause (-conditional_lit)) {
|
|
575
|
+
LOG ("conditional %d negated in candidate clause", conditional_lit);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
LOG ("conditional %d does not occur negated in candidate clause",
|
|
580
|
+
conditional_lit);
|
|
581
|
+
|
|
582
|
+
condition_unassign (conditional_lit);
|
|
583
|
+
assert (!is_conditional_literal (conditional_lit));
|
|
584
|
+
unassigned.push_back (conditional_lit);
|
|
585
|
+
|
|
586
|
+
assert (remain.assigned > 0);
|
|
587
|
+
assert (remain.conditional > 0);
|
|
588
|
+
remain.conditional--;
|
|
589
|
+
remain.assigned--;
|
|
590
|
+
|
|
591
|
+
while (watched_autarky_literal && stats.condprops < limit &&
|
|
592
|
+
next.unassigned < unassigned.size ()) {
|
|
593
|
+
const int unassigned_lit = unassigned[next.unassigned++];
|
|
594
|
+
LOG ("processing next unassigned %d", unassigned_lit);
|
|
595
|
+
assert (!val (unassigned_lit));
|
|
596
|
+
#ifndef QUIET
|
|
597
|
+
props++;
|
|
598
|
+
#endif
|
|
599
|
+
stats.condprops++;
|
|
600
|
+
|
|
601
|
+
Occs &os = occs (unassigned_lit);
|
|
602
|
+
if (os.empty ())
|
|
603
|
+
continue;
|
|
604
|
+
|
|
605
|
+
// Traverse all watched clauses of 'unassigned_lit' and find
|
|
606
|
+
// replacement watches or if none is found turn the negation of all
|
|
607
|
+
// false autarky literals in that clause into conditional literals.
|
|
608
|
+
// If one of those autarky literals is the watched autarky literal
|
|
609
|
+
// in the candidate clause, that one has to be updated too.
|
|
610
|
+
//
|
|
611
|
+
// We expect that this loop is a hot-spot for the procedure and thus
|
|
612
|
+
// are more careful about accessing end points for iterating.
|
|
613
|
+
//
|
|
614
|
+
auto i = os.begin (), j = i;
|
|
615
|
+
for (; watched_autarky_literal && j != os.end (); j++) {
|
|
616
|
+
Clause *d = *i++ = *j;
|
|
617
|
+
|
|
618
|
+
int replacement = 0; // New watched literal in 'd'.
|
|
619
|
+
int negative = 0; // Negative autarky literals in 'd'.
|
|
620
|
+
|
|
621
|
+
for (const_literal_iterator l = d->begin (); l != d->end ();
|
|
622
|
+
l++) {
|
|
623
|
+
const int lit = *l;
|
|
624
|
+
const signed char tmp = val (lit);
|
|
625
|
+
if (tmp > 0)
|
|
626
|
+
replacement = lit;
|
|
627
|
+
if (tmp < 0 && is_autarky_literal (-lit))
|
|
628
|
+
negative++;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (replacement) {
|
|
632
|
+
LOG ("found replacement %d for unassigned %d", replacement,
|
|
633
|
+
unassigned_lit);
|
|
634
|
+
LOG (d, "unwatching %d in", unassigned_lit);
|
|
635
|
+
i--; // Drop watch!
|
|
636
|
+
LOG (d, "watching %d in", replacement);
|
|
637
|
+
|
|
638
|
+
assert (replacement != unassigned_lit);
|
|
639
|
+
occs (replacement).push_back (d);
|
|
640
|
+
|
|
641
|
+
continue; // ... with next watched clause 'd'.
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
LOG ("no replacement found for unassigned %d", unassigned_lit);
|
|
645
|
+
|
|
646
|
+
// Keep watching 'd' by 'unassigned_lit' if no replacement found.
|
|
647
|
+
|
|
648
|
+
if (!negative) {
|
|
649
|
+
LOG (d, "no negative autarky literals left in");
|
|
650
|
+
continue; // ... with next watched clause 'd'.
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
LOG (d, "found %d negative autarky literals in", negative);
|
|
654
|
+
|
|
655
|
+
for (const_literal_iterator l = d->begin ();
|
|
656
|
+
watched_autarky_literal && l != d->end (); l++) {
|
|
657
|
+
const int lit = *l;
|
|
658
|
+
if (!is_autarky_literal (-lit))
|
|
659
|
+
continue;
|
|
660
|
+
mark_as_conditional_literal (-lit);
|
|
661
|
+
conditional.push_back (-lit);
|
|
662
|
+
|
|
663
|
+
remain.conditional++;
|
|
664
|
+
assert (remain.autarky > 0);
|
|
665
|
+
remain.autarky--;
|
|
666
|
+
|
|
667
|
+
if (-lit != watched_autarky_literal)
|
|
668
|
+
continue;
|
|
669
|
+
|
|
670
|
+
LOG ("need to replace autarky literal %d in candidate", -lit);
|
|
671
|
+
replacement = 0;
|
|
672
|
+
|
|
673
|
+
// TODO save starting point because we only move it forward?
|
|
674
|
+
|
|
675
|
+
for (const_literal_iterator k = c->begin ();
|
|
676
|
+
!replacement && k != c->end (); k++) {
|
|
677
|
+
const int other = *k;
|
|
678
|
+
if (is_autarky_literal (other))
|
|
679
|
+
replacement = other;
|
|
680
|
+
}
|
|
681
|
+
watched_autarky_literal = replacement;
|
|
682
|
+
|
|
683
|
+
if (replacement) {
|
|
684
|
+
LOG (c, "watching autarky %d instead %d in candidate",
|
|
685
|
+
replacement, watched_autarky_literal);
|
|
686
|
+
watched_autarky_literal = replacement;
|
|
687
|
+
} else {
|
|
688
|
+
LOG ("failed to find an autarky replacement");
|
|
689
|
+
watched_autarky_literal = 0; // Breaks out of 4 loops!!!!!
|
|
690
|
+
}
|
|
691
|
+
} // End of loop of turning autarky literals into conditionals.
|
|
692
|
+
} // End of loop of all watched clauses of an unassigned literal.
|
|
693
|
+
//
|
|
694
|
+
// We might abort the occurrence traversal early but already
|
|
695
|
+
// removed some watches, thus have to just copy the rest.
|
|
696
|
+
//
|
|
697
|
+
if (i < j) {
|
|
698
|
+
while (j != os.end ())
|
|
699
|
+
*i++ = *j++;
|
|
700
|
+
LOG ("flushed %zd occurrences of %d", os.end () - i,
|
|
701
|
+
unassigned_lit);
|
|
702
|
+
os.resize (i - os.begin ());
|
|
703
|
+
}
|
|
704
|
+
} // End of loop which goes over all unprocessed unassigned literals.
|
|
705
|
+
} // End of loop which goes over all unprocessed conditional literals.
|
|
706
|
+
|
|
707
|
+
// We are still processing the candidate 'c' and now have reached a
|
|
708
|
+
// final fix-point assignment partitioned into a conditional and an
|
|
709
|
+
// autarky part, or during unassigned literals figured that there is no
|
|
710
|
+
// positive autarky literal left in 'c'.
|
|
711
|
+
|
|
712
|
+
LOG ("remaining assignment of size %zd", remain.assigned);
|
|
713
|
+
LOG ("remaining conditional part of size %zd", remain.conditional);
|
|
714
|
+
LOG ("remaining autarky part of size %zd", remain.autarky);
|
|
715
|
+
//
|
|
716
|
+
assert (remain.assigned - remain.conditional == remain.autarky);
|
|
717
|
+
//
|
|
718
|
+
#if defined(LOGGING) || !defined(NDEBUG)
|
|
719
|
+
//
|
|
720
|
+
// This is a sanity check, that the size of our implicit representation
|
|
721
|
+
// of the autarky part matches our 'remain' counts. We need the same
|
|
722
|
+
// code for determining autarky literals as in the loop below which adds
|
|
723
|
+
// autarky literals to the extension stack.
|
|
724
|
+
//
|
|
725
|
+
struct {
|
|
726
|
+
size_t assigned, conditional, autarky;
|
|
727
|
+
} check;
|
|
728
|
+
check.assigned = check.conditional = check.autarky = 0;
|
|
729
|
+
for (size_t i = 0; i < trail.size (); i++) {
|
|
730
|
+
const int lit = trail[i];
|
|
731
|
+
if (val (lit)) {
|
|
732
|
+
check.assigned++;
|
|
733
|
+
if (is_conditional_literal (lit)) {
|
|
734
|
+
LOG ("remaining conditional %d", lit);
|
|
735
|
+
assert (!is_autarky_literal (lit));
|
|
736
|
+
check.conditional++;
|
|
737
|
+
} else {
|
|
738
|
+
assert (is_autarky_literal (lit));
|
|
739
|
+
LOG ("remaining autarky %d", lit);
|
|
740
|
+
check.autarky++;
|
|
741
|
+
}
|
|
742
|
+
} else {
|
|
743
|
+
assert (!is_autarky_literal (lit));
|
|
744
|
+
assert (!is_conditional_literal (lit));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
assert (remain.assigned == check.assigned);
|
|
748
|
+
assert (remain.conditional == check.conditional);
|
|
749
|
+
assert (remain.autarky == check.autarky);
|
|
750
|
+
#endif
|
|
751
|
+
|
|
752
|
+
// Success if an autarky literal is left in the clause and
|
|
753
|
+
// we did not abort the loop too early because the propagation
|
|
754
|
+
// limit was hit.
|
|
755
|
+
//
|
|
756
|
+
if (watched_autarky_literal && stats.condprops < limit) {
|
|
757
|
+
assert (is_autarky_literal (watched_autarky_literal));
|
|
758
|
+
assert (is_in_candidate_clause (watched_autarky_literal));
|
|
759
|
+
|
|
760
|
+
blocked++;
|
|
761
|
+
stats.conditioned++;
|
|
762
|
+
LOG (c, "positive autarky literal %d globally blocks",
|
|
763
|
+
watched_autarky_literal);
|
|
764
|
+
|
|
765
|
+
LOG ("remaining %zd assigned literals %.0f%%", remain.assigned,
|
|
766
|
+
percent (remain.assigned, initial.assigned));
|
|
767
|
+
LOG ("remaining %zd conditional literals %.0f%%", remain.conditional,
|
|
768
|
+
percent (remain.conditional, remain.assigned));
|
|
769
|
+
LOG ("remaining %zd autarky literals %.0f%%", remain.autarky,
|
|
770
|
+
percent (remain.autarky, remain.assigned));
|
|
771
|
+
|
|
772
|
+
// A satisfying assignment of a formula after removing a globally
|
|
773
|
+
// blocked clause might not satisfy that clause. As for variable
|
|
774
|
+
// elimination and classical blocked clauses, we thus maintain an
|
|
775
|
+
// extension stack for reconstructing an assignment which both
|
|
776
|
+
// satisfies the remaining formula as well as the clause.
|
|
777
|
+
//
|
|
778
|
+
// For globally blocked clauses we simply have to flip all literals in
|
|
779
|
+
// the autarky part and thus save the autarky on the extension stack
|
|
780
|
+
// in addition to the removed clause. In the classical situation (in
|
|
781
|
+
// bounded variable elimination etc.) we simply save one literal on
|
|
782
|
+
// the extension stack.
|
|
783
|
+
//
|
|
784
|
+
// TODO find a way to shrink the autarky part or some other way to
|
|
785
|
+
// avoid pushing too many literals on the extension stack.
|
|
786
|
+
//
|
|
787
|
+
external->push_zero_on_extension_stack ();
|
|
788
|
+
for (const auto &lit : trail)
|
|
789
|
+
if (is_autarky_literal (lit))
|
|
790
|
+
external->push_witness_literal_on_extension_stack (lit);
|
|
791
|
+
if (proof)
|
|
792
|
+
proof->weaken_minus (c);
|
|
793
|
+
external->push_clause_on_extension_stack (c);
|
|
794
|
+
|
|
795
|
+
mark_garbage (c);
|
|
796
|
+
|
|
797
|
+
stats.condassrem += remain.assigned;
|
|
798
|
+
stats.condcondrem += remain.conditional;
|
|
799
|
+
stats.condautrem += remain.autarky;
|
|
800
|
+
stats.condassirem += initial.assigned;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// In this last part specific to one candidate clause, we have to get
|
|
804
|
+
// back to the initial assignment and reset conditionals. First we
|
|
805
|
+
// assign all the unassigned literals (if necessary).
|
|
806
|
+
//
|
|
807
|
+
if (!unassigned.empty ()) {
|
|
808
|
+
LOG ("reassigning %zd literals", unassigned.size ());
|
|
809
|
+
while (!unassigned.empty ()) {
|
|
810
|
+
const int lit = unassigned.back ();
|
|
811
|
+
unassigned.pop_back ();
|
|
812
|
+
condition_assign (lit);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// Then we remove from the conditional stack autarky literals which
|
|
817
|
+
// became conditional and also reset their 'conditional' bit.
|
|
818
|
+
//
|
|
819
|
+
if (initial.conditional < conditional.size ()) {
|
|
820
|
+
LOG ("flushing %zd autarky literals from conditional stack",
|
|
821
|
+
conditional.size () - initial.conditional);
|
|
822
|
+
while (initial.conditional < conditional.size ()) {
|
|
823
|
+
const int lit = conditional.back ();
|
|
824
|
+
conditional.pop_back ();
|
|
825
|
+
unmark_as_conditional_literal (lit);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Finally unmark all literals in the candidate clause.
|
|
830
|
+
//
|
|
831
|
+
for (const_literal_iterator l = c->begin (); l != c->end (); l++)
|
|
832
|
+
unmark_in_candidate_clause (*l);
|
|
833
|
+
|
|
834
|
+
} // End of loop over all candidate clauses.
|
|
835
|
+
|
|
836
|
+
PHASE ("condition", stats.conditionings,
|
|
837
|
+
"globally blocked %ld clauses %.0f%%", blocked,
|
|
838
|
+
percent (blocked, candidates.size ()));
|
|
839
|
+
|
|
840
|
+
// Unmark initial conditional variables.
|
|
841
|
+
//
|
|
842
|
+
for (const auto &lit : conditional)
|
|
843
|
+
unmark_as_conditional_literal (lit);
|
|
844
|
+
|
|
845
|
+
erase_vector (unassigned);
|
|
846
|
+
erase_vector (conditional);
|
|
847
|
+
erase_vector (candidates);
|
|
848
|
+
|
|
849
|
+
// Unassign additionally assigned literals.
|
|
850
|
+
//
|
|
851
|
+
#if defined(LOGGING) || !defined(NDEBUG)
|
|
852
|
+
int additionally_unassigned = 0;
|
|
853
|
+
#endif
|
|
854
|
+
while (trail.size () > initial_trail_level) {
|
|
855
|
+
int lit = trail.back ();
|
|
856
|
+
trail.pop_back ();
|
|
857
|
+
condition_unassign (lit);
|
|
858
|
+
#if defined(LOGGING) || !defined(NDEBUG)
|
|
859
|
+
additionally_unassigned++;
|
|
860
|
+
#endif
|
|
861
|
+
}
|
|
862
|
+
LOG ("unassigned %d additionally assigned literals",
|
|
863
|
+
additionally_unassigned);
|
|
864
|
+
assert (additionally_unassigned == additionally_assigned);
|
|
865
|
+
|
|
866
|
+
if (level > initial_level) {
|
|
867
|
+
LOG ("reset condition decision level");
|
|
868
|
+
level = initial_level;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
reset_occs ();
|
|
872
|
+
delete_garbage_clauses ();
|
|
873
|
+
|
|
874
|
+
// Reassign previously assigned variables again.
|
|
875
|
+
//
|
|
876
|
+
LOG ("reassigning previously assigned variables");
|
|
877
|
+
for (size_t i = 0; i < initial_trail_level; i++) {
|
|
878
|
+
const int lit = trail[i];
|
|
879
|
+
const signed char tmp = val (lit);
|
|
880
|
+
assert (tmp >= 0);
|
|
881
|
+
if (!tmp)
|
|
882
|
+
condition_assign (lit);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
#ifndef NDEBUG
|
|
886
|
+
for (const auto &lit : trail)
|
|
887
|
+
assert (!marked (lit));
|
|
888
|
+
#endif
|
|
889
|
+
|
|
890
|
+
unprotect_reasons ();
|
|
891
|
+
|
|
892
|
+
return blocked;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
void Internal::condition (bool update_limits) {
|
|
896
|
+
|
|
897
|
+
if (unsat)
|
|
898
|
+
return;
|
|
899
|
+
if (!stats.current.irredundant)
|
|
900
|
+
return;
|
|
901
|
+
|
|
902
|
+
START_SIMPLIFIER (condition, CONDITION);
|
|
903
|
+
stats.conditionings++;
|
|
904
|
+
|
|
905
|
+
// Propagation limit to avoid too much work in 'condition'. We mark
|
|
906
|
+
// tried candidate clauses after giving up, such that next time we run
|
|
907
|
+
// 'condition' we can try them.
|
|
908
|
+
//
|
|
909
|
+
long limit = stats.propagations.search;
|
|
910
|
+
limit *= opts.conditioneffort;
|
|
911
|
+
limit /= 1000;
|
|
912
|
+
if (limit < opts.conditionmineff)
|
|
913
|
+
limit = opts.conditionmineff;
|
|
914
|
+
if (limit > opts.conditionmaxeff)
|
|
915
|
+
limit = opts.conditionmaxeff;
|
|
916
|
+
assert (stats.current.irredundant);
|
|
917
|
+
limit *= 2.0 * active () / (double) stats.current.irredundant;
|
|
918
|
+
limit = max (limit, 2l * active ());
|
|
919
|
+
|
|
920
|
+
PHASE ("condition", stats.conditionings,
|
|
921
|
+
"started after %" PRIu64 " conflicts limited by %ld propagations",
|
|
922
|
+
stats.conflicts, limit);
|
|
923
|
+
|
|
924
|
+
long blocked = condition_round (limit);
|
|
925
|
+
|
|
926
|
+
STOP_SIMPLIFIER (condition, CONDITION);
|
|
927
|
+
report ('g', !blocked);
|
|
928
|
+
|
|
929
|
+
if (!update_limits)
|
|
930
|
+
return;
|
|
931
|
+
|
|
932
|
+
long delta = opts.conditionint * (stats.conditionings + 1);
|
|
933
|
+
lim.condition = stats.conflicts + delta;
|
|
934
|
+
|
|
935
|
+
PHASE ("condition", stats.conditionings,
|
|
936
|
+
"next limit at %" PRIu64 " after %ld conflicts", lim.condition,
|
|
937
|
+
delta);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
} // namespace CaDiCaL
|