COPASI API  4.16.103
COptMethodPraxis.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/optimization/COptMethodPraxis.cpp,v $
3 // $Revision: 1.13 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/06/20 21:16:37 $
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 #include "copasi.h"
24 
25 #include "COptMethodPraxis.h"
26 #include "COptProblem.h"
27 #include "COptItem.h"
28 #include "COptTask.h"
29 
32 
34  COptMethod(CCopasiTask::optimization, CCopasiMethod::Praxis, pParent),
35  mpPraxis(new FPraxisTemplate<COptMethodPraxis>(this, &COptMethodPraxis::evaluateFunction)),
36  mpCPraxis(new CPraxis())
37 {
38  addParameter("Tolerance", CCopasiParameter::DOUBLE, (C_FLOAT64) 1.e-005);
39  initObjects();
40 }
41 
43  const CCopasiContainer * pParent):
44  COptMethod(src, pParent),
45  mpPraxis(new FPraxisTemplate<COptMethodPraxis>(this, &COptMethodPraxis::evaluateFunction)),
46  mpCPraxis(new CPraxis())
47 {initObjects();}
48 
50 {
53  cleanup();
54 }
55 
57 {
59 }
60 
62 {
63  if (!initialize()) return false;
64 
65  C_INT i;
66  C_INT prin = 0;
67  C_FLOAT64 tmp = 0.0;
68  C_FLOAT64 machep, stepmx, d1, d2;
69 
70  // initial point is the first guess but we have to make sure that
71  // we are within the parameter domain
72 
73  for (i = 0; i < mVariableSize; i++)
74  {
75  const COptItem & OptItem = *(*mpOptItem)[i];
76  mCurrent[i] = OptItem.getStartValue();
77 
78  //force it to be within the bounds
79  switch (OptItem.checkConstraint(mCurrent[i]))
80  {
81  case - 1:
82  mCurrent[i] = *OptItem.getLowerBoundValue();
83  break;
84 
85  case 1:
86  mCurrent[i] = *OptItem.getUpperBoundValue();
87  break;
88  }
89 
90  //set the value
91  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
92  }
93 
94  // Report the first value as the current best
95  mBestValue = evaluate();
96  mBest = mCurrent;
98 
99  // We found a new best value lets report it.
101 
102  //estimate the machine epsilon
103  d1 = 1.0;
104 
105  do
106  {
107  d1 /= 2.0;
108  d2 = d1 + 1.;
109  }
110  while (d2 != 1.0);
111 
112  machep = d1 * 2.0;
113 
114  //estimate the maximum step size
115  stepmx = 0.6;
116 
117  //carry out the minimisation
118  try
119  {
120  mpCPraxis->praxis_(&mTolerance, &machep, &stepmx, &mVariableSize, &prin, mCurrent.array(), mpPraxis, &tmp);
121  }
122  catch (bool)
123  {}
124 
125  return true;
126 }
127 
129 {
130  cleanup();
131 
132  if (!COptMethod::initialize()) return false;
133 
134  mTolerance = * getValue("Tolerance").pDOUBLE;
135  mIteration = 0;
136 
137  mVariableSize = (C_INT) mpOptItem->size();
140 
141  mContinue = true;
142 
143  return true;
144 }
145 
147 {
148  return true;
149 }
150 
151 // evaluate the value of the objective function
153 {
154  C_INT i;
155 
156  for (i = 0; i < *n; i++)
157  (*(*mpSetCalculateVariable)[i])(x[i]);
158 
159  //carry out the function evaluation
160  evaluate();
161 
163  {
164  // We found a new best value lets report it.
165  // and store that value
166  for (i = 0; i < *n; i++)
167  mBest[i] = x[i];
168 
171 
172  // We found a new best value lets report it.
174  }
175 
176  if (!mContinue)
177  throw bool(mContinue);
178 
179  return mEvaluationValue;
180 }
181 
183 {
184  // We do not need to check whether the parametric constraints are fulfilled
185  // since the parameters are created within the bounds.
186 
189 
190  // when we leave the either the parameter or functional domain
191  // we penalize the objective value by forcing it to be larger
192  // than the best value recorded so far.
197 
198  return mEvaluationValue;
199 }
C_FLOAT64 praxis_(C_FLOAT64 *t0, C_FLOAT64 *machep, C_FLOAT64 *h0, C_INT *n, C_INT *prin, C_FLOAT64 *x, FPraxis *f, C_FLOAT64 *fmin)
Definition: CPraxis.cpp:69
virtual ~COptMethodPraxis()
#define C_INT
Definition: copasi.h:115
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
#define pdelete(p)
Definition: copasi.h:215
virtual bool initialize()
Definition: COptMethod.cpp:189
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
CVector< C_FLOAT64 > mBest
virtual bool optimise()
const C_FLOAT64 & evaluateFunction(C_FLOAT64 *, C_INT *)
CVector< C_FLOAT64 > mCurrent
virtual bool calculate()
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const Value & getValue() const
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
unsigned C_INT32 mIteration
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool checkFunctionalConstraints()
COptMethodPraxis(const COptMethodPraxis &src, const CCopasiContainer *pParent=NULL)
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
C_FLOAT64 mEvaluationValue
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
bool addParameter(const CCopasiParameter &parameter)
virtual bool initialize()
virtual bool checkParametricConstraints()
virtual bool cleanup()
const C_FLOAT64 & getCalculateValue() const
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
const C_FLOAT64 & evaluate()