ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_drattracer.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9/*------------------------------------------------------------------------*/
10
12 : internal (i), file (f), binary (b)
13#ifndef CADICAL_QUIET
14 ,
15 added (0), deleted (0)
16#endif
17{
18 (void) internal;
19}
20
22 internal = i;
23 file->connect_internal (internal);
24 LOG ("DRAT TRACER connected to internal");
25}
26
28 LOG ("DRAT TRACER delete");
29 delete file;
30}
31
32/*------------------------------------------------------------------------*/
33
34inline void DratTracer::put_binary_zero () {
35 CADICAL_assert (binary);
37 file->put ((unsigned char) 0);
38}
39
40inline void DratTracer::put_binary_lit (int lit) {
41 CADICAL_assert (binary);
43 CADICAL_assert (lit != INT_MIN);
44 unsigned idx = abs (lit);
45 CADICAL_assert (idx < (1u << 31));
46 unsigned x = 2u * idx + (lit < 0);
47 unsigned char ch;
48 while (x & ~0x7f) {
49 ch = (x & 0x7f) | 0x80;
50 file->put (ch);
51 x >>= 7;
52 }
53 ch = x;
54 file->put (ch);
55}
56
57/*------------------------------------------------------------------------*/
58
59void DratTracer::drat_add_clause (const vector<int> &clause) {
60 if (binary)
61 file->put ('a');
62 for (const auto &external_lit : clause)
63 if (binary)
64 put_binary_lit (external_lit);
65 else
66 file->put (external_lit), file->put (' ');
67 if (binary)
68 put_binary_zero ();
69 else
70 file->put ("0\n");
71}
72void DratTracer::drat_delete_clause (const vector<int> &clause) {
73 if (binary)
74 file->put ('d');
75 else
76 file->put ("d ");
77 for (const auto &external_lit : clause)
78 if (binary)
79 put_binary_lit (external_lit);
80 else
81 file->put (external_lit), file->put (' ');
82 if (binary)
83 put_binary_zero ();
84 else
85 file->put ("0\n");
86}
87
88/*------------------------------------------------------------------------*/
89
91 const vector<int> &clause,
92 const vector<int64_t> &) {
93 if (file->closed ())
94 return;
95 LOG ("DRAT TRACER tracing addition of derived clause");
96 drat_add_clause (clause);
97#ifndef CADICAL_QUIET
98 added++;
99#endif
100}
101
102void DratTracer::delete_clause (int64_t, bool, const vector<int> &clause) {
103 if (file->closed ())
104 return;
105 LOG ("DRAT TRACER tracing deletion of clause");
106 drat_delete_clause (clause);
107#ifndef CADICAL_QUIET
108 deleted++;
109#endif
110}
111
112/*------------------------------------------------------------------------*/
113
114bool DratTracer::closed () { return file->closed (); }
115
116#ifndef CADICAL_QUIET
117
118void DratTracer::print_statistics () {
119 uint64_t bytes = file->bytes ();
120 uint64_t total = added + deleted;
121 MSG ("DRAT %" PRId64 " added clauses %.2f%%", added,
122 percent (added, total));
123 MSG ("DRAT %" PRId64 " deleted clauses %.2f%%", deleted,
124 percent (deleted, total));
125 MSG ("DRAT %" PRId64 " bytes (%.2f MB)", bytes,
126 bytes / (double) (1 << 20));
127}
128
129#endif
130
131void DratTracer::close (bool print) {
133 file->close ();
134#ifndef CADICAL_QUIET
135 if (print) {
136 MSG ("DRAT proof file '%s' closed", file->name ());
137 print_statistics ();
138 }
139#else
140 (void) print;
141#endif
142}
143
144void DratTracer::flush (bool print) {
146 file->flush ();
147#ifndef CADICAL_QUIET
148 if (print) {
149 MSG ("DRAT proof file '%s' flushed", file->name ());
150 print_statistics ();
151 }
152#else
153 (void) print;
154#endif
155}
156
157} // namespace CaDiCaL
158
#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(...)
DratTracer(Internal *, File *file, bool binary)
void connect_internal(Internal *i) 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
void close(bool) 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