COPASI API  4.16.103
COptMethodStatistics.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/optimization/COptMethodStatistics.cpp,v $
3 // $Revision: 1.8 $
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 "COptMethod.h"
26 #include "COptProblem.h"
27 #include "COptItem.h"
28 #include "COptTask.h"
29 
30 #include "COptMethodStatistics.h"
31 
34 
36  COptMethod(CCopasiTask::optimization, CCopasiMethod::Statistics)
37 {
38  initObjects();
39 }
40 
42  COptMethod(src)
43 {initObjects();}
44 
45 /**
46  * Destructor
47  */
49 {//*** added similar to coptga
50  cleanup();
51 }
52 
53 /**
54  * Optimizer Function
55  * Returns: true if properly initialized
56  * should return a boolean
57  */
59 {
60  cleanup();
61 
62  if (!COptMethod::initialize()) return false;
63 
64  mBestValue = std::numeric_limits< C_FLOAT64 >::infinity();
65 
66  mVariableSize = mpOptItem->size();
68 
69  return true;
70 }
71 
72 /**
73  * Optimizer Function
74  * Returns: nothing
75  * should return a boolean
76  */
78 {
79  bool Continue = true;
80 
81  if (!initialize()) return false;
82 
83  size_t j;
84 
85  // Initialize the population
86  // first individual is the initial guess
87  for (j = 0; j < mVariableSize; j++)
88  {
89  C_FLOAT64 & mut = mIndividual[j];
90  COptItem & OptItem = *(*mpOptItem)[j];
91 
92  mut = OptItem.getStartValue();
93 
94  // force it to be within the bounds
95  switch (OptItem.checkConstraint(mut))
96  {
97  case - 1:
98  mut = *OptItem.getLowerBoundValue();
99  break;
100 
101  case 1:
102  mut = *OptItem.getUpperBoundValue();
103  break;
104  }
105 
106  // We need to set the value here so that further checks take
107  // account of the value.
108  (*(*mpSetCalculateVariable)[j])(mut);
109  }
110 
111  Continue = evaluate(mIndividual);
112 
113  mBestValue = mValue;
115 
116  // We found a new best value lets report it.
117  //if (mpReport) mpReport->printBody();
119 
120  return true;
121 }
122 
123 // evaluate the fitness of one individual
125 {
126  bool Continue = true;
127 
128  // We do not need to check whether the parametric constraints are fulfilled
129  // since the parameters are created within the bounds.
130 
131  // evaluate the fitness
132  Continue = mpOptProblem->calculate();
133 
134  // check whether the functional constraints are fulfilled
137  else
139 
140  return Continue;
141 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
virtual bool initialize()
Definition: COptMethod.cpp:189
CVector< C_FLOAT64 > mIndividual
bool evaluate(const CVector< C_FLOAT64 > &individual)
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)
virtual bool cleanup()
Definition: COptMethod.cpp:215
virtual bool calculate()
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool checkFunctionalConstraints()
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
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
const C_FLOAT64 & getCalculateValue() const
#define max(a, b)
Definition: f2c.h:176