COPASI API  4.16.103
COptMethod.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 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) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * COptMethod class
17  * This class describes the interface to all optimization methods.
18  * The various method like RandomSearch or GA have to be derived from
19  * this class.
20  *
21  * Created for COPASI by Stefan Hoops 2002
22  */
23 
24 #include <limits.h>
25 
26 #include "copasi.h"
27 
28 #include "COptTask.h"
29 #include "COptMethod.h"
30 #include "COptProblem.h"
31 
32 #include "CRandomSearch.h"
33 #include "COptMethodDE.h"
34 #include "COptMethodSS.h"
35 #include "COptMethodGA.h"
36 #include "COptMethodGASR.h"
37 #include "COptMethodHookeJeeves.h"
39 #include "COptMethodNelderMead.h"
40 #include "COptMethodPS.h"
41 #include "COptMethodSA.h"
42 #include "COptMethodCoranaWalk.h"
43 #include "COptMethodSRES.h"
44 #include "COptMethodStatistics.h"
46 #include "COptMethodEP.h"
47 #include "COptMethodPraxis.h"
49 
51 {
52  COptMethod * pMethod = NULL;
53 
54  switch (subType)
55  {
57  pMethod = new COptMethodDE();
58  break;
59 
60  case ScatterSearch:
61  pMethod = new COptMethodSS();
62  break;
63 
65  pMethod = new COptMethodEP();
66  break;
67 
68  case GeneticAlgorithm:
69  pMethod = new COptMethodGA();
70  break;
71 
72  case GeneticAlgorithmSR:
73  pMethod = new COptMethodGASR();
74  break;
75 
76  case HookeJeeves:
77  pMethod = new COptMethodHookeJeeves();
78  break;
79 
80  case LevenbergMarquardt:
81  pMethod = new COptMethodLevenbergMarquardt();
82  break;
83 
84  case NelderMead:
85  pMethod = new COptMethodNelderMead();
86  break;
87 
88  case RandomSearch:
89  pMethod = new CRandomSearch();
90  break;
91 
92  case SimulatedAnnealing:
93  pMethod = new COptMethodSA();
94  break;
95 
96  case CoranaWalk:
97  pMethod = new COptMethodCoranaWalk();
98  break;
99 
100  case SRES:
101  pMethod = new COptMethodSRES();
102  break;
103 
104  case Statistics:
105  pMethod = new COptMethodStatistics();
106  break;
107 
108  case SteepestDescent:
109  pMethod = new COptMethodSteepestDescent();
110  break;
111 
112  case ParticleSwarm:
113  pMethod = new COptMethodPS();
114  break;
115 
116  case Praxis:
117  pMethod = new COptMethodPraxis();
118  break;
119 
120  case TruncatedNewton:
121  pMethod = new COptMethodTruncatedNewton();
122  break;
123 
124  default:
125  pMethod = new COptMethodGA();
126  break;
127  }
128 
129  return pMethod;
130 }
131 
132 // Default constructor
134  CCopasiMethod(CCopasiTask::optimization, CCopasiMethod::unset),
135  mpOptProblem(NULL),
136  mpParentTask(NULL),
137  mBounds(false),
138  mpSetCalculateVariable(NULL),
139  mpOptItem(NULL),
140  mpOptContraints(NULL)
142 
144  const COptMethod::SubType & subType,
145  const CCopasiContainer * pParent):
146  CCopasiMethod(taskType, subType, pParent),
147  mpOptProblem(NULL),
148  mpParentTask(NULL),
149  mBounds(false),
150  mpSetCalculateVariable(NULL),
151  mpOptItem(NULL),
152  mpOptContraints(NULL)
154 
156  const CCopasiContainer * pParent):
157  CCopasiMethod(src, pParent),
158  mpOptProblem(src.mpOptProblem),
159  mpParentTask(src.mpParentTask),
160  mBounds(src.mBounds),
161  mpSetCalculateVariable(src.mpSetCalculateVariable),
162  mpOptItem(src.mpOptItem),
163  mpOptContraints(src.mpOptContraints)
165 
166 //YOHE: seems "virtual" cannot be outside of class declaration
168 {}
169 
171 {
172  assert(problem);
173  mpOptProblem = problem;
174 }
175 
176 // Returns True if this method is capable of handling adjustable parameter boundary
177 // constraints, False otherwise
179 {
180  return mBounds;
181 }
182 
183 //virtual C_INT32 COptMethod::Optimise(C_FLOAT64 (*func) (void))
185 {
186  return false;
187 }
188 
190 {
191  if (!mpOptProblem)
192  return false;
193 
195  return false;
196 
198  return false;
199 
201  return false;
202 
203  mpParentTask = dynamic_cast<COptTask *>(getObjectParent());
204 
205  if (!mpParentTask) return false;
206 
207  /*if (pTask &&
208  (mpReport = &pTask->getReport()) &&
209  !mpReport->getStream())
210  mpReport = NULL;*/
211 
212  return true;
213 }
214 
216 {return true;}
217 
218 //virtual
220 {
221  if (!CCopasiMethod::isValidProblem(pProblem)) return false;
222 
223  const COptProblem * pTP = dynamic_cast<const COptProblem *>(pProblem);
224 
225  if (!pTP)
226  {
227  CCopasiMessage(CCopasiMessage::EXCEPTION, "Problem is not an optimization problem.");
228  return false;
229  }
230 
231  return true;
232 }
virtual bool isValidProblem(const CCopasiProblem *pProblem)
Definition: COptMethod.cpp:219
COptTask * mpParentTask
Definition: COptMethod.h:58
virtual bool initialize()
Definition: COptMethod.cpp:189
virtual ~COptMethod()
Definition: COptMethod.cpp:167
void setProblem(COptProblem *problem)
Definition: COptMethod.cpp:170
static COptMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::RandomSearch)
Definition: COptMethod.cpp:50
const std::vector< COptItem * > & getConstraintList() const
const std::vector< UpdateMethod * > & getCalculateVariableUpdateMethods() const
COptProblem * mpOptProblem
Definition: COptMethod.h:56
const std::vector< COptItem * > * mpOptContraints
Definition: COptMethod.h:75
const bool mBounds
Definition: COptMethod.h:60
bool isBounded(void)
Definition: COptMethod.cpp:178
virtual bool isValidProblem(const CCopasiProblem *pProblem)
virtual bool cleanup()
Definition: COptMethod.cpp:215
const std::vector< COptItem * > & getOptItemList() const
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
virtual bool optimise()
Definition: COptMethod.cpp:184
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
CCopasiContainer * getObjectParent() const
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202