COPASI API  4.16.103
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
CStepMatrix Class Reference

#include <CStepMatrix.h>

Inheritance diagram for CStepMatrix:
Inheritance graph
[legend]
Collaboration diagram for CStepMatrix:
Collaboration graph
[legend]

Public Types

typedef CStepMatrixColumn *const * const_iterator
 

Public Member Functions

void add (CStepMatrixColumn *pColumn)
 
CStepMatrixColumnaddColumn (const CZeroSet &set, const CStepMatrixColumn *pPositive, const CStepMatrixColumn *pNegative)
 
const_iterator begin () const
 
void compact ()
 
void convertRow ()
 
 CStepMatrix (size_t rows)
 
 CStepMatrix (CMatrix< C_INT64 > &nullspaceMatrix)
 
const_iterator end () const
 
void getAllUnsetBitIndexes (const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
 
size_t getFirstUnconvertedRow () const
 
size_t getNumUnconvertedRows () const
 
void getUnsetBitIndexes (const CStepMatrixColumn *pColumn, CVector< size_t > &indexes) const
 
void removeColumn (CStepMatrixColumn *pColumn)
 
void removeInvalidColumns (std::vector< CStepMatrixColumn * > &invalidColumns)
 
bool splitColumns (std::vector< CStepMatrixColumn * > &PositiveColumns, std::vector< CStepMatrixColumn * > &NegativeColumns, std::vector< CStepMatrixColumn * > &NullColumns)
 
 ~CStepMatrix ()
 

Private Types

typedef CStepMatrixColumn ** iterator
 
- Private Types inherited from CVectorCore< CStepMatrixColumn * >
typedef CStepMatrixColumnelementType
 

Private Member Functions

void convertRow (const size_t &index, CMatrix< C_INT64 > &nullspaceMatrix)
 
 CStepMatrix ()
 
- Private Member Functions inherited from CVector< CStepMatrixColumn * >
 CVector (size_t size=0)
 
 CVector (const CVector< CStepMatrixColumn * > &src)
 
CVector< CStepMatrixColumn * > & operator= (const CVectorCore< CStepMatrixColumn * > &rhs)
 
CVector< CStepMatrixColumn * > & operator= (const CVector< CStepMatrixColumn * > &rhs)
 
CVector< CStepMatrixColumn * > & operator= (const CStepMatrixColumn *&value)
 
void resize (size_t size, const bool &copy=false)
 
 ~CVector ()
 
void copy (const CVectorCore< CStepMatrixColumn * > &rhs)
 
- Private Member Functions inherited from CVectorCore< CStepMatrixColumn * >
bool applyPivot (const CVectorCore< size_t > &pivot)
 
CStepMatrixColumn ** array ()
 
const CStepMatrixColumn ** array () const
 
 CVectorCore (const size_t &size=0, CStepMatrixColumn **vector=NULL)
 
 CVectorCore (const CVectorCore< CStepMatrixColumn * > &src)
 
CStepMatrixColumn *& operator() (const size_t &row)
 
const CStepMatrixColumn *& operator() (const size_t &row) const
 
CVectorCore< CStepMatrixColumn * > & operator= (const CStepMatrixColumn *&value)
 
CStepMatrixColumn *& operator[] (const size_t &row)
 
const CStepMatrixColumn *& operator[] (const size_t &row) const
 
size_t size () const
 
 ~CVectorCore ()
 

Private Attributes

iterator mBeyond
 
size_t mFirstUnconvertedRow
 
iterator mInsert
 
CVector< size_t > mPivot
 
size_t mRows
 
- Private Attributes inherited from CVectorCore< CStepMatrixColumn * >
size_t mSize
 
CStepMatrixColumn ** mVector
 

Friends

std::ostream & operator<< (std::ostream &, const CStepMatrix &)
 

Detailed Description

Definition at line 23 of file CStepMatrix.h.

Member Typedef Documentation

Definition at line 29 of file CStepMatrix.h.

Definition at line 26 of file CStepMatrix.h.

Constructor & Destructor Documentation

CStepMatrix::CStepMatrix ( )
private

Definition at line 26 of file CStepMatrix.cpp.

26  :
28  mRows(0),
29  mPivot(0),
31 {}
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
size_t mRows
Definition: CStepMatrix.h:130
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
CStepMatrix::CStepMatrix ( size_t  rows)

Definition at line 33 of file CStepMatrix.cpp.

References CVectorCore< CType >::array(), mPivot, and mRows.

33  :
35  mRows(rows),
36  mPivot(rows),
38 {
39  size_t * pPivot = mPivot.array();
40 
41  for (size_t i = 0; i < mRows; ++i, ++pPivot)
42  {
43  *pPivot = i;
44  }
45 }
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
size_t mRows
Definition: CStepMatrix.h:130
CType * array()
Definition: CVector.h:139
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
CStepMatrix::CStepMatrix ( CMatrix< C_INT64 > &  nullspaceMatrix)

Definition at line 47 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), CVectorCore< CType >::array(), CMatrix< CType >::array(), C_INT64, convertRow(), mBeyond, mFirstUnconvertedRow, mInsert, mPivot, mRows, CMatrix< CType >::numCols(), CStepMatrixColumn::push_front(), CVector< CStepMatrixColumn * >::resize(), and CMatrix< CType >::size().

47  :
49  mRows(nullspaceMatrix.numRows()),
50  mPivot(nullspaceMatrix.numRows()),
52 {
53  size_t Cols = nullspaceMatrix.numCols();
54 
55  resize(Cols);
56  iterator it = array();
57  mInsert = mBeyond = it + Cols;
58 
59  CVector< CStepMatrixColumn * > Columns(Cols);
60  CStepMatrixColumn ** pColumn = Columns.array();
61  CStepMatrixColumn ** pColumnEnd = pColumn + Cols;
62 
63  for (; pColumn != pColumnEnd; ++pColumn, ++it)
64  {
65  *pColumn = new CStepMatrixColumn(mRows);
66 
67  (*pColumn)->setIterator(it);
68  *it = *pColumn;
69  }
70 
71  size_t i;
72  size_t j;
73  const C_INT64 * pValue = nullspaceMatrix.array();
74  size_t * pPivot = mPivot.array();
75 
76  std::vector< size_t > NegativeRows;
77  bool hasNegative;
78  bool hasPositive;
79 
80  for (i = 0; i < mRows; ++i, ++pPivot)
81  {
82  *pPivot = i;
83 
84  hasNegative = false;
85  hasPositive = false;
86 
87  for (j = 0; j < Cols; ++j, ++pValue)
88  {
89  if (*pValue > 0)
90  {
91  hasPositive = true;
92  }
93  else if (*pValue < 0)
94  {
95  hasNegative = true;
96  }
97  }
98 
99  if ((!hasNegative && hasPositive))
100  {
101  convertRow(i, nullspaceMatrix);
102  }
103  }
104 
105  // We need to add the information of the unconverted rows of nullspace matrix
106  // to the columns
107 
108  if (nullspaceMatrix.size() != 0 &&
110  {
111  pValue = & nullspaceMatrix(mFirstUnconvertedRow, 0);
112  }
113  else
114  {
115  pValue = NULL;
116  }
117 
118  for (i = mFirstUnconvertedRow; i < mRows; ++i)
119  {
120  pColumn = Columns.array();
121 
122  for (j = 0; j < Cols; ++j, ++pValue, ++pColumn)
123  {
124  (*pColumn)->push_front(*pValue);
125  }
126  }
127 }
void push_front(const C_INT64 &value)
virtual size_t numRows() const
Definition: CMatrix.h:138
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
#define C_INT64
Definition: copasi.h:88
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
size_t mRows
Definition: CStepMatrix.h:130
iterator mInsert
Definition: CStepMatrix.h:136
void convertRow()
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
virtual size_t size() const
Definition: CMatrix.h:132
iterator mBeyond
Definition: CStepMatrix.h:138
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
CStepMatrix::~CStepMatrix ( )

Definition at line 129 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), and mInsert.

130 {
131  iterator it = array();
132 
133  for (; it != mInsert; ++it)
134  {
135  if (*it != NULL)
136  {
137  delete *it;
138  }
139  }
140 }
iterator mInsert
Definition: CStepMatrix.h:136
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26

Member Function Documentation

void CStepMatrix::add ( CStepMatrixColumn pColumn)
inline

Definition at line 50 of file CStepMatrix.h.

References CVectorCore< CStepMatrixColumn * >::array(), end(), max, mBeyond, mInsert, CVector< CStepMatrixColumn * >::resize(), CStepMatrixColumn::setIterator(), and CVectorCore< CStepMatrixColumn * >::size().

Referenced by addColumn(), and CBitPatternMethod::buildFluxModeMatrix().

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  }
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
const_iterator end() const
iterator mInsert
Definition: CStepMatrix.h:136
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
iterator mBeyond
Definition: CStepMatrix.h:138
void setIterator(CStepMatrixColumn **it)
#define max(a, b)
Definition: f2c.h:176
CStepMatrixColumn * CStepMatrix::addColumn ( const CZeroSet set,
const CStepMatrixColumn pPositive,
const CStepMatrixColumn pNegative 
)

Add the linear combination of the two columns to the step matrix if appropriate and remove columns if necessary.

Parameters
constCZeroSet & set
constCStepMatrixColumn * pPositive
constCStepMatrixColumn * pNegative
Returns
CStepMatrixColumn * pColumn

Definition at line 181 of file CStepMatrix.cpp.

References add().

Referenced by CBitPatternTreeMethod::combine(), and CBitPatternMethod::combine().

184 {
185  CStepMatrixColumn * pColumn = new CStepMatrixColumn(set, pPositive, pNegative);
186 
187  add(pColumn);
188 
189  return pColumn;
190 }
void add(CStepMatrixColumn *pColumn)
Definition: CStepMatrix.h:50
CStepMatrix::const_iterator CStepMatrix::begin ( ) const

Definition at line 289 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array().

Referenced by CBitPatternTreeMethod::buildFluxModes(), CBitPatternMethod::buildFluxModes(), and operator<<().

290 {
291  return array();
292 }
CStepMatrixColumn ** array()
Definition: CVector.h:139
void CStepMatrix::compact ( )

Definition at line 345 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), and mInsert.

Referenced by CBitPatternMethod::calculate(), and CBitPatternTreeMethod::calculate().

346 {
347  iterator from = array();
348  iterator to = array();
349 
350  for (; from != mInsert; ++from)
351  {
352  if (*from != NULL)
353  {
354  (*from)->setIterator(to);
355  *to = *from;
356 
357  ++to;
358  }
359  }
360 
361  mInsert = to;
362 }
iterator mInsert
Definition: CStepMatrix.h:136
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
void CStepMatrix::convertRow ( )

Definition at line 142 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), mFirstUnconvertedRow, and mInsert.

Referenced by CBitPatternMethod::calculate(), CBitPatternTreeMethod::calculate(), CStepMatrix(), and splitColumns().

143 {
145 
146  iterator it = array();
147 
148  for (; it != mInsert; ++it)
149  {
150  assert(*it != NULL);
151 
152  assert((*it)->getMultiplier() >= 0);
153 
154  if ((*it)->getMultiplier() > 0)
155  {
156  (*it)->unsetBit(Index);
157  }
158 
159  (*it)->truncate();
160  }
161 
163 }
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
iterator mInsert
Definition: CStepMatrix.h:136
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
void CStepMatrix::convertRow ( const size_t &  index,
CMatrix< C_INT64 > &  nullspaceMatrix 
)
private

Definition at line 299 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), C_INT64, mFirstUnconvertedRow, mInsert, and mPivot.

301 {
303 
304  iterator it = array();
305 
306  C_INT64 * pValue = & nullspaceMatrix(index, 0);
307 
308  if (mFirstUnconvertedRow != index)
309  {
310  C_INT64 * pFirstUnconvertedValue = & nullspaceMatrix(mFirstUnconvertedRow, 0);
311 
312  for (; it != mInsert; ++it, ++pValue, ++pFirstUnconvertedValue)
313  {
314  // At this point the matrix is compact since no columns have been destroyed,
315  // i.e., we do not need to check whether *it != NULL.
316  assert(*pValue >= 0);
317 
318  if (*pValue > 0)
319  {
320  (*it)->unsetBit(Index);
321  }
322 
323  *pValue = *pFirstUnconvertedValue;
324  }
325 
326  // We need to remember the reordering.
327  size_t tmp = mPivot[index];
330  }
331  else
332  {
333  for (; it != mInsert; ++it, ++pValue)
334  {
335  if (*pValue != 0)
336  {
337  (*it)->unsetBit(Index);
338  }
339  }
340  }
341 
343 }
#define C_INT64
Definition: copasi.h:88
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
iterator mInsert
Definition: CStepMatrix.h:136
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
CStepMatrix::const_iterator CStepMatrix::end ( ) const

Definition at line 294 of file CStepMatrix.cpp.

References mInsert.

Referenced by add(), CBitPatternTreeMethod::buildFluxModes(), CBitPatternMethod::buildFluxModes(), operator<<(), and removeInvalidColumns().

295 {
296  return mInsert;
297 }
iterator mInsert
Definition: CStepMatrix.h:136
void CStepMatrix::getAllUnsetBitIndexes ( const CStepMatrixColumn pColumn,
CVector< size_t > &  indexes 
) const

Definition at line 249 of file CStepMatrix.cpp.

References CVectorCore< CType >::array(), CStepMatrixColumn::getAllUnsetBitIndexes(), mPivot, and CVectorCore< CType >::size().

Referenced by CBitPatternMethod::getAllUnsetBitIndexes().

251 {
252  pColumn->getAllUnsetBitIndexes(indexes);
253 
254  // Apply the QR pivot
255  size_t * pIndex = indexes.array();
256  size_t * pIndexEnd = pIndex + indexes.size();
257 
258  for (; pIndex != pIndexEnd; ++pIndex)
259  *pIndex = mPivot[*pIndex];
260 
261  //DebugFile << "@CSM: " << indexes << std::endl;
262 }
size_t size() const
Definition: CVector.h:100
void getAllUnsetBitIndexes(CVector< size_t > &indexes) const
CType * array()
Definition: CVector.h:139
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
size_t CStepMatrix::getFirstUnconvertedRow ( ) const

Definition at line 171 of file CStepMatrix.cpp.

References mFirstUnconvertedRow.

Referenced by CBitPatternMethod::calculate(), and CBitPatternTreeMethod::calculate().

172 {
173  return mFirstUnconvertedRow;
174 }
size_t mFirstUnconvertedRow
Definition: CStepMatrix.h:134
size_t CStepMatrix::getNumUnconvertedRows ( ) const
void CStepMatrix::getUnsetBitIndexes ( const CStepMatrixColumn pColumn,
CVector< size_t > &  indexes 
) const

Definition at line 264 of file CStepMatrix.cpp.

References CVectorCore< CType >::array(), CZeroSet::getNumberOfUnsetBits(), CStepMatrixColumn::getZeroSet(), CZeroSet::isSet(), mPivot, CVector< CType >::resize(), and CVectorCore< CType >::size().

Referenced by CBitPatternTreeMethod::getUnsetBitIndexes(), and CBitPatternMethod::getUnsetBitIndexes().

266 {
267  const CZeroSet & ZeroSet = pColumn->getZeroSet();
268 
269  indexes.resize(ZeroSet.getNumberOfUnsetBits());
270  size_t * pIndex = indexes.array();
271  size_t * pIndexEnd = pIndex + indexes.size();
272 
273  CZeroSet::CIndex Bit = 0;
274  size_t Index = 0;
275 
276  for (; pIndex != pIndexEnd; ++Bit, ++Index)
277  {
278  if (!ZeroSet.isSet(Bit))
279  {
280  // Apply pivot.
281  *pIndex = mPivot[Index];
282  pIndex++;
283  }
284  }
285 
286  return;
287 }
size_t getNumberOfUnsetBits() const
Definition: CZeroSet.h:90
const CZeroSet & getZeroSet() const
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
bool isSet(const CIndex &index) const
Definition: CZeroSet.h:80
size_t size() const
Definition: CVector.h:100
CType * array()
Definition: CVector.h:139
CVector< size_t > mPivot
Definition: CStepMatrix.h:132
void CStepMatrix::removeColumn ( CStepMatrixColumn pColumn)

Definition at line 192 of file CStepMatrix.cpp.

Referenced by CBitPatternTreeMethod::combine(), CBitPatternMethod::combine(), and removeInvalidColumns().

193 {
194  delete pColumn;
195 }
void CStepMatrix::removeInvalidColumns ( std::vector< CStepMatrixColumn * > &  invalidColumns)

Definition at line 238 of file CStepMatrix.cpp.

References end(), and removeColumn().

Referenced by CBitPatternMethod::calculate(), CBitPatternTreeMethod::calculate(), CBitPatternTreeMethod::findRemoveInvalidColumns(), and CBitPatternMethod::findRemoveInvalidColumns().

239 {
240  std::vector< CStepMatrixColumn * >::iterator it = invalidColumns.begin();
241  std::vector< CStepMatrixColumn * >::iterator end = invalidColumns.end();
242 
243  for (; it != end; ++it)
244  {
245  removeColumn(*it);
246  }
247 }
const_iterator end() const
void removeColumn(CStepMatrixColumn *pColumn)
bool CStepMatrix::splitColumns ( std::vector< CStepMatrixColumn * > &  PositiveColumns,
std::vector< CStepMatrixColumn * > &  NegativeColumns,
std::vector< CStepMatrixColumn * > &  NullColumns 
)

Definition at line 197 of file CStepMatrix.cpp.

References CVectorCore< CStepMatrixColumn * >::array(), C_INT64, convertRow(), and mInsert.

Referenced by CBitPatternMethod::calculate(), and CBitPatternTreeMethod::calculate().

200 {
201  assert(PositiveColumns.empty());
202  assert(NegativeColumns.empty());
203  assert(NullColumns.empty());
204 
205  iterator it = array();
206 
207  for (; it != mInsert; ++it)
208  {
209  assert(*it != NULL);
210 
211  const C_INT64 & Value = (*it)->getMultiplier();
212 
213  if (Value > 0)
214  {
215  PositiveColumns.push_back(*it);
216  }
217  else if (Value < 0)
218  {
219  NegativeColumns.push_back(*it);
220  }
221  else
222  {
223  NullColumns.push_back(*it);
224  }
225  }
226 
227  if (NegativeColumns.empty())
228  {
229  // We do not have any linear combinations, thus we can convert immediately
230  convertRow();
231 
232  return false;
233  }
234 
235  return true;
236 }
#define C_INT64
Definition: copasi.h:88
iterator mInsert
Definition: CStepMatrix.h:136
void convertRow()
CStepMatrixColumn ** array()
Definition: CVector.h:139
CStepMatrixColumn ** iterator
Definition: CStepMatrix.h:26

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CStepMatrix m 
)
friend

Definition at line 364 of file CStepMatrix.cpp.

365 {
366  os << m.mPivot << std::endl;
367 
368  CZeroSet::CIndex Bit;
369 
372 
373  for (it = m.begin(); it != end; ++it)
374  {
375  os << **it << std::endl;
376  }
377 
378  return os;
379 }
CStepMatrixColumn *const * const_iterator
Definition: CStepMatrix.h:29
const_iterator begin() const
const_iterator end() const
CVector< size_t > mPivot
Definition: CStepMatrix.h:132

Member Data Documentation

iterator CStepMatrix::mBeyond
private

Definition at line 138 of file CStepMatrix.h.

Referenced by add(), and CStepMatrix().

size_t CStepMatrix::mFirstUnconvertedRow
private
iterator CStepMatrix::mInsert
private

Definition at line 136 of file CStepMatrix.h.

Referenced by add(), compact(), convertRow(), CStepMatrix(), end(), splitColumns(), and ~CStepMatrix().

CVector< size_t > CStepMatrix::mPivot
private
size_t CStepMatrix::mRows
private

Definition at line 130 of file CStepMatrix.h.

Referenced by CStepMatrix(), and getNumUnconvertedRows().


The documentation for this class was generated from the following files: