1 /********************* */
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
14 ** \brief [[ Add one-line brief description here ]]
16 ** [[ Add lengthier description here ]]
17 ** \todo document this file
21 #include "theory/arith/tableau.h"
24 using namespace CVC4::theory
;
25 using namespace CVC4::theory::arith
;
30 while(!d_basicVariables
.empty()){
31 ArithVar curr
= *(d_basicVariables
.begin());
32 ReducedRowVector
* vec
= removeRow(curr
);
37 void Tableau::addRow(ArithVar basicVar
,
38 const std::vector
<Rational
>& coeffs
,
39 const std::vector
<ArithVar
>& variables
){
41 Assert(coeffs
.size() == variables
.size());
43 //The new basic variable cannot already be a basic variable
44 Assert(!d_basicVariables
.isMember(basicVar
));
45 d_basicVariables
.add(basicVar
);
46 ReducedRowVector
* row_current
= new ReducedRowVector(basicVar
,variables
, coeffs
,d_rowCount
, d_columnMatrix
);
47 d_rowsTable
[basicVar
] = row_current
;
49 //A variable in the row may have been made non-basic already.
50 //If this is the case we fake pivoting this variable
51 vector
<ArithVar
>::const_iterator varsIter
= variables
.begin();
52 vector
<ArithVar
>::const_iterator varsEnd
= variables
.end();
54 for( ; varsIter
!= varsEnd
; ++varsIter
){
55 ArithVar var
= *varsIter
;
57 if(d_basicVariables
.isMember(var
)){
58 ReducedRowVector
& row_var
= lookup(var
);
59 row_current
->substitute(row_var
);
64 ReducedRowVector
* Tableau::removeRow(ArithVar basic
){
65 Assert(d_basicVariables
.isMember(basic
));
67 ReducedRowVector
* row
= d_rowsTable
[basic
];
69 d_basicVariables
.remove(basic
);
70 d_rowsTable
[basic
] = NULL
;
75 void Tableau::pivot(ArithVar x_r
, ArithVar x_s
){
76 Assert(d_basicVariables
.isMember(x_r
));
77 Assert(!d_basicVariables
.isMember(x_s
));
79 Debug("tableau") << "Tableau::pivot(" << x_r
<<", " <<x_s
<<")" << endl
;
81 ReducedRowVector
* row_s
= d_rowsTable
[x_r
];
82 Assert(row_s
!= NULL
);
83 Assert(row_s
->has(x_s
));
85 //Swap x_r and x_s in d_activeRows
86 d_rowsTable
[x_s
] = row_s
;
87 d_rowsTable
[x_r
] = NULL
;
89 d_basicVariables
.remove(x_r
);
91 d_basicVariables
.add(x_s
);
95 ArithVarSet::VarList
copy(getColumn(x_s
).getList());
96 vector
<ArithVar
>::iterator basicIter
= copy
.begin(), endIter
= copy
.end();
98 for(; basicIter
!= endIter
; ++basicIter
){
99 ArithVar basic
= *basicIter
;
100 if(basic
== x_s
) continue;
102 ReducedRowVector
& row_k
= lookup(basic
);
103 Assert(row_k
.has(x_s
));
105 row_k
.substitute(*row_s
);
107 Assert(getColumn(x_s
).size() == 1);
108 Assert(getRowCount(x_s
) == 1);
111 void Tableau::printTableau(){
112 Debug("tableau") << "Tableau::d_activeRows" << endl
;
114 typedef RowsTable::iterator table_iter
;
115 for(table_iter rowIter
= d_rowsTable
.begin(), end
= d_rowsTable
.end();
116 rowIter
!= end
; ++rowIter
){
117 ReducedRowVector
* row_k
= *rowIter
;