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.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +26 -0
  3. data/README.md +101 -0
  4. data/ext/cadical/cadical/LICENSE +28 -0
  5. data/ext/cadical/cadical/README.md +65 -0
  6. data/ext/cadical/cadical/VERSION +1 -0
  7. data/ext/cadical/cadical/src/analyze.cpp +1360 -0
  8. data/ext/cadical/cadical/src/arena.cpp +30 -0
  9. data/ext/cadical/cadical/src/arena.hpp +105 -0
  10. data/ext/cadical/cadical/src/assume.cpp +616 -0
  11. data/ext/cadical/cadical/src/averages.cpp +34 -0
  12. data/ext/cadical/cadical/src/averages.hpp +37 -0
  13. data/ext/cadical/cadical/src/backbone.cpp +631 -0
  14. data/ext/cadical/cadical/src/backtrack.cpp +177 -0
  15. data/ext/cadical/cadical/src/backward.cpp +231 -0
  16. data/ext/cadical/cadical/src/bins.cpp +22 -0
  17. data/ext/cadical/cadical/src/bins.hpp +22 -0
  18. data/ext/cadical/cadical/src/block.cpp +824 -0
  19. data/ext/cadical/cadical/src/block.hpp +37 -0
  20. data/ext/cadical/cadical/src/cadical.cpp +1026 -0
  21. data/ext/cadical/cadical/src/cadical.hpp +1419 -0
  22. data/ext/cadical/cadical/src/ccadical.cpp +208 -0
  23. data/ext/cadical/cadical/src/ccadical.h +74 -0
  24. data/ext/cadical/cadical/src/checker.cpp +649 -0
  25. data/ext/cadical/cadical/src/checker.hpp +173 -0
  26. data/ext/cadical/cadical/src/clause.cpp +689 -0
  27. data/ext/cadical/cadical/src/clause.hpp +190 -0
  28. data/ext/cadical/cadical/src/collect.cpp +545 -0
  29. data/ext/cadical/cadical/src/compact.cpp +550 -0
  30. data/ext/cadical/cadical/src/condition.cpp +940 -0
  31. data/ext/cadical/cadical/src/config.cpp +101 -0
  32. data/ext/cadical/cadical/src/config.hpp +20 -0
  33. data/ext/cadical/cadical/src/congruence.cpp +7880 -0
  34. data/ext/cadical/cadical/src/congruence.hpp +757 -0
  35. data/ext/cadical/cadical/src/constrain.cpp +64 -0
  36. data/ext/cadical/cadical/src/contract.cpp +27 -0
  37. data/ext/cadical/cadical/src/contract.hpp +139 -0
  38. data/ext/cadical/cadical/src/cover.cpp +704 -0
  39. data/ext/cadical/cadical/src/cover.hpp +34 -0
  40. data/ext/cadical/cadical/src/decide.cpp +347 -0
  41. data/ext/cadical/cadical/src/decompose.cpp +738 -0
  42. data/ext/cadical/cadical/src/decompose.hpp +23 -0
  43. data/ext/cadical/cadical/src/deduplicate.cpp +275 -0
  44. data/ext/cadical/cadical/src/definition.cpp +283 -0
  45. data/ext/cadical/cadical/src/delay.hpp +38 -0
  46. data/ext/cadical/cadical/src/drattracer.cpp +153 -0
  47. data/ext/cadical/cadical/src/drattracer.hpp +55 -0
  48. data/ext/cadical/cadical/src/elim.cpp +1171 -0
  49. data/ext/cadical/cadical/src/elim.hpp +53 -0
  50. data/ext/cadical/cadical/src/elimfast.cpp +570 -0
  51. data/ext/cadical/cadical/src/ema.cpp +95 -0
  52. data/ext/cadical/cadical/src/ema.hpp +68 -0
  53. data/ext/cadical/cadical/src/extend.cpp +289 -0
  54. data/ext/cadical/cadical/src/external.cpp +1034 -0
  55. data/ext/cadical/cadical/src/external.hpp +487 -0
  56. data/ext/cadical/cadical/src/external_propagate.cpp +1316 -0
  57. data/ext/cadical/cadical/src/factor.cpp +1011 -0
  58. data/ext/cadical/cadical/src/factor.hpp +54 -0
  59. data/ext/cadical/cadical/src/file.cpp +506 -0
  60. data/ext/cadical/cadical/src/file.hpp +210 -0
  61. data/ext/cadical/cadical/src/flags.cpp +135 -0
  62. data/ext/cadical/cadical/src/flags.hpp +93 -0
  63. data/ext/cadical/cadical/src/flip.cpp +269 -0
  64. data/ext/cadical/cadical/src/format.cpp +89 -0
  65. data/ext/cadical/cadical/src/format.hpp +36 -0
  66. data/ext/cadical/cadical/src/frattracer.cpp +277 -0
  67. data/ext/cadical/cadical/src/frattracer.hpp +67 -0
  68. data/ext/cadical/cadical/src/gates.cpp +766 -0
  69. data/ext/cadical/cadical/src/heap.hpp +212 -0
  70. data/ext/cadical/cadical/src/idruptracer.cpp +566 -0
  71. data/ext/cadical/cadical/src/idruptracer.hpp +112 -0
  72. data/ext/cadical/cadical/src/instantiate.cpp +365 -0
  73. data/ext/cadical/cadical/src/instantiate.hpp +45 -0
  74. data/ext/cadical/cadical/src/internal.cpp +1265 -0
  75. data/ext/cadical/cadical/src/internal.hpp +1941 -0
  76. data/ext/cadical/cadical/src/inttypes.hpp +34 -0
  77. data/ext/cadical/cadical/src/ipasir.cpp +47 -0
  78. data/ext/cadical/cadical/src/ipasir.h +37 -0
  79. data/ext/cadical/cadical/src/kitten.c +2599 -0
  80. data/ext/cadical/cadical/src/kitten.h +97 -0
  81. data/ext/cadical/cadical/src/level.hpp +33 -0
  82. data/ext/cadical/cadical/src/lidruptracer.cpp +657 -0
  83. data/ext/cadical/cadical/src/lidruptracer.hpp +122 -0
  84. data/ext/cadical/cadical/src/limit.cpp +146 -0
  85. data/ext/cadical/cadical/src/limit.hpp +168 -0
  86. data/ext/cadical/cadical/src/logging.cpp +214 -0
  87. data/ext/cadical/cadical/src/logging.hpp +98 -0
  88. data/ext/cadical/cadical/src/lookahead.cpp +520 -0
  89. data/ext/cadical/cadical/src/lratchecker.cpp +833 -0
  90. data/ext/cadical/cadical/src/lratchecker.hpp +168 -0
  91. data/ext/cadical/cadical/src/lrattracer.cpp +200 -0
  92. data/ext/cadical/cadical/src/lrattracer.hpp +61 -0
  93. data/ext/cadical/cadical/src/lucky.cpp +506 -0
  94. data/ext/cadical/cadical/src/message.cpp +218 -0
  95. data/ext/cadical/cadical/src/message.hpp +65 -0
  96. data/ext/cadical/cadical/src/minimize.cpp +224 -0
  97. data/ext/cadical/cadical/src/mobical.cpp +5588 -0
  98. data/ext/cadical/cadical/src/occs.cpp +52 -0
  99. data/ext/cadical/cadical/src/occs.hpp +36 -0
  100. data/ext/cadical/cadical/src/options.cpp +359 -0
  101. data/ext/cadical/cadical/src/options.hpp +442 -0
  102. data/ext/cadical/cadical/src/parse.cpp +471 -0
  103. data/ext/cadical/cadical/src/parse.hpp +75 -0
  104. data/ext/cadical/cadical/src/phases.cpp +56 -0
  105. data/ext/cadical/cadical/src/phases.hpp +19 -0
  106. data/ext/cadical/cadical/src/probe.cpp +990 -0
  107. data/ext/cadical/cadical/src/profile.cpp +107 -0
  108. data/ext/cadical/cadical/src/profile.hpp +283 -0
  109. data/ext/cadical/cadical/src/proof.cpp +691 -0
  110. data/ext/cadical/cadical/src/proof.hpp +125 -0
  111. data/ext/cadical/cadical/src/propagate.cpp +584 -0
  112. data/ext/cadical/cadical/src/queue.cpp +90 -0
  113. data/ext/cadical/cadical/src/queue.hpp +74 -0
  114. data/ext/cadical/cadical/src/radix.hpp +180 -0
  115. data/ext/cadical/cadical/src/random.cpp +207 -0
  116. data/ext/cadical/cadical/src/random.h +44 -0
  117. data/ext/cadical/cadical/src/random.hpp +98 -0
  118. data/ext/cadical/cadical/src/range.hpp +125 -0
  119. data/ext/cadical/cadical/src/reap.cpp +127 -0
  120. data/ext/cadical/cadical/src/reap.hpp +28 -0
  121. data/ext/cadical/cadical/src/reduce.cpp +278 -0
  122. data/ext/cadical/cadical/src/reluctant.hpp +82 -0
  123. data/ext/cadical/cadical/src/rephase.cpp +402 -0
  124. data/ext/cadical/cadical/src/report.cpp +313 -0
  125. data/ext/cadical/cadical/src/resources.cpp +160 -0
  126. data/ext/cadical/cadical/src/resources.hpp +16 -0
  127. data/ext/cadical/cadical/src/restart.cpp +178 -0
  128. data/ext/cadical/cadical/src/restore.cpp +267 -0
  129. data/ext/cadical/cadical/src/score.cpp +51 -0
  130. data/ext/cadical/cadical/src/score.hpp +16 -0
  131. data/ext/cadical/cadical/src/shrink.cpp +507 -0
  132. data/ext/cadical/cadical/src/signal.cpp +136 -0
  133. data/ext/cadical/cadical/src/signal.hpp +33 -0
  134. data/ext/cadical/cadical/src/solution.cpp +50 -0
  135. data/ext/cadical/cadical/src/solver.cpp +1871 -0
  136. data/ext/cadical/cadical/src/stable.cpp +31 -0
  137. data/ext/cadical/cadical/src/stack.h +110 -0
  138. data/ext/cadical/cadical/src/stats.cpp +920 -0
  139. data/ext/cadical/cadical/src/stats.hpp +418 -0
  140. data/ext/cadical/cadical/src/subsume.cpp +645 -0
  141. data/ext/cadical/cadical/src/sweep.cpp +1960 -0
  142. data/ext/cadical/cadical/src/sweep.hpp +61 -0
  143. data/ext/cadical/cadical/src/terminal.cpp +38 -0
  144. data/ext/cadical/cadical/src/terminal.hpp +96 -0
  145. data/ext/cadical/cadical/src/ternary.cpp +450 -0
  146. data/ext/cadical/cadical/src/testing.hpp +24 -0
  147. data/ext/cadical/cadical/src/tier.cpp +189 -0
  148. data/ext/cadical/cadical/src/tracer.hpp +186 -0
  149. data/ext/cadical/cadical/src/transred.cpp +253 -0
  150. data/ext/cadical/cadical/src/unstable.cpp +29 -0
  151. data/ext/cadical/cadical/src/util.cpp +129 -0
  152. data/ext/cadical/cadical/src/util.hpp +181 -0
  153. data/ext/cadical/cadical/src/var.cpp +39 -0
  154. data/ext/cadical/cadical/src/var.hpp +22 -0
  155. data/ext/cadical/cadical/src/veripbtracer.cpp +427 -0
  156. data/ext/cadical/cadical/src/veripbtracer.hpp +106 -0
  157. data/ext/cadical/cadical/src/version.cpp +107 -0
  158. data/ext/cadical/cadical/src/version.hpp +13 -0
  159. data/ext/cadical/cadical/src/vivify.cpp +1893 -0
  160. data/ext/cadical/cadical/src/vivify.hpp +50 -0
  161. data/ext/cadical/cadical/src/walk.cpp +1088 -0
  162. data/ext/cadical/cadical/src/walk.hpp +91 -0
  163. data/ext/cadical/cadical/src/walk_full_occs.cpp +966 -0
  164. data/ext/cadical/cadical/src/warmup.cpp +403 -0
  165. data/ext/cadical/cadical/src/watch.cpp +126 -0
  166. data/ext/cadical/cadical/src/watch.hpp +77 -0
  167. data/ext/cadical/cadical_ext.c +778 -0
  168. data/ext/cadical/extconf.rb +26 -0
  169. data/lib/cadical/version.rb +3 -0
  170. data/lib/cadical.rb +12 -0
  171. metadata +218 -0
@@ -0,0 +1,704 @@
1
+ #include "internal.hpp"
2
+
3
+ namespace CaDiCaL {
4
+
5
+ /*------------------------------------------------------------------------*/
6
+
7
+ // Covered clause elimination (CCE) is described in our short LPAR-10 paper
8
+ // and later in more detail in our JAIR'15 article. Actually implement
9
+ // the asymmetric version which adds asymmetric literals too but still call
10
+ // it 'CCE' in the following (and not 'ACCE'). This implementation provides
11
+ // a simplified and cleaner version of the one implemented before in
12
+ // Lingeling. We still follow quite closely the original description in the
13
+ // literature, which is based on asymmetric literal addition (ALA) and
14
+ // covered literal addition (CLA). Both can be seen as kind of propagation,
15
+ // where the literals in the original and then extended clause are assigned
16
+ // to false, and the literals on the trail (actually we use our own 'added'
17
+ // stack for that) make up the extended clause. The ALA steps can be
18
+ // implemented by simple propagation (copied from 'propagate.cpp') using
19
+ // watches, while the CLA steps need full occurrence lists to determine the
20
+ // resolution candidate clauses. The CCE is successful if a conflict is
21
+ // found during ALA steps or if during a CLA step all resolution candidates
22
+ // of a literal on the trail are satisfied (the extended clause is blocked).
23
+
24
+ struct Coveror {
25
+ std::vector<int> added; // acts as trail
26
+ std::vector<int> extend; // extension stack for witness
27
+ std::vector<int> covered; // clause literals or added through CLA
28
+ std::vector<int> intersection; // of literals in resolution candidates
29
+
30
+ size_t alas, clas; // actual number of ALAs and CLAs
31
+
32
+ struct {
33
+ size_t added, covered;
34
+ } next; // propagate next ...
35
+
36
+ Coveror () : alas (0), clas (0) {}
37
+ };
38
+
39
+ /*------------------------------------------------------------------------*/
40
+
41
+ // Push on the extension stack a clause made up of the given literal, the
42
+ // original clause (initially copied to 'covered') and all the added covered
43
+ // literals so far. The given literal will act as blocking literal for that
44
+ // clause, if CCE is successful. Only in this case, this private extension
45
+ // stack is copied to the actual extension stack of the solver. Note, that
46
+ // even though all 'added' clauses correspond to the extended clause, we
47
+ // only need to save the original and added covered literals.
48
+
49
+ inline void Internal::cover_push_extension (int lit, Coveror &coveror) {
50
+ coveror.extend.push_back (0);
51
+ coveror.extend.push_back (lit); // blocking literal comes first
52
+ bool found = false;
53
+ for (const auto &other : coveror.covered)
54
+ if (lit == other)
55
+ assert (!found), found = true;
56
+ else
57
+ coveror.extend.push_back (other);
58
+ assert (found);
59
+ (void) found;
60
+ }
61
+
62
+ // Successful covered literal addition (CLA) step.
63
+
64
+ inline void Internal::covered_literal_addition (int lit, Coveror &coveror) {
65
+ require_mode (COVER);
66
+ assert (level == 1);
67
+ cover_push_extension (lit, coveror);
68
+ for (const auto &other : coveror.intersection) {
69
+ LOG ("covered literal addition %d", other);
70
+ assert (!vals[other]), assert (!vals[-other]);
71
+ set_val (other, -1);
72
+ coveror.covered.push_back (other);
73
+ coveror.added.push_back (other);
74
+ coveror.clas++;
75
+ }
76
+ coveror.next.covered = 0;
77
+ }
78
+
79
+ // Successful asymmetric literal addition (ALA) step.
80
+
81
+ inline void Internal::asymmetric_literal_addition (int lit,
82
+ Coveror &coveror) {
83
+ require_mode (COVER);
84
+ assert (level == 1);
85
+ LOG ("initial asymmetric literal addition %d", lit);
86
+ assert (!vals[lit]), assert (!vals[-lit]);
87
+ set_val (lit, -1);
88
+ coveror.added.push_back (lit);
89
+ coveror.alas++;
90
+ coveror.next.covered = 0;
91
+ }
92
+
93
+ /*------------------------------------------------------------------------*/
94
+
95
+ // In essence copied and adapted from 'propagate' in 'propagate.cpp'. Since
96
+ // this function is also a hot-spot here in 'cover' we specialize it in the
97
+ // same spirit as 'probe_propagate' and 'vivify_propagate'. Please refer to
98
+ // the detailed comments for 'propagate' in 'propagate.cpp' for details.
99
+
100
+ bool Internal::cover_propagate_asymmetric (int lit, Clause *ignore,
101
+ Coveror &coveror) {
102
+ require_mode (COVER);
103
+ stats.propagations.cover++;
104
+ assert (val (lit) < 0);
105
+ bool subsumed = false;
106
+ LOG ("asymmetric literal propagation of %d", lit);
107
+ Watches &ws = watches (lit);
108
+ const const_watch_iterator eow = ws.end ();
109
+ watch_iterator j = ws.begin ();
110
+ const_watch_iterator i = j;
111
+ while (!subsumed && i != eow) {
112
+ const Watch w = *j++ = *i++;
113
+ if (w.clause == ignore)
114
+ continue; // costly but necessary here ...
115
+ const signed char b = val (w.blit);
116
+ if (b > 0)
117
+ continue;
118
+ if (w.clause->garbage)
119
+ j--;
120
+ else if (w.binary ()) {
121
+ if (b < 0) {
122
+ LOG (w.clause, "found subsuming");
123
+ subsumed = true;
124
+ } else
125
+ asymmetric_literal_addition (-w.blit, coveror);
126
+ } else {
127
+ literal_iterator lits = w.clause->begin ();
128
+ const int other = lits[0] ^ lits[1] ^ lit;
129
+ lits[0] = other, lits[1] = lit;
130
+ const signed char u = val (other);
131
+ if (u > 0)
132
+ j[-1].blit = other;
133
+ else {
134
+ const int size = w.clause->size;
135
+ const const_literal_iterator end = lits + size;
136
+ const literal_iterator middle = lits + w.clause->pos;
137
+ literal_iterator k = middle;
138
+ signed char v = -1;
139
+ int r = 0;
140
+ while (k != end && (v = val (r = *k)) < 0)
141
+ k++;
142
+ if (v < 0) {
143
+ k = lits + 2;
144
+ assert (w.clause->pos <= size);
145
+ while (k != middle && (v = val (r = *k)) < 0)
146
+ k++;
147
+ }
148
+ w.clause->pos = k - lits;
149
+ assert (lits + 2 <= k), assert (k <= w.clause->end ());
150
+ if (v > 0)
151
+ j[-1].blit = r;
152
+ else if (!v) {
153
+ LOG (w.clause, "unwatch %d in", lit);
154
+ lits[1] = r;
155
+ *k = lit;
156
+ watch_literal (r, lit, w.clause);
157
+ j--;
158
+ } else if (!u) {
159
+ assert (v < 0);
160
+ asymmetric_literal_addition (-other, coveror);
161
+ } else {
162
+ assert (u < 0), assert (v < 0);
163
+ LOG (w.clause, "found subsuming");
164
+ subsumed = true;
165
+ break;
166
+ }
167
+ }
168
+ }
169
+ }
170
+ if (j != i) {
171
+ while (i != eow)
172
+ *j++ = *i++;
173
+ ws.resize (j - ws.begin ());
174
+ }
175
+ return subsumed;
176
+ }
177
+
178
+ // Covered literal addition (which needs full occurrence lists). The
179
+ // function returns 'true' if the extended clause is blocked on 'lit.'
180
+
181
+ bool Internal::cover_propagate_covered (int lit, Coveror &coveror) {
182
+ require_mode (COVER);
183
+
184
+ assert (val (lit) < 0);
185
+ if (frozen (lit)) {
186
+ LOG ("no covered propagation on frozen literal %d", lit);
187
+ return false;
188
+ }
189
+
190
+ stats.propagations.cover++;
191
+
192
+ LOG ("covered propagation of %d", lit);
193
+ assert (coveror.intersection.empty ());
194
+
195
+ Occs &os = occs (-lit);
196
+ const auto end = os.end ();
197
+ bool first = true;
198
+
199
+ // Compute the intersection of the literals in all the clauses with
200
+ // '-lit'. If all these clauses are double satisfied then we know that
201
+ // the extended clauses (in 'added') is blocked. All literals in the
202
+ // intersection can be added as covered literal. As soon the intersection
203
+ // becomes empty (during traversal of clauses with '-lit') we abort.
204
+
205
+ for (auto i = os.begin (); i != end; i++) {
206
+
207
+ Clause *c = *i;
208
+ if (c->garbage)
209
+ continue;
210
+
211
+ // First check whether clause is 'blocked', i.e., is double satisfied.
212
+
213
+ bool blocked = false;
214
+ for (const auto &other : *c) {
215
+ if (other == -lit)
216
+ continue;
217
+ const signed char tmp = val (other);
218
+ if (tmp < 0)
219
+ continue;
220
+ if (tmp > 0) {
221
+ blocked = true;
222
+ break;
223
+ }
224
+ }
225
+ if (blocked) { // ... if 'c' is double satisfied.
226
+ LOG (c, "blocked");
227
+ continue; // with next clause with '-lit'.
228
+ }
229
+
230
+ if (first) {
231
+
232
+ // Copy and mark literals of first clause.
233
+
234
+ for (const auto &other : *c) {
235
+ if (other == -lit)
236
+ continue;
237
+ const signed char tmp = val (other);
238
+ if (tmp < 0)
239
+ continue;
240
+ assert (!tmp);
241
+ coveror.intersection.push_back (other);
242
+ mark (other);
243
+ }
244
+
245
+ first = false;
246
+
247
+ } else {
248
+
249
+ // Unmark all literals in current clause.
250
+
251
+ for (const auto &other : *c) {
252
+ if (other == -lit)
253
+ continue;
254
+ signed char tmp = val (other);
255
+ if (tmp < 0)
256
+ continue;
257
+ assert (!tmp);
258
+ tmp = marked (other);
259
+ if (tmp > 0)
260
+ unmark (other);
261
+ }
262
+
263
+ // Then remove from intersection all marked literals.
264
+
265
+ const auto end = coveror.intersection.end ();
266
+ auto j = coveror.intersection.begin ();
267
+ for (auto k = j; k != end; k++) {
268
+ const int other = *j++ = *k;
269
+ const int tmp = marked (other);
270
+ assert (tmp >= 0);
271
+ if (tmp)
272
+ j--, unmark (other); // remove marked and unmark it
273
+ else
274
+ mark (other); // keep unmarked and mark it
275
+ }
276
+ const size_t new_size = j - coveror.intersection.begin ();
277
+ coveror.intersection.resize (new_size);
278
+
279
+ if (!coveror.intersection.empty ())
280
+ continue;
281
+
282
+ // No covered literal addition candidates in the intersection left!
283
+ // Move this clause triggering early abort to the beginning.
284
+ // This is a common move to front strategy to minimize effort.
285
+
286
+ auto begin = os.begin ();
287
+ while (i != begin) {
288
+ auto prev = i - 1;
289
+ *i = *prev;
290
+ i = prev;
291
+ }
292
+ *begin = c;
293
+
294
+ break; // early abort ...
295
+ }
296
+ }
297
+
298
+ bool res = false;
299
+ if (first) {
300
+ LOG ("all resolution candidates with %d blocked", -lit);
301
+ assert (coveror.intersection.empty ());
302
+ cover_push_extension (lit, coveror);
303
+ res = true;
304
+ } else if (coveror.intersection.empty ()) {
305
+ LOG ("empty intersection of resolution candidate literals");
306
+ } else {
307
+ LOG (coveror.intersection,
308
+ "non-empty intersection of resolution candidate literals");
309
+ covered_literal_addition (lit, coveror);
310
+ unmark (coveror.intersection);
311
+ coveror.intersection.clear ();
312
+ coveror.next.covered = 0; // Restart covering.
313
+ }
314
+
315
+ unmark (coveror.intersection);
316
+ coveror.intersection.clear ();
317
+
318
+ return res;
319
+ }
320
+
321
+ /*------------------------------------------------------------------------*/
322
+
323
+ bool Internal::cover_clause (Clause *c, Coveror &coveror) {
324
+
325
+ require_mode (COVER);
326
+ assert (!c->garbage);
327
+
328
+ LOG (c, "trying covered clauses elimination on");
329
+ bool satisfied = false;
330
+ for (const auto &lit : *c)
331
+ if (val (lit) > 0)
332
+ satisfied = true;
333
+
334
+ if (satisfied) {
335
+ LOG (c, "clause already satisfied");
336
+ mark_garbage (c);
337
+ return false;
338
+ }
339
+
340
+ assert (coveror.added.empty ());
341
+ assert (coveror.extend.empty ());
342
+ assert (coveror.covered.empty ());
343
+
344
+ assert (!level);
345
+ level = 1;
346
+ LOG ("assuming literals of candidate clause");
347
+ for (const auto &lit : *c) {
348
+ if (val (lit))
349
+ continue;
350
+ asymmetric_literal_addition (lit, coveror);
351
+ coveror.covered.push_back (lit);
352
+ }
353
+
354
+ bool tautological = false;
355
+
356
+ coveror.next.added = coveror.next.covered = 0;
357
+
358
+ while (!tautological) {
359
+ if (coveror.next.added < coveror.added.size ()) {
360
+ const int lit = coveror.added[coveror.next.added++];
361
+ tautological = cover_propagate_asymmetric (lit, c, coveror);
362
+ } else if (coveror.next.covered < coveror.covered.size ()) {
363
+ const int lit = coveror.covered[coveror.next.covered++];
364
+ tautological = cover_propagate_covered (lit, coveror);
365
+ } else
366
+ break;
367
+ }
368
+
369
+ if (tautological) {
370
+ if (coveror.extend.empty ()) {
371
+ stats.cover.asymmetric++;
372
+ stats.cover.total++;
373
+ LOG (c, "asymmetric tautological");
374
+ } else {
375
+ stats.cover.blocked++;
376
+ stats.cover.total++;
377
+ // Only copy extension stack if successful.
378
+ int prev = INT_MIN;
379
+ bool already_pushed = false;
380
+ int64_t last_id = 0;
381
+ LOG (c, "covered tautological");
382
+ assert (clause.empty ());
383
+ LOG (coveror.extend, "extension = ");
384
+ for (const auto &other : coveror.extend) {
385
+ if (!prev) {
386
+ // are we finishing a clause?
387
+ if (already_pushed) {
388
+ // add missing literals that are not needed for covering
389
+ // but avoid RAT proofs
390
+ for (auto i = 0, j = 0; i < c->size; ++i, ++j) {
391
+ const int lit = c->literals[i];
392
+ if (j >= (int) coveror.covered.size () ||
393
+ c->literals[i] != coveror.covered[j]) {
394
+ --j;
395
+ LOG ("adding lit %d not needed for ATA", lit);
396
+ clause.push_back (lit);
397
+ external->push_clause_literal_on_extension_stack (lit);
398
+ }
399
+ }
400
+ }
401
+ if (proof && already_pushed) {
402
+ if (lrat)
403
+ lrat_chain.push_back (c->id);
404
+ LOG ("LEARNING clause with id %" PRId64, last_id);
405
+ proof->add_derived_clause (last_id, false, clause, lrat_chain);
406
+ proof->weaken_plus (last_id, clause);
407
+ lrat_chain.clear ();
408
+ }
409
+ last_id = ++clause_id;
410
+ external->push_zero_on_extension_stack ();
411
+ external->push_witness_literal_on_extension_stack (other);
412
+ external->push_zero_on_extension_stack ();
413
+ external->push_id_on_extension_stack (last_id);
414
+ external->push_zero_on_extension_stack ();
415
+ clause.clear ();
416
+ already_pushed = true;
417
+ }
418
+ if (other) {
419
+ external->push_clause_literal_on_extension_stack (other);
420
+ clause.push_back (other);
421
+ LOG (clause, "current clause is");
422
+ }
423
+ prev = other;
424
+ }
425
+
426
+ if (proof) {
427
+ // add missing literals that are not needed for covering
428
+ // but avoid RAT proofs
429
+ for (auto i = 0, j = 0; i < c->size; ++i, ++j) {
430
+ const int lit = c->literals[i];
431
+ if (j >= (int) coveror.covered.size () ||
432
+ c->literals[i] != coveror.covered[j]) {
433
+ --j;
434
+ LOG ("adding lit %d not needed for ATA", lit);
435
+ clause.push_back (lit);
436
+ external->push_clause_literal_on_extension_stack (lit);
437
+ }
438
+ }
439
+ if (lrat)
440
+ lrat_chain.push_back (c->id);
441
+ proof->add_derived_clause (last_id, false, clause, lrat_chain);
442
+ proof->weaken_plus (last_id, clause);
443
+ lrat_chain.clear ();
444
+ }
445
+ clause.clear ();
446
+
447
+ mark_garbage (c);
448
+ }
449
+ }
450
+
451
+ // Backtrack and 'unassign' all literals.
452
+
453
+ assert (level == 1);
454
+ for (const auto &lit : coveror.added)
455
+ set_val (lit, 0);
456
+ level = 0;
457
+
458
+ coveror.covered.clear ();
459
+ coveror.extend.clear ();
460
+ coveror.added.clear ();
461
+
462
+ return tautological;
463
+ }
464
+
465
+ /*------------------------------------------------------------------------*/
466
+
467
+ // Not yet tried and larger clauses are tried first.
468
+
469
+ struct clause_covered_or_smaller {
470
+ bool operator() (const Clause *a, const Clause *b) {
471
+ if (a->covered && !b->covered)
472
+ return true;
473
+ if (!a->covered && b->covered)
474
+ return false;
475
+ return a->size < b->size;
476
+ }
477
+ };
478
+
479
+ int64_t Internal::cover_round () {
480
+
481
+ if (unsat)
482
+ return 0;
483
+
484
+ init_watches ();
485
+ connect_watches (true); // irredundant watches only is enough
486
+
487
+ int64_t delta = stats.propagations.search;
488
+ delta *= 1e-3 * opts.covereffort;
489
+ if (delta < opts.covermineff)
490
+ delta = opts.covermineff;
491
+ if (delta > opts.covermaxeff)
492
+ delta = opts.covermaxeff;
493
+ delta = max (delta, ((int64_t) 2) * active ());
494
+
495
+ PHASE ("cover", stats.cover.count,
496
+ "covered clause elimination limit of %" PRId64 " propagations",
497
+ delta);
498
+
499
+ int64_t limit = stats.propagations.cover + delta;
500
+
501
+ init_occs ();
502
+
503
+ vector<Clause *> schedule;
504
+ Coveror coveror;
505
+
506
+ // First connect all clauses and find all not yet tried clauses.
507
+ //
508
+ #ifndef QUIET
509
+ int64_t untried = 0;
510
+ #endif
511
+ //
512
+ for (auto c : clauses) {
513
+ assert (!c->frozen);
514
+ if (c->garbage)
515
+ continue;
516
+ if (c->redundant)
517
+ continue;
518
+ bool satisfied = false, allfrozen = true;
519
+ for (const auto &lit : *c)
520
+ if (val (lit) > 0) {
521
+ satisfied = true;
522
+ break;
523
+ } else if (allfrozen && !frozen (lit))
524
+ allfrozen = false;
525
+ if (satisfied) {
526
+ mark_garbage (c);
527
+ continue;
528
+ }
529
+ if (allfrozen) {
530
+ c->frozen = true;
531
+ continue;
532
+ }
533
+ for (const auto &lit : *c)
534
+ occs (lit).push_back (c);
535
+ if (c->size < opts.coverminclslim)
536
+ continue;
537
+ if (c->size > opts.covermaxclslim)
538
+ continue;
539
+ if (c->covered)
540
+ continue;
541
+ schedule.push_back (c);
542
+ #ifndef QUIET
543
+ untried++;
544
+ #endif
545
+ }
546
+
547
+ if (schedule.empty ()) {
548
+
549
+ PHASE ("cover", stats.cover.count, "no previously untried clause left");
550
+
551
+ for (auto c : clauses) {
552
+ if (c->garbage)
553
+ continue;
554
+ if (c->redundant)
555
+ continue;
556
+ if (c->frozen) {
557
+ c->frozen = false;
558
+ continue;
559
+ }
560
+ if (c->size < opts.coverminclslim)
561
+ continue;
562
+ if (c->size > opts.covermaxclslim)
563
+ continue;
564
+ assert (c->covered);
565
+ c->covered = false;
566
+ schedule.push_back (c);
567
+ }
568
+ } else { // Mix of tried and not tried clauses ....
569
+
570
+ for (auto c : clauses) {
571
+ if (c->garbage)
572
+ continue;
573
+ if (c->redundant)
574
+ continue;
575
+ if (c->frozen) {
576
+ c->frozen = false;
577
+ continue;
578
+ }
579
+ if (c->size < opts.coverminclslim)
580
+ continue;
581
+ if (c->size > opts.covermaxclslim)
582
+ continue;
583
+ if (!c->covered)
584
+ continue;
585
+ schedule.push_back (c);
586
+ }
587
+ }
588
+
589
+ stable_sort (schedule.begin (), schedule.end (),
590
+ clause_covered_or_smaller ());
591
+
592
+ #ifndef QUIET
593
+ const size_t scheduled = schedule.size ();
594
+ PHASE ("cover", stats.cover.count,
595
+ "scheduled %zd clauses %.0f%% with %" PRId64 " untried %.0f%%",
596
+ scheduled, percent (scheduled, stats.current.irredundant), untried,
597
+ percent (untried, scheduled));
598
+ #endif
599
+
600
+ // Heuristically it should be beneficial to intersect with smaller clauses
601
+ // first, since then the chances are higher that the intersection of
602
+ // resolution candidates becomes emptier earlier.
603
+
604
+ for (auto lit : lits) {
605
+ if (!active (lit))
606
+ continue;
607
+ Occs &os = occs (lit);
608
+ stable_sort (os.begin (), os.end (), clause_smaller_size ());
609
+ }
610
+
611
+ // This is the main loop of trying to do CCE of candidate clauses.
612
+ //
613
+ int64_t covered = 0;
614
+ //
615
+ while (!terminated_asynchronously () && !schedule.empty () &&
616
+ stats.propagations.cover < limit) {
617
+ Clause *c = schedule.back ();
618
+ schedule.pop_back ();
619
+ c->covered = true;
620
+ if (cover_clause (c, coveror))
621
+ covered++;
622
+ }
623
+
624
+ #ifndef QUIET
625
+ const size_t remain = schedule.size ();
626
+ const size_t tried = scheduled - remain;
627
+ PHASE ("cover", stats.cover.count,
628
+ "eliminated %" PRId64 " covered clauses out of %zd tried %.0f%%",
629
+ covered, tried, percent (covered, tried));
630
+ if (remain)
631
+ PHASE ("cover", stats.cover.count,
632
+ "remaining %zu clauses %.0f%% untried", remain,
633
+ percent (remain, scheduled));
634
+ else
635
+ PHASE ("cover", stats.cover.count, "all scheduled clauses tried");
636
+ #endif
637
+ reset_occs ();
638
+ reset_watches ();
639
+
640
+ return covered;
641
+ }
642
+
643
+ /*------------------------------------------------------------------------*/
644
+
645
+ bool Internal::cover () {
646
+
647
+ if (!opts.cover)
648
+ return false;
649
+ if (unsat)
650
+ return false;
651
+ if (terminated_asynchronously ())
652
+ return false;
653
+ if (!stats.current.irredundant)
654
+ return false;
655
+
656
+ // TODO: Our current algorithm for producing the necessary clauses on the
657
+ // reconstruction stack for extending the witness requires a covered
658
+ // literal addition step which (empirically) conflicts with flushing
659
+ // during restoring clauses (see 'regr00{48,51}.trace') even though
660
+ // flushing during restore is disabled by default (as is covered clause
661
+ // elimination). The consequence of combining these two options
662
+ // ('opts.cover' and 'opts.restoreflush') can thus produce incorrect
663
+ // witness reconstruction and thus invalid witnesses. This is quite
664
+ // infrequent (one out of half billion mobical test cases) but as the two
665
+ // regression traces show, does happen. Thus we disable the combination.
666
+ //
667
+ if (opts.restoreflush)
668
+ return false;
669
+
670
+ START_SIMPLIFIER (cover, COVER);
671
+
672
+ stats.cover.count++;
673
+
674
+ // During variable elimination unit clauses can be generated which need to
675
+ // be propagated properly over redundant clauses too. Since variable
676
+ // elimination avoids to have occurrence lists and watches at the same
677
+ // time this propagation is delayed until the end of variable elimination.
678
+ // Since we want to interleave CCE with it, we have to propagate here.
679
+ // Otherwise this triggers inconsistencies.
680
+ //
681
+ if (propagated < trail.size ()) {
682
+ init_watches ();
683
+ connect_watches (); // need to propagated over all clauses!
684
+ LOG ("elimination produced %zd units",
685
+ (size_t) (trail.size () - propagated));
686
+ if (!propagate ()) {
687
+ LOG ("propagating units before covered clause elimination "
688
+ "results in empty clause");
689
+ learn_empty_clause ();
690
+ assert (unsat);
691
+ }
692
+ reset_watches ();
693
+ }
694
+ assert (unsat || propagated == trail.size ());
695
+
696
+ int64_t covered = cover_round ();
697
+
698
+ STOP_SIMPLIFIER (cover, COVER);
699
+ report ('c', !opts.reportall && !covered);
700
+
701
+ return covered;
702
+ }
703
+
704
+ } // namespace CaDiCaL