ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
checker.hpp
Go to the documentation of this file.
1#ifndef _checker_hpp_INCLUDED
2#define _checker_hpp_INCLUDED
3
4#include "global.h"
5
6#include "tracer.hpp" // Alphabetically after 'checker'.
7
8#include <cstdint>
9
11
12namespace CaDiCaL {
13
14/*------------------------------------------------------------------------*/
15
16// This checker implements an online forward DRUP proof checker enabled by
17// 'opts.checkproof' (requires 'opts.check' also to be enabled). This is
18// useful for model basted testing (and delta-debugging), where we can not
19// rely on an external proof checker such as 'drat-trim'. We also do not
20// have yet a flow for offline incremental proof checking, while this
21// checker here can also be used in an incremental setting.
22//
23// In essence the checker implements is a simple propagation online SAT
24// solver with an additional hash table to find clauses fast for
25// 'delete_clause'. It requires its own data structure for clauses
26// ('CheckerClause') and watches ('CheckerWatch').
27//
28// In our experiments the checker slows down overall SAT solving time by a
29// factor of 3, which we contribute to its slightly less efficient
30// implementation.
31
32/*------------------------------------------------------------------------*/
33
35 CheckerClause *next; // collision chain link for hash table
36 uint64_t hash; // previously computed full 64-bit hash
37 unsigned size; // zero if this is a garbage clause
38 int literals[2]; // otherwise 'literals' of length 'size'
39};
40
42 int blit;
43 unsigned size;
47 : blit (b), size (c->size), clause (c) {}
48};
49
51
52/*------------------------------------------------------------------------*/
53
54class Checker : public StatTracer {
55
56 Internal *internal;
57
58 // Capacity of variable values.
59 //
60 int64_t size_vars;
61
62 // For the assignment we want to have an as fast access as possible and
63 // thus we use an array which can also be indexed by negative literals and
64 // is actually valid in the range [-size_vars+1, ..., size_vars-1].
65 //
66 signed char *vals;
67
68 // The 'watchers' and 'marks' data structures are not that time critical
69 // and thus we access them by first mapping a literal to 'unsigned'.
70 //
71 static unsigned l2u (int lit);
72 vector<CheckerWatcher> watchers; // watchers of literals
73 vector<signed char> marks; // mark bits of literals
74
75 signed char &mark (int lit);
76 CheckerWatcher &watcher (int lit);
77
78 bool inconsistent; // found or added empty clause
79
80 uint64_t num_clauses; // number of clauses in hash table
81 uint64_t num_garbage; // number of garbage clauses
82 uint64_t size_clauses; // size of clause hash table
83 CheckerClause **clauses; // hash table of clauses
84 CheckerClause *garbage; // linked list of garbage clauses
85
86 vector<int> unsimplified; // original clause for reporting
87 vector<int> simplified; // clause for sorting
88
89 vector<int> trail; // for propagation
90
91 unsigned next_to_propagate; // next to propagate on trail
92
93 void enlarge_vars (int64_t idx);
94 void import_literal (int lit);
95 void import_clause (const vector<int> &);
96 bool tautological ();
97
98 static const unsigned num_nonces = 4;
99
100 uint64_t nonces[num_nonces]; // random numbers for hashing
101 uint64_t last_hash; // last computed hash value of clause
102 int64_t last_id;
103 uint64_t compute_hash (); // compute and save hash value of clause
104
105 // Reduce hash value to the actual size.
106 //
107 static uint64_t reduce_hash (uint64_t hash, uint64_t size);
108
109 void enlarge_clauses (); // enlarge hash table for clauses
110 void insert (); // insert clause in hash table
111 CheckerClause **find (); // find clause position in hash table
112
113 void add_clause (const char *type);
114
115 void collect_garbage_clauses ();
116
117 CheckerClause *new_clause ();
118 void delete_clause (CheckerClause *);
119
120 signed char val (int lit); // returns '-1', '0' or '1'
121
122 bool clause_satisfied (CheckerClause *);
123
124 void assign (int lit); // assign a literal to true
125 void assume (int lit); // assume a literal
126 bool propagate (); // propagate and check for conflicts
127 void backtrack (unsigned); // prepare for next clause
128 bool check (); // check simplified clause is implied
129 bool check_blocked (); // check if clause is blocked
130
131 struct {
132
133 int64_t added; // number of added clauses
134 int64_t original; // number of added original clauses
135 int64_t derived; // number of added derived clauses
136
137 int64_t deleted; // number of deleted clauses
138
139 int64_t assumptions; // number of assumed literals
140 int64_t propagations; // number of propagated literals
141
142 int64_t insertions; // number of clauses added to hash table
143 int64_t collisions; // number of hash collisions in 'find'
144 int64_t searches; // number of searched clauses in 'find'
145
146 int64_t checks; // number of implication checks
147
148 int64_t collections; // garbage collections
149 int64_t units;
150
151 } stats;
152
153public:
154 Checker (Internal *);
155 virtual ~Checker ();
156
157 void connect_internal (Internal *i) override;
158
159 void add_original_clause (int64_t, bool, const vector<int> &,
160 bool = false) override;
161 void add_derived_clause (int64_t, bool, const vector<int> &,
162 const vector<int64_t> &) override;
163 void delete_clause (int64_t, bool, const vector<int> &) override;
164
165 void finalize_clause (int64_t, const vector<int> &) override {} // skip
166 void report_status (int, int64_t) override {} // skip
167 void begin_proof (int64_t) override {} // skip
168 void add_assumption_clause (int64_t, const vector<int> &,
169 const vector<int64_t> &) override;
170 void print_stats () override;
171 void dump (); // for debugging purposes only
172};
173
174} // namespace CaDiCaL
175
177
178#endif
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
int64_t collisions
Definition checker.hpp:143
void begin_proof(int64_t) override
Definition checker.hpp:167
void add_assumption_clause(int64_t, const vector< int > &, const vector< int64_t > &) override
void report_status(int, int64_t) override
Definition checker.hpp:166
int64_t collections
Definition checker.hpp:148
void connect_internal(Internal *i) override
int64_t assumptions
Definition checker.hpp:139
int64_t insertions
Definition checker.hpp:142
void add_original_clause(int64_t, bool, const vector< int > &, bool=false) override
void print_stats() override
void finalize_clause(int64_t, const vector< int > &) override
Definition checker.hpp:165
void add_derived_clause(int64_t, bool, const vector< int > &, const vector< int64_t > &) override
int64_t propagations
Definition checker.hpp:140
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
vector< CheckerWatch > CheckerWatcher
Definition checker.hpp:50
int lit
Definition satVec.h:130
CheckerClause * next
Definition checker.hpp:35
CheckerClause * clause
Definition checker.hpp:44
CheckerWatch(int b, CheckerClause *c)
Definition checker.hpp:46
signed char mark
Definition value.h:8