最早使用cmt的minisat改进版求解器2——vsids-master-1\minisat-performance

位置:

E:\CNKI E-Study\localestudy\Literature\SAT求解器学习_6B1FE1DF69904FE2AEC3542DCF408574\VSIDS paper\VISDS-solvers\vsids-master-1\vsids-master-1\minisat-performance\core

代码分析



Solver.h

  1 //============================================
  2 // Solver -- the main class:
  3
  4 class Solver {
  5 public:
  ...
 23
 24     bool      save_decision_trail;   // Whether to save decision trail
 25     bool      save_learned_clauses;   // Whether to save learned clauses
 26     bool      conflicting_vars_analysis;
 ...
 53     void    writeDecisionVar(Var next);
 54     void    writeLearnedClause(vec<Lit>& out_learnt);
 55     void    updateConflictAnalysis(Var v);
 56     void    updateConflictAnalysis(vec<Lit>& c);
 57
 58     // Track solver behavior
 59     FILE* decision_trail_file;
 60     FILE* learned_clauses_file;
 ...120
121     //XXX EXPERIMENT
122     std::vector<int> conflicting_vars_count;
123     std::vector< std::vector<double> > conflicting_vars_graph;
...
255 };

 1 inline void Solver::writeDecisionVar(Var next) {
 2     if (save_decision_trail) {
 3         assert((next != var_Undef) && (next>=0) && (next<=nVars()));
 4         // +1 is necessary because MiniSAT stores variables naming from 0 not 1
 5         //fprintf(decision_trail_file, "%d ", next+1);
 6         fprintf(decision_trail_file, "%d\n", next);
 7     }
 8 }
 9
10 inline void Solver::writeLearnedClause(vec<Lit>& out_learnt) {
11     if (save_learned_clauses) {
12         for(int i = 0; i < out_learnt.size(); i++)
13             fprintf(learned_clauses_file, "%d ", var(out_learnt[i]));
14         fprintf(learned_clauses_file, "\n");
15     }
16 }
17
18 inline void Solver::updateConflictAnalysis(Var v) {
19     if (conflicting_vars_analysis) {
20         // +1 at end is necessary because MiniSAT stores variables naming from 0 not 1
21         conflicting_vars_count[v] += 1;
22     }
23 }
24
25 inline void Solver::updateConflictAnalysis(vec<Lit>& c) {
26     if (conflicting_vars_analysis) {
27         int l,h;
28         //printf("asdf\n");
29         // +1 at end is necessary because MiniSAT stores variables naming from 0 not 1
30         for(int i = 0; i < c.size()-1; i++)
31             for(int j = i + 1; j < c.size(); j++){
32                 if(var(c[i]) < var(c[j])){
33                     l = var(c[i]);
34                     h = var(c[j]);
35                 }
36                 else{
37                     l = var(c[j]);
38                     h = var(c[i]);
39                 }
40                 //printf("%d %d\n",l,h);
41                 //XXX probably should change increment to correlate with clause size
42                 conflicting_vars_graph[l][h-l-1] += 1;
43             }
44
45     }
46 }


Solver.h中新增用于观察性能的代码段

Solver.cc


 1 lbool Solver::search(int nof_conflicts)
 2 {
 3     assert(ok);
 4     int         backtrack_level;
 5     int         conflictC = 0;
 6     vec<Lit>    learnt_clause;
 7     starts++;
 8
 9     for (;;){
10         CRef confl = propagate();
11         if (confl != CRef_Undef){
12             // CONFLICT
13             conflicts++; conflictC++;
14             if (decisionLevel() == 0) return l_False;
15
16             learnt_clause.clear();
17             analyze(confl, learnt_clause, backtrack_level);
18             cancelUntil(backtrack_level);
19
20             if (learnt_clause.size() == 1){
21                 uncheckedEnqueue(learnt_clause[0]);
22             }else{
23                 CRef cr = ca.alloc(learnt_clause, true);
24                 learnts.push(cr);
25                 attachClause(cr);
26                 claBumpActivity(ca[cr]);
27                 uncheckedEnqueue(learnt_clause[0], cr);
28             }
29
30             varDecayActivity();
31             claDecayActivity();
32
33             if (--learntsize_adjust_cnt == 0){
34                 learntsize_adjust_confl *= learntsize_adjust_inc;
35                 learntsize_adjust_cnt    = (int)learntsize_adjust_confl;
36                 max_learnts             *= learntsize_inc;
37
38                 if (verbosity >= 1)
39                     printf("| %9d | %7d %8d %8d | %8d %8d %6.0f | %6.3f %% |\n",
40                            (int)conflicts,
41                            (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]), nClauses(), (int)clauses_literals,
42                            (int)max_learnts, nLearnts(), (double)learnts_literals/nLearnts(), progressEstimate()*100);
43             }
44
45         }else{
46             // NO CONFLICT
47             if (nof_conflicts >= 0 && conflictC >= nof_conflicts || !withinBudget()){
48                 // Reached bound on number of conflicts:
49                 progress_estimate = progressEstimate();
50                 cancelUntil(0);
51                 return l_Undef; }
52
53             // Simplify the set of problem clauses:
54             if (decisionLevel() == 0 && !simplify())
55                 return l_False;
56
57             if (learnts.size()-nAssigns() >= max_learnts)
58                 // Reduce the set of learnt clauses:
59                 reduceDB();
60
61             Lit next = lit_Undef;
62             while (decisionLevel() < assumptions.size()){
63                 // Perform user provided assumption:
64                 Lit p = assumptions[decisionLevel()];
65                 if (value(p) == l_True){
66                     // Dummy decision level:
67                     newDecisionLevel();
68                 }else if (value(p) == l_False){
69                     analyzeFinal(~p, conflict);
70                     return l_False;
71                 }else{
72                     next = p;
73                     break;
74                 }
75             }
76
77             if (next == lit_Undef){
78                 // New variable decision:
79                 decisions++;
80                 next = pickBranchLit();
81
82
83                 if (next == lit_Undef)
84                     // Model found:
85                     return l_True;
86                 else
87                     writeDecisionVar(var(next));
88             }
89
90             // Increase decision level and enqueue ‘next‘
91             newDecisionLevel();
92             uncheckedEnqueue(next);
93         }
94     }
95 }

lbool Solver::search(int nof_conflicts)

函数writeDecisionVar(var(next))调用

 void Solver::analyze(CRef confl, vec& out_learnt, int& out_btlevel)

发生以下函数调用:

updateConflictAnalysis(var(out_learnt[i]));  updateConflictAnalysis(out_learnt);  writeLearnedClause(out_learnt);

1 Solver::~Solver()
2 {
3     if(save_decision_trail)
4         fclose(decision_trail_file);
5 }

备注:    bool   save_decision_trail;   // Whether to save decision trail

原文地址:https://www.cnblogs.com/yuweng1689/p/12695078.html

时间: 2024-08-01 11:22:55

最早使用cmt的minisat改进版求解器2——vsids-master-1\minisat-performance的相关文章

最早使用cmt的minisat改进版求解器3——vsids-master-1\countbridgemvsids

位置: E:\CNKI E-Study\localestudy\Literature\SAT求解器学习_6B1FE1DF69904FE2AEC3542DCF408574\VSIDS paper\VISDS-solvers\vsids-master-1\vsids-master-1\countbridgemvsids\core 代码解读 Solver.h 1 class Solver { ...100 101 // Statistics: (read-only member variable) 1

SAT求解器快速入门

从事组合优化或信息安全方向的研究人员,基于SMT研究,需要快速学习SAT求解器的基本原理和方法.以下是快速入门的几点体会: 1.理清需要——是完备求解器还是不完备求解器 完备求解器 能给出SAT.UNSAT.unknow三种确定的答案,尤其是UNSAT结论能给出证明推导过程,指出导致矛盾的关键路径.   不完备求解器能给出SAT.unknow两种结论.SAT结论给出一组可满足解即完成求解任务.可能会存在其他一组或多组可满足解.如果问题本身不知一组解,那么不同的求解器得出的可满足解可能不同. 2.

F-Chart.Engineering.Equation.Solver.Pro.v9.478-3D工程方程求解器

F-Chart.Engineering.Equation.Solver.Pro.v9.478-3D工程方程求解器 FunctionBay.RecurDyn.V8R4.SP1.1.Win64 Engineering Equation Solver的一 个主要特征是其高精确度的热力学和传输性质的数据库,提供了数百物质的方式来增强求解能力. Engineering Equation Solver是一款通用的方程求解程序,它可以数值化求解数千连接的非线性代数 和微分方程.该程序还可以用来解决微分和积分方

Maxwell顺态求解器电磁力分析

文源:技术邻 问题描述:求解一段通有正弦交流电的直导线在某一稳态磁场中的受力情况,并简单验证仿真结果. 模型介绍: 如上几何模型中10mm边长立方体代表永磁体,材料属性为材料库中的NdFe35,修改磁化方向为X方向,其他属性不变,如下图所示.其中黄色圆柱体代表铜导线,红色框线代表求解区域(真空).导线端面与求解域重合,电流不会泄漏以便顺利计算. Maxwell求解树如下: Solution type: Transient瞬态求解器 Boundaries:未指定,系统选取默认求解边界. Excit

在redhat6.4上编译z3求解器

因为项目需要,我们使用到了微软的z3求解器求约束,但是z3求解器在红帽平台上并没有发布编译好的二进制版本,而我们的运行环境是红帽的企业版6.4,因此需要自己编译相应的二进制. z3是由微软公司开发的一个优秀的SMT求解器(也就定理证明器),它能够检查逻辑表达式的可满足性.目前的最新版本是4.4.1,github主页. 从z3主页上面下载最新的代码 git clone [email protected]:Z3Prover/z3.git 切换工作目录到z3下执行 python ./scripts/m

编程之美之数独求解器的C++实现方法

编程之美的第一章的第15节,讲的是构造数独,一开始拿到这个问题的确没有思路, 不过看了书中的介绍之后, 发现原来这个的求解思路和N皇后问题是一致的, 但是不知道为啥,反正一开始确实没有想到这个回溯法,知道是用回溯法求解之后,问题就变得容易了很多. 这里我们不打算实现数独的构造,相反的,我们实现一个数独求解器,以后妈妈再也不用担心我的数独了. 当然求解器的思路和构造数独的思路一样,都是回溯法搜索,这里不再过多说明. 程序运行说明: 1.把待求解的数独数据放到in.txt文件中, 程序会自动读取他,

Altair.Acusolve.v12.0.311.HotFix.Win32_64.&amp;.Linux64 3CD计算流体动力学(CFD)求解器

Altair.Acusolve.v12.0.311.HotFix.Win32_64.&.Linux64 3CD计算流体动力学(CFD)求解器 Altair AcuSolve是一款领先的基于有限元的通用计算流体动力学(CFD)求解器,可以解决非常复杂的工业和科研问题.AcuSolve的稳健性 和扩展性求解技术在全非结构网格基础上仍能保持无与伦比的求解精度.无论是稳态的RANS仿真应用还是复杂瞬态的多物理场仿真, AcuSolve都能容易求解并保证良好的精度.领先的技术 精确的结果    AcuSo

人工智能包括约束求解器吗?

以下是翻译Optaplanner创始人Geoffrey De Smet的一篇文章<Does A.I. include constraint solvers?>. 因为英语及中文表达习惯的差异,以该博文发表示Optaplanner官网,其描述的问题及概念具有一定的上下文关联性:因此,为了认还不太熟悉Optaplanner的同学更容易理解,令文章更符合中文母语读者的阅读习惯,我并没有完全按字面生硬直译.其中添加了一些扩展性的意译,基本上能在脱离Optaplanner官网上下文情况下,一定程序上表达

QuantLib 金融计算——数学工具之求解器

目录 QuantLib 金融计算--数学工具之求解器 概述 调用方式 非 Newton 算法(不需要导数) Newton 算法(需要导数) 如果未做特别说明,文中的程序都是 Python3 代码. QuantLib 金融计算--数学工具之求解器 载入模块 import QuantLib as ql import scipy from scipy.stats import norm print(ql.__version__) 1.12 概述 QuantLib 提供了多种类型的一维求解器,用以求解单