ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_lrattracer.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
5#include <limits.h>
6
8
9namespace CaDiCaL {
10
11/*------------------------------------------------------------------------*/
12
14 : internal (i), file (f), binary (b)
15#ifndef CADICAL_QUIET
16 ,
17 added (0), deleted (0)
18#endif
19 ,
20 latest_id (0) {
21 (void) internal;
22}
23
25 internal = i;
26 file->connect_internal (internal);
27 LOG ("LRAT TRACER connected to internal");
28}
29
31 LOG ("LRAT TRACER delete");
32 delete file;
33}
34
35/*------------------------------------------------------------------------*/
36
37inline void LratTracer::put_binary_zero () {
38 CADICAL_assert (binary);
40 file->put ((unsigned char) 0);
41}
42
43inline void LratTracer::put_binary_lit (int lit) {
44 CADICAL_assert (binary);
46 CADICAL_assert (lit != INT_MIN);
47 unsigned idx = abs (lit);
48 CADICAL_assert (idx < (1u << 31));
49 unsigned x = 2 * idx + (lit < 0);
50 unsigned char ch;
51 while (x & ~0x7f) {
52 ch = (x & 0x7f) | 0x80;
53 file->put (ch);
54 x >>= 7;
55 }
56 ch = x;
57 file->put (ch);
58}
59
60inline void LratTracer::put_binary_id (int64_t id) {
61 CADICAL_assert (binary);
62 CADICAL_assert (file);
63 uint64_t x = abs (id);
64 x = 2 * x + (id < 0);
65 unsigned char ch;
66 while (x & ~0x7f) {
67 ch = (x & 0x7f) | 0x80;
68 file->put (ch);
69 x >>= 7;
70 }
71 ch = x;
72 file->put (ch);
73}
74
75/*------------------------------------------------------------------------*/
76
77void LratTracer::lrat_add_clause (int64_t id, const vector<int> &clause,
78 const vector<int64_t> &chain) {
79 if (delete_ids.size ()) {
80 if (!binary)
81 file->put (latest_id), file->put (" ");
82 if (binary)
83 file->put ('d');
84 else
85 file->put ("d ");
86 for (auto &did : delete_ids) {
87 if (binary)
88 put_binary_id (did);
89 else
90 file->put (did), file->put (" ");
91 }
92 if (binary)
93 put_binary_zero ();
94 else
95 file->put ("0\n");
96 delete_ids.clear ();
97 }
98 latest_id = id;
99
100 if (binary)
101 file->put ('a'), put_binary_id (id);
102 else
103 file->put (id), file->put (" ");
104 for (const auto &external_lit : clause)
105 if (binary)
106 put_binary_lit (external_lit);
107 else
108 file->put (external_lit), file->put (' ');
109 if (binary)
110 put_binary_zero ();
111 else
112 file->put ("0 ");
113 for (const auto &c : chain)
114 if (binary)
115 put_binary_id (c);
116 else
117 file->put (c), file->put (' '); // in proof chain, so they get
118 if (binary)
119 put_binary_zero (); // since cadical has no rat-steps
120 else
121 file->put ("0\n"); // this is just 2c here
122}
123
124void LratTracer::lrat_delete_clause (int64_t id) {
125 delete_ids.push_back (id); // pushing off deletion for later
126}
127
128/*------------------------------------------------------------------------*/
129
130void LratTracer::add_derived_clause (int64_t id, bool,
131 const vector<int> &clause,
132 const vector<int64_t> &chain) {
133 if (file->closed ())
134 return;
135 LOG ("LRAT TRACER tracing addition of derived clause");
136 lrat_add_clause (id, clause, chain);
137#ifndef CADICAL_QUIET
138 added++;
139#endif
140}
141
142void LratTracer::delete_clause (int64_t id, bool, const vector<int> &) {
143 if (file->closed ())
144 return;
145 LOG ("LRAT TRACER tracing deletion of clause");
146 lrat_delete_clause (id);
147#ifndef CADICAL_QUIET
148 deleted++;
149#endif
150}
151
152void LratTracer::begin_proof (int64_t id) {
153 if (file->closed ())
154 return;
155 LOG ("LRAT TRACER tracing begin of proof");
156 latest_id = id;
157}
158
159/*------------------------------------------------------------------------*/
160
161bool LratTracer::closed () { return file->closed (); }
162
163#ifndef CADICAL_QUIET
164
165void LratTracer::print_statistics () {
166 uint64_t bytes = file->bytes ();
167 uint64_t total = added + deleted;
168 MSG ("LRAT %" PRId64 " added clauses %.2f%%", added,
169 percent (added, total));
170 MSG ("LRAT %" PRId64 " deleted clauses %.2f%%", deleted,
171 percent (deleted, total));
172 MSG ("LRAT %" PRId64 " bytes (%.2f MB)", bytes,
173 bytes / (double) (1 << 20));
174}
175
176#endif
177
178void LratTracer::close (bool print) {
180 file->close ();
181#ifndef CADICAL_QUIET
182 if (print) {
183 MSG ("LRAT proof file '%s' closed", file->name ());
184 print_statistics ();
185 }
186#else
187 (void) print;
188#endif
189}
190
191void LratTracer::flush (bool print) {
193 file->flush ();
194#ifndef CADICAL_QUIET
195 if (print) {
196 MSG ("LRAT proof file '%s' flushed", file->name ());
197 print_statistics ();
198 }
199#else
200 (void) print;
201#endif
202}
203
204} // namespace CaDiCaL
205
#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 begin_proof(int64_t) override
void connect_internal(Internal *i) override
void close(bool) override
void flush(bool) override
void delete_clause(int64_t, bool, const vector< int > &) override
void add_derived_clause(int64_t, bool, const vector< int > &, const vector< int64_t > &) override
LratTracer(Internal *, File *file, bool binary)
#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