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

保存位置:E:\CNKI E-Study\localestudy\Literature\SAT求解器学习_6B1FE1DF69904FE2AEC3542DCF408574\VSIDS paper\VISDS-solvers\vsids-master-1\vsids-master-1\spatial_mvsids\core

来源:

文章—— https://link.springer.com/chapter/10.1007/978-3-319-26287-1_14

代码—— https://github.com/ezulkosk/vsids

 

代码解读


Solver.h

 1 class Solver{
 2     ...
 3     //XXX EXPERIMENT
 4     FILE* decision_trail_file;
 5     int                 prev_cmty; // -1 init
 6     vec<int>            cmtys;
 7     FMap<int>           frequencies_map;
 8     int                 cmty_switches;
 9     int                 iters_in_cmty;
10     int                 max_iters_in_cmty;
11     void    writeDecisionVar(Var next);// Write decision variable to file
12         
13     // Statistics: (read-only member variable)
14     uint64_t learnt_clause_vars, bridge_learnt_clause_vars;
1 inline void     Solver::writeDecisionVar(Var next) {
2     assert((next != var_Undef) && (next>=0) && (next<=nVars()));
3     // +1 is necessary because MiniSAT stores variables naming from 0 not 1
4     //fprintf(decision_trail_file, "%d ", next+1);
5     fprintf(decision_trail_file, "%d ", next);
6 }
 Solver.h中增加的有关数据成员与成员函数

Solver.cpp

 1 Solver::Solver() :
 2     //EXPERIMENT
 3     , cmty_switches(0), prev_cmty(-1), iters_in_cmty(0), max_iters_in_cmty(0)
 4 
11     , learnt_clause_vars (0)
12     , bridge_learnt_clause_vars(0)
13     ...
14 {}
15 
16 
17 Solver::~Solver()
18 {
19     fclose(decision_trail_file);
20 }
 1 lbool Solver::solve_()
 2 {
 3     /*
 4     if (!opt_cmty_file)
 5         fprintf(stderr, "missing community file\n"), exit(1);
 6     FILE* cmty_file = fopen(opt_cmty_file, "r");
 7     if (cmty_file == NULL)
 8         fprintf(stderr, "could not open file %s\n", (const char*) opt_cmty_file), exit(1);
 9 
10     int v;
11     int cmty;
12     cmtys.growTo(nVars());
13 
14     while (fscanf(cmty_file, "%d %d\n", &v, &cmty) == 2) {
15         cmtys[v] = cmty;
16     }
17 
18     int nCmtys = 0;
19     for (int i = 0; i < cmtys.size(); i++) {
20         if (nCmtys < cmtys[i]) nCmtys = cmtys[i];
21     }
22 
23     printf("Cmtys   : %d\n", nCmtys);
24     printf("Variables : %d\n", nVars());
25 
26     fclose(cmty_file);
27     */
28 ...
29 }
  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++;
                ...
 45 
 46         }else{
 47             // NO CONFLICT
 48             if (nof_conflicts >= 0 && conflictC >= nof_conflicts || !withinBudget()){
 49                 // Reached bound on number of conflicts:
 50                 progress_estimate = progressEstimate();
 51                 cancelUntil(0);
 52                 return l_Undef; }
 53 
 54             // Simplify the set of problem clauses:
 55             if (decisionLevel() == 0 && !simplify())
 56                 return l_False;
 57 
 58             if (learnts.size()-nAssigns() >= max_learnts)
 59                 // Reduce the set of learnt clauses:
 60                 reduceDB();
 61 
 62             Lit next = lit_Undef;
 63             while (decisionLevel() < assumptions.size()){
 64                 // Perform user provided assumption:
 65                 Lit p = assumptions[decisionLevel()];
 66                 if (value(p) == l_True){
 67                     // Dummy decision level:
 68                     newDecisionLevel();
 69                 }else if (value(p) == l_False){
 70                     analyzeFinal(~p, conflict);
 71                     return l_False;
 72                 }else{
 73                     next = p;
 74                     break;
 75                 }
 76             }
 77 
 78             if (next == lit_Undef){
 79                 // New variable decision:
 80                 decisions++;
 81                 next = pickBranchLit();
 82 
 83                 if (next == lit_Undef)
 84                     // Model found:
 85                     return l_True;
 86 
 87 
 88                 //XXX Experiment
 89 
 90                 //spatial locality - count + iters_in_cmty
 91                 iters_in_cmty++;
 92                 int temp;
 93 
 94                 writeDecisionVar(var(next));
 95                 //
 96                 if (cmtys[var(next)] != prev_cmty){
 97            
 98                     if(frequencies_map.has(iters_in_cmty, temp) == 0)
 99                         frequencies_map.insert(iters_in_cmty,1);
100                     else
101                         frequencies_map[iters_in_cmty] = frequencies_map[iters_in_cmty]+1;
102                     //printf("%d\n", frequencies_map.has(iters_in_cmty, temp));
103                     if(iters_in_cmty > max_iters_in_cmty)
104                         max_iters_in_cmty = iters_in_cmty;
105 
106                     printf("%d %d\n", prev_cmty, cmtys[var(next)]);
107                     prev_cmty = cmtys[var(next)];
108                     cmty_switches++;
109                     iters_in_cmty=0;
110                 }
111                 
112                 // vec
113                 if (cmtys[var(next)] != prev_cmty){
114                     if(spatial_frequencies.size() <= iters_in_cmty){
115                         spatial_frequencies.growTo(iters_in_cmty+1, 0);
116                         max_iters_in_cmty = iters_in_cmty;
117                     }
118                     spatial_frequencies[iters_in_cmty] = spatial_frequencies[iters_in_cmty]+1;
119                     prev_cmty = cmtys[var(next)];
120                     cmty_switches++;
121                     iters_in_cmty=0;
122                 }
123                 //
124 
125                 //TODO temporal locality
126 
127                 //TODO Exploit Backdoors - Count + Integral + Integral over time
128 
129                 //TODO Exploit Critical Variables - Count + Integral + Integral over time
130 
131                 //TODO outside SAT, Backdoors vs Critical Variables
132 
133             }
134 
135             // Increase decision level and enqueue 'next'
136             newDecisionLevel();
137             uncheckedEnqueue(next);
138         }
139     }
140 }
以上三处是Solver.cpp中有关cmt相关代码

猜你喜欢

转载自www.cnblogs.com/yuweng1689/p/12694454.html
今日推荐