- Adds a path for Theory to be passed a reference to Options.
authorTim King <taking@cs.nyu.edu>
Sun, 27 Feb 2011 19:59:52 +0000 (19:59 +0000)
committerTim King <taking@cs.nyu.edu>
Sun, 27 Feb 2011 19:59:52 +0000 (19:59 +0000)
- Adds 3 choices of heuristic variable orders to use in ArithPriorityQueue.
- Adds the pivot-rule command line option.

src/theory/arith/arith_priority_queue.cpp
src/theory/arith/arith_priority_queue.h
src/theory/arith/simplex.h
src/theory/arith/theory_arith.h
src/theory/theory.h
src/theory/theory_engine.cpp
src/theory/theory_engine.h
src/util/options.cpp
src/util/options.h

index 14a228e62deef3ddadec65fc713230c882007c25..23f547344f8ff98eb8ada47c5e4c81acae99e8c4 100644 (file)
@@ -12,9 +12,19 @@ using namespace CVC4::theory;
 using namespace CVC4::theory::arith;
 
 ArithPriorityQueue::ArithPriorityQueue(ArithPartialModel& pm, const Tableau& tableau):
-  d_partialModel(pm), d_tableau(tableau), d_modeInUse(Collection), d_ZERO_DELTA(0,0)
+  d_pivotRule(MINIMUM),
+  d_partialModel(pm),
+  d_tableau(tableau),
+  d_modeInUse(Collection),
+  d_ZERO_DELTA(0,0)
 {}
 
+void ArithPriorityQueue::setPivotRule(PivotRule rule){
+  Assert(!inDifferenceMode());
+  Debug("arith::setPivotRule") << "setting pivot rule " << rule << endl;
+  d_pivotRule = rule;
+}
+
 ArithVar ArithPriorityQueue::dequeueInconsistentBasicVariable(){
   AlwaysAssert(!inCollectionMode());
 
@@ -23,7 +33,17 @@ ArithVar ArithPriorityQueue::dequeueInconsistentBasicVariable(){
   if(inDifferenceMode()){
     while(!d_diffQueue.empty()){
       ArithVar var = d_diffQueue.front().variable();
-      pop_heap(d_diffQueue.begin(), d_diffQueue.end());
+      switch(d_pivotRule){
+      case MINIMUM:
+        pop_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::minimumRule);
+        break;
+      case BREAK_TIES:
+        pop_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::breakTiesRules);
+        break;
+      case MAXIMUM:
+        pop_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::maximumRule);
+        break;
+      }
       d_diffQueue.pop_back();
       Debug("arith_update") << "possiblyInconsistentGriggio var" << var << endl;
       if(basicAndInconsistent(var)){
@@ -73,7 +93,17 @@ void ArithPriorityQueue::enqueueIfInconsistent(ArithVar basic){
       break;
     case Difference:
       d_diffQueue.push_back(computeDiff(basic));
-      push_heap(d_diffQueue.begin(), d_diffQueue.end());
+      switch(d_pivotRule){
+      case MINIMUM:
+        push_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::minimumRule);
+        break;
+      case BREAK_TIES:
+        push_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::breakTiesRules);
+        break;
+      case MAXIMUM:
+        push_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::maximumRule);
+        break;
+      }
       break;
     default:
       Unreachable();
@@ -95,7 +125,19 @@ void ArithPriorityQueue::transitionToDifferenceMode() {
       d_diffQueue.push_back(computeDiff(var));
     }
   }
-  make_heap(d_diffQueue.begin(), d_diffQueue.end());
+
+  switch(d_pivotRule){
+  case MINIMUM:
+    make_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::minimumRule);
+    break;
+  case BREAK_TIES:
+    make_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::breakTiesRules);
+    break;
+  case MAXIMUM:
+    make_heap(d_diffQueue.begin(), d_diffQueue.end(), VarDRatPair::maximumRule);
+    break;
+  }
+
   d_candidates.clear();
   d_modeInUse = Difference;
 
index 2f150b73a8466341110d119c504ad5831a93445d..ec0a96aa3fbfad7f30d8432dc1b5b1f873f13b96 100644 (file)
@@ -41,8 +41,10 @@ namespace arith {
  * The queue begins in Collection mode.
  */
 class ArithPriorityQueue {
-private:
+public:
+  enum PivotRule {MINIMUM, BREAK_TIES, MAXIMUM};
 
+private:
   class VarDRatPair {
   private:
     ArithVar d_variable;
@@ -56,14 +58,38 @@ private:
       return d_variable;
     }
 
-    bool operator<(const VarDRatPair& other){
-      return d_orderBy > other.d_orderBy;
+    static bool minimumRule(const VarDRatPair& a, const VarDRatPair& b){
+      return a.d_orderBy > b.d_orderBy;
+    }
+    static bool maximumRule(const VarDRatPair& a, const VarDRatPair& b){
+      return a.d_orderBy < b.d_orderBy;
+    }
+
+    static bool breakTiesRules(const VarDRatPair& a, const VarDRatPair& b){
+      const Rational& nonInfA = a.d_orderBy.getNoninfinitesimalPart();
+      const Rational& nonInfB = b.d_orderBy.getNoninfinitesimalPart();
+      int cmpNonInf = nonInfA.cmp(nonInfB);
+      if(cmpNonInf == 0){
+        const Rational& infA = a.d_orderBy.getInfinitesimalPart();
+        const Rational& infB = b.d_orderBy.getInfinitesimalPart();
+        int cmpInf = infA.cmp(infB);
+        if(cmpInf == 0){
+          return a.d_variable > b.d_variable;
+        }else{
+          return cmpInf > 0;
+        }
+      }else{
+        return cmpNonInf > 0;
+      }
+
+      return a.d_orderBy > b.d_orderBy;
     }
   };
 
   typedef std::vector<VarDRatPair> DifferenceArray;
   typedef std::vector<ArithVar> ArithVarArray;
 
+  PivotRule d_pivotRule;
 
   /**
    * An unordered array with no heap structure for use during collection mode.
@@ -116,6 +142,9 @@ public:
 
   ArithPriorityQueue(ArithPartialModel& pm, const Tableau& tableau);
 
+  /** precondition: !inDifferenceMode() */
+  void setPivotRule(PivotRule rule);
+
   ArithVar dequeueInconsistentBasicVariable();
 
   void enqueueIfInconsistent(ArithVar basic);
index 3b86935bd078685325e3170797566b297e4eae9b..a32a188b494863fb873731b156bb4e26e4d7d1fc 100644 (file)
@@ -12,6 +12,8 @@
 #include "theory/arith/partial_model.h"
 #include "theory/output_channel.h"
 
+#include "util/options.h"
+
 #include "util/stats.h"
 
 #include <queue>
@@ -150,6 +152,22 @@ private:
   Node generateConflictBelow(ArithVar conflictVar);
 
 public:
+  void notifyOptions(const Options& opt){
+    switch(opt.pivotRule){
+    case Options::MINIMUM:
+      d_queue.setPivotRule(ArithPriorityQueue::MINIMUM);
+      break;
+    case Options::BREAK_TIES:
+      d_queue.setPivotRule(ArithPriorityQueue::BREAK_TIES);
+      break;
+    case Options::MAXIMUM:
+      d_queue.setPivotRule(ArithPriorityQueue::MAXIMUM);
+      break;
+    default:
+      Unhandled(opt.pivotRule);
+    }
+  }
+
   /**
    * Checks to make sure the assignment is consistent with the tableau.
    * This code is for debugging.
index e29054c16101791f37de53ec6049f5f4499e5ba0..dc841170b4d7f662346bfd6387d614c6416989df 100644 (file)
@@ -162,6 +162,9 @@ public:
 
   std::string identify() const { return std::string("TheoryArith"); }
 
+  void notifyOptions(const Options& opt) {
+    d_simplex.notifyOptions(opt);
+  }
 private:
 
   ArithVar determineLeftVariable(TNode assertion, Kind simpleKind);
index b4c3a897b505264abefe12efb8c1e1d8faa7aa69..85ea375f7e7e049c197514d9494724fb697f5620 100644 (file)
@@ -27,6 +27,7 @@
 #include "context/context.h"
 #include "context/cdlist.h"
 #include "context/cdo.h"
+#include "util/options.h"
 
 #include <string>
 #include <iostream>
@@ -95,6 +96,8 @@ protected:
     d_out(&out) {
   }
 
+
+
   /**
    * This is called at shutdown time by the TheoryEngine, just before
    * destruction.  It is important because there are destruction
@@ -376,6 +379,8 @@ public:
    */
   virtual std::string identify() const = 0;
 
+  virtual void notifyOptions(const Options& opt) {}
+
   //
   // CODE INVARIANT CHECKING (used only with CVC4_ASSERTIONS)
   //
index 97cb8f471d840f0df634372be641d8d59f1527ee..a577e8f9b36469b921178c8955821a3f14ae4ad4 100644 (file)
@@ -135,6 +135,7 @@ TheoryEngine::TheoryEngine(context::Context* ctxt, const Options& opts) :
   d_hasShutDown(false),
   d_incomplete(ctxt, false),
   d_valuation(this),
+  d_opts(opts),
   d_statistics() {
 
   Rewriter::init();
index 6a343717abde9d178cb87ae93e26b666a3dfba3d..7a82a1b05e20a24abb739f2f8206cfe172b92420 100644 (file)
@@ -154,6 +154,8 @@ class TheoryEngine {
    */
   Node removeITEs(TNode t);
 
+  const Options& d_opts;
+
 public:
 
   /**
@@ -174,6 +176,8 @@ public:
     TheoryClass* theory = new TheoryClass(d_context, d_theoryOut);
     d_theoryTable[theory->getId()] = theory;
     d_sharedTermManager->registerTheory(static_cast<TheoryClass*>(theory));
+
+    theory->notifyOptions(d_opts);
   }
 
   SharedTermManager* getSharedTermManager() {
index dcf146010cfd13d9ba7dee7d9a1752b4f44ac598..0c3915d1dd8c37b52ef3d41c3c50bc0662a02176 100644 (file)
@@ -120,7 +120,8 @@ enum OptionValue {
   NO_TYPE_CHECKING,
   LAZY_TYPE_CHECKING,
   EAGER_TYPE_CHECKING,
-  INCREMENTAL
+  INCREMENTAL,
+  PIVOT_RULE
 };/* enum OptionValue */
 
 /**
@@ -177,6 +178,7 @@ static struct option cmdlineOptions[] = {
   { "lazy-type-checking", no_argument, NULL, LAZY_TYPE_CHECKING},
   { "eager-type-checking", no_argument, NULL, EAGER_TYPE_CHECKING},
   { "incremental", no_argument, NULL, INCREMENTAL},
+  { "pivot-rule" , required_argument, NULL, PIVOT_RULE  },
   { NULL         , no_argument      , NULL, '\0'        }
 };/* if you add things to the above, please remember to update usage.h! */
 
@@ -374,6 +376,28 @@ throw(OptionException) {
       incrementalSolving = true;
       break;
 
+    case PIVOT_RULE:
+      if(!strcmp(optarg, "min")) {
+        pivotRule = MINIMUM;
+        break;
+      } else if(!strcmp(optarg, "min-break-ties")) {
+        pivotRule = BREAK_TIES;
+        break;
+      } else if(!strcmp(optarg, "max")) {
+        pivotRule = MAXIMUM;
+        break;
+      } else if(!strcmp(optarg, "help")) {
+        printf("Pivot rules available:\n");
+        printf("min\n");
+        printf("min-break-ties\n");
+        printf("max\n");
+        exit(1);
+      } else {
+        throw OptionException(string("unknown option for --pivot-rule: `") +
+                              optarg + "'.  Try --pivot-rule help.");
+      }
+      break;
+
     case SHOW_CONFIG:
       fputs(Configuration::about().c_str(), stdout);
       printf("\n");
index 1eca0d499105e5c05e816c9c49ac045ff5df541c..2618f8512aef7aea9b8a66b666914f379548a152 100644 (file)
@@ -129,6 +129,10 @@ struct CVC4_PUBLIC Options {
   /** Whether incemental solving (push/pop) */
   bool incrementalSolving;
 
+
+  typedef enum { MINIMUM, BREAK_TIES, MAXIMUM } ArithPivotRule;
+  ArithPivotRule pivotRule;
+
   Options() :
     binary_name(),
     statistics(false),
@@ -151,7 +155,9 @@ struct CVC4_PUBLIC Options {
     produceAssignments(false),
     typeChecking(DO_SEMANTIC_CHECKS_BY_DEFAULT),
     earlyTypeChecking(USE_EARLY_TYPE_CHECKING_BY_DEFAULT),
-    incrementalSolving(false) {
+    incrementalSolving(false),
+    pivotRule(MINIMUM)
+    {
   }
 
   /**