COPASI API  4.16.103
CStepMatrix.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #ifndef COPASI_CStepMatrix
12 #define COPASI_CStepMatrix
13 
14 #include <algorithm> // for std::max
15 #include <list>
16 #include <vector>
17 
20 
21 template <class CType> class CMatrix;
22 
23 class CStepMatrix: private CVector< CStepMatrixColumn * >
24 {
25 private:
27 
28 public:
30 
31  friend std::ostream & operator << (std::ostream &, const CStepMatrix &);
32 
33  // Operations
34 private:
35  CStepMatrix();
36 
37 public:
38  CStepMatrix(size_t rows);
39 
40  CStepMatrix(CMatrix< C_INT64 > & nullspaceMatrix);
41 
42  ~CStepMatrix();
43 
44 public:
45 
46  const_iterator begin() const;
47 
48  const_iterator end() const;
49 
50  void add(CStepMatrixColumn * pColumn)
51  {
52  if (pColumn != NULL)
53  {
54  if (mInsert >= mBeyond)
55  {
56  size_t OldSize = size();
57 
58  resize(std::max((size_t) 2, 2 * OldSize), true);
59 
60  mInsert = array() + OldSize;
61  mBeyond = array() + size();
62 
63  memset(mInsert, 0x0, OldSize * sizeof(CStepMatrixColumn *));
64 
65  //We need to update the iterators.
66  iterator it = array();
68 
69  for (; it != end; ++it)
70  {
71  if (*it != NULL)
72  {
73  (*it)->setIterator(it);
74  }
75  }
76  }
77 
78  pColumn->setIterator(mInsert);
79  *mInsert = pColumn;
80 
81  mInsert++;
82  }
83 
84  return;
85  }
86 
87  void convertRow();
88 
89  //void convertMatrix();
90 
91  size_t getFirstUnconvertedRow() const;
92 
93  size_t getNumUnconvertedRows() const;
94 
95  /**
96  * Add the linear combination of the two columns to the step matrix if
97  * appropriate and remove columns if necessary.
98  * @param const CZeroSet & set
99  * @param const CStepMatrixColumn * pPositive
100  * @param const CStepMatrixColumn * pNegative
101  * @return CStepMatrixColumn * pColumn
102  */
103  CStepMatrixColumn * addColumn(const CZeroSet & set,
104  const CStepMatrixColumn * pPositive,
105  const CStepMatrixColumn * pNegative);
106 
107  void removeColumn(CStepMatrixColumn * pColumn);
108 
109  bool splitColumns(std::vector< CStepMatrixColumn * > & PositiveColumns,
110  std::vector< CStepMatrixColumn * > & NegativeColumns,
111  std::vector< CStepMatrixColumn * > & NullColumns);
112 
113  void removeInvalidColumns(std::vector< CStepMatrixColumn * > & invalidColumns);
114 
115  void compact();
116 
117  void getAllUnsetBitIndexes(const CStepMatrixColumn * pColumn,
118  CVector<size_t> & indexes) const;
119 
120  void getUnsetBitIndexes(const CStepMatrixColumn * pColumn,
121  CVector< size_t > & indexes) const;
122 
123 private:
124 
125  void convertRow(const size_t & index,
126  CMatrix< C_INT64 > & nullspaceMatrix);
127 
128  // Attributes
129 private:
130  size_t mRows;
131 
133 
135 
137 
139 };
140 
141 #endif // COPASI_CStepMatrix
void removeInvalidColumns(std::vector< CStepMatrixColumn * > &invalidColumns)
void getUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
size_t getFirstUnconvertedRow() const
void getAllUnsetBitIndexes(const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
CStepMatrixColumn *const * const_iterator
Definition: CStepMatrix.h:29
void add(CStepMatrixColumn *pColumn)
Definition: CStepMatrix.h:50
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
friend std::ostream & operator<<(std::ostream &, const CStepMatrix &)
const_iterator begin() const
bool splitColumns(std::vector< CStepMatrixColumn * > &PositiveColumns, std::vector< CStepMatrixColumn * > &NegativeColumns, std::vector< CStepMatrixColumn * > &NullColumns)
size_t mRows
Definition: CStepMatrix.h:130
size_t getNumUnconvertedRows() const
const_iterator end() const
void removeColumn(CStepMatrixColumn *pColumn)
iterator mInsert
Definition: CStepMatrix.h:136
void convertRow()
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
void compact()
iterator mBeyond
Definition: CStepMatrix.h:138
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
void setIterator(CStepMatrixColumn **it)
CStepMatrixColumn * addColumn(const CZeroSet &set, const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative)
#define max(a, b)
Definition: f2c.h:176