1. 分析函数所涉及seen[v]使用
传播实例:求解过程演示_10.48.640112774.cn中的一段输出 1 decisions: 25; decision var: -2 2 the size of trail is 28. : 1 -6 -27 -2 -22 -23 -20 -13 -10 -28 25 29 14 7 -3 18 -4 16 17 -9
|
|
上述传播遇到冲突之后进行冲突分析代码如下: 1 void Solver::analyze(CRef confl, vec<Lit>& out_learnt, int& out_btlevel, int& out_lbd) 2 { 3 int pathC = 0; 4 Lit p = lit_Undef; 5 6 // Generate conflict clause: 7 out_learnt.push(); // (leave room for the asserting literal) 8 int index = trail.size() - 1; 9 int nDecisionLevel = level(var(ca[confl][0])); 10 assert(nDecisionLevel == level(var(ca[confl][0]))); 11 12 do{ 13 assert(confl != CRef_Undef); // (otherwise should be UIP) 14 Clause& c = ca[confl]; 15 16 // For binary clauses, we don't rearrange literals in propagate(), 17 // so check and make sure the first is an implied lit. 18 if (p != lit_Undef && c.size() == 2 && value(c[0]) == l_False){ 19 assert(value(c[1]) == l_True); 20 Lit tmp = c[0]; 21 c[0] = c[1], c[1] = tmp; } 22 23 for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){ 24 Lit q = c[j]; 25 26 if (!seen[var(q)] && level(var(q)) > 0){ 27 if (VSIDS){ 28 varBumpActivity(var(q), .5); 29 add_tmp.push(q); //收集参与冲突的文字 30 }else 31 conflicted[var(q)]++; 32 seen[var(q)] = 1; 33 if (level(var(q)) >= nDecisionLevel){ 34 pathC++; 35 }else 36 out_learnt.push(q); 37 } 38 } 39 40 // Select next clause to look at: 41 do { 42 while (!seen[var(trail[index--])]); 43 p = trail[index+1]; 44 } while (level(var(p)) < nDecisionLevel); 45 46 confl = reason(var(p)); 47 seen[var(p)] = 0; 48 pathC--; 49 50 }while (pathC > 0); 51 out_learnt[0] = ~p; 52 53 54 out_learnt.copyTo(analyze_toclear); 55 56 // Simplify conflict clause: 57 58 // Try further minimization? 59 60 // Recompute LBD if minimized. 61 62 // Find correct backtrack level: 63 64 for (int j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; 65 // ('seen[]' is now cleared) 66 }
|
|
演示学习子句生成过程如下,注意seen[v]可见性。
|
|
2. 冲突支配路径长度计算中所涉及seen[v]使用
// pathCs[k] is the number of variables assigned at level k, // it is initialized to 0 at the begining and reset to 0 after the function execution bool Solver::collectFirstUIP(CRef confl){ involved_lits.clear(); int max_level=1; Clause& c = ca[confl]; 代码运行完毕,seen[v]回复到不可见。 |
|