* 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:
public:
typedef VarList::const_iterator iterator;
- ArithVarSet() : d_list(), d_posVector() {}
+ ArithVarSetImpl() : d_list(), d_posVector() {}
size_t size() const {
return d_list.size();
}
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);
/** Invalidates iterators */
void add(ArithVar x){
Assert(!isMember(x));
+ if(permissiveBack && x >= allocated()){
+ increaseSize(x);
+ }
d_posVector[x] = size();
d_list.push_back(x);
}
}
};
+typedef ArithVarSetImpl<false> ArithVarSet;
+typedef ArithVarSetImpl<true> PermissiveBackArithVarSet;
+
}; /* namespace arith */
}; /* namespace theory */
}; /* namespace CVC4 */
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);
ArithVarContainsSet d_contains;
std::vector<uint32_t>& d_rowCount;
- std::vector<ArithVarSet>& d_columnMatrix;
+ std::vector<PermissiveBackArithVarSet>& d_columnMatrix;
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,
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);
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);
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);
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);
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){
namespace theory {
namespace arith {
-typedef ArithVarSet Column;
+typedef PermissiveBackArithVarSet Column;
typedef std::vector<Column> ColumnMatrix;
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 {