COPASI API  4.16.103
CScanProblem.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CScanProblem class.
17  */
18 
19 #include <string>
20 #include <cmath>
21 
22 #include "copasi.h"
23 #include "CScanProblem.h"
24 //#include "model/CModel.h"
25 //#include "model/CState.h"
26 
27 /**
28  * Default constructor.
29  * @param "CModel *" pModel
30  */
32  CCopasiProblem(CCopasiTask::scan, pParent),
33  mpScanItems(NULL)
34 {
36 }
37 
38 /**
39  * Copy constructor.
40  * @param "const CScanProblem &" src
41  */
43  const CCopasiContainer * pParent):
44  CCopasiProblem(src, pParent),
45  mpScanItems(NULL)
46 {
48 }
49 
50 /**
51  * Destructor.
52  */
54 {}
55 
57 {
59 
60  addGroup("ScanItems");
61  mpScanItems = dynamic_cast<CCopasiParameterGroup*>(getParameter("ScanItems"));
62 
63  addParameter("Output in subtask", CCopasiParameter::BOOL, true);
64  addParameter("Adjust initial conditions", CCopasiParameter::BOOL, false);
65 }
66 
67 //***********************************
68 
70 {
71  setValue("Subtask", (unsigned C_INT32)type);
72 }
73 
75 {return *(CCopasiTask::Type *) getValue("Subtask").pUINT;}
76 
77 //************************************
78 
80 {
81  setValue("Output in subtask", ois);
82 }
83 
85 {return * getValue("Output in subtask").pBOOL;}
86 
87 //************************************
88 
90 {
91  setValue("Adjust initial conditions", aic);
92 }
93 
95 {return * getValue("Adjust initial conditions").pBOOL;}
96 
97 //************************************
98 
101 {}
102 
104 {
105  return mpScanItems->size();
106 }
107 
109 {
111 
112  if (tmp->getType() != CCopasiParameter::GROUP)
113  {
114  // ERROR: not a parameter group!!!
115  return NULL;
116  }
117 
118  return (CCopasiParameterGroup*)tmp;
119 }
120 
122 {
124 
125  if (tmp->getType() != CCopasiParameter::GROUP)
126  {
127  // ERROR: not a parameter group!!!
128  return NULL;
129  }
130 
131  return (CCopasiParameterGroup*)tmp;
132 }
133 
134 //CScanProblem::Type CScanProblem::getScanItemType(size_t index);
136 {
137  CCopasiParameterGroup * pItem = createScanItem(type, steps, obj);
138  mpScanItems->addParameter(pItem);
139 
140  return pItem;
141 }
142 
143 bool CScanProblem::removeScanItem(const size_t & index)
144 {
145  return mpScanItems->removeParameter(index);
146 }
147 
148 // static
150 {
151  CCopasiParameterGroup * tmp = new CCopasiParameterGroup("ScanItem");
152 
153  //create common parameters
154  tmp->addParameter("Number of steps", CCopasiParameter::UINT, (unsigned C_INT32) steps);
155  tmp->addParameter("Type", CCopasiParameter::UINT, (unsigned C_INT32) type);
156 
157  if (obj)
158  tmp->addParameter("Object", CCopasiParameter::CN, obj->getCN());
159  else
161 
162  //create specific parameters
163  if ((type == SCAN_LINEAR) || (type == SCAN_RANDOM))
164  {
165  tmp->addParameter("Minimum", CCopasiParameter::DOUBLE, (C_FLOAT64) 0.0);
166  tmp->addParameter("Maximum", CCopasiParameter::DOUBLE, (C_FLOAT64) 1.0);
167  tmp->addParameter("log", CCopasiParameter::BOOL, false);
168  }
169 
170  if (type == SCAN_RANDOM)
171  {
172  tmp->addParameter("Distribution type", CCopasiParameter::UINT, (unsigned C_INT32)0);
173  }
174 
175  if (type == SCAN_BREAK)
176  {
177  tmp->addParameter("Report break", CCopasiParameter::UINT, (unsigned C_INT32)0);
178  tmp->addParameter("Plot break", CCopasiParameter::UINT, (unsigned C_INT32)0);
179  }
180 
181  return tmp;
182 }
183 
185 {
186  mpScanItems->clear();
187 }
188 
190 {
193 
194  for (; it != end; ++it)
195  {
196  if ((*it)->getType() != CCopasiParameter::GROUP)
197  {
198  continue;
199  }
200 
201  CCopasiParameterGroup * pGroup = static_cast< CCopasiParameterGroup * >(*it);
202  CCopasiParameter * pParam = pGroup->getParameter("Type");
203 
204  if (pParam == NULL || * (Type *) pParam->getValue().pUINT != SCAN_RANDOM)
205  {
206  continue;
207  }
208 
209  // Check whether distribution type is set and not uniform
210  pParam = pGroup->getParameter("Distribution type");
211 
212  if (pParam == NULL || * (Type *) pParam->getValue().pUINT == 0)
213  {
214  continue;
215  }
216 
217  // Check whether log is set and true
218  pParam = pGroup->getParameter("log");
219 
220  if (pParam == NULL || * pParam->getValue().pBOOL == false)
221  {
222  continue;
223  }
224 
225  // We need to fix min and max
226  pParam = pGroup->getParameter("Minimum");
227 
228  if (pParam != NULL)
229  {
230  pParam->setValue(log(*pParam->getValue().pDOUBLE));
231  }
232 
233  pParam = pGroup->getParameter("Maximum");
234 
235  if (pParam != NULL)
236  {
237  pParam->setValue(log(*pParam->getValue().pDOUBLE));
238  }
239  }
240 
241  return;
242 }
void setSubtask(CCopasiTask::Type type)
bool setValue(const CType &value)
virtual CCopasiObjectName getCN() const
CScanProblem(const CCopasiContainer *pParent=NULL)
index_iterator endIndex() const
size_t getNumberOfScanItems() const
#define C_UNUSED(p)
Definition: copasi.h:220
#define C_INT32
Definition: copasi.h:90
void clearScanItems()
CCopasiParameterGroup * addScanItem(CScanProblem::Type type, size_t steps=5, const CCopasiObject *obj=NULL)
bool removeParameter(const std::string &name)
const CCopasiParameter::Type & getType() const
bool addGroup(const std::string &name)
index_iterator beginIndex() const
const Value & getValue() const
static CCopasiParameterGroup * createScanItem(CScanProblem::Type type, size_t steps=5, const CCopasiObject *obj=NULL)
bool setValue(const std::string &name, const CType &value)
unsigned C_INT32 * pUINT
CCopasiParameter * getParameter(const std::string &name)
void setContinueFromCurrentState(bool aic)
bool getContinueFromCurrentState() const
void setOutputInSubtask(bool ois)
CCopasiParameterGroup * mpScanItems
Definition: CScanProblem.h:46
void initializeParameter()
#define C_FLOAT64
Definition: copasi.h:92
const bool & getOutputInSubtask() const
bool addParameter(const CCopasiParameter &parameter)
CCopasiTask::Type getSubtask() const
const CCopasiParameterGroup * getScanItem(size_t index) const
parameterGroup::iterator index_iterator
void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::NEXT)
bool removeScanItem(const size_t &index)