]> git.unchartedbackwaters.co.uk Git - francis/stp.git/commitdiff
CMS2 now has two types of learnt clause evaluation
authormsoos <msoos@e59a4935-1847-0410-ae03-e826735625c1>
Sun, 18 Apr 2010 15:50:28 +0000 (15:50 +0000)
committermsoos <msoos@e59a4935-1847-0410-ae03-e826735625c1>
Sun, 18 Apr 2010 15:50:28 +0000 (15:50 +0000)
CryptoMiniSat2 now has two types of learnt clause activity measures.
This means that different type of problems can be effectively solved
with the same solver that uses radically different measures of learnt
clause effectiveness. There are some rough edges for the moment: it's
really difficult which type of instance we are dealing with. So, the
'heuristic' that decides is really dumb. You can find it in
RestarTypeChooser.cpp. If you have a more refined heuristic in mind,
please share it with me!

git-svn-id: https://stp-fast-prover.svn.sourceforge.net/svnroot/stp-fast-prover/trunk/stp@688 e59a4935-1847-0410-ae03-e826735625c1

src/sat/cryptominisat2/Clause.h
src/sat/cryptominisat2/FailedVarSearcher.cpp
src/sat/cryptominisat2/RestartTypeChooser.cpp
src/sat/cryptominisat2/Solver.cpp
src/sat/cryptominisat2/Solver.h
src/sat/cryptominisat2/VERSION

index 730b62c424f6f4119edd9913b5dd13cbefb8ba71..043846628c4375a12868cc13277f0ffe42ffe9d7 100644 (file)
@@ -67,6 +67,7 @@ protected:
     uint32_t mySize:20;
     
     union  {int32_t act; uint32_t abst;} extra;
+    float oldActivityInter;
     #ifdef _MSC_VER
     Lit     data[1];
     #else
@@ -88,8 +89,11 @@ public:
         isLearnt = learnt;
         setGroup(_group);
         for (uint i = 0; i < ps.size(); i++) data[i] = ps[i];
-        if (learnt) extra.act = 0;
-        else calcAbstraction();
+        if (learnt) {
+            extra.act = 0;
+            oldActivityInter = 0;
+        } else
+            calcAbstraction();
     }
 
 public:
@@ -118,6 +122,15 @@ public:
     const bool   learnt      ()      const {
         return isLearnt;
     }
+    float&       oldActivity    () {
+        return oldActivityInter;
+    }
+    
+    const float&       oldActivity    () const {
+        return oldActivityInter;
+    }
+    
+    
     const bool getStrenghtened() const {
         return strenghtened;
     }
index f2de3da00f7c9f31c8f43fca109ba0c7a31f266f..171f9c7d202893bbf8b8e91d672356bf0b12d78a 100644 (file)
@@ -142,7 +142,7 @@ const bool FailedVarSearcher::search(uint64_t numProps)
     uint64_t origProps = solver.propagations;
     
     //If failed var searching is going good, do successively more and more of it
-    if (lastTimeFoundTruths > 500 || (double)lastTimeFoundTruths > (double)solver.order_heap.size() * 0.05) std::max(numPropsMultiplier*1.7, 5.0);
+    if (lastTimeFoundTruths > 500 || (double)lastTimeFoundTruths > (double)solver.order_heap.size() * 0.03) std::max(numPropsMultiplier*1.7, 5.0);
     else numPropsMultiplier = 1.0;
     numProps = (uint64_t) ((double)numProps * numPropsMultiplier);
     
@@ -156,6 +156,9 @@ const bool FailedVarSearcher::search(uint64_t numProps)
     propValue.resize(solver.nVars(), 0);
     vector<pair<Var, bool> > bothSame;
     
+    //For calculating how many variables have really been set
+    uint32_t origTrailSize = solver.trail.size();
+    
     //For 2-long xor (rule 6 of  Equivalent literal propagation in the DLL procedure by Chu-Min Li)
     set<TwoLongXor> twoLongXors;
     uint32_t toReplaceBefore = solver.varReplacer->getNewToReplaceVars();
@@ -325,7 +328,7 @@ end:
         }
     }
     
-    lastTimeFoundTruths = goodBothSame + numFailed;
+    lastTimeFoundTruths = solver.trail.size() - origTrailSize;
     
     solver.var_inc = backup_var_inc;
     std::copy(backup_activity.getData(), backup_activity.getDataEnd(), solver.activity.getData());
index 9130a1d2e0de26d52d1e8aa1a74f4db808471cbb..739c4499c799ce4b8b65fe9726cff4fb331533b3 100644 (file)
@@ -56,8 +56,11 @@ void RestartTypeChooser::addInfo()
 
 const RestartType RestartTypeChooser::choose()
 {
-    if (countVarsDegreeStDev().second  < 80 &&
+    pair<double, double> mypair = countVarsDegreeStDev();
+    if ((mypair.second  < 80 && 
         (avg() > (double)limit || ((avg() > (double)(limit*0.9) && stdDeviation(sameIns) < 5))))
+        ||
+        (mypair.second  < 80 && (double)solver.xorclauses.size() > (double)solver.nClauses()*0.1))
         return static_restart;
     else
         return dynamic_restart;
index e98bab43e19756b08d63fbec7d73720fba0bb194..fee91b55618084846b50e075e390316ec8841c28 100644 (file)
@@ -99,6 +99,7 @@ Solver::Solver() :
 
         , ok               (true)
         , var_inc          (128)
+        , cla_inc          (1)
         
         , curRestart       (1)
         , nbclausesbeforereduce (NBCLAUSESBEFOREREDUCE)
@@ -112,6 +113,7 @@ Solver::Solver() :
         , remove_satisfied (true)
         , mtrand((unsigned long int)0)
         , restartType      (static_restart)
+        , lastSelectedRestartType (static_restart)
         #ifdef STATS_NEEDED
         , logger(verbosity)
         , dynamic_behaviour_analysis(false) //do not document the proof as default
@@ -760,7 +762,7 @@ bool subset(const T1& A, const T2& B, vector<bool>& seen)
 |  Effect:
 |    Will undo part of the trail, upto but not beyond the assumption of the current decision level.
 |________________________________________________________________________________________________@*/
-Clause* Solver::analyze(Clause* confl, vec<Lit>& out_learnt, int& out_btlevel, int &nbLevels/*, int &merged*/)
+Clause* Solver::analyze(Clause* confl, vec<Lit>& out_learnt, int& out_btlevel, int &nbLevels, const bool update)
 {
     int pathC = 0;
     Lit p     = lit_Undef;
@@ -777,6 +779,9 @@ Clause* Solver::analyze(Clause* confl, vec<Lit>& out_learnt, int& out_btlevel, i
         Clause& c = *confl;
         if (p != lit_Undef)
             reverse_binary_clause(c);
+        
+        if (update && restartType == static_restart && c.learnt())
+            claBumpActivity(c);
 
         for (uint j = (p == lit_Undef) ? 0 : 1; j != c.size(); j++) {
             const Lit& q = c[j];
@@ -1229,30 +1234,39 @@ FoundWatch:
 |    Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked
 |    clauses are clauses that are reason to some assignment. Binary clauses are never removed.
 |________________________________________________________________________________________________@*/
-struct reduceDB_lt {
-    bool operator () (const Clause* x, const Clause* y) {
-        const uint xsize = x->size();
-        const uint ysize = y->size();
-        
-        // First criteria
-        if (xsize > 2 && ysize == 2) return 1;
-        if (ysize > 2 && xsize == 2) return 0;
-        
-        // Second criteria
-        if (x->activity() > y->activity()) return 1;
-        if (x->activity() < y->activity()) return 0;
-        
-        //return x->oldActivity() < y->oldActivity();
-        return xsize > ysize;
-    }
-};
+bool  reduceDB_ltMiniSat::operator () (const Clause* x, const Clause* y) {
+    const uint xsize = x->size();
+    const uint ysize = y->size();
+    
+    // First criteria
+    if (xsize > 2 && ysize == 2) return 1;
+    if (ysize > 2 && xsize == 2) return 0;
+    
+    return x->oldActivity() < y->oldActivity();
+}
+    
+bool  reduceDB_ltGlucose::operator () (const Clause* x, const Clause* y) {
+    const uint xsize = x->size();
+    const uint ysize = y->size();
+    
+    // First criteria
+    if (xsize > 2 && ysize == 2) return 1;
+    if (ysize > 2 && xsize == 2) return 0;
+    
+    if (x->activity() > y->activity()) return 1;
+    if (x->activity() < y->activity()) return 0;
+    return xsize > ysize;
+}
 
 void Solver::reduceDB()
 {
     uint32_t     i, j;
 
     nbReduceDB++;
-    std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_lt());
+    if (lastSelectedRestartType == dynamic_restart)
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltGlucose());
+    else
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltMiniSat());
     
     #ifdef VERBOSE_DEBUG
     std::cout << "Cleaning clauses" << endl;
@@ -1284,7 +1298,10 @@ const vec<Clause*>& Solver::get_learnts() const
 
 const vec<Clause*>& Solver::get_sorted_learnts()
 {
-    std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_lt());
+    if (lastSelectedRestartType == dynamic_restart)
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltGlucose());
+    else
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltMiniSat());
     return learnts;
 }
 
@@ -1331,7 +1348,11 @@ void Solver::dumpSortedLearnts(const char* file, const uint32_t maxSize)
     }
     
     fprintf(outfile, "c clauses from learnts\n");
-    std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_lt());
+    
+    if (lastSelectedRestartType == dynamic_restart)
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltGlucose());
+    else
+        std::sort(learnts.getData(), learnts.getData()+learnts.size(), reduceDB_ltMiniSat());
     for (int i = learnts.size()-1; i >= 0 ; i--) {
         if (learnts[i]->size() <= maxSize)
             learnts[i]->plainPrint(outfile);
@@ -1597,7 +1618,7 @@ llbool Solver::handle_conflict(vec<Lit>& learnt_clause, Clause* confl, int& conf
     if (decisionLevel() == 0)
         return l_False;
     learnt_clause.clear();
-    Clause* c = analyze(confl, learnt_clause, backtrack_level, nbLevels);
+    Clause* c = analyze(confl, learnt_clause, backtrack_level, nbLevels, update);
     if (update) {
         avgBranchDepth.push(decisionLevel());
         if (restartType == dynamic_restart)
@@ -1722,11 +1743,13 @@ inline void Solver::chooseRestartType(const uint& lastFullRestart)
                 tmp = fixRestartType;
             
             if (tmp == dynamic_restart) {
+                lastSelectedRestartType = dynamic_restart;
                 nbDecisionLevelHistory.fastclear();
                 nbDecisionLevelHistory.initSize(100);
                 if (verbosity >= 2)
                     printf("c |                           Decided on dynamic restart strategy                         |\n");
             } else  {
+                lastSelectedRestartType = static_restart;
                 if (verbosity >= 2)
                     printf("c |                            Decided on static restart strategy                         |\n");
                                 
@@ -1748,10 +1771,13 @@ inline void Solver::setDefaultRestartType()
 {
     if (fixRestartType != auto_restart) restartType = fixRestartType;
     else restartType = static_restart;
+    
     if (restartType == dynamic_restart) {
         nbDecisionLevelHistory.fastclear();
         nbDecisionLevelHistory.initSize(100);
     }
+    
+    lastSelectedRestartType = restartType;
 }
 
 const lbool Solver::simplifyProblem(const uint32_t numConfls, const uint64_t numProps)
index 2c232a3bd58603a8b856aaf539644043c9b769a7..9fcda6aecae4d3e21427cc12badbf6a5ef1c0e25 100644 (file)
@@ -67,6 +67,16 @@ using std::endl;
 //=================================================================================================
 // Solver -- the main class:
 
+struct reduceDB_ltMiniSat
+{
+    bool operator () (const Clause* x, const Clause* y);
+};
+
+struct reduceDB_ltGlucose
+{
+    bool operator () (const Clause* x, const Clause* y);
+};
+
 
 class Solver
 {
@@ -217,6 +227,7 @@ protected:
     vec<Clause*>        learnts;          // List of learnt clauses.
     vec<uint32_t>       activity;         // A heuristic measurement of the activity of a variable.
     uint32_t            var_inc;          // Amount to bump next variable with.
+    double              cla_inc;          // Amount to bump learnt clause oldActivity with
     vec<vec<Watched> >  watches;          // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
     vec<vec<XorClausePtr> > xorwatches;   // 'xorwatches[var]' is a list of constraints watching var in XOR clauses.
     vec<vec<WatchedBin> >  binwatches;
@@ -247,6 +258,7 @@ protected:
     bqueue<uint>        avgBranchDepth; // Avg branch depth
     MTRand              mtrand;           // random number generaton
     RestartType         restartType;      // Used internally to determine which restart strategy to choose
+    RestartType         lastSelectedRestartType; //the last selected restart type
     friend class        Logger;
     #ifdef STATS_NEEDED
     Logger logger;                        // dynamic logging, statistics
@@ -279,7 +291,7 @@ protected:
     Clause*  propagate        (const bool update = true);                         // Perform unit propagation. Returns possibly conflicting clause.
     Clause*  propagate_xors   (const Lit& p);
     void     cancelUntil      (int level);                                             // Backtrack until a certain level.
-    Clause*  analyze          (Clause* confl, vec<Lit>& out_learnt, int& out_btlevel, int &nblevels); // (bt = backtrack)
+    Clause*  analyze          (Clause* confl, vec<Lit>& out_learnt, int& out_btlevel, int &nblevels, const bool update); // (bt = backtrack)
     void     analyzeFinal     (Lit p, vec<Lit>& out_conflict);                         // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION?
     bool     litRedundant     (Lit p, uint32_t abstract_levels);                       // (helper method for 'analyze()')
     lbool    search           (int nof_conflicts, int nof_conflicts_fullrestart, const bool update = true);      // Search for a given number of conflicts.
@@ -289,6 +301,7 @@ protected:
 
     // Maintaining Variable/Clause activity:
     //
+    void     claBumpActivity (Clause& c);
     void     varDecayActivity ();                      // Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead.
     void     varBumpActivity  (Var v);                 // Increase a variable with the current 'bump' value.
     void     claDecayActivity ();                      // Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead.
@@ -397,6 +410,17 @@ inline void Solver::varBumpActivity(Var v)
         order_heap.decrease(v);
 }
 
+inline void Solver::claBumpActivity (Clause& c)
+{
+    if ( (c.oldActivity() += cla_inc) > 1e20 ) {
+        // Rescale:
+        for (uint32_t i = 0; i < learnts.size(); i++)
+            learnts[i]->oldActivity() *= 1e-17;
+        cla_inc *= 1e-20;
+    }
+}
+        
+
 inline bool     Solver::enqueue         (Lit p, Clause* from)
 {
     return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true);
index f3f456b6716c09043853899f2c67f5251ac37470..01ed823e3dc35ff2985e457ba59e4d5264266a08 100644 (file)
@@ -1,2 +1,2 @@
 CryptoMiniSat
-GIT revision: 3c04fa48505107a294986a85131b05a67c479ba1
+GIT revision: 3f1c377140a6808fe92a2126eb5ed420dfc6f051