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,657 @@
1
+ #include "internal.hpp"
2
+
3
+ namespace CaDiCaL {
4
+
5
+ /*------------------------------------------------------------------------*/
6
+
7
+ LidrupTracer::LidrupTracer (Internal *i, File *f, bool b)
8
+ : internal (i), file (f), binary (b), num_clauses (0), size_clauses (0),
9
+ clauses (0), last_hash (0), last_id (0), last_clause (0)
10
+ #ifndef QUIET
11
+ ,
12
+ added (0), deleted (0), weakened (0), restore (0), original (0),
13
+ solved (0), batched (0)
14
+ #endif
15
+ {
16
+ (void) internal;
17
+
18
+ // Initialize random number table for hash function.
19
+ //
20
+ Random random (42);
21
+ for (unsigned n = 0; n < num_nonces; n++) {
22
+ uint64_t nonce = random.next ();
23
+ if (!(nonce & 1))
24
+ nonce++;
25
+ assert (nonce), assert (nonce & 1);
26
+ nonces[n] = nonce;
27
+ }
28
+ #ifndef NDEBUG
29
+ binary = b;
30
+ #else
31
+ (void) b;
32
+ #endif
33
+ piping = file->piping ();
34
+ }
35
+
36
+ void LidrupTracer::connect_internal (Internal *i) {
37
+ internal = i;
38
+ file->connect_internal (internal);
39
+ LOG ("LIDRUP TRACER connected to internal");
40
+ }
41
+
42
+ LidrupTracer::~LidrupTracer () {
43
+ LOG ("LIDRUP TRACER delete");
44
+ delete file;
45
+ for (size_t i = 0; i < size_clauses; i++)
46
+ for (LidrupClause *c = clauses[i], *next; c; c = next)
47
+ next = c->next, delete_clause (c);
48
+ delete[] clauses;
49
+ }
50
+
51
+ /*------------------------------------------------------------------------*/
52
+
53
+ void LidrupTracer::enlarge_clauses () {
54
+ assert (num_clauses == size_clauses);
55
+ const uint64_t new_size_clauses = size_clauses ? 2 * size_clauses : 1;
56
+ LOG ("LIDRUP Tracer enlarging clauses of tracer from %" PRIu64
57
+ " to %" PRIu64,
58
+ (uint64_t) size_clauses, (uint64_t) new_size_clauses);
59
+ LidrupClause **new_clauses;
60
+ new_clauses = new LidrupClause *[new_size_clauses];
61
+ clear_n (new_clauses, new_size_clauses);
62
+ for (uint64_t i = 0; i < size_clauses; i++) {
63
+ for (LidrupClause *c = clauses[i], *next; c; c = next) {
64
+ next = c->next;
65
+ const uint64_t h = reduce_hash (c->hash, new_size_clauses);
66
+ c->next = new_clauses[h];
67
+ new_clauses[h] = c;
68
+ }
69
+ }
70
+ delete[] clauses;
71
+ clauses = new_clauses;
72
+ size_clauses = new_size_clauses;
73
+ }
74
+
75
+ LidrupClause *LidrupTracer::new_clause () {
76
+ LidrupClause *res = new LidrupClause;
77
+ res->next = 0;
78
+ res->hash = last_hash;
79
+ res->id = last_id;
80
+ for (const auto &id : imported_chain) {
81
+ res->chain.push_back (id);
82
+ }
83
+ for (const auto &lit : imported_clause) {
84
+ res->literals.push_back (lit);
85
+ }
86
+ last_clause = res;
87
+ num_clauses++;
88
+ return res;
89
+ }
90
+
91
+ void LidrupTracer::delete_clause (LidrupClause *c) {
92
+ assert (c);
93
+ num_clauses--;
94
+ delete c;
95
+ }
96
+
97
+ uint64_t LidrupTracer::reduce_hash (uint64_t hash, uint64_t size) {
98
+ assert (size > 0);
99
+ unsigned shift = 32;
100
+ uint64_t res = hash;
101
+ while ((((uint64_t) 1) << shift) > size) {
102
+ res ^= res >> shift;
103
+ shift >>= 1;
104
+ }
105
+ res &= size - 1;
106
+ assert (res < size);
107
+ return res;
108
+ }
109
+
110
+ uint64_t LidrupTracer::compute_hash (const int64_t id) {
111
+ assert (id > 0);
112
+ unsigned j = id % num_nonces;
113
+ uint64_t tmp = nonces[j] * (uint64_t) id;
114
+ return last_hash = tmp;
115
+ }
116
+
117
+ bool LidrupTracer::find_and_delete (const int64_t id) {
118
+ if (!num_clauses)
119
+ return false;
120
+ LidrupClause **res = 0, *c;
121
+ const uint64_t hash = compute_hash (id);
122
+ const uint64_t h = reduce_hash (hash, size_clauses);
123
+ for (res = clauses + h; (c = *res); res = &c->next) {
124
+ if (c->hash == hash && c->id == id) {
125
+ break;
126
+ }
127
+ if (!c->next)
128
+ return false;
129
+ }
130
+ if (!c)
131
+ return false;
132
+ assert (c && res);
133
+ *res = c->next;
134
+ for (auto &lit : c->literals) {
135
+ imported_clause.push_back (lit);
136
+ }
137
+ for (auto &cid : c->chain) {
138
+ imported_chain.push_back (cid);
139
+ }
140
+ delete_clause (c);
141
+ return true;
142
+ }
143
+
144
+ void LidrupTracer::insert () {
145
+ if (num_clauses == size_clauses)
146
+ enlarge_clauses ();
147
+ const uint64_t h = reduce_hash (compute_hash (last_id), size_clauses);
148
+ LidrupClause *c = new_clause ();
149
+ c->next = clauses[h];
150
+ clauses[h] = c;
151
+ }
152
+
153
+ /*------------------------------------------------------------------------*/
154
+
155
+ inline void LidrupTracer::flush_if_piping () {
156
+ if (piping)
157
+ file->flush ();
158
+ }
159
+
160
+ inline void LidrupTracer::put_binary_zero () {
161
+ assert (binary);
162
+ assert (file);
163
+ file->put ((unsigned char) 0);
164
+ }
165
+
166
+ inline void LidrupTracer::put_binary_lit (int lit) {
167
+ assert (binary);
168
+ assert (file);
169
+ assert (lit != INT_MIN);
170
+ unsigned x = 2 * abs (lit) + (lit < 0);
171
+ unsigned char ch;
172
+ while (x & ~0x7f) {
173
+ ch = (x & 0x7f) | 0x80;
174
+ file->put (ch);
175
+ x >>= 7;
176
+ }
177
+ ch = x;
178
+ file->put (ch);
179
+ }
180
+
181
+ inline void LidrupTracer::put_binary_id (int64_t id, bool can_be_negative) {
182
+ assert (binary);
183
+ assert (file);
184
+ uint64_t x = abs (id);
185
+ if (can_be_negative) {
186
+ x = 2 * x + (id < 0);
187
+ }
188
+ unsigned char ch;
189
+ while (x & ~0x7f) {
190
+ ch = (x & 0x7f) | 0x80;
191
+ file->put (ch);
192
+ x >>= 7;
193
+ }
194
+ ch = x;
195
+ file->put (ch);
196
+ }
197
+
198
+ /*------------------------------------------------------------------------*/
199
+
200
+ void LidrupTracer::lidrup_add_restored_clause (int64_t id) {
201
+ if (!batch_weaken.empty () || !batch_delete.empty ())
202
+ lidrup_batch_weaken_restore_and_delete ();
203
+ batch_restore.push_back (id);
204
+ }
205
+
206
+ void LidrupTracer::lidrup_add_derived_clause (
207
+ int64_t id, const vector<int> &clause, const vector<int64_t> &chain) {
208
+ lidrup_batch_weaken_restore_and_delete ();
209
+ if (binary) {
210
+ file->put ('l');
211
+ put_binary_id (id);
212
+ } else {
213
+ file->put ("l ");
214
+ file->put (id);
215
+ file->put (' ');
216
+ }
217
+ for (const auto &external_lit : clause)
218
+ if (binary)
219
+ put_binary_lit (external_lit);
220
+ else
221
+ file->put (external_lit), file->put (' ');
222
+ if (binary)
223
+ put_binary_zero ();
224
+ else
225
+ file->put ("0 ");
226
+ for (const auto &cid : chain)
227
+ if (binary)
228
+ put_binary_id (cid);
229
+ else
230
+ file->put (cid), file->put (' ');
231
+ if (binary)
232
+ put_binary_zero ();
233
+ else
234
+ file->put ("0\n");
235
+ }
236
+
237
+ void LidrupTracer::lidrup_add_original_clause (int64_t id,
238
+ const vector<int> &clause) {
239
+ lidrup_batch_weaken_restore_and_delete ();
240
+ if (binary) {
241
+ file->put ('i');
242
+ put_binary_id (id);
243
+ } else {
244
+ file->put ("i ");
245
+ file->put (id);
246
+ file->put (' ');
247
+ }
248
+ for (const auto &external_lit : clause)
249
+ if (binary)
250
+ put_binary_lit (external_lit);
251
+ else
252
+ file->put (external_lit), file->put (' ');
253
+ if (binary)
254
+ put_binary_zero ();
255
+ else
256
+ file->put ("0\n");
257
+ }
258
+
259
+ void LidrupTracer::lidrup_batch_weaken_restore_and_delete () {
260
+ assert (batch_weaken.empty () || batch_delete.empty ());
261
+ if (!batch_weaken.empty ()) {
262
+ if (binary) {
263
+ file->put ('w');
264
+ } else {
265
+ file->put ("w ");
266
+ }
267
+ for (const auto &id : batch_weaken) {
268
+ if (binary)
269
+ put_binary_id (id);
270
+ else
271
+ file->put (id), file->put (' ');
272
+ }
273
+ batch_weaken.clear ();
274
+ if (binary)
275
+ put_binary_zero ();
276
+ else
277
+ file->put ("0\n");
278
+ #ifndef QUIET
279
+ batched++;
280
+ #endif
281
+ }
282
+ if (!batch_delete.empty ()) {
283
+ if (binary) {
284
+ file->put ('d');
285
+ } else {
286
+ file->put ("d ");
287
+ }
288
+ for (const auto &id : batch_delete) {
289
+ if (binary)
290
+ put_binary_id (id);
291
+ else
292
+ file->put (id), file->put (' ');
293
+ }
294
+ batch_delete.clear ();
295
+ if (binary)
296
+ put_binary_zero ();
297
+ else
298
+ file->put ("0\n");
299
+ #ifndef QUIET
300
+ batched++;
301
+ #endif
302
+ }
303
+ if (!batch_restore.empty ()) {
304
+ if (binary) {
305
+ file->put ('r');
306
+ } else {
307
+ file->put ("r ");
308
+ }
309
+ for (const auto &id : batch_restore) {
310
+ if (binary)
311
+ put_binary_id (id);
312
+ else
313
+ file->put (id), file->put (' ');
314
+ }
315
+ batch_restore.clear ();
316
+ if (binary)
317
+ put_binary_zero ();
318
+ else
319
+ file->put ("0\n");
320
+ #ifndef QUIET
321
+ batched++;
322
+ #endif
323
+ }
324
+ }
325
+
326
+ void LidrupTracer::lidrup_conclude_and_delete (
327
+ const vector<int64_t> &conclusion) {
328
+ lidrup_batch_weaken_restore_and_delete ();
329
+ int64_t size = conclusion.size ();
330
+ if (size > 1) {
331
+ if (binary) {
332
+ file->put ('U');
333
+ put_binary_id (size);
334
+ } else {
335
+ file->put ("U ");
336
+ file->put (size), file->put ("\n");
337
+ }
338
+ }
339
+ for (auto &id : conclusion) {
340
+ if (binary)
341
+ file->put ('u');
342
+ else
343
+ file->put ("u ");
344
+ if (!find_and_delete (id)) {
345
+ assert (imported_clause.empty ());
346
+ assert (conclusion.size () == 1);
347
+ if (binary) {
348
+ put_binary_zero ();
349
+ put_binary_id (id);
350
+ put_binary_zero ();
351
+ } else {
352
+ file->put ("0 ");
353
+ file->put (id);
354
+ file->put (" 0\n");
355
+ }
356
+ } else {
357
+ for (const auto &external_lit : imported_clause) {
358
+ // flip sign...
359
+ const auto not_elit = -external_lit;
360
+ if (binary)
361
+ put_binary_lit (not_elit);
362
+ else
363
+ file->put (not_elit), file->put (' ');
364
+ }
365
+ if (binary)
366
+ put_binary_zero ();
367
+ else
368
+ file->put ("0 ");
369
+ for (const auto &cid : imported_chain) {
370
+ if (binary)
371
+ put_binary_id (cid);
372
+ else
373
+ file->put (cid), file->put (' ');
374
+ }
375
+ if (binary)
376
+ put_binary_zero ();
377
+ else
378
+ file->put ("0\n");
379
+ imported_clause.clear ();
380
+ imported_chain.clear ();
381
+ }
382
+ }
383
+ flush_if_piping ();
384
+ }
385
+
386
+ void LidrupTracer::lidrup_report_status (int status) {
387
+ lidrup_batch_weaken_restore_and_delete ();
388
+ if (binary)
389
+ file->put ('s');
390
+ else
391
+ file->put ("s ");
392
+ if (status == SATISFIABLE)
393
+ file->put ("SATISFIABLE");
394
+ else if (status == UNSATISFIABLE)
395
+ file->put ("UNSATISFIABLE");
396
+ else
397
+ file->put ("UNKNOWN");
398
+ if (!binary)
399
+ file->put ("\n");
400
+ flush_if_piping ();
401
+ }
402
+
403
+ void LidrupTracer::lidrup_conclude_sat (const vector<int> &model) {
404
+ lidrup_batch_weaken_restore_and_delete ();
405
+ if (binary)
406
+ file->put ('m');
407
+ else
408
+ file->put ("m ");
409
+ for (auto &lit : model) {
410
+ if (binary)
411
+ put_binary_lit (lit);
412
+ else
413
+ file->put (lit), file->put (' ');
414
+ }
415
+ if (binary)
416
+ put_binary_zero ();
417
+ else
418
+ file->put ("0\n");
419
+ flush_if_piping ();
420
+ }
421
+
422
+ void LidrupTracer::lidrup_conclude_unknown (const vector<int> &trail) {
423
+ lidrup_batch_weaken_restore_and_delete ();
424
+ if (binary)
425
+ file->put ('e');
426
+ else
427
+ file->put ("e ");
428
+ for (auto &lit : trail) {
429
+ if (binary)
430
+ put_binary_lit (lit);
431
+ else
432
+ file->put (lit), file->put (' ');
433
+ }
434
+ if (binary)
435
+ put_binary_zero ();
436
+ else
437
+ file->put ("0\n");
438
+ flush_if_piping ();
439
+ }
440
+
441
+ void LidrupTracer::lidrup_solve_query () {
442
+ lidrup_batch_weaken_restore_and_delete ();
443
+ if (binary)
444
+ file->put ('q');
445
+ else
446
+ file->put ("q ");
447
+ for (auto &lit : assumptions) {
448
+ if (binary)
449
+ put_binary_lit (lit);
450
+ else
451
+ file->put (lit), file->put (' ');
452
+ }
453
+ if (binary)
454
+ put_binary_zero ();
455
+ else
456
+ file->put ("0\n");
457
+ flush_if_piping ();
458
+ }
459
+
460
+ /*------------------------------------------------------------------------*/
461
+
462
+ void LidrupTracer::add_derived_clause (int64_t id, bool, int,
463
+ const vector<int> &clause,
464
+ const vector<int64_t> &chain) {
465
+ if (file->closed ())
466
+ return;
467
+ assert (imported_clause.empty ());
468
+ LOG (clause, "LIDRUP TRACER tracing addition of derived clause");
469
+ lidrup_add_derived_clause (id, clause, chain);
470
+ #ifndef QUIET
471
+ added++;
472
+ #endif
473
+ }
474
+
475
+ void LidrupTracer::add_assumption_clause (int64_t id,
476
+ const vector<int> &clause,
477
+ const vector<int64_t> &chain) {
478
+ if (file->closed ())
479
+ return;
480
+ assert (imported_clause.empty ());
481
+ LOG (clause,
482
+ "LIDRUP TRACER tracing addition of assumption clause[%" PRId64 "]",
483
+ id);
484
+ for (auto &lit : clause)
485
+ imported_clause.push_back (lit);
486
+ for (auto &cid : chain)
487
+ imported_chain.push_back (cid);
488
+ last_id = id;
489
+ insert ();
490
+ imported_clause.clear ();
491
+ imported_chain.clear ();
492
+ }
493
+
494
+ void LidrupTracer::delete_clause (int64_t id, bool, const vector<int> &) {
495
+ if (file->closed ())
496
+ return;
497
+ assert (imported_clause.empty ());
498
+ LOG ("LIDRUP TRACER tracing deletion of clause[%" PRId64 "]", id);
499
+ if (find_and_delete (id)) {
500
+ assert (imported_clause.empty ());
501
+ if (!batch_delete.empty () || !batch_restore.empty ())
502
+ lidrup_batch_weaken_restore_and_delete ();
503
+ batch_weaken.push_back (id);
504
+ #ifndef QUIET
505
+ weakened++;
506
+ #endif
507
+ } else {
508
+ if (!batch_weaken.empty () || !batch_restore.empty ())
509
+ lidrup_batch_weaken_restore_and_delete ();
510
+ batch_delete.push_back (id);
511
+ #ifndef QUIET
512
+ deleted++;
513
+ #endif
514
+ }
515
+ }
516
+
517
+ void LidrupTracer::weaken_minus (int64_t id, const vector<int> &) {
518
+ if (file->closed ())
519
+ return;
520
+ assert (imported_clause.empty ());
521
+ LOG ("LIDRUP TRACER tracing weaken minus of clause[%" PRId64 "]", id);
522
+ last_id = id;
523
+ insert ();
524
+ }
525
+
526
+ void LidrupTracer::conclude_unsat (ConclusionType,
527
+ const vector<int64_t> &conclusion) {
528
+ if (file->closed ())
529
+ return;
530
+ assert (imported_clause.empty ());
531
+ LOG (conclusion, "LIDRUP TRACER tracing conclusion of clause(s)");
532
+ lidrup_conclude_and_delete (conclusion);
533
+ }
534
+
535
+ void LidrupTracer::add_original_clause (int64_t id, bool,
536
+ const vector<int> &clause,
537
+ bool restored) {
538
+ if (file->closed ())
539
+ return;
540
+ if (!restored) {
541
+ LOG (clause, "LIDRUP TRACER tracing addition of original clause");
542
+ #ifndef QUIET
543
+ original++;
544
+ #endif
545
+ return lidrup_add_original_clause (id, clause);
546
+ }
547
+ assert (restored);
548
+ if (find_and_delete (id)) {
549
+ LOG (clause,
550
+ "LIDRUP TRACER the clause was not yet weakened, so no restore");
551
+ return;
552
+ }
553
+ LOG (clause, "LIDRUP TRACER tracing addition of restored clause");
554
+ lidrup_add_restored_clause (id);
555
+ #ifndef QUIET
556
+ restore++;
557
+ #endif
558
+ }
559
+
560
+ void LidrupTracer::report_status (int status, int64_t) {
561
+ if (file->closed ())
562
+ return;
563
+ LOG ("LIDRUP TRACER tracing report of status %d", status);
564
+ lidrup_report_status (status);
565
+ }
566
+
567
+ void LidrupTracer::conclude_sat (const vector<int> &model) {
568
+ if (file->closed ())
569
+ return;
570
+ LOG (model, "LIDRUP TRACER tracing conclusion of model");
571
+ lidrup_conclude_sat (model);
572
+ }
573
+
574
+ void LidrupTracer::conclude_unknown (const vector<int> &entrailed) {
575
+ if (file->closed ())
576
+ return;
577
+ LOG (entrailed, "LIDRUP TRACER tracing conclusion of UNK");
578
+ lidrup_conclude_unknown (entrailed);
579
+ }
580
+
581
+ void LidrupTracer::solve_query () {
582
+ if (file->closed ())
583
+ return;
584
+ LOG (assumptions, "LIDRUP TRACER tracing solve query with assumptions");
585
+ lidrup_solve_query ();
586
+ #ifndef QUIET
587
+ solved++;
588
+ #endif
589
+ }
590
+
591
+ void LidrupTracer::add_assumption (int lit) {
592
+ LOG ("LIDRUP TRACER tracing addition of assumption %d", lit);
593
+ assumptions.push_back (lit);
594
+ }
595
+
596
+ void LidrupTracer::reset_assumptions () {
597
+ LOG (assumptions, "LIDRUP TRACER tracing reset of assumptions");
598
+ assumptions.clear ();
599
+ }
600
+
601
+ /*------------------------------------------------------------------------*/
602
+
603
+ bool LidrupTracer::closed () { return file->closed (); }
604
+
605
+ #ifndef QUIET
606
+
607
+ void LidrupTracer::print_statistics () {
608
+ // TODO complete this.
609
+ uint64_t bytes = file->bytes ();
610
+ uint64_t total = added + deleted + weakened + restore + original;
611
+ MSG ("LIDRUP %" PRId64 " original clauses %.2f%%", original,
612
+ percent (original, total));
613
+ MSG ("LIDRUP %" PRId64 " learned clauses %.2f%%", added,
614
+ percent (added, total));
615
+ MSG ("LIDRUP %" PRId64 " deleted clauses %.2f%%", deleted,
616
+ percent (deleted, total));
617
+ MSG ("LIDRUP %" PRId64 " weakened clauses %.2f%%", weakened,
618
+ percent (weakened, total));
619
+ MSG ("LIDRUP %" PRId64 " restored clauses %.2f%%", restore,
620
+ percent (restore, total));
621
+ MSG ("LIDRUP %" PRId64 " batches of deletions, weaken and restores %.2f",
622
+ batched, relative (batched, deleted + restore + weakened));
623
+ MSG ("LIDRUP %" PRId64 " queries %.2f", solved, relative (solved, total));
624
+ MSG ("LIDRUP %" PRId64 " bytes (%.2f MB)", bytes,
625
+ bytes / (double) (1 << 20));
626
+ }
627
+
628
+ #endif
629
+
630
+ void LidrupTracer::close (bool print) {
631
+ assert (!closed ());
632
+ file->close ();
633
+ #ifndef QUIET
634
+ if (print) {
635
+ MSG ("LIDRUP proof file '%s' closed", file->name ());
636
+ print_statistics ();
637
+ }
638
+ #else
639
+ (void) print;
640
+ #endif
641
+ }
642
+
643
+ void LidrupTracer::flush (bool print) {
644
+ assert (!closed ());
645
+ lidrup_batch_weaken_restore_and_delete ();
646
+ file->flush ();
647
+ #ifndef QUIET
648
+ if (print) {
649
+ MSG ("LIDRUP proof file '%s' flushed", file->name ());
650
+ print_statistics ();
651
+ }
652
+ #else
653
+ (void) print;
654
+ #endif
655
+ }
656
+
657
+ } // namespace CaDiCaL