11static void reimport_literal (
kissat *
solver,
unsigned eidx,
13 import *import = &PEEK_STACK (solver->import, eidx);
16 LOG (
"reimporting external variable %u as internal literal %u (was %u)",
23#if !defined(KISSAT_QUIET) || !defined(KISSAT_NDEBUG)
24 const unsigned active =
solver->active;
26 const unsigned inactive =
solver->vars - active;
28 "compacting garbage collection "
29 "(%u inactive variables %.2f%%)",
30 inactive, kissat_percent (inactive,
solver->vars));
43 const unsigned ilit =
LIT (iidx);
49 mlit = mfixed =
LIT (vars);
50 LOG2 (
"first fixed %u mapped to %u assigned to %d", ilit, mfixed,
53 mfixed =
NOT (mfixed);
54 LOG2 (
"all other fixed mapped to %u", mfixed);
56 }
else if (
value < 0) {
58 LOG2 (
"negatively fixed %u mapped to %u", ilit, mlit);
61 LOG2 (
"positively fixed %u mapped to %u", ilit, mlit);
66 LOG2 (
"remapping %u to %u", ilit, mlit);
71 const unsigned eidx =
ABS (elit);
72 import *import = &PEEK_STACK (solver->import, eidx);
75 import->imported =
false;
76 LOG2 (
"external variable %d not imported anymore", eidx);
79 LOG2 (
"skipping inactive %u", ilit);
87 const unsigned eidx =
ABS (elit);
90 reimport_literal (
solver, eidx, mlit);
93 LOG (
"compacting to %u variables %.2f%% from %u", vars,
99static void compact_literal (
kissat *
solver,
unsigned dst_lit,
103 const unsigned dst_idx =
IDX (dst_lit);
104 const unsigned src_idx =
IDX (src_lit);
106 LOG (
"mapping old internal literal %u to %u", src_lit, dst_lit);
110 solver->phases.best[dst_idx] =
solver->phases.best[src_idx];
111 solver->phases.saved[dst_idx] =
solver->phases.saved[src_idx];
112 solver->phases.target[dst_idx] =
solver->phases.target[src_idx];
114 const unsigned not_src_lit =
NOT (src_lit);
115 const unsigned not_dst_lit =
NOT (dst_lit);
117 solver->values[not_dst_lit] =
solver->values[not_src_lit];
120static unsigned map_idx (
kissat *
solver,
unsigned iidx) {
125 const unsigned eidx =
ABS (elit);
127 import *import = &PEEK_STACK (solver->import, eidx);
131 const unsigned mlit =
import->lit;
132 const unsigned midx =
IDX (mlit);
138 LOG (
"compacting queue");
143 const unsigned midx = map_idx (
solver, idx);
147 l->stamp = ++
solver->queue.stamp;
148 if (idx ==
solver->queue.search.idx) {
149 solver->queue.search.idx = midx;
150 solver->queue.search.stamp = l->stamp;
154 solver->queue.last = prev;
157 const unsigned midx = map_idx (
solver, idx);
164static void compact_stack (
kissat *
solver, unsigneds *stack) {
166 const unsigned *
const end =
END_STACK (*stack);
167 for (
const unsigned *
p = q;
p != end;
p++) {
168 const unsigned idx = *
p;
169 const unsigned midx = map_idx (
solver, idx);
180 LOG (
"compacting scores");
183 memset (&new_scores, 0,
sizeof new_scores);
187 LOG (
"copying scores of tainted old scores heap");
189 const unsigned midx = map_idx (
solver, idx);
192 const double score = kissat_get_heap_score (old_scores, idx);
193 kissat_update_heap (
solver, &new_scores, midx, score);
196 LOG (
"no need to copy scores of old untainted scores heap");
198 LOG (
"now pushing mapped literals onto new heap");
200 const unsigned midx = map_idx (
solver, idx);
203 kissat_push_heap (
solver, &new_scores, midx);
207 *old_scores = new_scores;
211 LOG (
"compacting trail");
213 for (
size_t i = 0; i <
size; i++) {
215 const unsigned mlit = kissat_map_literal (
solver, ilit,
true);
218 const unsigned idx =
IDX (ilit);
222 const unsigned other = a->
reason;
224 const unsigned mother = kissat_map_literal (
solver, other,
true);
231 LOG (
"compacting frames");
233 for (
size_t level = 1; level <
size; level++) {
236 const unsigned mlit = kissat_map_literal (
solver, ilit,
true);
242static void compact_export (
kissat *
solver,
unsigned vars) {
243 LOG (
"compacting export");
247 for (
unsigned iidx = 0; iidx <
size; iidx++) {
251 const unsigned midx = map_idx (
solver, iidx);
260 for (
unsigned iidx = 0; iidx < vars; iidx++) {
263 const unsigned eidx =
ABS (elit);
264 const import *const import = &PEEK_STACK (solver->import, eidx);
268 unsigned mlit =
import->lit;
271 const unsigned ilit =
LIT (iidx);
277static void compact_units (
kissat *
solver,
unsigned mfixed) {
278 LOG (
"compacting units (first fixed %u)", mfixed);
281 const unsigned eidx =
ABS (elit);
282 const unsigned mlit = elit < 0 ?
NOT (mfixed) : mfixed;
283 const import *const import = &PEEK_STACK (solver->import, eidx);
286 const unsigned ilit =
import->lit;
288 reimport_literal (
solver, eidx, mlit);
292static void compact_best_and_target_values (
kissat *
solver,
unsigned vars) {
297 unsigned best_assigned = 0;
298 unsigned target_assigned = 0;
300 for (
unsigned idx = 0; idx < vars; idx++) {
301 if (!
flags[idx].active)
309 if (
solver->target_assigned != target_assigned) {
310 LOG (
"compacting target assigned from %u to %u",
311 solver->target_assigned, target_assigned);
312 solver->target_assigned = target_assigned;
315 if (
solver->best_assigned != best_assigned) {
316 LOG (
"compacting best assigned from %u to %u",
solver->best_assigned,
318 solver->best_assigned = best_assigned;
324 LOG (
"finalizing compacting");
329 if (vars ==
solver->vars) {
331 solver->compacting =
false;
332 LOG (
"number of variables does not change");
337 unsigned reduced =
solver->vars - vars;
338 LOG (
"compacted number of variables from %u to %u",
solver->vars, vars);
352 const unsigned ilit =
LIT (iidx);
353 const unsigned mlit = kissat_map_literal (
solver, ilit,
true);
355 compact_literal (
solver, mlit, ilit);
359 compact_units (
solver, mfixed);
370 compact_export (
solver, vars);
371 compact_best_and_target_values (
solver, vars);
375 solver->compacting =
false;
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define RESIZE_STACK(S, NEW_SIZE)
#define POKE_STACK(S, N, E)
#define all_stack(T, E, S)
#define SET_END_OF_STACK(S, P)
ABC_NAMESPACE_IMPL_START typedef signed char value
unsigned kissat_compact_literals(kissat *solver, unsigned *mfixed_ptr)
void kissat_finalize_compacting(kissat *solver, unsigned vars, unsigned mfixed)
ABC_NAMESPACE_IMPL_START void kissat_release_heap(kissat *solver, heap *heap)
void kissat_resize_heap(kissat *solver, heap *heap, unsigned new_size)
#define all_variables(IDX)
#define KISSAT_assert(ignore)
#define kissat_phase(...)
#define DISCONNECTED(IDX)
void kissat_decrease_size(kissat *solver)
#define VALID_INTERNAL_LITERAL(LIT)
#define VALID_EXTERNAL_LITERAL(LIT)