This commit is the promised clean up after removing row ejection.
[cvc5.git] / src / theory / arith / tableau.cpp
1 /********************* */
2 /*! \file tableau.cpp
3 ** \verbatim
4 ** Original author: taking
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
13 **
14 ** \brief [[ Add one-line brief description here ]]
15 **
16 ** [[ Add lengthier description here ]]
17 ** \todo document this file
18 **/
19
20
21 #include "theory/arith/tableau.h"
22
23 using namespace CVC4;
24 using namespace CVC4::theory;
25 using namespace CVC4::theory::arith;
26
27 void Tableau::addRow(ArithVar basicVar,
28 const std::vector<Rational>& coeffs,
29 const std::vector<ArithVar>& variables){
30
31 Assert(coeffs.size() == variables.size());
32 Assert(d_basicManager.isMember(basicVar));
33
34 //The new basic variable cannot already be a basic variable
35 Assert(!d_activeBasicVars.isMember(basicVar));
36 d_activeBasicVars.add(basicVar);
37 ReducedRowVector* row_current = new ReducedRowVector(basicVar,variables, coeffs,d_rowCount);
38 d_rowsTable[basicVar] = row_current;
39
40 //A variable in the row may have been made non-basic already.
41 //If this is the case we fake pivoting this variable
42 vector<ArithVar>::const_iterator varsIter = variables.begin();
43 vector<ArithVar>::const_iterator varsEnd = variables.end();
44
45 for( ; varsIter != varsEnd; ++varsIter){
46 ArithVar var = *varsIter;
47
48 if(d_basicManager.isMember(var)){
49 Assert(d_activeBasicVars.isMember(var));
50
51 ReducedRowVector& row_var = lookup(var);
52 row_current->substitute(row_var);
53 }
54 }
55 }
56
57 ReducedRowVector* Tableau::removeRow(ArithVar basic){
58 Assert(d_basicManager.isMember(basic));
59 Assert(d_activeBasicVars.isMember(basic));
60
61 ReducedRowVector* row = d_rowsTable[basic];
62
63 d_activeBasicVars.remove(basic);
64 d_rowsTable[basic] = NULL;
65
66 return row;
67 }
68
69 void Tableau::pivot(ArithVar x_r, ArithVar x_s){
70 Assert(d_basicManager.isMember(x_r));
71 Assert(!d_basicManager.isMember(x_s));
72
73 Debug("tableau") << "Tableau::pivot(" << x_r <<", " <<x_s <<")" << endl;
74
75 ReducedRowVector* row_s = d_rowsTable[x_r];
76 Assert(row_s != NULL);
77 Assert(row_s->has(x_s));
78
79 //Swap x_r and x_s in d_activeRows
80 d_rowsTable[x_s] = row_s;
81 d_rowsTable[x_r] = NULL;
82
83 d_activeBasicVars.remove(x_r);
84 d_basicManager.remove(x_r);
85
86 d_activeBasicVars.add(x_s);
87 d_basicManager.add(x_s);
88
89 row_s->pivot(x_s);
90
91 for(ArithVarSet::iterator basicIter = begin(), endIter = end();
92 basicIter != endIter; ++basicIter){
93 ArithVar basic = *basicIter;
94 if(basic == x_s) continue;
95
96 ReducedRowVector& row_k = lookup(basic);
97 if(row_k.has(x_s)){
98 row_k.substitute(*row_s);
99 }
100 }
101 }
102 void Tableau::printTableau(){
103 Debug("tableau") << "Tableau::d_activeRows" << endl;
104
105 typedef RowsTable::iterator table_iter;
106 for(table_iter rowIter = d_rowsTable.begin(), end = d_rowsTable.end();
107 rowIter != end; ++rowIter){
108 ReducedRowVector* row_k = *rowIter;
109 if(row_k != NULL){
110 row_k->printRow();
111 }
112 }
113 }