COPASI API  4.16.103
CTableauMatrix.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CTableauMatrix.cpp,v $
3 // $Revision: 1.19 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/07/08 20:13:34 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 /**
24  * CTableauMatrix class.
25  * Used to calculate elementary flux modes
26  *
27  * Created for Copasi by Stefan Hoops 2002-05-08
28  * (C) Stefan Hoops 2002
29  */
30 
31 #include <iostream>
32 
33 #include "copasi.h"
34 #include "CTableauMatrix.h"
35 
37  mLine(),
38  mFirstIrreversible(mLine.end())
39 {}
40 
41 CTableauMatrix::CTableauMatrix(const std::vector< std::vector< C_FLOAT64 > > & stoi,
42  const size_t & reversibleNumber):
43  mLine(),
44  mFirstIrreversible(mLine.end())
45 {
46  size_t ReactionCounter = 0;
47  size_t ReactionNumber = stoi.size();
48 
49  for (std::vector< std::vector< C_FLOAT64 > >::const_iterator Reaction = stoi.begin();
50  Reaction < stoi.end();
51  Reaction++, ReactionCounter++)
52  {
53  mLine.push_back(new CTableauLine(*Reaction,
54  (ReactionCounter < reversibleNumber) ? true : false,
55  ReactionCounter,
56  ReactionNumber));
57 
58  if (ReactionCounter == reversibleNumber)
59  {
61  }
62  }
63 }
64 
66 {
67  for (std::list< const CTableauLine * >::iterator i = mLine.begin();
68  i != mLine.end(); i++)
69  pdelete(*i);
70 }
71 
72 size_t CTableauMatrix::size() const
73 {return mLine.size();}
74 
75 std::list< const CTableauLine * >::iterator CTableauMatrix::begin()
76 {
77  return mLine.begin();
78 }
79 
80 std::list< const CTableauLine * >::const_iterator CTableauMatrix::begin() const
81 {
82  return mLine.begin();
83 }
84 
85 std::list< const CTableauLine * >::iterator CTableauMatrix::end()
86 {
87  return mLine.end();
88 }
89 
90 std::list< const CTableauLine * >::const_iterator CTableauMatrix::end() const
91 {
92  return mLine.end();
93 }
94 
96  const bool & check)
97 {
98  /* First we check whether we have a valid new flux mode */
99  if (!check || isValid(src))
100  {
101  if (src->isReversible())
102  {
105  }
106  else if (mFirstIrreversible == mLine.end())
107  {
109  }
110  else
111  {
112  mLine.push_back(src);
113  }
114  }
115  else
116  pdelete(src);
117 }
118 
119 void CTableauMatrix::removeLine(const std::list< const CTableauLine * >::iterator line)
120 {
121  if (line == mFirstIrreversible && mFirstIrreversible == mLine.begin())
122  {
123  mLine.pop_front();
124  mFirstIrreversible = mLine.begin();
125  }
126  else if (line == mFirstIrreversible)
127  {
129  mLine.erase(line);
131  }
132  else
133  {
134  mLine.erase(line);
135  }
136 }
137 
139 {
140  std::list< const CTableauLine * >::iterator i;
141  std::list< const CTableauLine * >::iterator tmp;
142 
143  /* Check whether we have already better lines */
144  for (i = mLine.begin(); i != mLine.end(); i++)
145  if ((*i)->getScore() < src->getScore())
146  return false;
147 
148  i = mLine.begin();
149 
150  /* Check whether the new line scores better than existing lines */
151 
152  /* If so the existing lines are removed */
153  for (i = mLine.begin(); i != mLine.end();)
154  if (src->getScore() < (*i)->getScore())
155  {
156  if (i == mLine.begin())
157  {
158  removeLine(i);
159  i = mLine.begin();
160  }
161  else
162  {
163  tmp = i;
164  tmp--;
165  removeLine(i);
166  i = tmp;
167  i++;
168  }
169  }
170  else
171  i++;
172 
173  return true;
174 }
175 
176 std::ostream & operator << (std::ostream & os, const CTableauMatrix & m)
177 {
178  os << "Tableau Matrix: Number of Lines = " << m.mLine.size() << std::endl;
179  std::list< const CTableauLine * >::const_iterator i;
180 
181  for (i = m.mLine.begin(); i != m.mLine.end(); i++)
182  {
183  os << (**i);
184  }
185 
186  return os;
187 }
#define pdelete(p)
Definition: copasi.h:215
const CFluxScore & getScore() const
std::list< const CTableauLine * >::iterator begin()
size_t size() const
std::list< const CTableauLine * >::iterator end()
std::ostream & operator<<(std::ostream &os, const CTableauMatrix &m)
bool isReversible() const
void removeLine(const std::list< const CTableauLine * >::iterator line)
std::list< const CTableauLine * >::iterator mFirstIrreversible
bool isValid(const CTableauLine *src)
void addLine(const CTableauLine *src, const bool &check=true)
std::list< const CTableauLine * > mLine