DecisionEngine: Use unique_ptr for enabled strategies. (#3984)
authorAina Niemetz <aina.niemetz@gmail.com>
Mon, 9 Mar 2020 21:54:30 +0000 (14:54 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Mar 2020 21:54:30 +0000 (14:54 -0700)
src/decision/decision_engine.cpp
src/decision/decision_engine.h

index 7d31d930fa16fe53ccdabe6b42dac55d34aaca01..63a09ba2c83254a1557b11173d21e14651f37261 100644 (file)
@@ -25,18 +25,17 @@ using namespace std;
 
 namespace CVC4 {
 
-DecisionEngine::DecisionEngine(context::Context *sc,
-                               context::UserContext *uc) :
-  d_enabledStrategies(),
-  d_needIteSkolemMap(),
-  d_relevancyStrategy(NULL),
-  d_assertions(uc),
-  d_cnfStream(NULL),
-  d_satSolver(NULL),
-  d_satContext(sc),
-  d_userContext(uc),
-  d_result(sc, SAT_VALUE_UNKNOWN),
-  d_engineState(0)
+DecisionEngine::DecisionEngine(context::Context* sc, context::UserContext* uc)
+    : d_enabledITEStrategies(),
+      d_needIteSkolemMap(),
+      d_relevancyStrategy(NULL),
+      d_assertions(uc),
+      d_cnfStream(NULL),
+      d_satSolver(NULL),
+      d_satContext(sc),
+      d_userContext(uc),
+      d_result(sc, SAT_VALUE_UNKNOWN),
+      d_engineState(0)
 {
   Trace("decision") << "Creating decision engine" << std::endl;
 }
@@ -54,10 +53,9 @@ void DecisionEngine::init()
 
   if (options::decisionMode() == options::DecisionMode::JUSTIFICATION)
   {
-    ITEDecisionStrategy* ds =
-      new decision::JustificationHeuristic(this, d_userContext, d_satContext);
-    d_enabledStrategies.push_back(ds);
-    d_needIteSkolemMap.push_back(ds);
+    d_enabledITEStrategies.emplace_back(new decision::JustificationHeuristic(
+        this, d_userContext, d_satContext));
+    d_needIteSkolemMap.push_back(d_enabledITEStrategies.back().get());
   }
 }
 
@@ -68,11 +66,7 @@ void DecisionEngine::shutdown()
   Assert(d_engineState == 1);
   d_engineState = 2;
 
-  for (DecisionStrategy* s : d_enabledStrategies)
-  {
-    delete s;
-  }
-  d_enabledStrategies.clear();
+  d_enabledITEStrategies.clear();
   d_needIteSkolemMap.clear();
 }
 
index afa3063251a47534bf5606e6c4c0f1b58dba4b41..28b15c9e0729f423d6cc60142ba3cadaf5269e5e 100644 (file)
@@ -38,8 +38,7 @@ using namespace CVC4::decision;
 namespace CVC4 {
 
 class DecisionEngine {
-
-  vector <DecisionStrategy* > d_enabledStrategies;
+  vector<std::unique_ptr<ITEDecisionStrategy>> d_enabledITEStrategies;
   vector <ITEDecisionStrategy* > d_needIteSkolemMap;
   RelevancyStrategy* d_relevancyStrategy;
 
@@ -72,13 +71,6 @@ public:
     Trace("decision") << "Destroying decision engine" << std::endl;
   }
 
-  // void setPropEngine(PropEngine* pe) {
-  //   // setPropEngine should not be called more than once
-  //   Assert(d_propEngine == NULL);
-  //   Assert(pe != NULL);
-  //   d_propEngine = pe;
-  // }
-
   void setSatSolver(DPLLSatSolverInterface* ss) {
     // setPropEngine should not be called more than once
     Assert(d_satSolver == NULL);
@@ -115,11 +107,11 @@ public:
         << "Forgot to set satSolver for decision engine?";
 
     SatLiteral ret = undefSatLiteral;
-    for(unsigned i = 0;
-        i < d_enabledStrategies.size()
-          and ret == undefSatLiteral
-          and stopSearch == false; ++i) {
-      ret = d_enabledStrategies[i]->getNext(stopSearch);
+    for (unsigned i = 0; i < d_enabledITEStrategies.size()
+                         and ret == undefSatLiteral and stopSearch == false;
+         ++i)
+    {
+      ret = d_enabledITEStrategies[i]->getNext(stopSearch);
     }
     return ret;
   }