COPASI API  4.16.103
CFitTask.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) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CFitTask class.
17  *
18  * This class implements a parameter estimation task which is comprised of a
19  * of a problem and a method.
20  *
21  */
22 #include "copasi.h"
23 
24 #include "CFitTask.h"
25 #include "CFitProblem.h"
26 #include "CFitMethod.h"
27 
29 
31  const CCopasiContainer * pParent):
32  COptTask(type, pParent)
33 {
35  mpProblem = new CFitProblem(type, this);
38  this->add(mpMethod, true);
39 
40  ((COptMethod *) mpMethod)->setProblem((COptProblem *) mpProblem);
41 }
42 
44  const CCopasiContainer * pParent):
45  COptTask(src, pParent)
46 {
48  mpProblem = new CFitProblem(*(CFitProblem *) src.mpProblem, this);
51  this->add(mpMethod, true);
52 
53  ((COptMethod *) mpMethod)->setProblem((COptProblem *) mpProblem);
54 }
55 
57 {cleanup();}
58 
60 
62 {
63  bool success = CCopasiTask::setCallBack(pCallBack);
64 
65  if (!mpProblem->setCallBack(pCallBack)) success = false;
66 
67  if (!mpMethod->setCallBack(pCallBack)) success = false;
68 
69  return success;
70 }
71 
73  COutputHandler * pOutputHandler,
74  std::ostream * pOstream)
75 {
76  return COptTask::initialize(of, pOutputHandler, pOstream);
77 }
78 
79 bool CFitTask::process(const bool & useInitialValues)
80 {
81  CFitProblem * pProblem = dynamic_cast<CFitProblem *>(mpProblem);
82  COptMethod * pMethod = dynamic_cast<COptMethod *>(mpMethod);
83 
84  if (!pProblem || !pMethod) return false;
85 
87 
88  if (useInitialValues)
89  {
90  pProblem->updateInitialState();
91  }
92 
93  pProblem->randomizeStartValues();
94  pProblem->rememberStartValues();
95 
97 
98  bool success = pMethod->optimise();
99 
100  pProblem->calculateStatistics();
101 
103 
104  return success;
105 }
106 
107 bool CFitTask::setMethodType(const int & type)
108 {
110 
111  if (mpMethod->getSubType() == Type) return true;
112 
113  pdelete(mpMethod);
114 
115  mpMethod = createMethod(Type);
116  this->add(mpMethod, true);
117 
118  return true;
119 }
120 
121 // virtual
122 CCopasiMethod * CFitTask::createMethod(const int & type) const
123 {
125 
126  return CFitMethod::createMethod(Type);
127 }
128 
130 {
131  CFitProblem * pFitProblem = dynamic_cast< CFitProblem * >(mpProblem);
132 
133  if (pFitProblem == NULL) return;
134 
135  pFitProblem->fixBuild55();
136 
137  return;
138 }
virtual bool setCallBack(CProcessReport *pCallBack)
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
#define pdelete(p)
Definition: copasi.h:215
void updateInitialState()
virtual bool setMethodType(const int &type)
Definition: CFitTask.cpp:107
virtual bool calculateStatistics(const C_FLOAT64 &factor=1.0e-003, const C_FLOAT64 &resolution=1.0e-009)
virtual bool setCallBack(CProcessReport *pCallBack)
virtual bool setCallBack(CProcessReport *pCallBack)
Definition: CFitTask.cpp:61
virtual void output(const COutputInterface::Activity &activity)
const CCopasiMethod::SubType & getSubType() const
void fixBuild55()
Definition: CFitTask.cpp:129
virtual bool isValidProblem(const CCopasiProblem *pProblem)
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
Definition: COptTask.cpp:101
CFitTask(const CCopasiTask::Type &type=CCopasiTask::parameterFitting, const CCopasiContainer *pParent=NULL)
Definition: CFitTask.cpp:30
void rememberStartValues()
virtual bool process(const bool &useInitialValues)
Definition: CFitTask.cpp:79
void randomizeStartValues()
virtual bool optimise()
Definition: COptMethod.cpp:184
void fixBuild55()
~CFitTask()
Definition: CFitTask.cpp:56
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
Definition: CFitTask.cpp:72
static COptMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::EvolutionaryProgram)
Definition: CFitMethod.cpp:26
void cleanup()
Definition: CFitTask.cpp:59
virtual CCopasiMethod * createMethod(const int &type) const
Definition: CFitTask.cpp:122
virtual bool add(CCopasiObject *pObject, const bool &adopt=true)
virtual bool setCallBack(CProcessReport *pCallBack)