#include <ext/hash_map>
+#include <map>
#include <set>
#ifndef __CVC4__THEORY__ARITH__TABLEAU_H
class Row {
TNode d_x_i;
- typedef __gnu_cxx::hash_map<TNode, Rational, NodeHashFunction> CoefficientTable;
+ typedef std::map<TNode, Rational> CoefficientTable;
- std::set<TNode> d_nonbasic;
CoefficientTable d_coeffs;
public:
- typedef std::set<TNode>::iterator iterator;
+ typedef CoefficientTable::iterator iterator;
/**
* Construct a row equal to:
*/
Row(TNode basic, TNode sum):
d_x_i(basic),
- d_nonbasic(),
d_coeffs(){
Assert(d_x_i.getMetaKind() == kind::metakind::VARIABLE);
Assert(var_i.getKind() == kind::VARIABLE);
Assert(!has(var_i));
- d_nonbasic.insert(var_i);
d_coeffs[var_i] = coeff.getConst<Rational>();
Assert(coeff.getConst<Rational>() != Rational(0,1));
Assert(d_coeffs[var_i] != Rational(0,1));
}
iterator begin(){
- return d_nonbasic.begin();
+ return d_coeffs.begin();
}
iterator end(){
- return d_nonbasic.end();
+ return d_coeffs.end();
}
TNode basicVar(){
d_coeffs[d_x_i] = Rational(Integer(-1));
d_coeffs.erase(x_j);
- d_nonbasic.erase(x_j);
- d_nonbasic.insert(d_x_i);
d_x_i = x_j;
- for(iterator nonbasicIter = d_nonbasic.begin();
- nonbasicIter != d_nonbasic.end();
- ++nonbasicIter){
- TNode nb = *nonbasicIter;
- d_coeffs[nb] *= negInverseA_rs;
+ for(iterator nonbasicIter = begin(), nonbasicIter_end = end();
+ nonbasicIter != nonbasicIter_end; ++nonbasicIter){
+ nonbasicIter->second *= negInverseA_rs;
}
}
TNode x_s = row_s.basicVar();
Assert(has(x_s));
- Assert(d_nonbasic.find(x_s) != d_nonbasic.end());
Assert(x_s != d_x_i);
Rational zero(0,1);
Rational a_rs = lookup(x_s);
Assert(a_rs != zero);
d_coeffs.erase(x_s);
- d_nonbasic.erase(x_s);
- for(iterator iter = row_s.d_nonbasic.begin();
- iter != row_s.d_nonbasic.end();
- ++iter){
- TNode x_j = *iter;
- Rational a_sj = row_s.lookup(x_j);
+ for(iterator iter = row_s.begin(), iter_end = row_s.end();
+ iter != iter_end; ++iter){
+ TNode x_j = iter->first;
+ Rational a_sj = iter->second;
a_sj *= a_rs;
CoefficientTable::iterator coeff_iter = d_coeffs.find(x_j);
coeff_iter->second += a_sj;
if(coeff_iter->second == zero){
d_coeffs.erase(coeff_iter);
- d_nonbasic.erase(x_j);
}
}else{
- d_nonbasic.insert(x_j);
d_coeffs.insert(std::make_pair(x_j,a_sj));
}
}
void printRow(){
Debug("tableau") << d_x_i << " ";
- for(iterator nonbasicIter = d_nonbasic.begin();
- nonbasicIter != d_nonbasic.end();
+ for(iterator nonbasicIter = d_coeffs.begin();
+ nonbasicIter != d_coeffs.end();
++nonbasicIter){
- TNode nb = *nonbasicIter;
+ TNode nb = nonbasicIter->first;
Debug("tableau") << "{" << nb << "," << d_coeffs[nb] << "}";
}
Debug("tableau") << std::endl;
basicIter != endIter; ++basicIter){
TNode basic = *basicIter;
Row* row_k = lookup(basic);
- if(row_k->basicVar() != x_s){
- if(row_k->has(x_s)){
- increaseActivity(basic, 30);
-
- row_k->subsitute(*row_s);
- }
+ if(row_k->has(x_s)){
+ increaseActivity(basic, 30);
+ row_k->subsitute(*row_s);
}
}
}
void updateRow(Row* row){
for(Row::iterator i=row->begin(), endIter = row->end(); i != endIter; ){
- TNode var = *i;
+ TNode var = i->first;
++i;
if(isBasic(var)){
Row* row_var = isActiveBasicVariable(var) ? lookup(var) : lookupEjected(var);
Row* row = d_tableau.lookup(x);
for(Row::iterator i = row->begin(); i != row->end();++i){
- TNode nonbasic = *i;
- const Rational& coeff = row->lookup(nonbasic);
+ TNode nonbasic = i->first;
+ const Rational& coeff = i->second;
const DeltaRational& assignment = d_partialModel.getAssignment(nonbasic);
sum = sum + (assignment * coeff);
}
Row* row = d_tableau.lookup(x);
for(Row::iterator i = row->begin(); i != row->end();++i){
- TNode nonbasic = *i;
- const Rational& coeff = row->lookup(nonbasic);
+ TNode nonbasic = i->first;
+ const Rational& coeff = i->second;
const DeltaRational& assignment = d_partialModel.getSafeAssignment(nonbasic);
sum = sum + (assignment * coeff);
}
Row* row_i = d_tableau.lookup(x_i);
for(Row::iterator nbi = row_i->begin(); nbi != row_i->end(); ++nbi){
- TNode nonbasic = *nbi;
- const Rational& a_ij = row_i->lookup(nonbasic);
+ TNode nonbasic = nbi->first;
+ const Rational& a_ij = nbi->second;
int cmp = a_ij.cmp(d_constants.d_ZERO);
if(above){ // beta(x_i) > u_i
if( cmp < 0 && d_partialModel.strictlyBelowUpperBound(nonbasic)){
nb << bound;
for(Row::iterator nbi = row_i->begin(); nbi != row_i->end(); ++nbi){
- TNode nonbasic = *nbi;
- const Rational& a_ij = row_i->lookup(nonbasic);
+ TNode nonbasic = nbi->first;
+ const Rational& a_ij = nbi->second;
Assert(a_ij != d_constants.d_ZERO);
nb << bound;
for(Row::iterator nbi = row_i->begin(); nbi != row_i->end(); ++nbi){
- TNode nonbasic = *nbi;
- const Rational& a_ij = row_i->lookup(nonbasic);
+ TNode nonbasic = nbi->first;
+ const Rational& a_ij = nbi->second;
Assert(a_ij != d_constants.d_ZERO);
for(Row::iterator nonbasicIter = row_k->begin();
nonbasicIter != row_k->end();
++nonbasicIter){
- TNode nonbasic = *nonbasicIter;
- const Rational& coeff = row_k->lookup(nonbasic);
+ TNode nonbasic = nonbasicIter->first;
+ const Rational& coeff = nonbasicIter->second;
DeltaRational beta = d_partialModel.getAssignment(nonbasic);
Debug("paranoid:check_tableau") << nonbasic << beta << coeff<<endl;
sum = sum + (beta*coeff);