- Adds PermissiveBackArithVarSet. This is very similar to ArithVarSet. The differenc...
authorTim King <taking@cs.nyu.edu>
Sat, 5 Mar 2011 23:10:41 +0000 (23:10 +0000)
committerTim King <taking@cs.nyu.edu>
Sat, 5 Mar 2011 23:10:41 +0000 (23:10 +0000)
src/theory/arith/arithvar_set.h
src/theory/arith/row_vector.cpp
src/theory/arith/row_vector.h
src/theory/arith/simplex.cpp
src/theory/arith/tableau.cpp
src/theory/arith/tableau.h

index 08bc905e0993a0ab4acdcd5749f808eb7e69d091..89b1c9507d85202e5c0327b9f8332f7847ad1efd 100644 (file)
@@ -32,11 +32,20 @@ namespace arith {
  * This is an abstraction of a set of ArithVars.
  * This class is designed to provide constant time insertion, deletion, and element_of
  * and fast iteration.
- * The cost of doing this is that it takes O(M) where M is the total number
- * of ArithVars in memory.
+ *
+ * ArithVarSets come in 2 varieties ArithVarSet, and PermissiveBackArithVarSet.
+ * The default ArithVarSet assumes that there is no knowledge assumed about ArithVars
+ * that are greater than allocated(). Asking isMember() of such an ArithVar
+ * is an assertion failure. The cost of doing this is that it takes O(M)
+ * where M is the total number of ArithVars in memory.
+ *
+ * PermissiveBackArithVarSet means that all ArithVars are implicitly not in the set,
+ * and any ArithVar past the end of d_posVector is not in the set.
+ * A permissiveBack allows for less memory to be consumed on average.
+ *
  */
-
-class ArithVarSet {
+template <bool permissiveBack>
+class ArithVarSetImpl {
 public:
   typedef std::vector<ArithVar> VarList;
 private:
@@ -50,7 +59,7 @@ private:
 public:
   typedef VarList::const_iterator iterator;
 
-  ArithVarSet() :  d_list(), d_posVector() {}
+  ArithVarSetImpl() :  d_list(), d_posVector() {}
 
   size_t size() const {
     return d_list.size();
@@ -78,13 +87,17 @@ public:
   }
 
   bool isMember(ArithVar x) const{
-    Assert(x <  allocated());
-    return d_posVector[x] != ARITHVAR_SENTINEL;
+    if(permissiveBack && x >=  allocated()){
+      return false;
+    }else{
+      Assert(x <  allocated());
+      return d_posVector[x] != ARITHVAR_SENTINEL;
+    }
   }
 
   /** Invalidates iterators */
   void init(ArithVar x, bool val) {
-    Assert(x >= size());
+    Assert(x >= allocated());
     increaseSize(x);
     if(val){
       add(x);
@@ -94,6 +107,9 @@ public:
   /** Invalidates iterators */
   void add(ArithVar x){
     Assert(!isMember(x));
+    if(permissiveBack && x >=  allocated()){
+      increaseSize(x);
+    }
     d_posVector[x] = size();
     d_list.push_back(x);
   }
@@ -139,6 +155,9 @@ public:
   }
 };
 
+typedef ArithVarSetImpl<false> ArithVarSet;
+typedef ArithVarSetImpl<true> PermissiveBackArithVarSet;
+
 }; /* namespace arith */
 }; /* namespace theory */
 }; /* namespace CVC4 */
index 9159d3d6fa4a5eb42677482f76283792cb319dfc..8edfb8612cc69b7c01dff4385396991b79f0aabe 100644 (file)
@@ -182,7 +182,7 @@ ReducedRowVector::ReducedRowVector(ArithVar basic,
                                    const std::vector<ArithVar>& variables,
                                    const std::vector<Rational>& coefficients,
                                    std::vector<uint32_t>& counts,
-                                   std::vector<ArithVarSet>& cm):
+                                   std::vector<PermissiveBackArithVarSet>& cm):
   d_basic(basic), d_rowCount(counts),  d_columnMatrix(cm)
 {
   zip(variables, coefficients, d_entries);
index 45412ad3e10afad9571c28da5d340299e1919be6..5fd471700bedd48155570a90a356a4daaf73fc99 100644 (file)
@@ -76,7 +76,7 @@ private:
   ArithVarContainsSet d_contains;
 
   std::vector<uint32_t>& d_rowCount;
-  std::vector<ArithVarSet>& d_columnMatrix;
+  std::vector<PermissiveBackArithVarSet>& d_columnMatrix;
 
 
 public:
@@ -85,7 +85,7 @@ public:
                    const std::vector< ArithVar >& variables,
                    const std::vector< Rational >& coefficients,
                    std::vector<uint32_t>& count,
-                   std::vector<ArithVarSet>& columnMatrix);
+                   std::vector< PermissiveBackArithVarSet >& columnMatrix);
   ~ReducedRowVector();
 
   void enqueueNonBasicVariablesAndCoefficients(std::vector< ArithVar >& variables,
index 7e83e1b9ea521e47334a6770959d9fd900fe6aa9..0e2c3797eff8c47da85366281e9e873e1be60813 100644 (file)
@@ -198,8 +198,8 @@ set<ArithVar> tableauAndHasSet(Tableau& tab, ArithVar v){
 
 set<ArithVar> columnIteratorSet(Tableau& tab,ArithVar v){
   set<ArithVar> has;
-  ArithVarSet::iterator basicIter = tab.beginColumn(v);
-  ArithVarSet::iterator endIter = tab.endColumn(v);
+  Column::iterator basicIter = tab.beginColumn(v);
+  Column::iterator endIter = tab.endColumn(v);
   for(; basicIter != endIter; ++basicIter){
     ArithVar basic = *basicIter;
     has.insert(basic);
@@ -222,8 +222,8 @@ void SimplexDecisionProcedure::update(ArithVar x_i, const DeltaRational& v){
   DeltaRational diff = v - assignment_x_i;
 
   Assert(matchingSets(d_tableau, x_i));
-  ArithVarSet::iterator basicIter = d_tableau.beginColumn(x_i);
-  ArithVarSet::iterator endIter   = d_tableau.endColumn(x_i);
+  Column::iterator basicIter = d_tableau.beginColumn(x_i);
+  Column::iterator endIter   = d_tableau.endColumn(x_i);
   for(; basicIter != endIter; ++basicIter){
     ArithVar x_j = *basicIter;
     ReducedRowVector& row_j = d_tableau.lookup(x_j);
@@ -295,8 +295,8 @@ void SimplexDecisionProcedure::pivotAndUpdate(ArithVar x_i, ArithVar x_j, DeltaR
 
 
   Assert(matchingSets(d_tableau, x_j));
-  ArithVarSet::iterator basicIter = d_tableau.beginColumn(x_j);
-  ArithVarSet::iterator endIter   = d_tableau.endColumn(x_j);
+  Column::iterator basicIter = d_tableau.beginColumn(x_j);
+  Column::iterator endIter   = d_tableau.endColumn(x_j);
   for(; basicIter != endIter; ++basicIter){
     ArithVar x_k = *basicIter;
     ReducedRowVector& row_k = d_tableau.lookup(x_k);
index 9769c628d8d9294e0a3931cde43bc852a901000a..a8bcd28cc0bf09e12f8e10ad2e86ae869ef35461 100644 (file)
@@ -36,7 +36,7 @@ void Tableau::internalCopy(const Tableau& tab){
   Debug("tableau::copy") << "tableau copy "<< N << endl;
 
   if(N > 1){
-    d_columnMatrix.insert(d_columnMatrix.end(), N, ArithVarSet());
+    d_columnMatrix.insert(d_columnMatrix.end(), N, Column());
     d_rowsTable.insert(d_rowsTable.end(), N, NULL);
     d_basicVariables.increaseSize(N-1);
 
@@ -155,7 +155,7 @@ void Tableau::pivot(ArithVar x_r, ArithVar x_s){
 
   row_s->pivot(x_s);
 
-  ArithVarSet::VarList copy(getColumn(x_s).getList());
+  Column::VarList copy(getColumn(x_s).getList());
   vector<ArithVar>::iterator basicIter = copy.begin(), endIter = copy.end();
 
   for(; basicIter != endIter; ++basicIter){
index 6fe24528520cc984a5fd44187c94a8347b578178..dad4bb2f5d0e807da571483e95b864cd537b0254 100644 (file)
@@ -37,7 +37,7 @@ namespace CVC4 {
 namespace theory {
 namespace arith {
 
-typedef ArithVarSet Column;
+typedef PermissiveBackArithVarSet Column;
 
 typedef std::vector<Column> ColumnMatrix;
 
@@ -79,15 +79,15 @@ public:
     d_rowsTable.push_back(NULL);
     d_rowCount.push_back(0);
 
-    d_columnMatrix.push_back(ArithVarSet());
+    d_columnMatrix.push_back(PermissiveBackArithVarSet());
 
     //TODO replace with version of ArithVarSet that handles misses as non-entries
     // not as buffer overflows
-    ColumnMatrix::iterator i = d_columnMatrix.begin(), end = d_columnMatrix.end();
-    for(; i != end; ++i){
-      Column& col = *i;
-      col.increaseSize(d_columnMatrix.size());
-    }
+    // ColumnMatrix::iterator i = d_columnMatrix.begin(), end = d_columnMatrix.end();
+    // for(; i != end; ++i){
+    //   Column& col = *i;
+    //   col.increaseSize(d_columnMatrix.size());
+    // }
   }
 
   bool isBasic(ArithVar v) const {