COPASI API  4.16.103
CCopasiTask.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CCopasiTask.cpp,v $
3 // $Revision: 1.81 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/16 13:16:47 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 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  * CCopasiTask class.
25  * This class is used to describe a task in COPASI. This class is
26  * intended to be used as the parent class for all tasks within COPASI.
27  *
28  * Created for COPASI by Stefan Hoops 2003
29  */
30 
31 #include "copasi.h"
32 
33 #include "CCopasiTask.h"
34 #include "CCopasiProblem.h"
35 #include "CCopasiMethod.h"
36 #include "report/CReport.h"
37 #include "report/CKeyFactory.h"
39 #include "model/CModel.h"
40 #include "model/CState.h"
42 #include "report/CCopasiTimer.h"
45 
46 const std::string CCopasiTask::TypeName[] =
47 {
48  "Steady-State",
49  "Time-Course",
50  "Scan",
51  "Elementary Flux Modes",
52  "Optimization",
53  "Parameter Estimation",
54  "Metabolic Control Analysis",
55  "Lyapunov Exponents",
56  "Time Scale Separation Analysis",
57  "Sensitivities",
58  "Moieties",
59  "Cross Section",
60  "Linear Noise Approximation",
61  "not specified",
62  ""
63 };
64 
65 const char* CCopasiTask::XMLType[] =
66 {
67  "steadyState",
68  "timeCourse",
69  "scan",
70  "fluxMode",
71  "optimization",
72  "parameterFitting",
73  "metabolicControlAnalysis",
74  "lyapunovExponents",
75  "timeScaleSeparationAnalysis",
76  "sensitivities",
77  "moieties",
78  "crosssection",
79  "linearNoiseApproximation",
80  "unset",
81  NULL
82 };
83 
84 const unsigned int CCopasiTask::ValidMethods[] =
85 {
87 };
88 
89 bool CCopasiTask::isValidMethod(const unsigned int & method,
90  const unsigned int * validMethods)
91 {
92  unsigned C_INT32 i;
93 
94  for (i = 0; validMethods[i] != CCopasiMethod::unset; i++)
95  if (method == validMethods[i]) return true;
96 
97  return false;
98 }
99 
100 CCopasiTask::CCopasiTask(const std::string & name,
101  const CCopasiContainer * pParent,
102  const std::string & type):
103  CCopasiContainer(name, pParent, type),
104  mType(CCopasiTask::unset),
105  mKey(CCopasiRootContainer::getKeyFactory()->add("Task", this)),
106  mDescription(this),
107  mResult(this),
108  mScheduled(false),
109  mUpdateModel(false),
110  mpInitialState(NULL),
111  mpProblem(NULL),
112  mpMethod(NULL),
113  mReport(),
114  mpCallBack(NULL),
115  mpSliders(NULL),
116  mDoOutput(OUTPUT_SE),
117  mOutputCounter(0)
118 {initObjects();}
119 
121  const CCopasiContainer * pParent,
122  const std::string & type):
123  CCopasiContainer(CCopasiTask::TypeName[taskType], pParent, type),
124  mType(taskType),
125  mKey(CCopasiRootContainer::getKeyFactory()->add("Task", this)),
126  mDescription(this),
127  mResult(this),
128  mScheduled(false),
129  mUpdateModel(false),
130  mpInitialState(NULL),
131  mpProblem(NULL),
132  mpMethod(NULL),
133  mReport(),
134  mpCallBack(NULL),
135  mpSliders(NULL),
136  mDoOutput(OUTPUT_SE),
137  mpOutputHandler(NULL),
138  mOutputCounter(0)
139 {initObjects();}
140 
142  const CCopasiContainer * pParent):
143  CCopasiContainer(src, pParent),
144  mType(src.mType),
145  mKey(CCopasiRootContainer::getKeyFactory()->add("Task", this)),
146  mDescription(src.mDescription, this),
147  mResult(src.mResult, this),
148  mScheduled(src.mScheduled),
149  mUpdateModel(src.mUpdateModel),
150  mpInitialState(src.mpInitialState ? new CState(*src.mpInitialState) : NULL),
151  mpProblem(NULL),
152  mpMethod(NULL),
153  mReport(src.mReport),
154  mpCallBack(NULL),
155  mpSliders(NULL),
156  mDoOutput(OUTPUT_SE),
157  mpOutputHandler(NULL),
158  mOutputCounter(0)
159 {initObjects();}
160 
162 {
164 
167  pdelete(mpMethod);
169 }
170 
171 //const std::string & CCopasiTask::getName() const {return getObjectName();}
172 
173 //bool CCopasiTask::setName(const std::string & name)
174 //{return setObjectName(name);}
175 
177 
178 void CCopasiTask::setType(const CCopasiTask::Type & type) {mType = type;}
179 
180 const std::string & CCopasiTask::getKey() const {return mKey;}
181 
182 void CCopasiTask::setScheduled(const bool & scheduled) {mScheduled = scheduled;}
183 
184 const bool & CCopasiTask::isScheduled() const {return mScheduled;}
185 
186 void CCopasiTask::setUpdateModel(const bool & updateModel) {mUpdateModel = updateModel;}
187 
188 const bool & CCopasiTask::isUpdateModel() const {return mUpdateModel;}
189 
191 {
192  mpCallBack = pCallBack;
193  return true;
194 }
195 
197 {
198  return mpCallBack;
199 }
200 
202 {
203  return mpOutputHandler;
204 }
205 
206 
208  COutputHandler * pOutputHandler,
209  std::ostream * pOstream)
210 {
211  bool success = true;
212 
213  if (!mpProblem)
214  {
216  return false;
217  }
218 
219  if (!mpProblem->getModel())
220  {
222  return false;
223  }
224 
225  if (!mpMethod)
226  {
228  return false;
229  }
230 
232  {
234  return false;
235  }
236 
238 
240 
241  mDoOutput = of;
242  mpOutputHandler = pOutputHandler;
243 
244  if (mDoOutput == NO_OUTPUT ||
245  mpOutputHandler == NULL) return true;
246 
247  mOutputCounter = 0;
248 
249  if (mDoOutput & REPORT)
250  {
251  if (mReport.open(getObjectDataModel(), pOstream) &&
252  mReport.getTarget() != "")
254  else if (pOstream == NULL)
256  }
257 
258  std::vector< CCopasiContainer * > ListOfContainer;
259  ListOfContainer.push_back(this);
260 
261  CCopasiDataModel* pDataModel = getObjectDataModel();
262  assert(pDataModel != NULL);
263 
264  if (!mpOutputHandler->compile(ListOfContainer, pDataModel))
265  {
266  // Warning
268  success = false;
269  }
270 
271  return success;
272 }
273 
274 bool CCopasiTask::process(const bool &)
275 {return false;}
276 
278 {
279  setCallBack(NULL);
280 
281  if (!mUpdateModel)
282  {
283  if (mpInitialState)
284  {
286  }
287 
289  }
290 
292 
293  return true;
294 }
295 
297 
299 
300 // virtual
301 bool CCopasiTask::setMethodType(const int & C_UNUSED(type))
302 {
303  return false;
304 }
305 
306 // virtual
307 CCopasiMethod * CCopasiTask::createMethod(const int & /* type */) const
308 {
309  return NULL;
310 }
311 
313 
315 
317 
319 {return mDescription;}
320 
322 {return mResult;}
323 
325 
327 {return mpSliders;}
328 
329 // output stuff
330 
332 {
333  if (mpOutputHandler != NULL)
334  switch (activity)
335  {
337 
338  if (mDoOutput != NO_OUTPUT)
339  {
340  mpOutputHandler->output(activity);
341  ++mOutputCounter;
342  }
343 
344  break;
345 
347 
348  if (mDoOutput & OUTPUT_BEFORE)
349  mpOutputHandler->output(activity);
350 
351  break;
352 
354 
355  if (mDoOutput & OUTPUT_AFTER)
356  mpOutputHandler->output(activity);
357 
358  break;
359  }
360 }
361 
363 {
364  if (mpOutputHandler != NULL)
365  switch (activity)
366  {
368 
369  if (mDoOutput)
370  mpOutputHandler->separate(activity);
371 
372  break;
373 
375 
376  if (mDoOutput & OUTPUT_BEFORE)
377  mpOutputHandler->separate(activity);
378 
379  break;
380 
382 
383  if (mDoOutput & OUTPUT_AFTER)
384  mpOutputHandler->separate(activity);
385 
386  break;
387  }
388 }
389 
391 {
393  new CCopasiTimer(CCopasiTimer::WALL, this);
395 }
396 
398  CCopasiObject("Description", pParent, "Object")
399 {}
400 
402  const CCopasiContainer * pParent):
403  CCopasiObject(src, pParent)
404 {}
405 
407 
408 void CCopasiTask::CDescription::print(std::ostream * ostream) const
409 {*ostream << *this;}
410 
411 std::ostream &operator<<(std::ostream &os,
412  const CCopasiTask::CDescription & o)
413 {
414  const CCopasiTask & Task = *static_cast<const CCopasiTask *>(o.getObjectParent());
415 
416  os << Task.getObjectName() << " Task" << std::endl << std::endl;
417 
418  if (Task.getProblem())
419  {
420  Task.getProblem()->print(&os);
421  os << std::endl;
422  }
423  else
424  os << "No Problem Specified!" << std::endl;
425 
426  if (Task.getMethod())
427  {
428  Task.getMethod()->print(&os);
429  os << std::endl;
430  }
431  else
432  os << "No Method Specified!" << std::endl;
433 
434  return os;
435 }
436 
438  CCopasiObject("Result", pParent, "Object")
439 {}
440 
442  const CCopasiContainer * pParent):
443  CCopasiObject(src, pParent)
444 {}
445 
447 
448 void CCopasiTask::CResult::print(std::ostream * ostream) const
449 {*ostream << *this;}
450 
451 std::ostream &operator<<(std::ostream &os,
452  const CCopasiTask::CResult & o)
453 {
454  const CCopasiTask & Task = *static_cast<const CCopasiTask *>(o.getObjectParent());
455 
456  os << Task.getObjectName() << " Result:" << std::endl << std::endl;
457 
458  if (Task.getProblem())
459  {
460  Task.getProblem()->printResult(&os);
461  os << std::endl;
462  }
463  else
464  os << "No Problem Specified!" << std::endl;
465 
466  return os;
467 }
CCopasiDataModel * getObjectDataModel()
virtual void separate(const Activity &activity)
bool remove(const std::string &key)
CResult mResult
Definition: CCopasiTask.h:212
virtual ~CCopasiTask()
virtual bool setCallBack(CProcessReport *pCallBack)
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
virtual void print(std::ostream *ostream) const
#define pdelete(p)
Definition: copasi.h:215
void setScheduled(const bool &scheduled)
virtual void separate(const COutputInterface::Activity &activity)
static const std::string TypeName[]
Definition: CCopasiTask.h:67
CCopasiProblem * getProblem()
friend std::ostream & operator<<(std::ostream &os, const CCopasiObject &o)
const std::string & getObjectName() const
virtual void print(std::ostream *ostream) const
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
static const unsigned int ValidMethods[]
Definition: CCopasiTask.h:77
const bool & isUpdateModel() const
CDescription(const CCopasiContainer *pParent=NULL)
bool mScheduled
Definition: CCopasiTask.h:217
void cleanup()
void setInitialState(const CState &state)
Definition: CModel.cpp:1774
CCopasiTask(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const std::string &type="Task")
CProcessReport * mpCallBack
Definition: CCopasiTask.h:249
void setType(const Type &type)
Definition: CState.h:305
CCopasiParameterGroup * getSliders()
const bool & isScheduled() const
const std::string & getTarget() const
Definition: CReport.cpp:89
CProcessReport * getCallBack() const
virtual void output(const COutputInterface::Activity &activity)
#define C_UNUSED(p)
Definition: copasi.h:220
CReport mReport
Definition: CCopasiTask.h:244
#define C_INT32
Definition: copasi.h:90
CState * mpInitialState
Definition: CCopasiTask.h:229
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
#define MCCopasiTask
static const char * XMLType[]
Definition: CCopasiTask.h:72
virtual void addInterface(COutputInterface *pInterface)
OutputFlag mDoOutput
Definition: CCopasiTask.h:463
std::string mKey
Definition: CCopasiTask.h:202
const CDescription & getDescription() const
virtual void print(std::ostream *ostream) const
virtual bool setMethodType(const int &type)
bool mUpdateModel
Definition: CCopasiTask.h:223
unsigned C_INT32 mOutputCounter
Definition: CCopasiTask.h:465
CCopasiParameterGroup * mpSliders
Definition: CCopasiTask.h:254
CDescription mDescription
Definition: CCopasiTask.h:207
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel *pDataModel)
virtual bool process(const bool &useInitialValues)
virtual bool restore(const bool &updateModel)
CCopasiMethod * getMethod()
virtual void output(const Activity &activity)
static CKeyFactory * getKeyFactory()
CReport & getReport()
const CState & getInitialState() const
Definition: CModel.cpp:1768
const CResult & getResult() const
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
virtual const std::string & getKey() const
virtual void print(std::ostream *ostream) const
std::ostream * open(const CCopasiDataModel *pDataModel, std::ostream *pOstream=NULL)
Definition: CReport.cpp:336
Type getType() const
static bool isValidMethod(const unsigned int &method, const unsigned int *validMethods)
Definition: CCopasiTask.cpp:89
virtual CCopasiMethod * createMethod(const int &type) const
COutputHandler * getOutputHandler() const
CResult(const CCopasiContainer *pParent=NULL)
bool updateInitialValues()
Definition: CModel.cpp:1461
COutputHandler * mpOutputHandler
Definition: CCopasiTask.h:464
virtual bool restore()
void setUpdateModel(const bool &updateModel)
virtual void printResult(std::ostream *ostream) const
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
CModel * getModel() const
CCopasiContainer * getObjectParent() const
void initObjects()