COPASI API  4.16.103
CEFMMethod.cpp
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CEFMMethod.cpp,v $
3  $Revision: 1.14 $
4  $Name: $
5  $Author: heilmand $
6  $Date: 2010/08/02 15:12:41 $
7  End CVS Header */
8 
9 // Copyright (C) 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  * CEFMMethod class
25  * This class describes the interface to all optimization methods.
26  * The various method like RandomSearch or GA have to be derived from
27  * this class.
28  *
29  * Created for COPASI by Stefan Hoops 2002
30  */
31 
32 #include "copasi.h"
33 
34 #include "CEFMTask.h"
35 #include "CEFMMethod.h"
36 #include "CEFMProblem.h"
37 
38 #include "CEFMAlgorithm.h"
39 #include "CBitPatternTreeMethod.h"
40 #include "CBitPatternMethod.h"
41 #ifdef COPASI_SSA
42 # include "CSSAMethod.h"
43 #endif
44 
45 #include "model/CModel.h"
46 
48 {
49  CEFMMethod * pMethod = NULL;
50 
51  switch (subType)
52  {
53  case EFMAlgorithm:
54  pMethod = new CEFMAlgorithm();
55  break;
56 
58  pMethod = new CBitPatternTreeMethod();
59  break;
60 
62  pMethod = new CBitPatternMethod();
63  break;
64 
65 #ifdef COPASI_SSA
66  case stoichiometricStabilityAnalysis:
67  pMethod = new CSSAMethod();
68  break;
69 #endif
70 
71  default:
72  pMethod = new CEFMAlgorithm();
73  break;
74  }
75 
76  return pMethod;
77 }
78 
79 // Default constructor
81  CCopasiMethod(CCopasiTask::fluxMode, CCopasiMethod::unset),
82  mpFluxModes(NULL),
83  mpReorderedReactions(NULL)
85 
87  const CEFMMethod::SubType & subType,
88  const CCopasiContainer * pParent):
89  CCopasiMethod(taskType, subType, pParent),
90  mpFluxModes(NULL),
91  mpReorderedReactions(NULL)
93 
95  const CCopasiContainer * pParent):
96  CCopasiMethod(src, pParent),
97  mpFluxModes(src.mpFluxModes),
98  mpReorderedReactions(src.mpReorderedReactions)
100 
102 {}
103 
105 {
106  return false;
107 }
108 
110 {
111  CEFMTask * pTask = dynamic_cast< CEFMTask * >(getObjectParent());
112 
113  if (pTask == NULL)
114  {
116  return false;
117  }
118 
119  CEFMProblem * pProblem = dynamic_cast< CEFMProblem *>(pTask->getProblem());
120 
121  if (pProblem == NULL)
122  {
124  return false;
125  }
126 
127  mpFluxModes = & pProblem->getFluxModes();
129 
130  mpReorderedReactions->clear();
131  mpFluxModes->clear();
132 
133  return true;
134 }
135 
137 {
138  if (!CCopasiMethod::isValidProblem(pProblem)) return false;
139 
140  if (pProblem == NULL)
141  {
142  return false;
143  }
144 
145  const CModel * pModel = pProblem ->getModel();
146 
147  if (pModel == NULL)
148  {
149  return false;
150  }
151 
152  // Check that the stoichiometry matrix contains only integers.
153 
154  const CMatrix< C_FLOAT64 > & RedStoi = pModel->getRedStoi();
155  const C_FLOAT64 * pValue = RedStoi.array();
156  const C_FLOAT64 * pValueEnd = pValue + RedStoi.size();
157 
158  for (; pValue != pValueEnd; ++pValue)
159  {
160  if (fabs(*pValue - floor(*pValue + 0.5)) > 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
161  {
162  break;
163  }
164  }
165 
166  if (pValue != pValueEnd)
167  {
168  const CReaction * pReaction = pModel->getReactions()[(pValue - RedStoi.array()) % RedStoi.numCols()];
169 
171 
172  return false;
173  }
174 
175  return true;
176 }
static CEFMMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::EFMAlgorithm)
Definition: CEFMMethod.cpp:47
CCopasiProblem * getProblem()
const std::string & getObjectName() const
std::vector< CFluxMode > * mpFluxModes
Definition: CEFMMethod.h:91
const CMatrix< C_FLOAT64 > & getRedStoi() const
Definition: CModel.cpp:1154
virtual bool initialize()
Definition: CEFMMethod.cpp:109
virtual bool isValidProblem(const CCopasiProblem *pProblem)
CTSSATask * pTask
virtual ~CEFMMethod()
Definition: CEFMMethod.cpp:101
const std::vector< CFluxMode > & getFluxModes() const
Definition: CEFMProblem.cpp:80
std::vector< const CReaction * > * mpReorderedReactions
Definition: CEFMMethod.h:96
virtual bool calculate()
Definition: CEFMMethod.cpp:104
const std::vector< const CReaction * > & getReorderedReactions() const
Definition: CEFMProblem.cpp:86
#define MCEFMAnalysis
#define C_FLOAT64
Definition: copasi.h:92
virtual size_t size() const
Definition: CMatrix.h:132
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
Definition: CModel.h:50
virtual size_t numCols() const
Definition: CMatrix.h:144
virtual CType * array()
Definition: CMatrix.h:337
CModel * getModel() const
CCopasiContainer * getObjectParent() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
virtual bool isValidProblem(const CCopasiProblem *pProblem)
Definition: CEFMMethod.cpp:136