包含以下数据成员的列传:

 

1. solver->clause

2. flags

3.frames

4.kitten

5.limit

 

 


 

1.

 

数据成员solver->clause

是一个文字序列,以一个工作栈的方式管理一部分文字;

主要包括在以下文件中:

internal.h

internal.c

 

主要的操作包括:

 

1.  RELEASE_STACK (solver->clause);

 

EMPTY_STACK (solver->clause),

2.

for (all_stack (unsigned, lit, solver->clause))
MARK (lit) = MARK (NOT (lit)) = 0;

 

CLEAR_STACK (solver->clause);

 

solver->clause_satisfied = false;
solver->clause_trivial = false;
solver->clause_shrink = false;

 

3.

assert (SIZE_STACK (solver->clause) < UINT_MAX);
PUSH_STACK (solver->clause, ilit);

 

----------  D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\deduce.c [60] PUSH_STACK (solver->clause, lit); [80] PUSH_STACK (solver->clause, INVALID_LIT); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\eliminate.c [250] PUSH_STACK (solver->clause, other); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\internal.c [294] PUSH_STACK (solver->clause, ilit); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\substitute.c [456] PUSH_STACK (solver->clause, repr_lit); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\sweep.c [904] PUSH_STACK (solver->clause, repr); [924] PUSH_STACK (solver->clause, other); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\vivify.c [73] PUSH_STACK (solver->clause, lit); [486] PUSH_STACK (solver->clause, implied); [530] PUSH_STACK (solver->clause, not_lit); [802] PUSH_STACK (solver->clause, first); [803] PUSH_STACK (solver->clause, second);

 

 

//clause.c

4.

reference kissat_new_original_clause (kissat *solver) {
const unsigned size = SIZE_STACK (solver->clause);
unsigned *lits = BEGIN_STACK (solver->clause);
kissat_sort_literals (solver, size, lits);
reference res = new_clause (solver, true, false, 0, size, lits);
return res;
}

reference kissat_new_irredundant_clause (kissat *solver) {
const unsigned size = SIZE_STACK (solver->clause);
unsigned *lits = BEGIN_STACK (solver->clause);
return new_clause (solver, false, false, 0, size, lits);
}

reference kissat_new_redundant_clause (kissat *solver, unsigned glue) {
const unsigned size = SIZE_STACK (solver->clause);
unsigned *lits = BEGIN_STACK (solver->clause);
return new_clause (solver, false, true, glue, size, lits);
}

 

//analyze.c

5.

(1)

for (all_stack (unsigned, lit, solver->clause))

  assert (all_assigned[IDX (lit)].analyzed);

(2)

for (all_stack (unsigned, lit, solver->clause)) {
  analyze_reason_side_literal (solver, limit, arena, all_assigned, lit);
  if (SIZE_STACK (solver->analyzed) > limit)
    break;
}

 

 

 

   

 

 

2.flags

 
//flags.c

static inline void activate_literal (kissat *solver, unsigned lit) {
  const unsigned idx = IDX (lit);
  flags *f = FLAGS (idx);
  if (f->active)
    return;
  lit = STRIP (lit);
  LOG ("activating %s", LOGVAR (idx));
  f->active = true;
  assert (!f->fixed);
  assert (!f->eliminated);
  solver->active++;
  INC (variables_activated);
  kissat_enqueue (solver, idx);
  const double score = 1.0 - 1.0 / solver->statistics.variables_activated;
  kissat_update_heap (solver, &solver->scores, idx, score);
  if (solver->stable) {
    const unsigned lit = LIT (idx);
    if (!VALUE (lit))
      kissat_push_heap (solver, &solver->scores, idx);
  }
  assert (solver->unassigned < UINT_MAX);
  solver->unassigned++;
  kissat_mark_removed_literal (solver, lit);
  kissat_mark_added_literal (solver, lit);
  assert (!VALUE (lit));
  assert (!VALUE (NOT (lit)));
  assert (!SAVED (idx));
  assert (!TARGET (idx));
  assert (!BEST (idx));
}

 

//flag.c

void
kissat_activate_literal (kissat *solver, unsigned lit) { activate_literal (solver, lit); } void kissat_activate_literals (kissat *solver, unsigned size, unsigned *lits) { for (unsigned i = 0; i < size; i++) activate_literal (solver, lits[i]); }

 

----------  D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\flags.c [50] void kissat_activate_literal (kissat *solver, unsigned lit) { ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\flags.h [29] void kissat_activate_literal (struct kissat *, unsigned); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\import.c [98] kissat_activate_literal (solver, res); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\internal.c [171] kissat_activate_literal (solver, LIT (idx));

 

 

 

 

 

 

//inlinequeue.h

static inline void kissat_enqueue (kissat *solver, unsigned idx) {
  assert (idx < solver->vars);
  links *links = solver->links, *l = links + idx;
  l->prev = l->next = DISCONNECT;
  kissat_enqueue_links (solver, idx, links, &solver->queue);
  LOG ("enqueued %s stamped %u", LOGVAR (idx), l->stamp);
  if (!VALUE (LIT (idx)))
    kissat_update_queue (solver, links, idx);
  kissat_check_queue (solver);
}

 

 

   
 
//inline.h


static inline void kissat_mark_removed_literal (kissat *solver,
                                                unsigned lit) {
  const unsigned idx = IDX (lit);
  flags *flags = FLAGS (idx);
  if (flags->fixed)
    return;
  if (!flags->eliminate) {
    LOG ("marking %s to be eliminated", LOGVAR (idx));
    flags->eliminate = true;
    INC (variables_eliminate);
  }
}

static inline void kissat_mark_added_literal (kissat *solver,
                                              unsigned lit) {
  const unsigned idx = IDX (lit);
  flags *flags = FLAGS (idx);
  if (!flags->subsume) {
    LOG ("marking %s to forward subsume", LOGVAR (idx));
    flags->subsume = true;
    INC (variables_subsume);
  }
  const unsigned bit = 1u << NEGATED (lit);
  if (!(flags->factor & bit)) {
    flags->factor |= bit;
    LOG ("marking literal %s to factor", LOGLIT (lit));
    INC (literals_factor);
  }
}

 

 
//kissat_mark_removed_literal 出现的地方  

----------  D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\clause.c [181] kissat_mark_removed_literal (solver, a); [182] kissat_mark_removed_literal (solver, b); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\clause.c.bak [181] kissat_mark_removed_literal (solver, a); [182] kissat_mark_removed_literal (solver, b); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\flags.c [27] kissat_mark_removed_literal (solver, lit); [108] kissat_mark_removed_literal (solver, lits[i]); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\forward.c [408] kissat_mark_removed_literal (solver, remove); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\inline.h [39] static inline void kissat_mark_removed_literal (kissat *solver, ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\strengthen.c [147] kissat_mark_removed_literal (solver, lit); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\vivify.c [733] kissat_mark_removed_literal (solver, lit); [831] kissat_mark_removed_literal (solver, lit);

 

 

 

   

3. frames与层有关系的属性

 

//promote.h

//从这段函数代码可以了解frames属性的应用

 1 static inline unsigned kissat_recompute_glue (kissat *solver, clause *c,
 2                                               unsigned limit) {
 3   assert (limit);
 4   assert (EMPTY_STACK (solver->promote));  //空的工作栈供临时使用
 5   unsigned res = 0;
 6   for (all_literals_in_clause (lit, c)) {
 7     assert (VALUE (lit));
 8     const unsigned level = LEVEL (lit);  //由文字lit得知所在层
 9     frame *frame = &FRAME (level);       //所在层对应frame
10     if (frame->promote)                  //frame的属性被使用
11       continue;
12     if (++res == limit)
13       break;
14     frame->promote = true;
15     PUSH_STACK (solver->promote, level);  //记录被使用过的层
16   }
17   for (all_stack (unsigned, level, solver->promote)) {
18     frame *frame = &FRAME (level);
19     assert (frame->promote);
20     frame->promote = false;     //恢复frame对应层属性
21   }
22   CLEAR_STACK (solver->promote);  //临时使用完毕后,清理。
23   return res;
24 }

 

 

 //decide.c

 1 void kissat_decide (kissat *solver) {
 2   START (decide);
 3   assert (solver->unassigned);
 4   if (solver->warming)
 5     INC (warming_decisions);
 6   else {
 7     INC (decisions);
 8     if (solver->stable)
 9       INC (stable_decisions);
10     else
11       INC (focused_decisions);
12   }
13   solver->level++;
14   assert (solver->level != INVALID_LEVEL);
15   const unsigned idx = kissat_next_decision_variable (solver);
16   const value value = kissat_decide_phase (solver, idx);
17   unsigned lit = LIT (idx);
18   if (value < 0)
19     lit = NOT (lit);
20   kissat_push_frame (solver, lit);
21   assert (solver->level < SIZE_STACK (solver->frames));
22   LOG ("decide literal %s", LOGLIT (lit));
23   kissat_assign_decision (solver, lit);
24   STOP (decide);
25 }
26 
27 void kissat_internal_assume (kissat *solver, unsigned lit) {
28   assert (solver->unassigned);
29   assert (!VALUE (lit));
30   solver->level++;
31   assert (solver->level != INVALID_LEVEL);
32   kissat_push_frame (solver, lit);
33   assert (solver->level < SIZE_STACK (solver->frames));
34   LOG ("assuming literal %s", LOGLIT (lit));
35   kissat_assign_decision (solver, lit);
36 }

 

 

//inlineframe.h

 1 #ifndef _inlineframes_h_INCLUDEDd
 2 #define _inlineframes_h_INCLUDEDd
 3 
 4 #include "allocate.h"
 5 #include "internal.h"
 6 
 7 static inline void kissat_push_frame (kissat *solver, unsigned decision) {
 8   assert (!solver->level || decision != UINT_MAX);
 9   const size_t trail = SIZE_ARRAY (solver->trail);
10   frame frame;
11   frame.decision = decision;
12   frame.promote = false;
13   frame.trail = trail;
14   frame.used = 0;
15   PUSH_STACK (solver->frames, frame);
16 }
17 
18 #endif

 

 

 //internal.c

 1 kissat *kissat_init (void) {
 2   kissat *solver = kissat_calloc (0, 1, sizeof *solver);
 3 #ifndef NOPTIONS
 4   kissat_init_options (&solver->options);
 5 #else
 6   kissat_init_options ();
 7 #endif
 8 #ifndef QUIET
 9   kissat_init_profiles (&solver->profiles);
10 #endif
11   START (total);
12   kissat_init_queue (solver);
13   assert (INTERNAL_MAX_LIT < UINT_MAX);
14   kissat_push_frame (solver, UINT_MAX);
15   solver->watching = true;
16   solver->conflict.size = 2;
17   solver->scinc = 1.0;
18   solver->first_reducible = INVALID_REF;
19   solver->last_irredundant = INVALID_REF;
20   kissat_reset_last_learned (solver);
21 #ifndef NDEBUG
22   kissat_init_checker (solver);
23 #endif 
24 
25   return solver;
26 }

 

 

重点:

(1)每一层frame中包含对应本层的信息:

  决策文字,决策文字所在trail位置,以及标识属性:bool promote; unsigned used;unsigned saved;

(2)回溯到new_level时,trail回溯到new_level的尾部文字之后;所以frames回溯到new_level+1层,以便获取这个指示位置。

详见:

//backtrack.c

1
void kissat_backtrack_without_updating_phases (kissat *solver, 2 unsigned new_level) { 3 assert (solver->level >= new_level); 4 if (solver->level == new_level) 5 return; 6 7 LOG ("backtracking to decision level %u", new_level); 8 9 frame *new_frame = &FRAME (new_level + 1); 10 SET_END_OF_STACK (solver->frames, new_frame); 11 12 value *values = solver->values; 13 unsigned *trail = BEGIN_ARRAY (solver->trail); 14 unsigned *new_end = trail + new_frame->trail; 15 assigned *assigned = solver->assigned; 16 17 unsigned *old_end = END_ARRAY (solver->trail); 18 unsigned unassigned = 0, reassigned = 0; 19 20 unsigned *q = new_end; 21 if (solver->stable) { 22 heap *scores = SCORES; 23 for (const unsigned *p = q; p != old_end; p++) { 24 const unsigned lit = *p; 25 const unsigned idx = IDX (lit); 26 assert (idx < VARS); 27 struct assigned *a = assigned + idx; 28 const unsigned level = a->level; 29 if (level <= new_level) { 30 const unsigned new_trail = q - trail; 31 assert (new_trail <= a->trail); 32 a->trail = new_trail; 33 *q++ = lit; 34 LOG ("reassign %s", LOGLIT (lit)); 35 reassigned++; 36 } else { 37 unassign (solver, values, lit); 38 add_unassigned_variable_back_to_heap (solver, scores, lit); 39 unassigned++; 40 } 41 } 42 } else { 43 links *links = solver->links; 44 for (const unsigned *p = q; p != old_end; p++) { 45 const unsigned lit = *p; 46 const unsigned idx = IDX (lit); 47 assert (idx < VARS); 48 struct assigned *a = assigned + idx; 49 const unsigned level = a->level; 50 if (level <= new_level) { 51 const unsigned new_trail = q - trail; 52 assert (new_trail <= a->trail); 53 a->trail = new_trail; 54 *q++ = lit; 55 LOG ("reassign %s", LOGLIT (lit)); 56 reassigned++; 57 } else { 58 unassign (solver, values, lit); 59 add_unassigned_variable_back_to_queue (solver, links, lit); 60 unassigned++; 61 } 62 } 63 } 64 SET_END_OF_ARRAY (solver->trail, q); 65 66 solver->level = new_level; 67 LOG ("unassigned %u literals", unassigned); 68 LOG ("reassigned %u literals", reassigned); 69 (void) unassigned, (void) reassigned; 70 71 assert (new_end <= END_ARRAY (solver->trail)); 72 LOG ("propagation will resume at trail position %zu", 73 (size_t) (new_end - trail)); 74 solver->propagate = new_end; 75 76 assert (!solver->extended); 77 }

 

   

 

 

4.kitten

 

//出现kitten的地方

----------  D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\definition.c [5] #include "kitten.h" [95] struct kitten *kitten = solver->kitten; [96] assert (kitten); [97] kitten_clear (kitten); [104] kitten_track_antecedents (kitten); [114] kitten_clause_with_id_and_exception (kitten, exported, 1, &other, [119] kitten_clause_with_id_and_exception (kitten, exported, c->size, [133] kitten_set_ticks_limit (kitten, limit); [134] int status = kitten_solve (kitten); [138] unsigned reduced = kitten_compute_clausal_core (kitten, &learned); [142] kitten_shrink_to_clausal_core (kitten); [143] kitten_shuffle_clauses (kitten); [144] kitten_set_ticks_limit (kitten, 10 * limit); [145] int tmp = kitten_solve (kitten); [154] reduced = kitten_compute_clausal_core (kitten, &learned); [163] kitten_traverse_core_ids (kitten, &extractor, traverse_definition_core); [214] kitten_traverse_core_clauses (kitten, &extractor, ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\eliminate.c [9] #include "kitten.h" [565] static void init_map_and_kitten (kissat *solver) { [568] assert (!solver->kitten); [569] solver->kitten = kitten_embedded (solver); [572] static void reset_map_and_kitten (kissat *solver) { [573] if (solver->kitten) { [574] kitten_release (solver->kitten); [575] solver->kitten = 0; [586] init_map_and_kitten (solver); [590] reset_map_and_kitten (solver);
---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\internal.h [74] struct kitten; [208] struct kitten *kitten;
---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\kitten.c
---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\kitten.h [1] #ifndef _kitten_h_INCLUDED [2] #define _kitten_h_INCLUDED [8] typedef struct kitten kitten; [10] kitten *kitten_init (void); [11] void kitten_clear (kitten *); [12] void kitten_release (kitten *); [14] void kitten_track_antecedents (kitten *); [16] void kitten_shuffle_clauses (kitten *); [17] void kitten_flip_phases (kitten *); [18] void kitten_randomize_phases (kitten *); [20] void kitten_assume (kitten *, unsigned lit); [22] void kitten_clause (kitten *, size_t size, unsigned *); [23] void kitten_unit (kitten *, unsigned); [24] void kitten_binary (kitten *, unsigned, unsigned); [26] void kitten_clause_with_id_and_exception (kitten *, unsigned id, [30] void kitten_no_ticks_limit (kitten *); [31] void kitten_set_ticks_limit (kitten *, uint64_t); [33] int kitten_solve (kitten *); [34] int kitten_status (kitten *); [36] signed char kitten_value (kitten *, unsigned); [37] signed char kitten_fixed (kitten *, unsigned); [38] bool kitten_failed (kitten *, unsigned); [39] bool kitten_flip_literal (kitten *, unsigned); [41] unsigned kitten_compute_clausal_core (kitten *, uint64_t *learned); [42] void kitten_shrink_to_clausal_core (kitten *); [44] void kitten_traverse_core_ids (kitten *, void *state, [47] void kitten_traverse_core_clauses (kitten *, void *state, [52] kitten *kitten_embedded (struct kissat *);

---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\options.h [37] OPTION (definitionticks, 1e6, 0, INT_MAX, "kitten ticks limits") \
---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\statistics.c [117] RELATIVE (NAME, kitten_propagations) [120] RELATIVE (NAME, kitten_solved) [234] PERCENT (NAME, kitten_flip) [237] PERCENT (NAME, kitten_solved)
---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\statistics.h [141] STATISTIC (kitten_conflicts, 1, PER_KITTEN_SOLVED, 0, "per solved") \ [142] STATISTIC (kitten_decisions, 1, PER_KITTEN_SOLVED, 0, "per solved") \ [143] STATISTIC (kitten_flip, 1, NO_SECONDARY, 0, 0) \ [144] STATISTIC (kitten_flipped, 1, PCNT_KITTEN_FLIP, "%", "flip") \ [145] COUNTER (kitten_propagations, 2, PER_KITTEN_SOLVED, 0, "per solved") \ [146] STATISTIC (kitten_sat, 1, PCNT_KITTEN_SOLVED, "%", "solved") \ [147] COUNTER (kitten_solved, 2, NO_SECONDARY, 0, 0) \ [148] COUNTER (kitten_ticks, 2, PER_KITTEN_PROP, 0, "per prop") \ [149] STATISTIC (kitten_unknown, 1, PCNT_KITTEN_SOLVED, "%", "solved") \ [150] STATISTIC (kitten_unsat, 1, PCNT_KITTEN_SOLVED, "%", "solved") \ [217] COUNTER (sweep_solved, 2, PCNT_KITTEN_SOLVED, "%", "kitten_solved") \ ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\sweep.c [4] #include "kitten.h" [42] kitten *kitten = solver->kitten; [43] kitten_randomize_phases (kitten); [45] int res = kitten_solve (kitten); [53] static void set_kitten_ticks_limit (sweeper *sweeper) { [56] if (solver->statistics.kitten_ticks < sweeper->limit.ticks) [57] remaining = sweeper->limit.ticks - solver->statistics.kitten_ticks; [58] LOG ("'kitten_ticks' remaining %" PRIu64, remaining); [59] kitten_set_ticks_limit (solver->kitten, remaining);
//。。。。。。。

---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\terminate.h [62] #define kitten_terminated_1 21 [63] #define kitten_terminated_2 22

 

   

5. limit

 

//各种判别界限的更新

----------  D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\decide.c [82] UPDATE_CONFLICT_LIMIT (randec, random_sequences, LOGN, false); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\eliminate.c [600] UPDATE_CONFLICT_LIMIT (eliminate, eliminations, NLOG2N, true); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\kimits.h [112] #define UPDATE_CONFLICT_LIMIT(NAME, COUNT, SCALE_COUNT_FUNCTION, \ ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\probe.c [85] UPDATE_CONFLICT_LIMIT (probe, probings, NLOGN, true); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\reduce.c [193] UPDATE_CONFLICT_LIMIT (reduce, reductions, SQRT, false); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\reorder.c [214] UPDATE_CONFLICT_LIMIT (reorder, reordered, LINEAR, false); ---------- D:\SAT_study2024\06outforImplieGraph\outInforToNetworkx_kissat2024
\kissat-sc2024-d776b9e1_restar_out_graph\src\rephase.c [119] UPDATE_CONFLICT_LIMIT (rephase, rephased, NLOG3N, false);

 

 

 //学习子句管理界限的触发判定与更新在 文件reduce.c中:

//触发

bool kissat_reducing (kissat *solver) {
  if (!GET_OPTION (reduce))
    return false;
  if (!solver->statistics.clauses_redundant)
    return false;
  if (CONFLICTS < solver->limits.reduce.conflicts)
    return false;
  return true;
}

 

 

//更新

 1 int kissat_reduce (kissat *solver) {
 2   START (reduce);
 3   INC (reductions);
 4   kissat_phase (solver, "reduce", GET (reductions),
 5                 "reduce limit %" PRIu64 " hit after %" PRIu64 " conflicts",
 6                 solver->limits.reduce.conflicts, CONFLICTS);
 7   kissat_compute_and_set_tier_limits (solver);
 8   bool compact = kissat_compacting (solver);
 9   reference start = compact ? 0 : solver->first_reducible;
10   if (start != INVALID_REF) {
11 #ifndef QUIET
12     size_t arena_size = SIZE_STACK (solver->arena);
13     size_t words_to_sweep = arena_size - start;
14     size_t bytes_to_sweep = sizeof (word) * words_to_sweep;
15     kissat_phase (solver, "reduce", GET (reductions),
16                   "reducing clauses after offset %" REFERENCE_FORMAT
17                   " in arena",
18                   start);
19     kissat_phase (solver, "reduce", GET (reductions),
20                   "reducing %zu words %s %.0f%%", words_to_sweep,
21                   FORMAT_BYTES (bytes_to_sweep),
22                   kissat_percent (words_to_sweep, arena_size));
23 #endif
24     if (kissat_flush_and_mark_reason_clauses (solver, start)) {
25       reducibles reds;
26       INIT_STACK (reds);
27       if (collect_reducibles (solver, &reds, start)) {
28         sort_reducibles (solver, &reds);
29         mark_less_useful_clauses_as_garbage (solver, &reds);
30         RELEASE_STACK (reds);
31         kissat_sparse_collect (solver, compact, start);
32       } else if (compact)
33         kissat_sparse_collect (solver, compact, start);
34       else
35         kissat_unmark_reason_clauses (solver, start);
36     } else
37       assert (solver->inconsistent);
38   } else
39     kissat_phase (solver, "reduce", GET (reductions), "nothing to reduce");
40   kissat_classify (solver);
41   UPDATE_CONFLICT_LIMIT (reduce, reductions, SQRT, false);
42   solver->last.conflicts.reduce = CONFLICTS;
43   REPORT (0, '-');
44   STOP (reduce);
45   return solver->inconsistent ? 20 : 0;
46 }

 

 

 

 //相关结构体定义与C语言宏操作设定新的增长区间。

//kimits.h

#ifndef _limits_h_INCLUDED
#define _limits_h_INCLUDED

#include <stdbool.h>
#include <stdint.h>

typedef struct bounds bounds;
typedef struct changes changes;
typedef struct delays delays;
typedef struct delay delay;
typedef struct remember remember;
typedef struct enabled enabled;
typedef struct limited limited;
typedef struct limits limits;

struct bounds {
  struct {
    uint64_t max_bound_completed;
    unsigned additional_clauses;
  } eliminate;
};

struct limits {
  uint64_t conflicts;
  uint64_t decisions;
  uint64_t reports;

  struct {
    uint64_t count;
    uint64_t ticks;
    uint64_t conflicts;
  } mode;

  struct {
    struct {
      uint64_t eliminate;
      uint64_t subsume;
    } variables;
    uint64_t conflicts;
  } eliminate;

  struct {
    uint64_t marked;
  } factor;

  struct {
    uint64_t conflicts;
  } probe, randec, reduce, reorder, rephase, restart;

  struct {
    uint64_t conflicts;
    uint64_t interval;
  } glue;
};

struct limited {
  bool conflicts;
  bool decisions;
};

struct enabled {
  bool eliminate;
  bool focus;
  bool mode;
  bool probe;
};

struct delay {
  unsigned count;
  unsigned current;
};

struct delays {
  delay bumpreasons;
  delay congruence;
  delay sweep;
  delay vivifyirr;
};

struct remember {
  struct {
    uint64_t eliminate;
    uint64_t probe;
  } ticks;
  struct {
    uint64_t reduce;
  } conflicts;
};

struct kissat;

changes kissat_changes (struct kissat *);

bool kissat_changed (changes before, changes after);

void kissat_init_limits (struct kissat *);

uint64_t kissat_scale_delta (struct kissat *, const char *, uint64_t);

double kissat_nlogpown (uint64_t, unsigned);
double kissat_sqrt (uint64_t);
double kissat_logn (uint64_t);

#define LOGN(COUNT) kissat_logn (COUNT)
#define LINEAR(COUNT) (COUNT)
#define NLOGN(COUNT) kissat_nlogpown (COUNT, 1)
#define NLOG2N(COUNT) kissat_nlogpown (COUNT, 2)
#define NLOG3N(COUNT) kissat_nlogpown (COUNT, 3)

#define SQRT(COUNT) kissat_sqrt (COUNT)

#define UPDATE_CONFLICT_LIMIT(NAME, COUNT, SCALE_COUNT_FUNCTION, \
                              SCALE_DELTA) \
  do { \
    if (solver->inconsistent) \
      break; \
    const struct statistics *statistics = &solver->statistics; \
    assert (statistics->COUNT > 0); \
    struct limits *limits = &solver->limits; \
    uint64_t DELTA = GET_OPTION (NAME##int); \
    const double SCALING = SCALE_COUNT_FUNCTION (statistics->COUNT); \
    assert (SCALING >= 1); \
    DELTA *= SCALING; \
    const uint64_t SCALED = \
        !(SCALE_DELTA) ? DELTA \
                       : kissat_scale_delta (solver, #NAME, DELTA); \
    limits->NAME.conflicts = CONFLICTS + SCALED; \
    kissat_phase ( \
        solver, #NAME, GET (COUNT), "new limit of %s after %s conflicts", \
        FORMAT_COUNT (limits->NAME.conflicts), FORMAT_COUNT (SCALED)); \
  } while (0)

#include <inttypes.h>

#define SET_EFFORT_LIMIT(LIMIT, NAME, START) \
  uint64_t LIMIT; \
  do { \
    const uint64_t OLD_LIMIT = solver->statistics.START; \
    const uint64_t TICKS = solver->statistics.search_ticks; \
    const uint64_t LAST = solver->probing ? solver->last.ticks.probe \
                                          : solver->last.ticks.eliminate; \
    uint64_t REFERENCE = TICKS - LAST; \
    const uint64_t MINEFFORT = 1e6 * GET_OPTION (mineffort); \
    if (REFERENCE < MINEFFORT) { \
      REFERENCE = MINEFFORT; \
      kissat_extremely_verbose ( \
          solver, #NAME " effort reference %s set to 'mineffort'", \
          FORMAT_COUNT (REFERENCE)); \
    } else { \
      kissat_extremely_verbose ( \
          solver, #NAME " effort reference %s = %s - %s 'search_ticks'", \
          FORMAT_COUNT (REFERENCE), FORMAT_COUNT (TICKS), \
          FORMAT_COUNT (LAST)); \
    } \
    const double EFFORT = (double) GET_OPTION (NAME##effort) * 1e-3; \
    const uint64_t DELTA = EFFORT * REFERENCE; \
\
    kissat_extremely_verbose ( \
        solver, #NAME " effort delta %s = %g * %s '" #START "'", \
        FORMAT_COUNT (DELTA), EFFORT, FORMAT_COUNT (REFERENCE)); \
\
    const uint64_t NEW_LIMIT = OLD_LIMIT + DELTA; \
    kissat_very_verbose (solver, \
                         #NAME " effort limit %s = %s + %s '" #START "'", \
                         FORMAT_COUNT (NEW_LIMIT), \
                         FORMAT_COUNT (OLD_LIMIT), FORMAT_COUNT (DELTA)); \
\
    LIMIT = NEW_LIMIT; \
\
  } while (0)

struct kissat;

bool kissat_delaying (struct kissat *, delay *);
void kissat_bump_delay (struct kissat *, delay *);
void kissat_reduce_delay (struct kissat *, delay *);

#define DELAYING(NAME) kissat_delaying (solver, &solver->delays.NAME)

#define BUMP_DELAY(NAME) kissat_bump_delay (solver, &solver->delays.NAME)

#define REDUCE_DELAY(NAME) \
  kissat_reduce_delay (solver, &solver->delays.NAME)

#endif
kimits.h

 

//kimits.c

#include "internal.h"
#include "logging.h"
#include "mode.h"
#include "print.h"
#include "reduce.h"
#include "rephase.h"
#include "resources.h"
#include "restart.h"

#include <inttypes.h>
#include <math.h>

double kissat_logn (uint64_t count) {
  assert (count > 0);
  const double res = log10 (count + 9);
  assert (res >= 1);
  return res;
}

double kissat_sqrt (uint64_t count) {
  assert (count > 0);
  const double res = sqrt (count);
  assert (res >= 1);
  return res;
}

double kissat_nlogpown (uint64_t count, unsigned exponent) {
  assert (count > 0);
  const double tmp = log10 (count + 9);
  double factor = 1;
  while (exponent--)
    factor *= tmp;
  assert (factor >= 1);
  const double res = count * factor;
  assert (res >= 1);
  return res;
}

uint64_t kissat_scale_delta (kissat *solver, const char *pretty,
                             uint64_t delta) {
  const uint64_t C = BINIRR_CLAUSES;
  double f = kissat_logn (C + 1) - 5;
  const double ff = f * f;
  assert (ff >= 0);
  const double fff = 4.5 * ff + 25;
  uint64_t scaled = fff * delta;
  assert (delta <= scaled);
  // clang-format off
  kissat_very_verbose (solver,
    "scaled %s delta %" PRIu64
    " = %g * %" PRIu64
    " = (4.5 (log10(%" PRIu64 ") - 5)^2 + 25) * %" PRIu64,
    pretty, scaled, fff, delta, C, delta);
  // clang-format on
  (void) pretty;
  return scaled;
}

static void init_enabled (kissat *solver) {
  bool probe;
  if (!GET_OPTION (simplify))
    probe = false;
  else if (!GET_OPTION (probe))
    probe = false;
  else if (GET_OPTION (substitute))
    probe = true;
  else if (GET_OPTION (sweep))
    probe = true;
  else if (GET_OPTION (vivify))
    probe = true;
  else
    probe = false;
  kissat_very_verbose (solver, "probing %sabled", probe ? "en" : "dis");
  solver->enabled.probe = probe;

  bool eliminate;
  if (!GET_OPTION (simplify))
    eliminate = false;
  else if (!GET_OPTION (eliminate))
    eliminate = false;
  else
    eliminate = true;
  kissat_very_verbose (solver, "eliminate %sabled",
                       eliminate ? "en" : "dis");
  solver->enabled.eliminate = eliminate;
}

#define INIT_CONFLICT_LIMIT(NAME, SCALE) \
  do { \
    const uint64_t DELTA = GET_OPTION (NAME##init); \
    const uint64_t SCALED = \
        !(SCALE) ? DELTA : kissat_scale_delta (solver, #NAME, DELTA); \
    limits->NAME.conflicts = CONFLICTS + SCALED; \
    kissat_very_verbose (solver, \
                         "initial " #NAME " limit of %s conflicts", \
                         FORMAT_COUNT (limits->NAME.conflicts)); \
  } while (0)

void kissat_init_limits (kissat *solver) {
  assert (solver->statistics.searches == 1);

  init_enabled (solver);

  limits *limits = &solver->limits;

  if (GET_OPTION (randec))
    INIT_CONFLICT_LIMIT (randec, false);

  if (GET_OPTION (reduce))
    INIT_CONFLICT_LIMIT (reduce, false);

  if (GET_OPTION (reorder))
    INIT_CONFLICT_LIMIT (reorder, false);

  if (GET_OPTION (rephase))
    INIT_CONFLICT_LIMIT (rephase, false);

  if (!solver->stable)
    kissat_update_focused_restart_limit (solver);

  kissat_init_mode_limit (solver);

  if (solver->enabled.eliminate) {
    INIT_CONFLICT_LIMIT (eliminate, true);
    solver->bounds.eliminate.max_bound_completed = 0;
    solver->bounds.eliminate.additional_clauses = 0;
    kissat_very_verbose (solver, "reset elimination bound to zero");
  }

  if (solver->enabled.probe)
    INIT_CONFLICT_LIMIT (probe, true);
}

#ifndef QUIET

static const char *delay_description (kissat *solver, delay *delay) {
  delays *delays = &solver->delays;
  if (delay == &delays->bumpreasons)
    return "bumping reason side literals";
  else if (delay == &delays->congruence)
    return "congruence closure";
  else if (delay == &delays->sweep)
    return "sweeping";
  else {
    assert (delay == &delays->vivifyirr);
    return "vivifying irredundant clauses";
  }
}

#endif

#define VERY_VERBOSE_IF_NOT_BUMPREASONS(...) \
  VERY_VERBOSE_OR_LOG (delay == &solver->delays.bumpreasons, __VA_ARGS__)

void kissat_reduce_delay (kissat *solver, delay *delay) {
  if (!delay->current)
    return;
  delay->current /= 2;
  VERY_VERBOSE_IF_NOT_BUMPREASONS (
      solver, "%s delay interval decreased to %u",
      delay_description (solver, delay), delay->current);
  delay->count = delay->current;
#ifdef QUIET
  (void) solver;
#endif
}

void kissat_bump_delay (kissat *solver, delay *delay) {
  delay->current += delay->current < UINT_MAX;
  VERY_VERBOSE_IF_NOT_BUMPREASONS (
      solver, "%s delay interval increased to %u",
      delay_description (solver, delay), delay->current);
  delay->count = delay->current;
#ifdef QUIET
  (void) solver;
#endif
}

bool kissat_delaying (kissat *solver, delay *delay) {
  if (delay->count) {
    delay->count--;
    VERY_VERBOSE_IF_NOT_BUMPREASONS (
        solver, "%s still delayed (%u more times)",
        delay_description (solver, delay), delay->current);
    return true;
  } else {
    VERY_VERBOSE_IF_NOT_BUMPREASONS (solver, "%s not delayed",
                                     delay_description (solver, delay));
    return false;
  }
#ifdef QUIET
  (void) solver;
#endif
}
kimits.c

 

 

 //决策方式的转换限定

//decide.c

 1 void kissat_start_random_sequence (kissat *solver) {
 2   if (!GET_OPTION (randec))
 3     return;
 4 
 5   if (solver->stable && !GET_OPTION (randecstable))
 6     return;
 7 
 8   if (!solver->stable && !GET_OPTION (randecfocused))
 9     return;
10 
11   if (solver->randec)
12     kissat_very_verbose (solver,
13                          "continuing random decision sequence "
14                          "at %s conflicts",
15                          FORMAT_COUNT (CONFLICTS));
16   else {
17     INC (random_sequences);
18     const uint64_t count = solver->statistics.random_sequences;
19     const unsigned length = GET_OPTION (randeclength) * LOGN (count);
20     kissat_very_verbose (solver,
21                          "starting random decision sequence "
22                          "at %s conflicts for %s conflicts",
23                          FORMAT_COUNT (CONFLICTS), FORMAT_COUNT (length));
24     solver->randec = length;
25 
26     UPDATE_CONFLICT_LIMIT (randec, random_sequences, LOGN, false);
27   }
28 }

 

 

 // 相位转换界限

 // rephase.c

 1 static char reset_phases (kissat *solver) {
 2   const uint64_t count = GET (rephased);
 3   assert (count > 0);
 4   const uint64_t select = (count - 1) % (uint64_t) size_rephase_schedule;
 5   const char type = rephase_schedule[select](solver);
 6   kissat_phase (
 7       solver, "rephase", GET (rephased), "%s phases in %s search mode",
 8       rephase_type_as_string (type), solver->stable ? "stable" : "focused");
 9   LOG ("copying saved phases as target phases");
10   memcpy (solver->phases.target, solver->phases.saved, VARS);
11   UPDATE_CONFLICT_LIMIT (rephase, rephased, NLOG3N, false);
12   kissat_reset_target_assigned (solver);
13   if (type == 'B')
14     kissat_reset_best_assigned (solver);
15   return type;
16 }

 

 

// reorder.c

 1 void kissat_reorder (kissat *solver) {
 2   START (reorder);
 3   INC (reordered);
 4   assert (!solver->level);
 5   kissat_phase (solver, "reorder", GET (reordered),
 6                 "reorder limit %" PRIu64 " hit a after %" PRIu64
 7                 " conflicts in %s mode ",
 8                 solver->limits.reorder.conflicts, CONFLICTS,
 9                 solver->stable ? "stable" : "focused");
10   if (solver->stable)
11     reorder_stable (solver);
12   else
13     reorder_focused (solver);
14   kissat_phase (solver, "reorder", GET (reordered),
15                 "reordered decisions in %s search mode",
16                 solver->stable ? "stable" : "focused");
17   UPDATE_CONFLICT_LIMIT (reorder, reordered, LINEAR, false);
18   REPORT (0, 'o');
19   STOP (reorder);
20 }

 

 

//probe.c 

 1 int kissat_probe (kissat *solver) {
 2   assert (!solver->inconsistent);
 3   INC (probings);
 4   assert (!solver->probing);
 5   solver->probing = true;
 6   const unsigned max_rounds = GET_OPTION (proberounds);
 7   for (unsigned round = 0; round != max_rounds; round++) {
 8     unsigned before = solver->active;
 9     probe (solver);
10     if (solver->inconsistent)
11       break;
12     if (before == solver->active)
13       break;
14   }
15   kissat_classify (solver);
16   UPDATE_CONFLICT_LIMIT (probe, probings, NLOGN, true);
17   solver->last.ticks.probe = solver->statistics.search_ticks;
18   assert (solver->probing);
19   solver->probing = false;
20   return solver->inconsistent ? 20 : 0;
21 }

 

 

//变量消除

//eliminate.c

1 int kissat_eliminate (kissat *solver) {
2   assert (!solver->inconsistent);
3   INC (eliminations);
4   eliminate (solver);
5   kissat_classify (solver);
6   UPDATE_CONFLICT_LIMIT (eliminate, eliminations, NLOG2N, true);
7   solver->last.ticks.eliminate = solver->statistics.search_ticks;
8   return solver->inconsistent ? 20 : 0;
9 }

 

static void eliminate (kissat *solver) {
  kissat_backtrack_propagate_and_flush_trail (solver);
  assert (!solver->inconsistent);
  STOP_SEARCH_AND_START_SIMPLIFIER (eliminate);
  kissat_phase (solver, "eliminate", GET (eliminations),
                "elimination limit of %" PRIu64 " conflicts hit",
                solver->limits.eliminate.conflicts);
  init_map_and_kitten (solver);
  kissat_enter_dense_mode (solver, 0);
  eliminate_variables (solver);
  kissat_resume_sparse_mode (solver, true, 0);
  reset_map_and_kitten (solver);
  kissat_check_statistics (solver);
  STOP_SIMPLIFIER_AND_RESUME_SEARCH (eliminate);
}

 

//顺便指出,internal.h定义kissat类型包含以下数据成员:

//internal.h

  bounds bounds;
  classification classification;
  delays delays;
  enabled enabled;
  limited limited;
  limits limits;
  remember last;
  unsigned walked;

 

   
   
   

 

posted on 2024-09-23 17:19  海阔凭鱼跃越  阅读(11)  评论(0编辑  收藏  举报