COPASI API  4.16.103
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
CFunctionAnalyzer Class Reference

#include <CFunctionAnalyzer.h>

Collaboration diagram for CFunctionAnalyzer:
Collaboration graph
[legend]

Classes

class  CValue
 
class  Result
 

Public Types

enum  Mode { NOOBJECT, GENERAL, POSITIVE, ACTUAL }
 

Public Member Functions

 CFunctionAnalyzer (const CFunction *f, const CReaction *reaction=NULL)
 
void checkKineticFunction (const CFunction *f, const CReaction *reaction=NULL)
 
const ResultgetResult () const
 

Static Public Member Functions

static void constructCallParameters (const CFunctionParameters &fp, std::vector< CValue > &callParameters, bool posi)
 
static CValue evaluateNode (const CEvaluationNode *node, const std::vector< CValue > &callParameters, Mode mode)
 
static std::string write (int level, bool rt, const std::string &text, const std::string &longText)
 

Static Protected Member Functions

static void constructCallParametersActualValues (std::vector< CValue > &callParameters, const CReaction *reaction)
 

Protected Attributes

Result mResult
 

Detailed Description

This class performs an analysis of a kinetic function. The function to analyze is passed to the constructor. The result can be retrieved with the getResult() method. The Result class has methods for reporting. The reporting methods may assume that the function (and possibly the reaction) still exists, so don't delete the function between the analysis and the reporting of the results!

Definition at line 44 of file CFunctionAnalyzer.h.

Member Enumeration Documentation

Mode tells how to interpret an object in CValue arithmetics. NOOBJECT means objects are invalid (e.g. for functions, where no object nodes should occur). GENERAL means concentrations and volumes are positive, all other values positive, zero, or negative. POSITIVE means all objects are positive. ACTUAL means the actual value is used for local parameters and constant values.

Enumerator
NOOBJECT 
GENERAL 
POSITIVE 
ACTUAL 

Definition at line 204 of file CFunctionAnalyzer.h.

Constructor & Destructor Documentation

CFunctionAnalyzer::CFunctionAnalyzer ( const CFunction f,
const CReaction reaction = NULL 
)
inline

Definition at line 193 of file CFunctionAnalyzer.h.

References checkKineticFunction().

194  {checkKineticFunction(f, reaction);};
void checkKineticFunction(const CFunction *f, const CReaction *reaction=NULL)

Member Function Documentation

void CFunctionAnalyzer::checkKineticFunction ( const CFunction f,
const CReaction reaction = NULL 
)

Definition at line 1220 of file CFunctionAnalyzer.cpp.

References CFunctionAnalyzer::Result::clear(), constructCallParameters(), constructCallParametersActualValues(), evaluateNode(), CFunctionParameters::getNumberOfParametersByUsage(), CCopasiObject::getObjectName(), getResult(), CEvaluationTree::getRoot(), CFunction::getVariables(), CFunction::isReversible(), CFunctionAnalyzer::Result::mBPart, CFunctionAnalyzer::Result::mFPart, CFunctionAnalyzer::Result::mIrreversibleKineticsWithProducts, CFunctionAnalyzer::Result::mOriginalFunction, CFunctionAnalyzer::Result::mpFunction, CFunctionAnalyzer::Result::FunctionInformation::mProductZero, mResult, CFunctionAnalyzer::Result::mReversibleNonSplitable, CFunctionAnalyzer::Result::FunctionInformation::mSubstrateZero, CFunctionAnalyzer::Result::FunctionInformation::mUnchangedParameters, NOOBJECT, pdelete, CFunctionParameter::PRODUCT, CFunctionParameters::size(), CFunction::splitFunction(), CFunctionParameter::SUBSTRATE, TriFalse, TriTrue, and CFunctionAnalyzer::CValue::zero.

Referenced by CFunctionAnalyzer().

1221 {
1222  mResult.clear();
1223  mResult.mpFunction = f;
1224 
1225  //assume mass action is ok.
1226  if (dynamic_cast<const CMassAction*>(f)) return;
1227 
1228  if (f->isReversible() == TriFalse)
1230  {
1231  // An irreversible kinetics should not depend on products.
1233  }
1234 
1235  std::vector<CValue> callParameters;
1236  CValue tmpValue;
1237 
1238  //***** just the kinetic function *****
1239 
1240  //construct call parameter vector
1241  constructCallParameters(f->getVariables(), callParameters, false);
1242  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1243  mResult.mOriginalFunction.mUnchangedParameters.push_back(tmpValue);
1244 
1245  //construct call parameter vector
1246  constructCallParameters(f->getVariables(), callParameters, true);
1247  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1248  mResult.mOriginalFunction.mUnchangedParameters.push_back(tmpValue);
1249 
1250  if (reaction)
1251  {
1252  //construct call parameter vector
1253  constructCallParametersActualValues(callParameters, reaction);
1254  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1255  mResult.mOriginalFunction.mUnchangedParameters.push_back(tmpValue);
1256  }
1257  else
1258  {
1259  }
1260 
1261  //***** now the kinetic function with single substrates or products == zero ******
1262  std::vector<CValue> tmpValueVector;
1263 
1264  size_t i, imax = f->getVariables().size();
1265 
1266  for (i = 0; i < imax; ++i)
1267  {
1268  if (f->getVariables()[i]->getUsage() == CFunctionParameter::SUBSTRATE)
1269  {
1270  tmpValueVector.clear();
1271 
1272  //construct call parameter vector
1273  constructCallParameters(f->getVariables(), callParameters, false);
1274  //set one substrate to zero
1275  callParameters[i] = CValue::zero;
1276  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1277  tmpValueVector.push_back(tmpValue);
1278 
1279  //construct call parameter vector
1280  constructCallParameters(f->getVariables(), callParameters, true);
1281  //set one substrate to zero
1282  callParameters[i] = CValue::zero;
1283  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1284  tmpValueVector.push_back(tmpValue);
1285 
1286  if (reaction)
1287  {
1288  //construct call parameter vector
1289  constructCallParametersActualValues(callParameters, reaction);
1290  //set one substrate to zero
1291  callParameters[i] = CValue::zero;
1292  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1293 
1294  //test if result is indeed 0 (as is required)
1295  tmpValueVector.push_back(tmpValue);
1296  }
1297  else
1298  {
1299  }
1300 
1301  mResult.mOriginalFunction.mSubstrateZero.push_back(std::pair<std::pair<size_t, std::string>, std::vector<CValue> >(std::pair<size_t, std::string>(i, f->getVariables()[i]->getObjectName()), tmpValueVector));
1302  }
1303 
1304  if (f->getVariables()[i]->getUsage() == CFunctionParameter::PRODUCT)
1305  {
1306  tmpValueVector.clear();
1307 
1308  //construct call parameter vector
1309  constructCallParameters(f->getVariables(), callParameters, false);
1310  //set one product to zero
1311  callParameters[i] = CValue::zero;
1312  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1313  tmpValueVector.push_back(tmpValue);
1314 
1315  //construct call parameter vector
1316  constructCallParameters(f->getVariables(), callParameters, true);
1317  //set one substrate to zero
1318  callParameters[i] = CValue::zero;
1319  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1320  tmpValueVector.push_back(tmpValue);
1321 
1322  if (reaction)
1323  {
1324  //construct call parameter vector
1325  constructCallParametersActualValues(callParameters, reaction);
1326  //set one substrate to zero
1327  callParameters[i] = CValue::zero;
1328  tmpValue = CFunctionAnalyzer::evaluateNode(f->getRoot(), callParameters, NOOBJECT);
1329  tmpValueVector.push_back(tmpValue);
1330  }
1331  else
1332  {
1333  }
1334 
1335  mResult.mOriginalFunction.mProductZero.push_back(std::pair<std::pair<size_t, std::string>, std::vector<CValue> >(std::pair<size_t, std::string>(i, f->getVariables()[i]->getObjectName()), tmpValueVector));
1336  }
1337  }
1338 
1339  //try to split reversible functions
1340  if ((f->isReversible() == TriTrue))
1341  {
1342  std::pair<CFunction *, CFunction *> tmp;
1343  tmp = f->splitFunction(NULL, "f", "b");
1344 
1345  if ((tmp.first == NULL) || (tmp.second == NULL))
1346  {
1348  }
1349  else
1350  {
1351  CFunctionAnalyzer fa1(tmp.first);
1352  mResult.mFPart = fa1.getResult().mOriginalFunction;
1353 
1354  CFunctionAnalyzer fa2(tmp.second);
1355  mResult.mBPart = fa2.getResult().mOriginalFunction;
1356  }
1357 
1358  pdelete(tmp.first);
1359  pdelete(tmp.second);
1360  }
1361 }
#define pdelete(p)
Definition: copasi.h:215
std::vector< std::pair< std::pair< size_t, std::string >, std::vector< CValue > > > mProductZero
const std::string & getObjectName() const
static CValue evaluateNode(const CEvaluationNode *node, const std::vector< CValue > &callParameters, Mode mode)
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
static void constructCallParametersActualValues(std::vector< CValue > &callParameters, const CReaction *reaction)
FunctionInformation mBPart
static void constructCallParameters(const CFunctionParameters &fp, std::vector< CValue > &callParameters, bool posi)
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
std::pair< CFunction *, CFunction * > splitFunction(const CEvaluationNode *node, const std::string &name1, const std::string &name2) const
Definition: CFunction.cpp:445
FunctionInformation mOriginalFunction
std::vector< std::pair< std::pair< size_t, std::string >, std::vector< CValue > > > mSubstrateZero
const CFunction * mpFunction
CEvaluationNode * getRoot()
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
FunctionInformation mFPart
void CFunctionAnalyzer::constructCallParameters ( const CFunctionParameters fp,
std::vector< CValue > &  callParameters,
bool  posi 
)
static

constructs call parameters for use with the evaluateNode() method

Definition at line 994 of file CFunctionAnalyzer.cpp.

References CFunctionParameter::MODIFIER, CFunctionParameter::PARAMETER, CFunctionAnalyzer::CValue::positive, CFunctionParameter::PRODUCT, CFunctionParameters::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TEMPORARY, CFunctionParameter::TIME, CFunctionAnalyzer::CValue::unknown, CFunctionParameter::VARIABLE, and CFunctionParameter::VOLUME.

Referenced by checkKineticFunction(), and CFunction::splitFunction().

995 {
996  size_t i, imax = fp.size();
997  callParameters.resize(imax);
998 
999  for (i = 0; i < imax; ++i)
1000  {
1001  CFunctionParameter::Role role = fp[i]->getUsage();
1002 
1003  switch (role)
1004  {
1009  callParameters[i] = CValue::positive;
1010  break;
1011 
1016  callParameters[i] = posi ? CValue::positive : CValue::unknown;
1017  break;
1018  }
1019  }
1020 }
void CFunctionAnalyzer::constructCallParametersActualValues ( std::vector< CValue > &  callParameters,
const CReaction reaction 
)
staticprotected

constructs call parameters for use with the evaluateNode() method, using the actual values for local parameters and fixed entities.

Definition at line 1023 of file CFunctionAnalyzer.cpp.

References CModelEntity::FIXED, CKeyFactory::get(), CReaction::getFunctionParameters(), CModelEntity::getInitialValue(), CCopasiRootContainer::getKeyFactory(), CReaction::getParameterMappings(), CModelEntity::getStatus(), CCopasiParameter::getValue(), CFunctionParameter::MODIFIER, CFunctionParameter::PARAMETER, CCopasiParameter::Value::pDOUBLE, CFunctionAnalyzer::CValue::positive, CFunctionParameter::PRODUCT, CFunctionParameters::size(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TEMPORARY, CFunctionParameter::TIME, CFunctionAnalyzer::CValue::unknown, CFunctionParameter::VARIABLE, and CFunctionParameter::VOLUME.

Referenced by checkKineticFunction().

1024 {
1025  size_t i, imax = reaction->getFunctionParameters().size();
1026  callParameters.resize(imax);
1027 
1028  for (i = 0; i < imax; ++i)
1029  {
1030  const CModelEntity * pME;
1031  const CCopasiParameter * pCP;
1032 
1033  CFunctionParameter::Role role = reaction->getFunctionParameters()[i]->getUsage();
1034 
1035  switch (role)
1036  {
1042  callParameters[i] = CValue::unknown;
1043  pME = dynamic_cast<const CModelEntity*>(CCopasiRootContainer::getKeyFactory()->get(reaction->getParameterMappings()[i][0]));
1044 
1045  if (pME)
1046  {
1047  if (pME->getStatus() == CModelEntity::FIXED)
1048  callParameters[i] = CValue(pME->getInitialValue());
1049  else
1050  callParameters[i] = CValue::positive;
1051  }
1052 
1053  pCP = dynamic_cast<const CCopasiParameter*>(CCopasiRootContainer::getKeyFactory()->get(reaction->getParameterMappings()[i][0]));
1054 
1055  if (pCP)
1056  {
1057  callParameters[i] = CValue(*pCP->getValue().pDOUBLE);
1058  }
1059 
1060  break;
1061 
1065  callParameters[i] = CValue::unknown;
1066  break;
1067  }
1068  }
1069 }
CCopasiObject * get(const std::string &key)
const C_FLOAT64 & getInitialValue() const
const CFunctionParameters & getFunctionParameters() const
Definition: CReaction.cpp:576
const Value & getValue() const
static CKeyFactory * getKeyFactory()
const CModelEntity::Status & getStatus() const
const std::vector< std::vector< std::string > > & getParameterMappings() const
Definition: CReaction.h:285
CFunctionAnalyzer::CValue CFunctionAnalyzer::evaluateNode ( const CEvaluationNode node,
const std::vector< CValue > &  callParameters,
Mode  mode 
)
static

Do the CValue arithmetics of a tree. The callParameters contain the CValues corresponding to the CEvaluationNodeVariable nodes. The value of mode should not have an effect if this is called for a function tree.

Definition at line 1072 of file CFunctionAnalyzer.cpp.

References CEvaluationNode::CALL, CEvaluationNode::CHOICE, CNodeContextIterator< Node, Context >::context(), CEvaluationNodeOperator::DIVIDE, CNodeContextIterator< Node, Context >::end(), CEvaluationNode::FUNCTION, CEvaluationNodeCall::getCalledTree(), CEvaluationNodeVariable::getIndex(), CEvaluationNodeCall::getListOfChildNodes(), CEvaluationTree::getRoot(), CEvaluationNode::getType(), CEvaluationNode::getValue(), CFunction::getVariables(), CFunctionAnalyzer::CValue::invalid, CEvaluationNodeOperator::MINUS, CEvaluationNodeFunction::MINUS, CEvaluationNodeOperator::MULTIPLY, CNodeContextIterator< Node, Context >::next(), NOOBJECT, CEvaluationNode::NUMBER, CEvaluationNode::OBJECT, CEvaluationNode::OPERATOR, CNodeContextIterator< Node, Context >::parentContextPtr(), CEvaluationNodeOperator::PLUS, CFunctionAnalyzer::CValue::positive, POSITIVE, CEvaluationNodeOperator::POWER, CFunctionParameters::size(), CEvaluationNode::subType(), CEvaluationNode::type(), CFunctionAnalyzer::CValue::unknown, and CEvaluationNode::VARIABLE.

Referenced by checkKineticFunction(), and CEvaluationNode::findTopMinus().

1074 {
1076  CValue Result = CValue::invalid;
1077 
1078  while (itNode.next() != itNode.end())
1079  {
1080  if (*itNode == NULL)
1081  {
1082  continue;
1083  }
1084 
1085  switch (CEvaluationNode::type(itNode->getType()))
1086  {
1088 
1089  switch ((CEvaluationNodeOperator::SubType) CEvaluationNode::subType(itNode->getType()))
1090  {
1092  Result = itNode.context()[0] * itNode.context()[1];
1093  break;
1094 
1096  Result = itNode.context()[0] / itNode.context()[1];
1097  break;
1098 
1100  Result = itNode.context()[0] + itNode.context()[1];
1101  break;
1102 
1104  Result = itNode.context()[0] - itNode.context()[1];
1105  break;
1106 
1108  Result = itNode.context()[0] ^ itNode.context()[1];
1109  break;
1110 
1111  // case MODULUS:
1112  // Value = (C_FLOAT64) (((size_t) mpLeft->value()) % ((size_t) mpRight->value()));
1113  // break;
1114  //
1115 
1116  default:
1117  Result = CValue::unknown;
1118  break;
1119  }
1120 
1121  break;
1122 
1124  Result = itNode->getValue();
1125  break;
1126 
1128  {
1129  const CEvaluationNodeVariable * pENV = static_cast<const CEvaluationNodeVariable*>(*itNode);
1130 
1131  if (callParameters.size() < pENV->getIndex() + 1)
1132  {
1133  Result = CValue::invalid;
1134  }
1135  else
1136  {
1137  Result = callParameters[pENV->getIndex()];
1138  }
1139  }
1140 
1141  break;
1142 
1144 
1145  switch ((CEvaluationNodeFunction::SubType) CEvaluationNode::subType(itNode->getType()))
1146  {
1148  Result = itNode.context()[0].invert();
1149  break;
1150 
1151  default:
1152  Result = CValue::unknown;
1153  break;
1154  }
1155 
1156  break;
1157 
1159  //TODO: implement
1160  Result = CValue::unknown;
1161  break;
1162 
1163  case CEvaluationNode::CALL:
1164  {
1165  const CEvaluationNodeCall * pENCall = static_cast<const CEvaluationNodeCall*>(*itNode);
1166 
1167  //some checks
1168  if (pENCall->getCalledTree() && pENCall->getCalledTree()->getRoot())
1169  {
1170  const CFunction * tmpFunc = dynamic_cast<const CFunction*>(pENCall->getCalledTree());
1171 
1172  if (tmpFunc && tmpFunc->getVariables().size() == pENCall->getListOfChildNodes().size())
1173  {
1174  Result = evaluateNode(pENCall->getCalledTree()->getRoot(), itNode.context(), mode);
1175  }
1176  else
1177  {
1178  Result = CValue::invalid;
1179  }
1180  }
1181  else
1182  {
1183  Result = CValue::invalid;
1184  }
1185  }
1186  break;
1187 
1189 
1190  if (mode == NOOBJECT)
1191  {
1192  Result = CValue::invalid;
1193  }
1194  else if (mode == POSITIVE)
1195  {
1196  Result = CValue::positive;
1197  }
1198  else
1199  {
1200  //TODO: implement GENERAL and ACTUAL
1201  Result = CValue::unknown;
1202  }
1203 
1204  break;
1205 
1206  default:
1207  Result = CValue::unknown;
1208  break;
1209  }
1210 
1211  if (itNode.parentContextPtr() != NULL)
1212  {
1213  itNode.parentContextPtr()->push_back(Result);
1214  }
1215  }
1216 
1217  return Result;
1218 }
const CEvaluationTree * getCalledTree() const
static CValue evaluateNode(const CEvaluationNode *node, const std::vector< CValue > &callParameters, Mode mode)
const std::vector< CEvaluationNode * > getListOfChildNodes() const
static Type type(const Type &type)
static Type subType(const Type &type)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CEvaluationNode * getRoot()
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
const Result& CFunctionAnalyzer::getResult ( ) const
inline

Definition at line 196 of file CFunctionAnalyzer.h.

References mResult.

Referenced by checkKineticFunction().

196 {return mResult;};
std::string CFunctionAnalyzer::write ( int  level,
bool  rt,
const std::string &  text,
const std::string &  longText 
)
static

Definition at line 1364 of file CFunctionAnalyzer.cpp.

Referenced by CFunctionAnalyzer::Result::FunctionInformation::writeAnalysis(), CModelAnalyzer::ReactionResult::writeResult(), and CFunctionAnalyzer::Result::writeResult().

1365 {
1366  std::string color;
1367 
1368  switch (level)
1369  {
1370  case 0: color = "\"#008000\""; break;
1371 
1372  case 1: color = "\"#909000\""; break;
1373 
1374  case 2: color = "\"#800000\""; break;
1375 
1376  case 3: color = "\"#c04040\""; break;
1377 
1378  default: color = "\"#0000a0\""; break;
1379  }
1380 
1381  std::string ret;
1382 
1383  if (rt) ret += "<p><font color=" + color + ">";
1384 
1385  ret += (text + "\n");
1386 
1387  if (longText != "")
1388  {
1389  if (rt) ret += "<br>";
1390 
1391  ret += longText + "\n";
1392  }
1393 
1394  if (rt) ret += "</font></p>";
1395 
1396  return ret;
1397 }

Member Data Documentation

Result CFunctionAnalyzer::mResult
protected

Definition at line 220 of file CFunctionAnalyzer.h.

Referenced by checkKineticFunction(), and getResult().


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