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
;
27 void Tableau::addRow(ArithVar basicVar
,
28 const std::vector
<Rational
>& coeffs
,
29 const std::vector
<ArithVar
>& variables
){
31 Assert(coeffs
.size() == variables
.size());
32 Assert(d_basicManager
.isMember(basicVar
));
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
;
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();
45 for( ; varsIter
!= varsEnd
; ++varsIter
){
46 ArithVar var
= *varsIter
;
48 if(d_basicManager
.isMember(var
)){
50 if(!isActiveBasicVariable(var)){
53 Assert(isActiveBasicVariable(var));
55 Assert(d_activeBasicVars
.isMember(var
));
57 ReducedRowVector
& row_var
= lookup(var
);
58 row_current
->substitute(row_var
);
63 ReducedRowVector
* Tableau::removeRow(ArithVar basic
){
64 Assert(d_basicManager
.isMember(basic
));
65 Assert(d_activeBasicVars
.isMember(basic
));
67 ReducedRowVector
* row
= d_rowsTable
[basic
];
69 d_activeBasicVars
.remove(basic
);
70 d_rowsTable
[basic
] = NULL
;
75 void Tableau::pivot(ArithVar x_r
, ArithVar x_s
){
76 Assert(d_basicManager
.isMember(x_r
));
77 Assert(!d_basicManager
.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_activeBasicVars
.remove(x_r
);
90 d_basicManager
.remove(x_r
);
92 d_activeBasicVars
.add(x_s
);
93 d_basicManager
.add(x_s
);
97 for(ArithVarSet::iterator basicIter
= begin(), endIter
= end();
98 basicIter
!= endIter
; ++basicIter
){
99 ArithVar basic
= *basicIter
;
100 if(basic
== x_s
) continue;
102 ReducedRowVector
& row_k
= lookup(basic
);
104 d_activityMonitor
[basic
] += 30;
105 row_k
.substitute(*row_s
);
109 void Tableau::printTableau(){
110 Debug("tableau") << "Tableau::d_activeRows" << endl
;
112 typedef RowsTable::iterator table_iter
;
113 for(table_iter rowIter
= d_rowsTable
.begin(), end
= d_rowsTable
.end();
114 rowIter
!= end
; ++rowIter
){
115 ReducedRowVector
* row_k
= *rowIter
;
124 void Tableau::updateRow(ReducedRowVector* row){
125 ArithVar basic = row->basic();
126 for(ReducedRowVector::NonZeroIterator i=row->beginNonZero(), endIter = row->endNonZero(); i != endIter; ){
127 ArithVar var = i->first;
129 if(var != basic && d_basicManager.isMember(var)){
130 ReducedRowVector* row_var = isActiveBasicVariable(var) ? lookup(var) : lookupEjected(var);
132 Assert(row_var != row);
133 row->substitute(*row_var);
135 i = row->beginNonZero();
136 endIter = row->endNonZero();