指针solver对应类型kissat在internal.h中定义

下面从使用的角度来了解solver个主要数据成员

  assign.c中几个函数
 
static inline void
kissat_assign (kissat * solver,
#ifdef INLINE_ASSIGN
           value * values, assigned * assigned,
#endif
           unsigned lit,
           bool binary, bool redundant, unsigned level, unsigned reason)
{
  assert (binary || !redundant);
  const unsigned not_lit = NOT (lit);
#ifndef INLINE_ASSIGN
  value *values = solver->values;
  assigned *assigned = solver->assigned;
#endif
  assert (!values[lit]);
  assert (!values[not_lit]);

  values[lit] = 1;
  values[not_lit] = -1;

  assert (solver->unassigned > 0);
  solver->unassigned--;

  const unsigned idx = IDX (lit);
  struct assigned *a = assigned + idx;

  if (level)
    {
      a->level = level;
      a->binary = binary;
      a->redundant = redundant;
      a->reason = reason;
    }
  else
    {
      a->level = 0;
      a->binary = false;
      a->redundant = false;
      a->reason = UNIT;
    }

  if (!solver->probing)
    {
      const bool negated = NEGATED (lit);  //文字是否为负文字,为真表示是负文字,为假表示为正文字
      const value value = BOOL_TO_VALUE (negated);
      SAVED (idx) = value;  //变元的取值 来自于文字取值为真时对应变元的值
    }

  PUSH_STACK (solver->trail, lit);

  if (!level)
    {
      kissat_mark_fixed_literal (solver, lit);
      assert (solver->unflushed < UINT_MAX);
      solver->unflushed++;
    }

  watches *watches = &WATCHES (not_lit);
  if (!watches->size)
    {
      watch *w = BEGIN_WATCHES (*watches);
      __builtin_prefetch (w, 0, 1);
    }
}

 

#ifdef INLINE_ASSIGN
static inline
#endif
  void
kissat_assign_reference (kissat * solver,
#ifdef INLINE_ASSIGN
             value * values, assigned * assigned,
#endif
             unsigned lit, reference ref, clause * reason)
{
  assert (reason == kissat_dereference_clause (solver, ref)); //确认ref位置对应的子句就是reason
#ifndef INLINE_ASSIGN
  assigned *assigned = solver->assigned;
  value *values = solver->values;
#endif
  const unsigned level =
    kissat_assignment_level (solver, values, assigned, lit, reason);
  assert (ref != DECISION);
  assert (ref != UNIT);
  kissat_assign (solver,
#ifdef INLINE_ASSIGN
         values, assigned,
#endif
         lit, false, false, level, ref);
  LOGREF (ref, "assign %s reason", LOGLIT (lit));
}

 

 

//返回赋值文字所在的层数值
static
inline unsigned kissat_assignment_level (kissat * solver, value * values, assigned * assigned, unsigned lit, clause * reason) { unsigned res = 0; for (all_literals_in_clause (other, reason)) { if (other == lit) continue; assert (values[other] < 0), (void) values; const unsigned other_idx = IDX (other); struct assigned *a = assigned + other_idx; const unsigned level = a->level; if (res < level) res = level; } #ifdef NDEBUG (void) solver; #endif return res; }

//该代码介绍了如何访问一个子句的所有文字,文字所对应的赋值,赋值体的其它属性

 

 

   

 kissat类型的定义

  internal.h
 
struct kissat
{
#ifdef LOGGING
  bool compacting;
#endif
  bool extended;
  bool inconsistent;
  bool iterating;
  bool probing;
#ifndef QUIET
  bool sectioned;
#endif
  bool stable;
  bool watching;
#ifdef COVERAGE
  volatile unsigned terminate;
#else
  volatile bool terminate;
#endif

  unsigned vars;
  unsigned size;
  unsigned active;

  ints export;
  ints units;
  imports import;
  extensions extend;
  unsigneds witness;

  assigned *assigned;
  flags *flags;

  mark *marks;

  value *values;
  phase *phases;

  eliminated eliminated;
  unsigneds etrail;

  links *links;
  queue queue;

  rephased rephased;

  heap scores;
  double scinc;

// CHB 
  heap scores_chb;
  unsigned *conflicted_chb;
  double step_chb;
  double step_dec_chb;
  double step_min_chb;

// MAB
  unsigned heuristic;
  bool mab;
  double mabc;
  double mab_reward[2];
  unsigned mab_select[2];
  unsigned mab_heuristics;
  double mab_decisions;
  unsigned *mab_chosen;
  unsigned mab_chosen_tot;

  heap schedule;

  unsigned level;
  frames frames;

  unsigneds trail;
  unsigned propagated;

  unsigned best_assigned;
  unsigned consistently_assigned;
  unsigned target_assigned;
  unsigned unflushed;
  unsigned unassigned;

  unsigneds delayed;

#if defined(LOGGING) || !defined(NDEBUG)
  unsigneds resolvent_lits;
#endif
  unsigned resolvent_size;
  unsigned antecedent_size;

  unsigned transitive;

  unsigneds analyzed;
  idxranks bump;
  unsigneds levels;
  unsigneds minimize;
  unsigneds poisoned;
  unsigneds promote;
  unsigneds removable;

  clause conflict;

  temporary clause;

  arena arena;
  clueue clueue;
  vectors vectors;
  reference first_reducible;
  reference last_irredundant;
  watches *watches;

  sizes sorter;

  generator random;
  averages averages[2];
  reluctant reluctant;

  bounds bounds;
  delays delays;
  enabled enabled;
  limited limited;
  limits limits;
  waiting waiting;

  statistics statistics;
  mode mode;

  uint64_t ticks;

  format format;

  statches antecedents[2];
  statches gates[2];
  patches xorted[2];
  unsigneds resolvents;
  bool resolve_gate;

#ifndef NMETRICS
  uint64_t *gate_eliminated;
#else
  bool gate_eliminated;
#endif

#if !defined(NDEBUG) || !defined(NPROOFS)
  unsigneds added;
  unsigneds removed;
#endif

#if !defined(NDEBUG) || !defined(NPROOFS) || defined(LOGGING)
  ints original;
  size_t offset_of_last_original_clause;
#endif

#ifndef QUIET
  profiles profiles;
#endif

#ifndef NOPTIONS
  options options;
#endif

#ifndef NDEBUG
  checker *checker;
#endif

#ifndef NPROOFS
  proof *proof;
#endif
};

 

   

 

posted on 2023-05-03 13:20  海阔凭鱼跃越  阅读(88)  评论(0编辑  收藏  举报