定义

// Solver state:
//
bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used!

初始化 , ok                 (true)
   
使用

在以下函数中数据成员ok被使用

 

bool Solver::simplifyLearnt_x(vec<CRef>& learnts_x);

bool Solver::simplifyLearnt_core();

bool Solver::simplifyLearnt_tier2();

bool Solver::simplifyAll()

bool Solver::addClause_(vec<Lit>& ps);

bool Solver::simplify();

lbool Solver::search(int& nof_conflicts){assert(ok);......}

lbool Solver::solve_()
{
    // signal(SIGALRM, SIGALRM_switch);
    // alarm(2500);

    model.clear();
    conflict.clear();
    if (!ok) return l_False;

    solves++;

     ......

}

void Solver::toDimacs(FILE* f, const vec<Lit>& assumps);

 

simplifyAll

化简的

含义:

移除

已满足

的子句

simplifyAll集中使用在每次重启(实际进行了条件限定)之后,见search函数的前部。

主要进行的工作是:和simplify函数只是移除sat子句不同,是真正利用自动推理相关原理进行化简

simplifyAll直接关联的化简函数如下:

——void Solver::simpleAnalyze(CRef confl, vec<Lit>& out_learnt, vec<CRef>& reason_clause, bool True_confl)

——void Solver::simplifyLearnt(Clause& c)

——bool Solver::simplifyLearnt_x(vec<CRef>& learnts_x)

——bool Solver::simplifyLearnt_core()

——bool Solver::simplifyLearnt_tier2()

 

bool Solver::simplifyAll()
{
    ////
    simplified_length_record = original_length_record = 0;

    if (!ok || propagate() != CRef_Undef)
        return ok = false;

    //// cleanLearnts(also can delete these code), here just for analyzing
    //if (local_learnts_dirty) cleanLearnts(learnts_local, LOCAL);
    //if (tier2_learnts_dirty) cleanLearnts(learnts_tier2, TIER2);
    //local_learnts_dirty = tier2_learnts_dirty = false;

    if (!simplifyLearnt_core()) return ok = false;
    if (!simplifyLearnt_tier2()) return ok = false;
    //if (!simplifyLearnt_x(learnts_local)) return ok = false;

    checkGarbage();

    ////
    //  printf("c size_reduce_ratio     : %4.2f%%\n",
    //         original_length_record == 0 ? 0 : 
//(original_length_record - simplified_length_record) * 100 / (double)original_length_record); return true; }

 

 

 赋值改变的操作体现在几个化简函数体中。主要代码段如下:

      return ok = (propagate() == CRef_Undef);//传播没有遇到冲突返回值为CRef_Undef

 

 1 if (c.size() == 1){
 2                     // when unit clause occur, enqueue and propagate
 3                     uncheckedEnqueue(c[0]);
 4                     if (propagate() != CRef_Undef){
 5                         ok = false;
 6                         return false;
 7                     }
 8                     // delete the clause memory in logic
 9                     c.mark(1);
10                     ca.free(cr);
11 //#ifdef BIN_DRUP
12 //                    binDRUP('d', c, drup_file);
13 //#else
14 //                    fprintf(drup_file, "d ");
15 //                    for (int i = 0; i < c.size(); i++)
16 //                        fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1));
17 //                    fprintf(drup_file, "0\n");
18 //#endif
19                 }
20 。。。。。。。
21 }

 

simplify

化简的

含义:

移除

已满足

的子句

【前 提】:传播的0层中已经有若干文字(bool Solver::addClause_(vec<Lit>& ps)增加子句时,

                单文字子句直接进入传播的0层)

 

【simplify化简操作调用】:

      1.在真正的CDCL开始之间已经被调用过,见派生类函数:bool SimpSolver::eliminate_()之中。

      2.化简函数simplify其余的调用都在每次search函数被调用,见lbool Solver::search(int& nof_conflicts)之中。

         在传播没有发现冲突阶段集中了若干操作:

           —— 化简操作

      // Simplify the set of problem clauses:
      if (decisionLevel() == 0 && !simplify())   //首先决策层为0层时,才会进行simplif()的调用
          return l_False;

            ——学习子句管理(删除)

            ——是否“重启”的检查

 

 1 /*________________________________________________________________________________________
 2 |
 3 |  simplify : [void]  ->  [bool]
 4 |  
 5 |  Description:
 6 |    Simplify the clause database according to the current top-level assigment. 
Currently, the only
7 | thing done here is the removal of satisfied clauses, but more things can be put here. 8 |__________________________________________________________________________________________
@
*/ 9 bool Solver::simplify() 10 { 11 assert(decisionLevel() == 0); //首先决策层为0层时,才会进行simplif()的调用 12 13 if (!ok || propagate() != CRef_Undef) 14 return ok = false; 15 16 if (nAssigns() == simpDB_assigns || (simpDB_props > 0)) 17 return true; 18 19 // Remove satisfied clauses: 20 removeSatisfied(learnts_core); // Should clean core first. 21 safeRemoveSatisfied(learnts_tier2, TIER2); 22 safeRemoveSatisfied(learnts_local, LOCAL); 23 if (remove_satisfied) // Can be turned off. 24 removeSatisfied(clauses); 25 checkGarbage(); 26 rebuildOrderHeap(); 27 28 simpDB_assigns = nAssigns(); 29 simpDB_props = clauses_literals + learnts_literals;
// (shouldn't depend on stats really, but it will do for now) 30 31 return true; 32 }

 

   
posted on 2021-05-16 11:36  海阔凭鱼跃越  阅读(205)  评论(0编辑  收藏  举报