32static inline int lit_is_removable(
solver_t* s,
unsigned lit,
unsigned min_level)
34 unsigned top = vec_uint_size(s->
tagged);
37 vec_uint_clear(s->
stack);
38 vec_uint_push_back(s->
stack, lit2var(
lit));
39 while (vec_uint_size(s->
stack)) {
41 unsigned var = vec_uint_pop_back(s->
stack);
42 struct clause *c = clause_fetch(s, var_reason(s, var));
53 for (i = 1; i < c->
size; i++) {
59 if (vec_char_at(s->
seen, var) || var_dlevel(s, var) == 0)
66 if (var_reason(s, var) !=
UNDEF && ((1 << (var_dlevel(s, var) & 31)) & min_level)) {
67 vec_uint_push_back(s->
stack, var);
68 vec_uint_push_back(s->
tagged, var);
69 vec_char_assign(s->
seen, var, 1);
72 vec_char_assign(s->
seen, var, 0);
73 vec_uint_shrink(s->
tagged, top);
88static inline unsigned clause_clac_lbd(
solver_t *s,
unsigned *
lits,
unsigned size)
94 for (i = 0; i <
size; i++) {
95 unsigned level = lit_dlevel(s,
lits[i]);
106 unsigned *
lits = vec_uint_data(clause_lits);
109 unsigned neg_lit = lit_compl(
lits[0]);
126 sz = vec_uint_size(clause_lits) - 1;
127 for (i = 1; i < vec_uint_size(clause_lits) -
counter; i++)
129 stk_swap(
unsigned, lits[i], lits[sz]);
133 vec_uint_shrink(clause_lits, vec_uint_size(clause_lits) -
counter);
140 unsigned *lits = vec_uint_data(clause_lits);
141 unsigned min_level = 0;
142 unsigned clause_size;
144 for (i = 1; i < vec_uint_size(clause_lits); i++) {
145 unsigned level = lit_dlevel(s, lits[i]);
146 min_level |= 1 << (level & 31);
151 vec_uint_push_back(s->
tagged, lit2var(i));
152 for (i = j = 1; i < vec_uint_size(clause_lits); i++)
153 if (lit_reason(s, lits[i]) ==
UNDEF || !lit_is_removable(s, lits[i], min_level))
155 vec_uint_shrink(clause_lits, j);
158 clause_size = vec_uint_size(clause_lits);
159 if (clause_size <= s->opts.clause_max_sz_bin_resol &&
161 clause_bin_resolution(s, clause_lits);
164static inline void clause_realloc(
struct cdb *dest,
struct cdb *src,
unsigned *
cref)
167 struct clause *new_clause;
168 struct clause *old_clause = cdb_handler(src, *cref);
171 *cref = (unsigned) old_clause->
size;
174 new_cref = cdb_append(dest, 3 + old_clause->
f_learnt + old_clause->
size);
175 new_clause = cdb_handler(dest, new_cref);
176 memcpy(new_clause, old_clause, (
size_t)((3 + old_clause->
f_learnt + old_clause->
size) * 4));
178 old_clause->
size = (unsigned) new_cref;
185static inline unsigned solver_decide(
solver_t *s)
187 unsigned next_var =
UNDEF;
194 next_var = heap_remove_min(s->
var_order);
195 if (solver_has_marks(s) && !var_mark(s, next_var))
201static inline void solver_new_decision(
solver_t *s,
unsigned lit)
203 if (solver_has_marks(s) && !var_mark(s, lit2var(
lit)))
215 unsigned *
lits = vec_uint_data(learnt);
216 unsigned max = lit_dlevel(s,
lits[1]);
218 if (vec_uint_size(learnt) == 1)
220 for (i = 2; i < vec_uint_size(learnt); i++) {
221 if (lit_dlevel(s,
lits[i]) > max) {
222 max = lit_dlevel(s,
lits[i]);
229 return lit_dlevel(s,
lits[1]);
254 unsigned *bt_level,
unsigned *
lbd)
257 unsigned *trail = vec_uint_data(s->
trail);
258 unsigned idx = vec_uint_size(s->
trail) - 1;
259 unsigned n_paths = 0;
263 vec_uint_push_back(learnt,
UNDEF);
270 clause = clause_fetch(s, cref);
279 clause_act_bump(s,
clause);
292 if (vec_char_at(s->
seen, var) || var_dlevel(s, var) == 0)
294 vec_char_assign(s->
seen, var, 1);
295 var_act_bump(s, var);
296 if (var_dlevel(s, var) == solver_dlevel(s)) {
298 if (var_reason(s, var) !=
UNDEF && clause_fetch(s, var_reason(s, var))->
f_learnt)
301 vec_uint_push_back(learnt,
lits[j]);
304 while (!vec_char_at(s->
seen, lit2var(trail[idx--])));
307 cref = lit_reason(s,
p);
308 vec_char_assign(s->
seen, lit2var(
p), 0);
310 }
while (n_paths > 0);
312 vec_uint_data(learnt)[0] = lit_compl(
p);
313 clause_minimize(s, learnt);
314 *bt_level = solver_calc_bt_level(s, learnt);
315 *
lbd = clause_clac_lbd(s, vec_uint_data(learnt), vec_uint_size(learnt));
319 if (clause_fetch(s, var_reason(s, var))->
lbd < *
lbd)
320 var_act_bump(s, var);
325 vec_char_assign(s->
seen, var, 0);
326 vec_uint_clear(s->
tagged);
329static inline int solver_rst(
solver_t *s)
331 return b_queue_is_valid(s->
bq_lbd) &&
335static inline int solver_block_rst(
solver_t *s)
338 b_queue_is_valid(s->
bq_lbd) &&
342static inline void solver_handle_conflict(
solver_t *s,
unsigned confl_cref)
349 solver_analyze(s, confl_cref, s->
temp_lits, &bt_level, &
lbd);
356 clause_watch(s, cref);
358 solver_enqueue(s, vec_uint_at(s->
temp_lits, 0), cref);
363static inline void solver_analyze_final(
solver_t *s,
unsigned lit)
371 if (solver_dlevel(s) == 0)
373 vec_char_assign(s->
seen, lit2var(
lit), 1);
374 for (i = vec_uint_size(s->
trail); i --> vec_uint_at(s->
trail_lim, 0);) {
375 unsigned var = lit2var(vec_uint_at(s->
trail, i));
377 if (vec_char_at(s->
seen, var)) {
378 unsigned reason = var_reason(s, var);
380 assert(var_dlevel(s, var) > 0);
390 vec_char_assign(s->
seen, var, 0);
393 vec_char_assign(s->
seen, lit2var(
lit), 0);
397static inline void solver_garbage_collect(
solver_t *s)
406 for (i = 0; i < 2 * vec_char_size(s->
assigns); i++) {
413 for (i = 0; i < vec_uint_size(s->
trail); i++)
414 if (lit_reason(s, vec_uint_at(s->
trail, i)) !=
UNDEF)
417 array = vec_uint_data(s->
learnts);
418 for (i = 0; i < vec_uint_size(s->
learnts); i++)
419 clause_realloc(new_cdb, s->
all_clauses, &(array[i]));
422 for (i = 0; i < vec_uint_size(s->
originals); i++)
423 clause_realloc(new_cdb, s->
all_clauses, &(array[i]));
429static inline void solver_reduce_cdb(
solver_t *s)
432 unsigned n_learnts = vec_uint_size(s->
learnts);
435 struct clause **learnts_cls;
439 learnts_cls[i] = clause_fetch(s, cref);
441 limit = (
unsigned)(n_learnts * s->opts.learnt_ratio);
443 satoko_sort((
void **)learnts_cls, n_learnts,
444 (
int (*)(
const void *,
const void *)) clause_compare);
446 if (learnts_cls[n_learnts / 2]->
lbd <= 3)
447 s->RC2 += s->opts.inc_special_reduce;
448 if (learnts_cls[n_learnts - 1]->
lbd <= 6)
449 s->RC2 += s->opts.inc_special_reduce;
451 vec_uint_clear(s->learnts);
452 for (i = 0; i < n_learnts; i++) {
454 cref = cdb_cref(s->all_clauses, (
unsigned *)
clause);
459 clause_unwatch(s, cref);
460 cdb_remove(s->all_clauses,
clause);
465 vec_uint_push_back(s->learnts, cref);
470 if (s->opts.verbose) {
471 printf(
"reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) \n",
472 vec_uint_size(s->learnts), n_learnts,
473 100.0 * vec_uint_size(s->learnts) / n_learnts);
476 if (cdb_wasted(s->all_clauses) > cdb_size(s->all_clauses) * s->opts.garbage_max_ratio)
477 solver_garbage_collect(s);
494 clause = clause_fetch(s, cref);
503 vec_uint_push_back(s->
learnts, cref);
507 clause_act_bump(s,
clause);
519 if (solver_dlevel(s) <= level)
521 for (i = vec_uint_size(s->
trail); i --> vec_uint_at(s->
trail_lim, level);) {
522 unsigned var = lit2var(vec_uint_at(s->
trail, i));
536 unsigned conf_cref =
UNDEF;
539 unsigned n_propagations = 0;
550 if (solver_has_marks(s) && !var_mark(s, lit2var(i->
blocker)))
559 begin = watch_list_array(ws);
560 end = begin + watch_list_size(ws);
561 for (i = j = begin + ws->
n_bin; i < end;) {
565 if (solver_has_marks(s) && !var_mark(s, lit2var(i->
blocker))) {
578 neg_lit = lit_compl(
p);
579 if (lits[0] == neg_lit)
580 stk_swap(
unsigned, lits[0], lits[1]);
581 assert(lits[1] == neg_lit);
596 watch_list_push(vec_wl_at(s->
watches, lit_compl(lits[1])), w, 0);
612 solver_enqueue(s, lits[0], i->
cref);
619 watch_list_shrink(ws, j - watch_list_array(ws));
632 if (confl_cref !=
UNDEF) {
635 if (solver_dlevel(s) == 0)
639 if (solver_block_rst(s))
641 solver_handle_conflict(s, confl_cref);
647 if (solver_rst(s) || solver_check_limits(s) == 0 || solver_stop(s) ||
660 solver_reduce_cdb(s);
667 while (solver_dlevel(s) < vec_uint_size(s->
assumptions)) {
672 solver_analyze_final(s, lit_compl(
lit));
680 if (next_lit ==
UNDEF) {
682 next_lit = solver_decide(s);
683 if (next_lit ==
UNDEF) {
688 solver_new_decision(s, next_lit);
701 fprintf(stdout,
"[Satoko] Checking for trail(%u) inconsistencies...\n", vec_uint_size(s->
trail));
702 vec_uint_duplicate(trail_dup, s->
trail);
703 vec_uint_sort(trail_dup, 1);
704 array = vec_uint_data(trail_dup);
705 for (i = 1; i < vec_uint_size(trail_dup); i++) {
706 if (array[i - 1] == lit_compl(array[i])) {
707 fprintf(stdout,
"[Satoko] Inconsistent trail: %u %u\n", array[i - 1], array[i]);
712 for (i = 0; i < vec_uint_size(trail_dup); i++) {
713 if (var_value(s, lit2var(array[i])) != lit_polarity(array[i])) {
714 fprintf(stdout,
"[Satoko] Inconsistent trail assignment: %u, %u\n", vec_char_at(s->
assigns, lit2var(array[i])), array[i]);
719 fprintf(stdout,
"[Satoko] Trail OK.\n");
720 vec_uint_print(trail_dup);
721 vec_uint_free(trail_dup);
729 fprintf(stdout,
"[Satoko] Checking clauses (%d)...\n", vec_uint_size(s->
originals));
740 vec_uint_print(s->
trail);
741 fprintf(stdout,
"[Satoko] FOUND UNSAT CLAUSE]: (%d) ", i);
746 fprintf(stdout,
"[Satoko] All SAT - OK\n");
753 fprintf(stdout,
"[Satoko] Checking clauses (%d)... \n", vec_uint_size(s->
originals));
763 fprintf(stdout,
"[Satoko] FOUND UNSAT CLAUSE: (%d) ", i);
768 fprintf(stdout,
"[Satoko] All SAT - OK\n");
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define stk_swap(type, a, b)
#define satoko_alloc(type, n_elements)
struct solver_t_ solver_t
char satoko_var_polarity(satoko_t *, unsigned)
int satoko_simplify(satoko_t *)
void solver_debug_check_clauses(solver_t *s)
void solver_cancel_until(solver_t *s, unsigned level)
unsigned solver_propagate(solver_t *s)
char solver_search(solver_t *s)
unsigned solver_clause_create(solver_t *s, vec_uint_t *lits, unsigned f_learnt)
void solver_debug_check_trail(solver_t *s)
void solver_debug_check(solver_t *s, int result)
for(p=first;p->value< newval;p=p->next)
union clause::@075032140136325172206014200035176200302203305006 data[0]
unsigned clause_min_lbd_bin_resol
unsigned lbd_freeze_clause
vec_uint_t * final_conflict
struct satoko_stats stats
#define vec_uint_foreach(vec, entry, i)
typedefABC_NAMESPACE_HEADER_START struct vec_uint_t_ vec_uint_t
#define vec_uint_foreach_start(vec, entry, i, start)
#define watch_list_foreach_bin(vec, watch, lit)
#define watch_list_foreach(vec, watch, lit)