COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
COptMethodDE Class Reference

#include <COptMethodDE.h>

Inheritance diagram for COptMethodDE:
Inheritance graph
[legend]
Collaboration diagram for COptMethodDE:
Collaboration graph
[legend]

Public Member Functions

 COptMethodDE (const COptMethodDE &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodDE ()
 
- Public Member Functions inherited from COptMethod
 COptMethod (const COptMethod &src, const CCopasiContainer *pParent=NULL)
 
bool isBounded (void)
 
virtual bool isValidProblem (const CCopasiProblem *pProblem)
 
void setProblem (COptProblem *problem)
 
virtual ~COptMethod ()
 
- Public Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiMethod &src, const CCopasiContainer *pParent=NULL)
 
const CCopasiMethod::SubTypegetSubType () const
 
const CCopasiTask::TypegetType () const
 
virtual void load (CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
 
virtual void print (std::ostream *ostream) const
 
virtual void printResult (std::ostream *ostream) const
 
virtual bool setCallBack (CProcessReport *pCallBack)
 
virtual ~CCopasiMethod ()
 
- Public Member Functions inherited from CCopasiParameterGroup
bool addGroup (const std::string &name)
 
bool addParameter (const CCopasiParameter &parameter)
 
bool addParameter (const std::string &name, const CCopasiParameter::Type type)
 
template<class CType >
bool addParameter (const std::string &name, const CCopasiParameter::Type type, const CType &value)
 
void addParameter (CCopasiParameter *pParameter)
 
CCopasiParameterGroupassertGroup (const std::string &name)
 
template<class CType >
CCopasiParameterassertParameter (const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
 
index_iterator beginIndex () const
 
name_iterator beginName () const
 
 CCopasiParameterGroup (const CCopasiParameterGroup &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameterGroup (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &objectType="ParameterGroup")
 
void clear ()
 
virtual bool elevateChildren ()
 
index_iterator endIndex () const
 
name_iterator endName () const
 
CCopasiParameterGroupgetGroup (const std::string &name)
 
const CCopasiParameterGroupgetGroup (const std::string &name) const
 
CCopasiParameterGroupgetGroup (const size_t &index)
 
const CCopasiParameterGroupgetGroup (const size_t &index) const
 
size_t getIndex (const std::string &name) const
 
std::string getKey (const std::string &name) const
 
std::string getKey (const size_t &index) const
 
virtual const std::string & getName (const size_t &index) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
CCopasiParametergetParameter (const std::string &name)
 
const CCopasiParametergetParameter (const std::string &name) const
 
CCopasiParametergetParameter (const size_t &index)
 
const CCopasiParametergetParameter (const size_t &index) const
 
CCopasiParameter::Type getType (const std::string &name) const
 
CCopasiParameter::Type getType (const size_t &index) const
 
std::string getUniqueParameterName (const CCopasiParameter *pParameter) const
 
const CCopasiParameter::ValuegetValue (const std::string &name) const
 
const CCopasiParameter::ValuegetValue (const size_t &index) const
 
CCopasiParameter::ValuegetValue (const std::string &name)
 
CCopasiParameter::ValuegetValue (const size_t &index)
 
CCopasiParameterGroupoperator= (const CCopasiParameterGroup &rhs)
 
bool removeParameter (const std::string &name)
 
bool removeParameter (const size_t &index)
 
template<class CType >
bool setValue (const std::string &name, const CType &value)
 
template<class CType >
bool setValue (const size_t &index, const CType &value)
 
size_t size () const
 
bool swap (const size_t &iFrom, const size_t &iTo)
 
bool swap (index_iterator &from, index_iterator &to)
 
virtual ~CCopasiParameterGroup ()
 
- Public Member Functions inherited from CCopasiParameter
 CCopasiParameter (const CCopasiParameter &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameter (const std::string &name, const Type &type, const void *pValue=NULL, const CCopasiContainer *pParent=NULL, const std::string &objectType="Parameter")
 
virtual CCopasiObjectName getCN () const
 
virtual const std::string & getKey () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const CCopasiParameter::TypegetType () const
 
const ValuegetValue () const
 
ValuegetValue ()
 
virtual voidgetValuePointer () const
 
CCopasiObjectgetValueReference () const
 
bool isValidValue (const C_FLOAT64 &value) const
 
bool isValidValue (const C_INT32 &value) const
 
bool isValidValue (const unsigned C_INT32 &value) const
 
bool isValidValue (const bool &value) const
 
bool isValidValue (const std::string &value) const
 
bool isValidValue (const CCopasiObjectName &value) const
 
bool isValidValue (const std::vector< CCopasiParameter * > &value) const
 
CCopasiParameteroperator= (const CCopasiParameter &rhs)
 
template<class CType >
bool setValue (const CType &value)
 
bool setValue (const std::vector< CCopasiParameter * > &value)
 
virtual ~CCopasiParameter ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Private Member Functions

void boost ()
 
virtual bool cleanup ()
 
 COptMethodDE (const CCopasiContainer *pParent=NULL)
 
bool creation (size_t first, size_t last=std::numeric_limits< size_t >::max())
 
bool evaluate (const CVector< C_FLOAT64 > &individual)
 
size_t fittest ()
 
virtual bool initialize ()
 
void initObjects ()
 
bool replicate ()
 

Private Attributes

size_t mBestIndex
 
C_FLOAT64 mBestValue
 
C_FLOAT64 mEvaluationValue
 
unsigned C_INT32 mGeneration
 
unsigned C_INT32 mGenerations
 
size_t mhGenerations
 
std::vector< CVector
< C_FLOAT64 > * > 
mIndividual
 
C_FLOAT64 mMutationVarians
 
unsigned C_INT32 mPopulationSize
 
CPermutationmpPermutation
 
CRandommpRandom
 
CVector< C_FLOAT64mValue
 
size_t mVariableSize
 

Friends

COptMethodCOptMethod::createMethod (CCopasiMethod::SubType subType)
 

Additional Inherited Members

- Public Types inherited from CCopasiMethod
enum  SubType {
  unset = 0, RandomSearch, RandomSearchMaster, SimulatedAnnealing,
  CoranaWalk, DifferentialEvolution, ScatterSearch, GeneticAlgorithm,
  EvolutionaryProgram, SteepestDescent, HybridGASA, GeneticAlgorithmSR,
  HookeJeeves, LevenbergMarquardt, NelderMead, SRES,
  Statistics, ParticleSwarm, Praxis, TruncatedNewton,
  Newton, deterministic, LSODAR, directMethod,
  stochastic, tauLeap, adaptiveSA, hybrid,
  hybridLSODA, hybridODE45, DsaLsodar, tssILDM,
  tssILDMModified, tssCSP, mcaMethodReder, scanMethod,
  lyapWolf, sensMethod, EFMAlgorithm, EFMBitPatternTreeAlgorithm,
  EFMBitPatternAlgorithm, Householder, crossSectionMethod, linearNoiseApproximation
}
 
- Public Types inherited from CCopasiParameterGroup
typedef parameterGroup::iterator index_iterator
 
typedef
CCopasiContainer::objectMap::iterator 
name_iterator
 
typedef std::vector
< CCopasiParameter * > 
parameterGroup
 
- Public Types inherited from CCopasiParameter
enum  Type {
  DOUBLE = 0, UDOUBLE, INT, UINT,
  BOOL, GROUP, STRING, CN,
  KEY, FILE, EXPRESSION, INVALID
}
 
- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Member Functions inherited from COptMethod
static COptMethodcreateMethod (CCopasiMethod::SubType subType=CCopasiMethod::RandomSearch)
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Attributes inherited from CCopasiMethod
static const std::string SubTypeName []
 
static const char * XMLSubType []
 
- Static Public Attributes inherited from CCopasiParameter
static const std::string TypeName []
 
static const char * XMLType []
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Protected Member Functions inherited from COptMethod
 COptMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiParameterGroup
 CCopasiParameterGroup ()
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 
- Protected Attributes inherited from COptMethod
const bool mBounds
 
const std::vector< COptItem * > * mpOptContraints
 
const std::vector< COptItem * > * mpOptItem
 
COptProblemmpOptProblem
 
COptTaskmpParentTask
 
const std::vector
< UpdateMethod * > * 
mpSetCalculateVariable
 
- Protected Attributes inherited from CCopasiMethod
CProcessReportmpCallBack
 
- Protected Attributes inherited from CCopasiParameter
std::string mKey
 
CCopasiObjectmpValueReference
 
size_t mSize
 
Value mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 20 of file COptMethodDE.h.

Constructor & Destructor Documentation

COptMethodDE::COptMethodDE ( const COptMethodDE src,
const CCopasiContainer pParent = NULL 
)

Copy Constructor

Parameters
constCOptMethodDE & src
constCCopasiContainer * pParent (default: NULL)

Definition at line 46 of file COptMethodDE.cpp.

References initObjects().

47  :
48  COptMethod(src, pParent),
49  mGenerations(0),
50  mPopulationSize(0),
51  mpRandom(NULL),
52  mVariableSize(0),
53  mIndividual(0),
54  mpPermutation(NULL),
56  mValue(0),
57  mMutationVarians(0.1),
60  mGeneration(0)
61 {initObjects();}
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
CPermutation * mpPermutation
Definition: COptMethodDE.h:134
size_t mBestIndex
Definition: COptMethodDE.h:152
C_FLOAT64 mBestValue
Definition: COptMethodDE.h:151
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t mVariableSize
Definition: COptMethodDE.h:124
unsigned C_INT32 mGenerations
Definition: COptMethodDE.h:104
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
void initObjects()
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
C_FLOAT64 mMutationVarians
Definition: COptMethodDE.h:149
unsigned C_INT32 mGeneration
Definition: COptMethodDE.h:153
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
#define max(a, b)
Definition: f2c.h:176
COptMethodDE::~COptMethodDE ( )
virtual

Destructor

Definition at line 63 of file COptMethodDE.cpp.

References cleanup().

64 {cleanup();}
virtual bool cleanup()
COptMethodDE::COptMethodDE ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 22 of file COptMethodDE.cpp.

References CCopasiParameterGroup::addParameter(), C_INT32, initObjects(), CRandom::mt19937, and CCopasiParameter::UINT.

22  :
24  mGenerations(0),
25  mPopulationSize(0),
26  mpRandom(NULL),
27  mVariableSize(0),
28  mIndividual(0),
29  mpPermutation(NULL),
31  mValue(0),
32  mMutationVarians(0.1),
35  mGeneration(0)
36 
37 {
38  addParameter("Number of Generations", CCopasiParameter::UINT, (unsigned C_INT32) 2000);
39  addParameter("Population Size", CCopasiParameter::UINT, (unsigned C_INT32) 10);
40  addParameter("Random Number Generator", CCopasiParameter::UINT, (unsigned C_INT32) CRandom::mt19937);
41  addParameter("Seed", CCopasiParameter::UINT, (unsigned C_INT32) 0);
42 
43  initObjects();
44 }
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
CPermutation * mpPermutation
Definition: COptMethodDE.h:134
size_t mBestIndex
Definition: COptMethodDE.h:152
C_FLOAT64 mBestValue
Definition: COptMethodDE.h:151
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_INT32
Definition: copasi.h:90
size_t mVariableSize
Definition: COptMethodDE.h:124
unsigned C_INT32 mGenerations
Definition: COptMethodDE.h:104
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
void initObjects()
bool addParameter(const CCopasiParameter &parameter)
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
C_FLOAT64 mMutationVarians
Definition: COptMethodDE.h:149
unsigned C_INT32 mGeneration
Definition: COptMethodDE.h:153
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
#define max(a, b)
Definition: f2c.h:176

Member Function Documentation

void COptMethodDE::boost ( )
private

Definition at line 237 of file COptMethodDE.cpp.

References mIndividual, mPopulationSize, and mValue.

238 {
239  size_t i;
240 
241  for (i = 2 * mPopulationSize; i < 3 * mPopulationSize; i++)
242  if (mValue[i] < mValue[i - 2 * mPopulationSize])
243  {
244  *mIndividual[i - 2 * mPopulationSize] = *mIndividual[i];
245  mValue[i - 2 * mPopulationSize] = mValue[i];
246  }
247 }
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
bool COptMethodDE::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 380 of file COptMethodDE.cpp.

References mIndividual, mpPermutation, mpRandom, and pdelete.

Referenced by initialize(), optimise(), and ~COptMethodDE().

381 {
382  size_t i;
383 
384  pdelete(mpRandom);
386 
387  for (i = 0; i < mIndividual.size(); i++)
388  pdelete(mIndividual[i]);
389 
390  return true;
391 }
#define pdelete(p)
Definition: copasi.h:215
CPermutation * mpPermutation
Definition: COptMethodDE.h:134
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
bool COptMethodDE::creation ( size_t  first,
size_t  last = std::numeric_limits<size_t>::max() 
)
private

Initialise the population

Parameters
size_tfirst
size_tlast (default: population size)
Returns
bool continue

Definition at line 250 of file COptMethodDE.cpp.

References C_FLOAT64, COptItem::checkConstraint(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), COptItem::getUpperBoundValue(), max, mBestIndex, mEvaluationValue, min, mIndividual, mPopulationSize, mpRandom, mValue, and mVariableSize.

Referenced by optimise().

251 {
252  size_t Last = std::min(last, (size_t) mPopulationSize);
253  size_t i, j;
254 
255  C_FLOAT64 mn;
256  C_FLOAT64 mx;
257  C_FLOAT64 la;
258 
259  bool Continue = true;
260 
261  for (i = first; i < Last && Continue; i++)
262  {
263  // We do not want to loose the best individual;
264  if (mBestIndex != i)
265  for (j = 0; j < mVariableSize; j++)
266  {
267  // calculate lower and upper bounds
268  COptItem & OptItem = *(*mpOptItem)[j];
269  mn = *OptItem.getLowerBoundValue();
270  mx = *OptItem.getUpperBoundValue();
271 
272  C_FLOAT64 & mut = (*mIndividual[i])[j];
273 
274  try
275  {
276  // determine if linear or log scale
277  if ((mn < 0.0) || (mx <= 0.0))
278  mut = mn + mpRandom->getRandomCC() * (mx - mn);
279  else
280  {
281  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
282 
283  if (la < 1.8)
284  mut = mn + mpRandom->getRandomCC() * (mx - mn);
285  else
286  mut = pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
287  }
288  }
289 
290  catch (...)
291  {
292  mut = (mx + mn) * 0.5;
293  }
294 
295  // force it to be within the bounds
296  switch (OptItem.checkConstraint(mut))
297  {
298  case - 1:
299  mut = *OptItem.getLowerBoundValue();
300  break;
301 
302  case 1:
303  mut = *OptItem.getUpperBoundValue();
304  break;
305  }
306 
307  // We need to set the value here so that further checks take
308  // account of the value.
309  (*(*mpSetCalculateVariable)[j])(mut);
310  }
311 
312  // calculate its fitness
313  Continue &= evaluate(*mIndividual[i]);
315  }
316 
317  return Continue;
318 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
size_t mBestIndex
Definition: COptMethodDE.h:152
bool evaluate(const CVector< C_FLOAT64 > &individual)
size_t mVariableSize
Definition: COptMethodDE.h:124
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
#define C_FLOAT64
Definition: copasi.h:92
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
#define min(a, b)
Definition: f2c.h:175
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
#define max(a, b)
Definition: f2c.h:176
bool COptMethodDE::evaluate ( const CVector< C_FLOAT64 > &  individual)
private

Evaluate the fitness of one individual

Parameters
constCVector< C_FLOAT64 > & individual
Returns
bool continue

Definition at line 67 of file COptMethodDE.cpp.

References COptProblem::calculate(), COptProblem::checkFunctionalConstraints(), COptProblem::getCalculateValue(), mEvaluationValue, and COptMethod::mpOptProblem.

Referenced by creation(), optimise(), and replicate().

68 {
69  bool Continue = true;
70 
71  // We do not need to check whether the parametric constraints are fulfilled
72  // since the parameters are created within the bounds.
73 
74  // evaluate the fitness
75  Continue &= mpOptProblem->calculate();
76 
77  // check whether the functional constraints are fulfilled
79  mEvaluationValue = std::numeric_limits<C_FLOAT64>::infinity();
80  else
82 
83  return Continue;
84 }
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
virtual bool checkFunctionalConstraints()
const C_FLOAT64 & getCalculateValue() const
size_t COptMethodDE::fittest ( void  )
private

Find the best individual at this generation

Returns
size_t fittest

Definition at line 221 of file COptMethodDE.cpp.

References C_FLOAT64, C_INVALID_INDEX, max, mPopulationSize, and mValue.

Referenced by optimise().

222 {
223  size_t i, BestIndex = C_INVALID_INDEX;
225 
226  for (i = 0; i < mPopulationSize; i++)
227  if (mValue[i] < BestValue)
228  {
229  BestIndex = i;
230  BestValue = mValue[i];
231  }
232 
233  return BestIndex;
234 }
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_FLOAT64
Definition: copasi.h:92
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
#define max(a, b)
Definition: f2c.h:176
bool COptMethodDE::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 325 of file COptMethodDE.cpp.

References CProcessReport::addItem(), cleanup(), CRandom::createGenerator(), CProcessReport::finishItem(), CCopasiParameter::getValue(), COptMethod::initialize(), mBestValue, mGeneration, mGenerations, mhGenerations, mIndividual, mMutationVarians, CCopasiMethod::mpCallBack, COptMethod::mpOptItem, mPopulationSize, mpPermutation, mpRandom, mValue, mVariableSize, CCopasiParameter::Value::pUINT, CVector< CType >::resize(), and CCopasiParameterGroup::setValue().

Referenced by optimise().

326 {
327  cleanup();
328 
329  size_t i;
330 
331  if (!COptMethod::initialize())
332  {
333  if (mpCallBack)
335 
336  return false;
337  }
338 
339  mGenerations = * getValue("Number of Generations").pUINT;
340  mGeneration = 0;
341 
342  if (mpCallBack)
343  mhGenerations =
344  mpCallBack->addItem("Current Generation",
345  mGeneration,
346  & mGenerations);
347 
348  mGeneration++;
349 
350  mPopulationSize = * getValue("Population Size").pUINT;
351 
352  if (mPopulationSize < 4)
353  {
354  mPopulationSize = 4;
355  setValue("Population Size", mPopulationSize);
356  }
357 
358  mpRandom =
359  CRandom::createGenerator(* (CRandom::Type *) getValue("Random Number Generator").pUINT,
360  * getValue("Seed").pUINT);
361 
363 
364  mVariableSize = mpOptItem->size();
365 
366  mIndividual.resize(3 * mPopulationSize);
367 
368  for (i = 0; i < 3 * mPopulationSize; i++)
370 
371  mValue.resize(3 * mPopulationSize);
372  mValue = std::numeric_limits<C_FLOAT64>::infinity();
373  mBestValue = std::numeric_limits<C_FLOAT64>::infinity();
374 
375  mMutationVarians = 0.1;
376 
377  return true;
378 }
virtual bool cleanup()
virtual bool initialize()
Definition: COptMethod.cpp:189
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
CPermutation * mpPermutation
Definition: COptMethodDE.h:134
C_FLOAT64 mBestValue
Definition: COptMethodDE.h:151
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
size_t mVariableSize
Definition: COptMethodDE.h:124
unsigned C_INT32 mGenerations
Definition: COptMethodDE.h:104
size_t mhGenerations
Definition: COptMethodDE.h:109
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
const Value & getValue() const
bool setValue(const std::string &name, const CType &value)
unsigned C_INT32 * pUINT
virtual bool finishItem(const size_t &handle)
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
C_FLOAT64 mMutationVarians
Definition: COptMethodDE.h:149
unsigned C_INT32 mGeneration
Definition: COptMethodDE.h:153
CProcessReport * mpCallBack
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
void COptMethodDE::initObjects ( )
private

Initialize contained objects.

Definition at line 320 of file COptMethodDE.cpp.

References CCopasiContainer::addObjectReference(), mGeneration, and CCopasiObject::ValueInt.

Referenced by COptMethodDE().

321 {
323 }
unsigned C_INT32 mGeneration
Definition: COptMethodDE.h:153
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodDE::optimise ( void  )
virtual

Execute the optimization algorithm calling simulation routine when needed. It is noted that this procedure can give feedback of its progress by the callback function set with SetCallback. @ return success;

Reimplemented from COptMethod.

Definition at line 393 of file COptMethodDE.cpp.

References C_FLOAT64, C_INVALID_INDEX, COptItem::checkConstraint(), cleanup(), creation(), COutputInterface::DURING, evaluate(), CProcessReport::finishItem(), fittest(), COptItem::getLowerBoundValue(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), initialize(), mBestIndex, mBestValue, mEvaluationValue, mGeneration, mGenerations, mhGenerations, mIndividual, CCopasiMethod::mpCallBack, COptMethod::mpOptProblem, mPopulationSize, COptMethod::mpParentTask, mValue, mVariableSize, CCopasiTask::output(), CProcessReport::progressItem(), replicate(), and COptProblem::setSolution().

394 {
395  bool Continue = true;
396 
397  if (!initialize())
398  {
399  if (mpCallBack)
401 
402  return false;
403  }
404 
405  size_t i;
406 
407  // initialise the population
408  // first individual is the initial guess
409  for (i = 0; i < mVariableSize; i++)
410  {
411  C_FLOAT64 & mut = (*mIndividual[0])[i];
412  COptItem & OptItem = *(*mpOptItem)[i];
413 
414  mut = OptItem.getStartValue();
415 
416  // force it to be within the bounds
417  switch (OptItem.checkConstraint(mut))
418  {
419  case - 1:
420  mut = *OptItem.getLowerBoundValue();
421  break;
422 
423  case 1:
424  mut = *OptItem.getUpperBoundValue();
425  break;
426  }
427 
428  // We need to set the value here so that further checks take
429  // account of the value.
430  (*(*mpSetCalculateVariable)[i])(mut);
431  }
432 
433  Continue &= evaluate(*mIndividual[0]);
435 
436  if (!isnan(mEvaluationValue))
437  {
438  // and store that value
439  mBestValue = mValue[0];
440  Continue &= mpOptProblem->setSolution(mBestValue, *mIndividual[0]);
441 
442  // We found a new best value lets report it.
444  }
445 
446  // the others are random
447  Continue &= creation(1, mPopulationSize);
448 
449  mBestIndex = fittest();
450 
451  if (mBestIndex != C_INVALID_INDEX &&
453  {
454  // and store that value
457 
458  // We found a new best value lets report it.
460  }
461 
462  if (!Continue)
463  {
464  if (mpCallBack)
466 
467  cleanup();
468  return true;
469  }
470 
471  size_t Stalled = 0;
472 
473  // ITERATE FOR gener GENERATIONS
474  for (mGeneration = 2;
475  mGeneration <= mGenerations && Continue;
476  mGeneration++, Stalled++)
477  {
478  if (Stalled > 10)
479  {
480  Continue &= creation((size_t) 0.4 * mPopulationSize, (size_t) 0.8 * mPopulationSize);
481  }
482 
483  // perturb the population a bit
484  Continue &= creation((size_t)(mPopulationSize * 0.9), mPopulationSize);
485 
486  Continue &= replicate();
487 
488  // get the index of the fittest
489  mBestIndex = fittest();
490 
491  if (mBestIndex != C_INVALID_INDEX &&
492  mValue[mBestIndex] < mBestValue)
493  {
494  Stalled = 0;
496 
497  Continue &= mpOptProblem->setSolution(mBestValue, *mIndividual[mBestIndex]);
498 
499  // We found a new best value lets report it.
500  //if (mpReport) mpReport->printBody();
502  }
503 
504  if (mpCallBack)
505  Continue &= mpCallBack->progressItem(mhGenerations);
506  }
507 
508  if (mpCallBack)
510 
511  cleanup();
512 
513  return true;
514 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
virtual bool cleanup()
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
size_t mBestIndex
Definition: COptMethodDE.h:152
C_FLOAT64 mBestValue
Definition: COptMethodDE.h:151
bool evaluate(const CVector< C_FLOAT64 > &individual)
bool creation(size_t first, size_t last=std::numeric_limits< size_t >::max())
#define C_INVALID_INDEX
Definition: copasi.h:222
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
virtual bool progressItem(const size_t &handle)
size_t mVariableSize
Definition: COptMethodDE.h:124
unsigned C_INT32 mGenerations
Definition: COptMethodDE.h:104
size_t mhGenerations
Definition: COptMethodDE.h:109
bool replicate()
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
virtual bool initialize()
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool finishItem(const size_t &handle)
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
#define C_FLOAT64
Definition: copasi.h:92
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
unsigned C_INT32 mGeneration
Definition: COptMethodDE.h:153
CProcessReport * mpCallBack
size_t fittest()
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144
bool COptMethodDE::replicate ( void  )
private

Replicate the individuals with crossover

Returns
bool continue

Definition at line 86 of file COptMethodDE.cpp.

References C_FLOAT64, C_INVALID_INDEX, COptItem::checkConstraint(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomNormal(), CRandom::getRandomU(), COptItem::getUpperBoundValue(), mBestIndex, mEvaluationValue, mIndividual, mMutationVarians, mPopulationSize, mpPermutation, mpRandom, mValue, mVariableSize, CPermutation::next(), CPermutation::pick(), and CPermutation::shuffle().

Referenced by optimise().

87 {
88  size_t i, j;
89  size_t a, b, c;
90 
91  bool Continue = true;
92 
93  for (i = mPopulationSize; i < 2 * mPopulationSize && Continue; i++)
94  {
96 
97  // MUTATION a, b, c in [0, mPopulationSize - 1]
98  a = mpPermutation->pick();
99  // b is guaranteed to be different from a
100  b = mpPermutation->next();
101  // c is guaranteed to be different from a and b
102  c = mpPermutation->next();
103 
104  // MUTATE CURRENT GENERATION
105  for (j = 0; j < mVariableSize; j++)
106  {
107  COptItem & OptItem = *(*mpOptItem)[j];
108  C_FLOAT64 & mut = (*mIndividual[i])[j];
109 
110  mut = (*mIndividual[c])[j] + 2 * ((*mIndividual[a])[j] - (*mIndividual[b])[j]);
111 
112  // force it to be within the bounds
113  switch (OptItem.checkConstraint(mut))
114  {
115  case - 1:
116  mut = *OptItem.getLowerBoundValue();
117  break;
118 
119  case 1:
120  mut = *OptItem.getUpperBoundValue();
121  break;
122  }
123 
124  // We need to set the value here so that further checks take
125  // account of the value.
126  (*(*mpSetCalculateVariable)[j])(mut);
127  }
128 
129  Continue &= evaluate(*mIndividual[i]);
131  }
132 
133  //CROSSOVER MUTATED GENERATION WITH THE CURRENT ONE
134  for (i = 2 * mPopulationSize; i < 3 * mPopulationSize && Continue; i++)
135  {
136  for (j = 0; j < mVariableSize; j++)
137  {
138 
139  COptItem & OptItem = *(*mpOptItem)[j];
140  C_FLOAT64 & mut = (*mIndividual[i])[j];
141 
142  size_t r = mpRandom->getRandomU(mPopulationSize - 1);
143 
144  if (r < 0.6 * mPopulationSize)
145  {
146  mut = (*mIndividual[i - mPopulationSize])[j] *
148  }
149 
150  else
151  mut = (*mIndividual[i - 2 * mPopulationSize])[j];
152 
153  // force it to be within the bounds
154  switch (OptItem.checkConstraint(mut))
155  {
156  case - 1:
157  mut = *OptItem.getLowerBoundValue();
158  break;
159 
160  case 1:
161  mut = *OptItem.getUpperBoundValue();
162  break;
163  }
164 
165  (*(*mpSetCalculateVariable)[j])(mut);
166  }
167 
168  Continue &= evaluate(*mIndividual[i]);
170  }
171 
172  //SELECT NEXT GENERATION
173  for (i = 2 * mPopulationSize; i < 3 * mPopulationSize && Continue; i++)
174  {
175  if (mValue[i - mPopulationSize] > mValue[i] && mValue[i - 2 * mPopulationSize] > mValue[i])
176  {
177  *mIndividual[i - 2 * mPopulationSize] = *mIndividual[i];
178  mValue[i - 2 * mPopulationSize] = mValue[i];
179  }
180  else if (mValue[i - mPopulationSize] < mValue[i - 2 * mPopulationSize])
181  {
184  }
185  else if (mBestIndex != i && mBestIndex == C_INVALID_INDEX)
186  {
187  for (j = 0; j < mVariableSize; j++)
188  {
189  COptItem & OptItem = *(*mpOptItem)[j];
190  C_FLOAT64 & mut = (*mIndividual[i - 2 * mPopulationSize])[j];
191 
192  size_t r = mpRandom->getRandomU(mPopulationSize - 1);
193 
194  if (r < 0.6 * mPopulationSize)
196 
197  // force it to be within the bounds
198  switch (OptItem.checkConstraint(mut))
199  {
200  case - 1:
201  mut = *OptItem.getLowerBoundValue();
202  break;
203 
204  case 1:
205  mut = *OptItem.getUpperBoundValue();
206  break;
207  }
208 
209  (*(*mpSetCalculateVariable)[j])(mut);
210  }
211 
212  Continue &= evaluate(*mIndividual[i - 2 * mPopulationSize]);
214  }
215  }
216 
217  return Continue;
218 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
unsigned C_INT32 mPopulationSize
Definition: COptMethodDE.h:114
virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:292
const size_t & next()
CPermutation * mpPermutation
Definition: COptMethodDE.h:134
size_t mBestIndex
Definition: COptMethodDE.h:152
bool evaluate(const CVector< C_FLOAT64 > &individual)
#define C_INVALID_INDEX
Definition: copasi.h:222
const size_t & pick()
size_t mVariableSize
Definition: COptMethodDE.h:124
virtual unsigned C_INT32 getRandomU()
Definition: CRandom.cpp:173
C_FLOAT64 mEvaluationValue
Definition: COptMethodDE.h:139
void shuffle(const size_t &swaps=C_INVALID_INDEX)
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
#define C_FLOAT64
Definition: copasi.h:92
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CRandom * mpRandom
Definition: COptMethodDE.h:119
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodDE.h:129
C_FLOAT64 mMutationVarians
Definition: COptMethodDE.h:149
CVector< C_FLOAT64 > mValue
Definition: COptMethodDE.h:144

Friends And Related Function Documentation

Member Data Documentation

size_t COptMethodDE::mBestIndex
private

Definition at line 152 of file COptMethodDE.h.

Referenced by creation(), optimise(), and replicate().

C_FLOAT64 COptMethodDE::mBestValue
private

Definition at line 151 of file COptMethodDE.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodDE::mEvaluationValue
private

The value of the last evaluation.

Definition at line 139 of file COptMethodDE.h.

Referenced by creation(), evaluate(), optimise(), and replicate().

unsigned C_INT32 COptMethodDE::mGeneration
private

Definition at line 153 of file COptMethodDE.h.

Referenced by initialize(), initObjects(), and optimise().

unsigned C_INT32 COptMethodDE::mGenerations
private

number of generations

Definition at line 104 of file COptMethodDE.h.

Referenced by initialize(), and optimise().

size_t COptMethodDE::mhGenerations
private

Handle to the process report item "Current Generation"

Definition at line 109 of file COptMethodDE.h.

Referenced by initialize(), and optimise().

std::vector< CVector < C_FLOAT64 > * > COptMethodDE::mIndividual
private

for array of individuals w/ candidate values for the parameters

Definition at line 129 of file COptMethodDE.h.

Referenced by boost(), cleanup(), creation(), initialize(), optimise(), and replicate().

C_FLOAT64 COptMethodDE::mMutationVarians
private

variance for mutations

Definition at line 149 of file COptMethodDE.h.

Referenced by initialize(), and replicate().

unsigned C_INT32 COptMethodDE::mPopulationSize
private

size of the population

Definition at line 114 of file COptMethodDE.h.

Referenced by boost(), creation(), fittest(), initialize(), optimise(), and replicate().

CPermutation* COptMethodDE::mpPermutation
private

A permutation of integers used to for replication;

Definition at line 134 of file COptMethodDE.h.

Referenced by cleanup(), initialize(), and replicate().

CRandom* COptMethodDE::mpRandom
private

a pointer to the randomnumber generator.

Definition at line 119 of file COptMethodDE.h.

Referenced by cleanup(), creation(), initialize(), and replicate().

CVector< C_FLOAT64 > COptMethodDE::mValue
private

array of values of objective function f/ individuals

Definition at line 144 of file COptMethodDE.h.

Referenced by boost(), creation(), fittest(), initialize(), optimise(), and replicate().

size_t COptMethodDE::mVariableSize
private

number of parameters

Definition at line 124 of file COptMethodDE.h.

Referenced by creation(), initialize(), optimise(), and replicate().


The documentation for this class was generated from the following files: