ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_frattracer.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9/*------------------------------------------------------------------------*/
10
11FratTracer::FratTracer (Internal *i, File *f, bool b, bool a)
12 : internal (i), file (f), binary (b), with_antecedents (a)
13#ifndef CADICAL_QUIET
14 ,
15 added (0), deleted (0), finalized (0), original (0)
16#endif
17{
18 (void) internal;
19}
20
22 internal = i;
23 file->connect_internal (internal);
24 LOG ("FRAT TRACER connected to internal");
25}
26
28 LOG ("FRAT TRACER delete");
29 delete file;
30}
31
32/*------------------------------------------------------------------------*/
33
34inline void FratTracer::put_binary_zero () {
35 CADICAL_assert (binary);
37 file->put ((unsigned char) 0);
38}
39
40inline void FratTracer::put_binary_lit (int lit) {
41 CADICAL_assert (binary);
43 CADICAL_assert (lit != INT_MIN);
44 unsigned x = 2 * abs (lit) + (lit < 0);
45 unsigned char ch;
46 while (x & ~0x7f) {
47 ch = (x & 0x7f) | 0x80;
48 file->put (ch);
49 x >>= 7;
50 }
51 ch = x;
52 file->put (ch);
53}
54
55inline void FratTracer::put_binary_id (int64_t id, bool can_be_negative) {
56 CADICAL_assert (binary);
57 CADICAL_assert (file);
58 uint64_t x = abs (id);
59 if (can_be_negative) {
60 x = 2 * x + (id < 0);
61 }
62 unsigned char ch;
63 while (x & ~0x7f) {
64 ch = (x & 0x7f) | 0x80;
65 file->put (ch);
66 x >>= 7;
67 }
68 ch = x;
69 file->put (ch);
70}
71
72/*------------------------------------------------------------------------*/
73
74void FratTracer::frat_add_original_clause (int64_t id,
75 const vector<int> &clause) {
76 if (binary)
77 file->put ('o');
78 else
79 file->put ("o ");
80 if (binary)
81 put_binary_id (id);
82 else
83 file->put (id), file->put (" ");
84 for (const auto &external_lit : clause)
85 if (binary)
86 put_binary_lit (external_lit);
87 else
88 file->put (external_lit), file->put (' ');
89 if (binary)
90 put_binary_zero ();
91 else
92 file->put ("0\n");
93}
94
95void FratTracer::frat_add_derived_clause (int64_t id,
96 const vector<int> &clause) {
97 if (binary)
98 file->put ('a');
99 else
100 file->put ("a ");
101 if (binary)
102 put_binary_id (id);
103 else
104 file->put (id), file->put (" ");
105 for (const auto &external_lit : clause)
106 if (binary)
107 put_binary_lit (external_lit);
108 else
109 file->put (external_lit), file->put (' ');
110 if (binary)
111 put_binary_zero ();
112 else
113 file->put ("0\n");
114}
115
116void FratTracer::frat_add_derived_clause (int64_t id,
117 const vector<int> &clause,
118 const vector<int64_t> &chain) {
119 if (binary)
120 file->put ('a');
121 else
122 file->put ("a ");
123 if (binary)
124 put_binary_id (id);
125 else
126 file->put (id), file->put (" ");
127 for (const auto &external_lit : clause)
128 if (binary)
129 put_binary_lit (external_lit);
130 else
131 file->put (external_lit), file->put (' ');
132 if (binary)
133 put_binary_zero (), file->put ('l');
134 else
135 file->put ("0 l ");
136 for (const auto &c : chain)
137 if (binary)
138 put_binary_id (c, true); // LRAT can have negative ids
139 else
140 file->put (c), file->put (' '); // in proof chain, so they get
141 if (binary)
142 put_binary_zero (); // since cadical has no rat-steps
143 else
144 file->put ("0\n"); // this is just 2c here
145}
146
147void FratTracer::frat_delete_clause (int64_t id,
148 const vector<int> &clause) {
149 if (binary)
150 file->put ('d');
151 else
152 file->put ("d ");
153 if (binary)
154 put_binary_id (id);
155 else
156 file->put (id), file->put (" ");
157 for (const auto &external_lit : clause)
158 if (binary)
159 put_binary_lit (external_lit);
160 else
161 file->put (external_lit), file->put (' ');
162 if (binary)
163 put_binary_zero ();
164 else
165 file->put ("0\n");
166}
167
168void FratTracer::frat_finalize_clause (int64_t id,
169 const vector<int> &clause) {
170 if (binary)
171 file->put ('f');
172 else
173 file->put ("f ");
174 if (binary)
175 put_binary_id (id);
176 else
177 file->put (id), file->put (" ");
178 for (const auto &external_lit : clause)
179 if (binary)
180 put_binary_lit (external_lit);
181 else
182 file->put (external_lit), file->put (' ');
183 if (binary)
184 put_binary_zero ();
185 else
186 file->put ("0\n");
187}
188
189/*------------------------------------------------------------------------*/
190
191void FratTracer::add_original_clause (int64_t id, bool,
192 const vector<int> &clause, bool) {
193 if (file->closed ())
194 return;
195 LOG ("FRAT TRACER tracing addition of original clause");
196 frat_add_original_clause (id, clause);
197}
198
199void FratTracer::add_derived_clause (int64_t id, bool,
200 const vector<int> &clause,
201 const vector<int64_t> &chain) {
202 if (file->closed ())
203 return;
204 LOG ("FRAT TRACER tracing addition of derived clause");
205 if (with_antecedents)
206 frat_add_derived_clause (id, clause, chain);
207 else
208 frat_add_derived_clause (id, clause);
209#ifndef CADICAL_QUIET
210 added++;
211#endif
212}
213
214void FratTracer::delete_clause (int64_t id, bool,
215 const vector<int> &clause) {
216 if (file->closed ())
217 return;
218 LOG ("FRAT TRACER tracing deletion of clause");
219 frat_delete_clause (id, clause);
220#ifndef CADICAL_QUIET
221 deleted++;
222#endif
223}
224
226 if (file->closed ())
227 return;
228 LOG ("FRAT TRACER tracing finalization of clause");
229 frat_finalize_clause (id, clause);
230}
231
232/*------------------------------------------------------------------------*/
233
234bool FratTracer::closed () { return file->closed (); }
235
236#ifndef CADICAL_QUIET
237
238void FratTracer::print_statistics () {
239 uint64_t bytes = file->bytes ();
240 uint64_t total = original + added + deleted + finalized;
241 MSG ("FRAT %" PRId64 " original clauses %.2f%%", original,
242 percent (original, total));
243 MSG ("FRAT %" PRId64 " added clauses %.2f%%", added,
244 percent (added, total));
245 MSG ("FRAT %" PRId64 " deleted clauses %.2f%%", deleted,
246 percent (deleted, total));
247 MSG ("FRAT %" PRId64 " finalized clauses %.2f%%", finalized,
248 percent (finalized, total));
249 MSG ("FRAT %" PRId64 " bytes (%.2f MB)", bytes,
250 bytes / (double) (1 << 20));
251}
252
253#endif
254
255void FratTracer::close (bool print) {
257 file->close ();
258#ifndef CADICAL_QUIET
259 if (print) {
260 MSG ("FRAT proof file '%s' closed", file->name ());
261 print_statistics ();
262 }
263#else
264 (void) print;
265#endif
266}
267
268void FratTracer::flush (bool print) {
270 file->flush ();
271#ifndef CADICAL_QUIET
272 if (print) {
273 MSG ("FRAT proof file '%s' flushed", file->name ());
274 print_statistics ();
275 }
276#else
277 (void) print;
278#endif
279}
280
281} // namespace CaDiCaL
282
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
#define CADICAL_QUIET
Definition global.h:8
#define LOG(...)
void flush(bool) override
FratTracer(Internal *, File *file, bool binary, bool antecedents)
void connect_internal(Internal *i) override
void add_derived_clause(int64_t, bool, const vector< int > &, const vector< int64_t > &) override
void close(bool) override
void add_original_clause(int64_t, bool, const vector< int > &, bool=false) override
void delete_clause(int64_t, bool, const vector< int > &) override
void finalize_clause(int64_t, const vector< int > &) override
#define MSG(...)
Definition message.hpp:49
double percent(double a, double b)
Definition util.hpp:21
struct clause_t clause
STRUCTURE DEFINITIONS ///.
Definition satClause.h:48
int lit
Definition satVec.h:130
Definition file.h:23
uint64_t bytes
Definition file.h:29