COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFixLocalReactionParameters Class Reference

#include <CFixLocalReactionParameters.h>

Collaboration diagram for CFixLocalReactionParameters:
Collaboration graph
[legend]

Public Member Functions

 CFixLocalReactionParameters ()
 
void fixModel (CModel *pModel)
 
 ~CFixLocalReactionParameters ()
 

Private Member Functions

void changeModel ()
 
void checkModel ()
 

Private Attributes

std::multimap
< CCopasiParameter
*, CExpression * > 
mChanges
 
CModelmpModel
 

Detailed Description

Definition at line 23 of file CFixLocalReactionParameters.h.

Constructor & Destructor Documentation

CFixLocalReactionParameters::CFixLocalReactionParameters ( )

Constructor

Definition at line 23 of file CFixLocalReactionParameters.cpp.

23  :
24  mpModel(NULL),
25  mChanges()
26 {}
std::multimap< CCopasiParameter *, CExpression * > mChanges
CFixLocalReactionParameters::~CFixLocalReactionParameters ( )

Constructor

Definition at line 28 of file CFixLocalReactionParameters.cpp.

29 {}

Member Function Documentation

void CFixLocalReactionParameters::changeModel ( )
private

Change the model

Definition at line 81 of file CFixLocalReactionParameters.cpp.

References C_INT32, CModel::createModelValue(), CCopasiParameter::getCN(), CCopasiObject::getCN(), CModelEntity::getKey(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectName(), CCopasiParameter::getValue(), CReaction::isLocalParameter(), mChanges, MCXML, mpModel, CCopasiParameter::Value::pDOUBLE, CReaction::setParameterMapping(), and CCopasiMessage::WARNING.

Referenced by fixModel().

82 {
83  CCopasiParameter * pParameter = NULL;
84  CModelValue * pModelValue = NULL;
85  CReaction * pReaction = NULL;
86 
87  std::stringstream NameStream;
88  std::stringstream Message;
89 
90  std::string OldCN;
91  std::string NewCNBase;
92  std::string NewCN;
93  std::string Infix;
94 
95  std::string::size_type Start;
96 
97  // Loop through all changes.
98  std::multimap< CCopasiParameter *, CExpression * >::const_iterator itChanges = mChanges.begin();
99  std::multimap< CCopasiParameter *, CExpression * >::const_iterator endChanges = mChanges.end();
100 
101  for (; itChanges != endChanges; ++itChanges)
102  {
103  if (pParameter != itChanges->first)
104  {
105  // We have a new parameter
106  pParameter = itChanges->first;
107  OldCN = "<" + pParameter->getCN() + ",Reference=";
108 
109  // Create a global quantity of type FIXED.
110  std::string Name = pParameter->getObjectName();
111  pReaction = static_cast< CReaction * >(pParameter->getObjectAncestor("Reaction"));
112  Name += "{" + pReaction->getObjectName() + "}";
113 
114  pModelValue = mpModel->createModelValue(Name,
115  *pParameter->getValue().pDOUBLE);
116 
117  // In case the created name is not unique we append _n with increasing n
118  // until we succeed;
119  C_INT32 index = 0;
120  while (pModelValue == NULL)
121  {
122  NameStream.str("");
123  NameStream << Name << "_" << index++;
124  pModelValue = mpModel->createModelValue(NameStream.str(),
125  *pParameter->getValue().pDOUBLE);
126  }
127  NewCNBase = "<" + pModelValue->getCN() + ",Reference=";
128 
129  // If the parameter is actually used in the reaction
130  // it is changed to the global quantity.
131  if (pReaction->isLocalParameter(pParameter->getObjectName()))
132  pReaction->setParameterMapping(pParameter->getObjectName(), pModelValue->getKey());
133 
134  Message << " " << pParameter->getObjectName() << " in " << pReaction->getObjectName()
135  << " is replaced by " << pModelValue->getObjectName() << std::endl;
136  }
137 
138  // We need to distinguish between initial and other expressions.
139  if (itChanges->second->getObjectName().compare(0, 7, "Initial") == 0)
140  NewCN = NewCNBase + "Initial";
141  else
142  NewCN = NewCNBase;
143 
144  // Replace the OldCN of the parameter with the NewCN of global quantity in all expressions.
145  Infix = itChanges->second->getInfix();
146 
147  // There may be more than one occurrence.
148  Start = 0;
149  while ((Start = Infix.find(OldCN), Start) != std::string::npos)
150  Infix.replace(Start, OldCN.length(), NewCN);
151 
152  itChanges->second->setInfix(Infix);
153  }
154 
155  CCopasiMessage(CCopasiMessage::WARNING, MCXML + 14, Message.str().c_str());
156 }
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual CCopasiObjectName getCN() const
const std::string & getObjectName() const
std::multimap< CCopasiParameter *, CExpression * > mChanges
bool isLocalParameter(const size_t &index) const
Definition: CReaction.cpp:449
#define MCXML
CModelValue * createModelValue(const std::string &name, const C_FLOAT64 &value=0.0)
Definition: CModel.cpp:2838
#define C_INT32
Definition: copasi.h:90
virtual const std::string & getKey() const
struct MESSAGES Message
const Value & getValue() const
virtual CCopasiObjectName getCN() const
void setParameterMapping(const size_t &index, const std::string &key)
Definition: CReaction.cpp:339
void CFixLocalReactionParameters::checkModel ( )
private

Checks whether the model needs to be fixed and builds the listed of needed changes

Definition at line 43 of file CFixLocalReactionParameters.cpp.

References CCopasiVector< T >::begin(), CCopasiVector< T >::end(), CStateTemplate::getEntities(), CModel::getReactions(), CModel::getStateTemplate(), mChanges, mpModel, and CStateTemplate::size().

Referenced by fixModel().

44 {
45  // Clear recorded changes
46  mChanges.clear();
47 
48  // Check for all reactions
51 
52  for (; itReaction != endReaction; ++itReaction)
53  {
54  // Check for all local parameters
55  CCopasiParameterGroup::index_iterator itParameter = (*itReaction)->getParameters().beginIndex();
56  CCopasiParameterGroup::index_iterator endParameter = (*itReaction)->getParameters().endIndex();
57 
58  for (; itParameter != endParameter; ++itParameter)
59  {
60  // Check for all entities' expressions and initial expressions
61  // whether the CN of the parameter appears in the infix.
62  // Note '>' is already properly escaped in the CN
63  std::string CN = "<" + (*itParameter)->getCN() + ",Reference=Value>";
64 
65  CModelEntity *const*ppEntity = mpModel->getStateTemplate().getEntities();
66  CModelEntity *const*ppEntityEnd = ppEntity + mpModel->getStateTemplate().size();
67  for (; ppEntity != ppEntityEnd; ++ppEntity)
68  {
69  if ((*ppEntity)->getExpression().find(CN) != std::string::npos)
70  mChanges.insert
71  (std::pair< CCopasiParameter * const, CExpression * >(*itParameter, (*ppEntity)->getExpressionPtr()));
72 
73  if ((*ppEntity)->getInitialExpression().find(CN) != std::string::npos)
74  mChanges.insert
75  (std::pair< CCopasiParameter * const, CExpression * >(*itParameter, (*ppEntity)->getInitialExpressionPtr()));
76  }
77  }
78  }
79 }
iterator begin()
std::multimap< CCopasiParameter *, CExpression * > mChanges
const size_t & size() const
Definition: CState.cpp:242
iterator end()
std::vector< CType * >::const_iterator const_iterator
Definition: CCopasiVector.h:57
const CStateTemplate & getStateTemplate() const
Definition: CModel.cpp:1172
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
parameterGroup::iterator index_iterator
CModelEntity ** getEntities()
Definition: CState.cpp:204
void CFixLocalReactionParameters::fixModel ( CModel pModel)

Check and fix the given model if needed

Parameters
CModel* pModel

Definition at line 31 of file CFixLocalReactionParameters.cpp.

References changeModel(), checkModel(), mChanges, and mpModel.

32 {
33  if (pModel == NULL) return;
34 
35  mpModel = pModel;
36  checkModel();
37 
38  if (mChanges.size() == 0) return;
39 
40  changeModel();
41 }
std::multimap< CCopasiParameter *, CExpression * > mChanges

Member Data Documentation

std::multimap< CCopasiParameter *, CExpression * > CFixLocalReactionParameters::mChanges
private

Definition at line 65 of file CFixLocalReactionParameters.h.

Referenced by changeModel(), checkModel(), and fixModel().

CModel* CFixLocalReactionParameters::mpModel
private

The model which needs to be fixed.

Definition at line 60 of file CFixLocalReactionParameters.h.

Referenced by changeModel(), checkModel(), and fixModel().


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