ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
dense.c
Go to the documentation of this file.
1#define INLINE_SORT
2
3#include "dense.h"
4#include "inline.h"
5#include "proprobe.h"
6#include "propsearch.h"
7#include "trail.h"
8
9#include "sort.c"
10
11#include <string.h>
12
14
15static void flush_large_watches (kissat *solver, litpairs *irredundant) {
16 KISSAT_assert (!solver->level);
17 KISSAT_assert (solver->watching);
18#ifndef LOGGING
19 LOG ("flushing large watches");
20 if (irredundant)
21 LOG ("flushing and saving irredundant binary clauses too");
22 else
23 LOG ("keep watching irredundant binary clauses");
24#endif
25 const value *const values = solver->values;
26 mark *const marks = solver->marks;
27#ifndef KISSAT_NDEBUG
28 for (all_literals (lit))
29 KISSAT_assert (!marks[lit]);
30#endif
31 size_t flushed = 0, collected = 0;
32#ifdef LOGGING
33 size_t deduplicated = 0;
34#endif
35 watches *all_watches = solver->watches;
36 unsigneds *marked = &solver->analyzed;
37 for (all_literals (lit)) {
38 const value lit_value = values[lit];
39 watches *watches = all_watches + lit;
40 watch *begin = BEGIN_WATCHES (*watches), *q = begin;
41 const watch *const end_watches = END_WATCHES (*watches), *p = q;
42 KISSAT_assert (EMPTY_STACK (*marked));
43 while (p != end_watches) {
44 const watch watch = *p++;
45 if (watch.type.binary) {
46 const unsigned other = watch.binary.lit;
47 const value other_value = values[other];
48 if (!lit_value && !other_value) {
49 const mark mark = marks[other];
50 if (mark) {
51 if (lit < other) {
53#ifdef LOGGING
54 deduplicated++;
55#endif
56 }
57 } else {
58 marks[other] = 1;
59 PUSH_STACK (*marked, other);
60 if (irredundant) {
61 const unsigned other = watch.binary.lit;
62 if (lit < other) {
63 const litpair litpair = {.lits = {lit, other}};
65 }
66 } else
67 *q++ = watch;
68 }
69 } else {
70 KISSAT_assert (lit_value > 0 || other_value > 0);
71 if (lit < other) {
73 collected++;
74 }
75 }
76 } else {
77 flushed++;
78 p++;
79 }
80 }
81 if (irredundant)
82 memset (watches, 0, sizeof *watches);
83 else
85 for (all_stack (unsigned, other, *marked))
86 marks[other] = 0;
87 CLEAR_ARRAY (*marked);
88 }
89 KISSAT_assert (EMPTY_STACK (*marked));
90 LOG ("flushed %zu large watches", flushed);
91 LOG ("removed %zu duplicated binary clauses", deduplicated);
92 LOG ("collected %zu satisfied binary clauses", collected);
93 if (irredundant) {
94 LOG ("saved %zu irredundant binary clauses", SIZE_STACK (*irredundant));
96 }
97 (void) collected;
98 (void) flushed;
99}
100
102 KISSAT_assert (!solver->level);
103 KISSAT_assert (solver->watching);
104 KISSAT_assert (kissat_propagated (solver));
105 LOG ("entering dense mode with full occurrence lists");
106 if (irredundant)
107 flush_large_watches (solver, irredundant);
108 else
110 LOG ("switched to full occurrence lists");
111 solver->watching = false;
112}
113
114static void resume_watching_irredundant_binaries (kissat *solver,
115 litpairs *binaries) {
116 KISSAT_assert (binaries);
117#ifdef LOGGING
118 size_t resumed_watching = 0;
119#endif
120 watches *all_watches = solver->watches;
121 for (all_stack (litpair, litpair, *binaries)) {
122 const unsigned first = litpair.lits[0];
123 const unsigned second = litpair.lits[1];
124
125 KISSAT_assert (!ELIMINATED (IDX (first)));
126 KISSAT_assert (!ELIMINATED (IDX (second)));
127
128 watches *first_watches = all_watches + first;
129 watch first_watch = kissat_binary_watch (second);
130 PUSH_WATCHES (*first_watches, first_watch);
131
132 watches *second_watches = all_watches + second;
133 watch second_watch = kissat_binary_watch (first);
134 PUSH_WATCHES (*second_watches, second_watch);
135
136#ifdef LOGGING
137 resumed_watching++;
138#endif
139 }
140 LOG ("resumed watching %zu binary clauses", resumed_watching);
141}
142
143static void
144resume_watching_large_clauses_after_elimination (kissat *solver) {
145#ifdef LOGGING
146 size_t resumed_watching_redundant = 0;
147 size_t resumed_watching_irredundant = 0;
148#endif
149 const flags *const flags = solver->flags;
150 watches *watches = solver->watches;
151 const value *const values = solver->values;
152 const assigned *const assigned = solver->assigned;
153 ward *const arena = BEGIN_STACK (solver->arena);
154
155 for (all_clauses (c)) {
156 if (c->garbage)
157 continue;
158 bool collect = false;
159 for (all_literals_in_clause (lit, c)) {
160 if (values[lit] > 0) {
161 LOGCLS (c, "%s satisfied", LOGLIT (lit));
162 collect = true;
163 break;
164 }
165 const unsigned idx = IDX (lit);
166 if (flags[idx].eliminated) {
167 LOGCLS (c, "containing eliminated %s", LOGLIT (lit));
168 collect = true;
169 break;
170 }
171 }
172 if (collect) {
174 continue;
175 }
176
177 KISSAT_assert (c->size > 2);
178
179 unsigned *lits = c->lits;
180 kissat_sort_literals (solver, values, assigned, c->size, lits);
181 c->searched = 2;
182
183 const reference ref = (ward *) c - arena;
184 const unsigned l0 = lits[0];
185 const unsigned l1 = lits[1];
186
187 kissat_push_blocking_watch (solver, watches + l0, l1, ref);
188 kissat_push_blocking_watch (solver, watches + l1, l0, ref);
189
190#ifdef LOGGING
191 if (c->redundant)
192 resumed_watching_redundant++;
193 else
194 resumed_watching_irredundant++;
195#endif
196 }
197 LOG ("resumed watching %zu irredundant and %zu redundant large clauses",
198 resumed_watching_irredundant, resumed_watching_redundant);
199}
200
201void kissat_resume_sparse_mode (kissat *solver, bool flush_eliminated,
202 litpairs *irredundant) {
203 KISSAT_assert (!solver->level);
204 KISSAT_assert (!solver->watching);
205 if (solver->inconsistent)
206 return;
207 LOG ("resuming sparse mode watching clauses");
209 LOG ("switched to watching clauses");
210 solver->watching = true;
211 if (irredundant) {
212 LOG ("resuming watching %zu irredundant binaries",
214 resume_watching_irredundant_binaries (solver, irredundant);
215 }
216 if (flush_eliminated)
217 resume_watching_large_clauses_after_elimination (solver);
218 else
220 LOG ("forcing to propagate units on all clauses");
221 kissat_reset_propagate (solver);
222
223 clause *conflict;
224 if (solver->probing)
225 conflict = kissat_probing_propagate (solver, 0, true);
226 else
227 conflict = kissat_search_propagate (solver);
228
229#ifndef KISSAT_NDEBUG
230 if (conflict)
231 KISSAT_assert (solver->inconsistent);
232 else
233 KISSAT_assert (kissat_trail_flushed (solver));
234#else
235 (void) conflict;
236#endif
237}
238
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_HEADER_START typedef word ward
Definition arena.h:12
#define CLEAR_ARRAY
Definition array.h:45
#define BEGIN_STACK(S)
Definition stack.h:46
#define all_stack(T, E, S)
Definition stack.h:94
#define SIZE_STACK(S)
Definition stack.h:19
#define EMPTY_STACK(S)
Definition stack.h:18
#define PUSH_STACK(S, E)
Definition stack.h:39
#define LOG(...)
ABC_NAMESPACE_IMPL_START typedef signed char value
void kissat_mark_clause_as_garbage(kissat *solver, clause *c)
Definition clause.c:164
void kissat_delete_binary(kissat *solver, unsigned a, unsigned b)
Definition clause.c:181
void kissat_enter_dense_mode(kissat *solver, litpairs *irredundant)
Definition dense.c:101
void kissat_resume_sparse_mode(kissat *solver, bool flush_eliminated, litpairs *irredundant)
Definition dense.c:201
pcover irredundant()
Cube * p
Definition exorList.c:222
#define ELIMINATED(IDX)
Definition flags.h:27
#define all_literals(LIT)
Definition internal.h:274
#define all_clauses(C)
Definition internal.h:279
void kissat_sort_literals(struct kissat *, unsigned size, unsigned *lits)
Definition sort.c:85
#define all_literals_in_clause(LIT, C)
Definition clause.h:47
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define LOGCLS(...)
Definition logging.h:415
#define LOGLIT(...)
Definition logging.hpp:99
unsigned short ref
Definition giaNewBdd.h:38
clause * kissat_probing_propagate(kissat *solver, clause *ignore, bool flush)
Definition proprobe.c:37
clause * kissat_search_propagate(kissat *solver)
Definition propsearch.c:46
ABC_NAMESPACE_HEADER_START typedef unsigned reference
Definition reference.h:9
int lit
Definition satVec.h:130
#define IDX(LIT)
Definition literal.h:28
Definition flags.h:11
unsigned lits[2]
Definition watch.h:65
Definition watch.h:41
watch_type type
Definition watch.h:42
binary_watch binary
Definition watch.h:43
char * memset()
signed char mark
Definition value.h:8
void kissat_release_vectors(kissat *solver)
Definition vector.c:284
void kissat_watch_large_clauses(kissat *solver)
Definition watch.c:145
void kissat_flush_large_watches(kissat *solver)
Definition watch.c:112
void kissat_flush_large_connected(kissat *solver)
Definition watch.c:206
#define BEGIN_WATCHES(WS)
Definition watch.h:115
#define PUSH_WATCHES(W, E)
Definition watch.h:106
#define END_WATCHES(WS)
Definition watch.h:118
#define SET_END_OF_WATCHES(WS, P)
Definition watch.h:128
vector watches
Definition watch.h:49