summaryrefslogtreecommitdiff
path: root/src/theory/arith/tableau.h
blob: dad4bb2f5d0e807da571483e95b864cd537b0254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*********************                                                        */
/*! \file tableau.h
 ** \verbatim
 ** Original author: taking
 ** Major contributors: mdeters
 ** Minor contributors (to current version): dejan
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief [[ Add one-line brief description here ]]
 **
 ** [[ Add lengthier description here ]]
 ** \todo document this file
 **/


#include "expr/node.h"
#include "expr/attribute.h"

#include "theory/arith/arith_utilities.h"
#include "theory/arith/arithvar_set.h"
#include "theory/arith/normal_form.h"

#include "theory/arith/row_vector.h"

#include <ext/hash_map>
#include <set>

#ifndef __CVC4__THEORY__ARITH__TABLEAU_H
#define __CVC4__THEORY__ARITH__TABLEAU_H

namespace CVC4 {
namespace theory {
namespace arith {

typedef PermissiveBackArithVarSet Column;

typedef std::vector<Column> ColumnMatrix;

class Tableau {
private:

  typedef std::vector< ReducedRowVector* > RowsTable;

  RowsTable d_rowsTable;

  ArithVarSet d_basicVariables;

  std::vector<uint32_t> d_rowCount;
  ColumnMatrix d_columnMatrix;

public:
  /**
   * Constructs an empty tableau.
   */
  Tableau() :
    d_rowsTable(),
    d_basicVariables(),
    d_rowCount(),
    d_columnMatrix()
  {}

  /** Copy constructor. */
  Tableau(const Tableau& tab);
  ~Tableau();

  Tableau& operator=(const Tableau& tab);

  size_t getNumRows() const {
    return d_basicVariables.size();
  }

  void increaseSize(){
    d_basicVariables.increaseSize();
    d_rowsTable.push_back(NULL);
    d_rowCount.push_back(0);

    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());
    // }
  }

  bool isBasic(ArithVar v) const {
    return d_basicVariables.isMember(v);
  }

  ArithVarSet::iterator begin(){
    return d_basicVariables.begin();
  }

  ArithVarSet::iterator end(){
    return d_basicVariables.end();
  }

  const Column& getColumn(ArithVar v){
    Assert(v < d_columnMatrix.size());
    return d_columnMatrix[v];
  }

  Column::iterator beginColumn(ArithVar v){
    return getColumn(v).begin();
  }
  Column::iterator endColumn(ArithVar v){
    return getColumn(v).end();
  }


  ReducedRowVector& lookup(ArithVar var){
    Assert(d_basicVariables.isMember(var));
    Assert(d_rowsTable[var] != NULL);
    return *(d_rowsTable[var]);
  }

  uint32_t getRowCount(ArithVar x){
    Assert(x < d_rowCount.size());
    AlwaysAssert(d_rowCount[x] == getColumn(x).size());

    return d_rowCount[x];
  }

  /**
   * Adds a row to the tableau.
   * The new row is equivalent to:
   *   basicVar = \sum_i coeffs[i] * variables[i]
   * preconditions:
   *   basicVar is already declared to be basic
   *   basicVar does not have a row associated with it in the tableau.
   *
   * Note: each variables[i] does not have to be non-basic.
   * Pivoting will be mimicked if it is basic.
   */
  void addRow(ArithVar basicVar,
              const std::vector<Rational>& coeffs,
              const std::vector<ArithVar>& variables);

  /**
   * preconditions:
   *   x_r is basic,
   *   x_s is non-basic, and
   *   a_rs != 0.
   */
  void pivot(ArithVar x_r, ArithVar x_s);

  void printTableau();

  ReducedRowVector* removeRow(ArithVar basic);


private:
  /** Copies the datastructures in tab to this.*/
  void internalCopy(const Tableau& tab);

  /** Clears the structures in the tableau. */
  void clear();
};

}; /* namespace arith  */
}; /* namespace theory */
}; /* namespace CVC4   */

#endif /* __CVC4__THEORY__ARITH__TABLEAU_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback