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

#include <COptMethodEP.h>

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

Public Member Functions

 COptMethodEP (const COptMethodEP &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodEP ()
 
- 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

virtual bool cleanup ()
 
 COptMethodEP (const CCopasiContainer *pParent=NULL)
 
bool creation ()
 
bool evaluate (const CVector< C_FLOAT64 > &individual)
 
size_t fittest ()
 
virtual bool initialize ()
 
void initObjects ()
 
bool mutate (size_t i)
 
bool replicate ()
 
bool select ()
 
bool swap (size_t from, size_t to)
 

Private Attributes

size_t mBestIndex
 
C_FLOAT64 mBestValue
 
unsigned C_INT32 mCurrentIteration
 
C_FLOAT64 mEvaluationValue
 
unsigned C_INT32 mGeneration
 
unsigned C_INT32 mGenerations
 
size_t mhGenerations
 
std::vector< CVector
< C_FLOAT64 > * > 
mIndividual
 
CVector< size_t > mLosses
 
CVector< size_t > mPivot
 
unsigned C_INT32 mPopulationSize
 
CRandommpRandom
 
CVector< C_FLOAT64mValue
 
size_t mVariableSize
 
std::vector< CVector
< C_FLOAT64 > * > 
mVariance
 
double tau1
 
double tau2
 

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 27 of file COptMethodEP.h.

Constructor & Destructor Documentation

COptMethodEP::COptMethodEP ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Definition at line 28 of file COptMethodEP.cpp.

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

28  :
30  mGenerations(0),
31  mGeneration(0),
32  mPopulationSize(0),
33  mpRandom(NULL),
35  mLosses(0),
38  mValue(0),
39  mVariableSize(0),
40  mIndividual(0),
41  mVariance(0)
42 {
43  addParameter("Number of Generations", CCopasiParameter::UINT, (unsigned C_INT32) 200);
44  addParameter("Population Size", CCopasiParameter::UINT, (unsigned C_INT32) 20);
45  addParameter("Random Number Generator", CCopasiParameter::UINT, (unsigned C_INT32) CRandom::mt19937);
46  addParameter("Seed", CCopasiParameter::UINT, (unsigned C_INT32) 0);
47 
48  initObjects();
49 }
C_FLOAT64 mEvaluationValue
Definition: COptMethodEP.h:170
size_t mVariableSize
Definition: COptMethodEP.h:180
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CRandom * mpRandom
Definition: COptMethodEP.h:149
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_INT32
Definition: copasi.h:90
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
bool addParameter(const CCopasiParameter &parameter)
C_FLOAT64 mBestValue
Definition: COptMethodEP.h:165
void initObjects()
size_t mBestIndex
Definition: COptMethodEP.h:151
unsigned C_INT32 mGeneration
Definition: COptMethodEP.h:134
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
unsigned C_INT32 mGenerations
Definition: COptMethodEP.h:129
#define max(a, b)
Definition: f2c.h:176
COptMethodEP::COptMethodEP ( const COptMethodEP src,
const CCopasiContainer pParent = NULL 
)

Copy Constructor

Parameters
constCOptMethodEP & src

Definition at line 51 of file COptMethodEP.cpp.

References initObjects().

52  : COptMethod(src, pParent),
53  mGenerations(0),
54  mGeneration(0),
55  mPopulationSize(0),
56  mpRandom(NULL),
58  mLosses(0),
61  mValue(0),
62  mVariableSize(0),
63  mIndividual(0),
64  mVariance(0)
65 {initObjects();}
C_FLOAT64 mEvaluationValue
Definition: COptMethodEP.h:170
size_t mVariableSize
Definition: COptMethodEP.h:180
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CRandom * mpRandom
Definition: COptMethodEP.h:149
#define C_INVALID_INDEX
Definition: copasi.h:222
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
C_FLOAT64 mBestValue
Definition: COptMethodEP.h:165
void initObjects()
size_t mBestIndex
Definition: COptMethodEP.h:151
unsigned C_INT32 mGeneration
Definition: COptMethodEP.h:134
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
unsigned C_INT32 mGenerations
Definition: COptMethodEP.h:129
#define max(a, b)
Definition: f2c.h:176
COptMethodEP::~COptMethodEP ( )
virtual

Destructor

Definition at line 67 of file COptMethodEP.cpp.

References cleanup().

68 {
69  cleanup();
70 }
virtual bool cleanup()

Member Function Documentation

bool COptMethodEP::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 145 of file COptMethodEP.cpp.

References mIndividual, mpRandom, mVariance, and pdelete.

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

146 {
147  size_t i;
148  // pdelete all used variables
149  pdelete(mpRandom);
150 
151  for (i = 0; i < mIndividual.size(); i++)
152  {
153  pdelete(mIndividual[i]);
154  pdelete(mVariance[i]);
155  }
156 
157  return true;
158 }
#define pdelete(p)
Definition: copasi.h:215
CRandom * mpRandom
Definition: COptMethodEP.h:149
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
bool COptMethodEP::creation ( )
private

Initialise the population

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

Definition at line 233 of file COptMethodEP.cpp.

References C_FLOAT64, COptItem::checkConstraint(), COptItem::checkLowerBound(), COptItem::checkUpperBound(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), CRandom::getRandomNormal(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), max, mEvaluationValue, min, mIndividual, mPopulationSize, mpRandom, mValue, mVariableSize, and mVariance.

Referenced by optimise().

234 {
235  size_t i;
236  size_t j;
237 
238  C_FLOAT64 mn;
239  C_FLOAT64 mx;
240  C_FLOAT64 la;
241 
242  bool Continue = true;
243 
244  // set the first individual to the initial guess
245 
246  for (i = 0; i < mVariableSize; i++)
247  {
248  C_FLOAT64 & mut = (*mIndividual[0])[i];
249  COptItem & OptItem = *(*mpOptItem)[i];
250 
251  mut = OptItem.getStartValue();
252 
253  // force it to be within the bounds
254  switch (OptItem.checkConstraint(mut))
255  {
256  case - 1:
257  mut = *OptItem.getLowerBoundValue();
258 
259  if (!OptItem.checkLowerBound(mut)) // Inequality
260  {
261  if (mut == 0.0)
263  else
264  mut += mut * std::numeric_limits< C_FLOAT64 >::epsilon();
265  }
266 
267  break;
268 
269  case 1:
270  mut = *OptItem.getUpperBoundValue();
271 
272  if (!OptItem.checkUpperBound(mut)) // Inequality
273  {
274  if (mut == 0.0)
276  else
277  mut -= mut * std::numeric_limits< C_FLOAT64 >::epsilon();
278  }
279 
280  break;
281  }
282 
283  // We need to set the value here so that further checks take
284  // account of the value.
285  (*(*mpSetCalculateVariable)[i])(mut);
286 
287  // Set the variance for this parameter.
288  (*mVariance[0])[i] = fabs(mut) * 0.5;
289  }
290 
291  Continue = evaluate(*mIndividual[0]);
293  //candx[0] = evaluate(0);
294 
295  // and copy it to the rest
296  // for(i=1; i<half; i++)
297  // candx[i] = candx[0];
298  // set the other half to random values within the boundaries
299  // for(i=half; i<mVariableSizeze; i++)
300 
301  for (i = 1; i < mPopulationSize; i++)
302  {
303  for (j = 0; j < mVariableSize; j++)
304  {
305  C_FLOAT64 & mut = (*mIndividual[i])[j];
306  COptItem & OptItem = *(*mpOptItem)[j];
307 
308  // calculate lower and upper bounds
309  mn = *OptItem.getLowerBoundValue();
310  mx = *OptItem.getUpperBoundValue();
311 
312  try
313  {
314  // First determine the location of the interval
315  // Secondly determine whether to distribute the parameter linearly or not
316  // depending on the location and act uppon it.
317  if (0.0 <= mn) // the interval [mn, mx) is in [0, inf)
318  {
319  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
320 
321  if (la < 1.8 || !(mn > 0.0)) // linear
322  mut = mn + mpRandom->getRandomCC() * (mx - mn);
323  else
324  mut = pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
325  }
326  else if (mx > 0) // 0 is in the interval (mn, mx)
327  {
328  la = log10(mx) + log10(-mn);
329 
330  if (la < 3.6) // linear
331  mut = mn + mpRandom->getRandomCC() * (mx - mn);
332  else
333  {
334  C_FLOAT64 mean = (mx + mn) * 0.5;
335  C_FLOAT64 sigma = mean * 0.01;
336 
337  do
338  {
339  mut = mpRandom->getRandomNormal(mean, sigma);
340  }
341  while ((mut < mn) || (mut > mx));
342  }
343  }
344  else // the interval (mn, mx] is in (-inf, 0]
345  {
346  // Switch lower and upper bound and change sign, i.e.,
347  // we can treat it similarly as location 1:
348  mx = - *OptItem.getLowerBoundValue();
349  mn = - *OptItem.getUpperBoundValue();
350 
351  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
352 
353  if (la < 1.8 || !(mn > 0.0)) // linear
354  mut = - (mn + mpRandom->getRandomCC() * (mx - mn));
355  else
356  mut = - pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
357  }
358  }
359 
360  catch (...)
361  {
362  mut = (mx + mn) * 0.5;
363  }
364 
365  // force it to be within the bounds
366  switch (OptItem.checkConstraint(mut))
367  {
368  case - 1:
369  mut = *OptItem.getLowerBoundValue();
370 
371  if (!OptItem.checkLowerBound(mut)) // Inequality
372  {
373  if (mut == 0.0)
375  else
376  mut += mut * std::numeric_limits< C_FLOAT64 >::epsilon();
377  }
378 
379  break;
380 
381  case 1:
382  mut = *OptItem.getUpperBoundValue();
383 
384  if (!OptItem.checkUpperBound(mut)) // Inequality
385  {
386  if (mut == 0.0)
388  else
389  mut -= mut * std::numeric_limits< C_FLOAT64 >::epsilon();
390  }
391 
392  break;
393  }
394 
395  // We need to set the value here so that further checks take
396  // account of the value.
397  (*(*mpSetCalculateVariable)[j])(mut);
398 
399  // Set the variance for this parameter.
400  (*mVariance[i])[j] = fabs(mut) * 0.5;
401  }
402 
403  // calculate its fitness
404  Continue = evaluate(*mIndividual[i]);
406  }
407 
408  return Continue;
409 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
bool checkLowerBound(const C_FLOAT64 &value) const
Definition: COptItem.cpp:435
virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:292
C_FLOAT64 mEvaluationValue
Definition: COptMethodEP.h:170
size_t mVariableSize
Definition: COptMethodEP.h:180
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CRandom * mpRandom
Definition: COptMethodEP.h:149
bool checkUpperBound(const C_FLOAT64 &value) const
Definition: COptItem.cpp:438
bool evaluate(const CVector< C_FLOAT64 > &individual)
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
#define C_FLOAT64
Definition: copasi.h:92
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
#define min(a, b)
Definition: f2c.h:175
#define max(a, b)
Definition: f2c.h:176
bool COptMethodEP::evaluate ( const CVector< C_FLOAT64 > &  individual)
private

Evaluate the objective function for the current parameters

Returns
const C_FLOAT64 & objectiveValue

Definition at line 209 of file COptMethodEP.cpp.

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

Referenced by creation(), and mutate().

210 {
211  bool Continue = true;
212 
213  // We do not need to check whether the parametric constraints are fulfilled
214  // since the parameters are created within the bounds.
215 
216  // evaluate the fitness
217  Continue = mpOptProblem->calculate();
218 
219  // check whether the functional constraints are fulfilled
221  mEvaluationValue = std::numeric_limits<C_FLOAT64>::infinity();
222  else
224 
225  return Continue;
226 }
C_FLOAT64 mEvaluationValue
Definition: COptMethodEP.h:170
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
virtual bool checkFunctionalConstraints()
const C_FLOAT64 & getCalculateValue() const
size_t COptMethodEP::fittest ( void  )
private

Find the best individual at this generation

Returns
size_t fittest

Definition at line 471 of file COptMethodEP.cpp.

References C_FLOAT64, mLosses, mPopulationSize, and mValue.

Referenced by optimise().

472 {
473  size_t i, BestIndex = 0;
474  C_FLOAT64 BestValue = mValue[0];
475 
476  for (i = 1; i < mPopulationSize && !mLosses[i]; i++)
477  if (mValue[i] < BestValue)
478  {
479  BestIndex = i;
480  BestValue = mValue[i];
481  }
482 
483  return BestIndex;
484 }
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
#define C_FLOAT64
Definition: copasi.h:92
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
bool COptMethodEP::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 160 of file COptMethodEP.cpp.

References CProcessReport::addItem(), cleanup(), CRandom::createGenerator(), CCopasiParameter::getValue(), COptMethod::initialize(), mGeneration, mGenerations, mhGenerations, mIndividual, mLosses, CCopasiMethod::mpCallBack, COptMethod::mpOptItem, mPopulationSize, mpRandom, mValue, mVariableSize, mVariance, CCopasiParameter::Value::pUINT, CVector< CType >::resize(), tau1, and tau2.

Referenced by optimise().

161 {
162  cleanup();
163 
164  size_t i;
165 
166  if (!COptMethod::initialize()) return false;
167 
168  mGenerations = * getValue("Number of Generations").pUINT;
169  mGeneration = 0;
170 
171  if (mpCallBack)
172  mhGenerations =
173  mpCallBack->addItem("Current Generation",
174  mGeneration,
175  & mGenerations);
176 
177  mGeneration++;
178 
179  mPopulationSize = * getValue("Population Size").pUINT;
180  mpRandom =
181  CRandom::createGenerator(* (CRandom::Type *) getValue("Random Number Generator").pUINT,
182  * getValue("Seed").pUINT);
183 
184  mVariableSize = mpOptItem->size();
185 
186  mIndividual.resize(2 * mPopulationSize);
187  mVariance.resize(2 * mPopulationSize);
188 
189  for (i = 0; i < 2 * mPopulationSize; i++)
190  {
193  }
194 
195  mValue.resize(2 * mPopulationSize);
196  mValue = std::numeric_limits< C_FLOAT64 >::infinity();
197 
198  mLosses.resize(2 * mPopulationSize);
199  mLosses = 0;
200 
201  // Initialize the parameters to update the variances
202  tau1 = 1.0 / sqrt(2 * double(mVariableSize));
203  tau2 = 1.0 / sqrt(2 * sqrt(double(mVariableSize)));
204 
205  return true;
206 }
virtual bool initialize()
Definition: COptMethod.cpp:189
size_t mVariableSize
Definition: COptMethodEP.h:180
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CRandom * mpRandom
Definition: COptMethodEP.h:149
virtual bool cleanup()
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
size_t mhGenerations
Definition: COptMethodEP.h:139
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
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
unsigned C_INT32 * pUINT
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
unsigned C_INT32 mGeneration
Definition: COptMethodEP.h:134
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
CProcessReport * mpCallBack
unsigned C_INT32 mGenerations
Definition: COptMethodEP.h:129
void COptMethodEP::initObjects ( )
private

Initialize contained objects.

Definition at line 228 of file COptMethodEP.cpp.

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

Referenced by COptMethodEP().

229 {
231 }
unsigned C_INT32 mGeneration
Definition: COptMethodEP.h:134
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodEP::mutate ( size_t  i)
private

Mutate one individual

Parameters
CVector<C_FLOAT64 > & individual
Returns
bool success

Definition at line 511 of file COptMethodEP.cpp.

References C_FLOAT64, COptItem::checkConstraint(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomNormal01(), COptItem::getUpperBoundValue(), max, mEvaluationValue, mIndividual, mpRandom, mValue, mVariableSize, mVariance, tau1, and tau2.

Referenced by replicate().

512 {
513  size_t j;
514  C_FLOAT64 v1;
515 
516  CVector<C_FLOAT64> & Individual = *mIndividual[i];
517  CVector<C_FLOAT64> & Variance = *mVariance[i];
518 
519  v1 = mpRandom->getRandomNormal01();
520 
521  // update the variances
522  for (j = 0; j < mVariableSize; j++)
523  {
524  C_FLOAT64 & mut = Individual[j];
525  COptItem & OptItem = *(*mpOptItem)[j];
526 
527  try
528  {
529  // update the parameter for the variances
530  Variance[j] =
531  std::max(Variance[j] * exp(tau1 * v1 + tau2 * mpRandom->getRandomNormal01()), 1e-8);
532 
533  // calculate the mutated parameter
534  mut += Variance[j] * mpRandom->getRandomNormal01();
535  }
536 
537  catch (...)
538  {
539  mut = (*OptItem.getUpperBoundValue() + *OptItem.getLowerBoundValue()) * 0.5;
540  }
541 
542  // force it to be within the bounds
543  switch (OptItem.checkConstraint(mut))
544  {
545  case - 1:
546  mut = *OptItem.getLowerBoundValue();
547  break;
548 
549  case 1:
550  mut = *OptItem.getUpperBoundValue();
551  break;
552  }
553 
554  // We need to set the value here so that further checks take
555  // account of the value.
556  (*(*mpSetCalculateVariable)[j])(mut);
557  }
558 
559  // calculate its fitness
560  bool Continue = evaluate(Individual);
562 
563  return Continue;
564 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
C_FLOAT64 mEvaluationValue
Definition: COptMethodEP.h:170
size_t mVariableSize
Definition: COptMethodEP.h:180
CRandom * mpRandom
Definition: COptMethodEP.h:149
virtual C_FLOAT64 getRandomNormal01()
Definition: CRandom.cpp:261
bool evaluate(const CVector< C_FLOAT64 > &individual)
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
#define C_FLOAT64
Definition: copasi.h:92
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
#define max(a, b)
Definition: f2c.h:176
bool COptMethodEP::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.

Reimplemented from COptMethod.

Definition at line 72 of file COptMethodEP.cpp.

References C_INVALID_INDEX, cleanup(), creation(), COutputInterface::DURING, CProcessReport::finishItem(), fittest(), initialize(), mBestIndex, mBestValue, mGeneration, mGenerations, mhGenerations, mIndividual, CCopasiMethod::mpCallBack, COptMethod::mpOptProblem, COptMethod::mpParentTask, mValue, CCopasiTask::output(), CProcessReport::progressItem(), replicate(), select(), and COptProblem::setSolution().

73 {
74  if (!initialize())
75  {
76  if (mpCallBack)
78 
79  return false;
80  }
81 
82  bool Continue = true;
83 
84  // Initialize the population
85  Continue = creation();
86 
87  // get the index of the fittest
88  mBestIndex = fittest();
89 
91  {
92  // and store that value
95 
96  // We found a new best value lets report it.
98  }
99 
100  if (!Continue)
101  {
102  if (mpCallBack)
104 
105  cleanup();
106  return true;
107  }
108 
109  // iterate over Generations
110  for (mGeneration = 2; mGeneration <= mGenerations && Continue; mGeneration++)
111  {
112  // replicate the individuals
113  Continue = replicate();
114 
115  // select the most fit
116  Continue = select();
117 
118  // get the index of the fittest
119  mBestIndex = fittest();
120 
121  if (mBestIndex != C_INVALID_INDEX &&
122  mValue[mBestIndex] < mBestValue)
123  {
125 
126  Continue = mpOptProblem->setSolution(mBestValue, *mIndividual[mBestIndex]);
127 
128  // We found a new best value lets report it.
129  //if (mpReport) mpReport->printBody();
131  }
132 
133  if (mpCallBack)
135  }
136 
137  if (mpCallBack)
139 
140  cleanup();
141 
142  return true;
143 }
COptTask * mpParentTask
Definition: COptMethod.h:58
size_t fittest()
virtual bool cleanup()
size_t mhGenerations
Definition: COptMethodEP.h:139
#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)
virtual bool initialize()
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool finishItem(const size_t &handle)
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
C_FLOAT64 mBestValue
Definition: COptMethodEP.h:165
size_t mBestIndex
Definition: COptMethodEP.h:151
unsigned C_INT32 mGeneration
Definition: COptMethodEP.h:134
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
CProcessReport * mpCallBack
unsigned C_INT32 mGenerations
Definition: COptMethodEP.h:129
bool COptMethodEP::replicate ( void  )
private

Replicate the individuals with crossover

Returns
bool continue

Definition at line 486 of file COptMethodEP.cpp.

References mIndividual, mPopulationSize, mutate(), mValue, mVariableSize, and mVariance.

Referenced by optimise().

487 {
488  size_t i;
489  size_t j;
490  bool Continue = true;
491 
492  // iterate over parents
493  for (i = 0; i < mPopulationSize && Continue; i++)
494  {
495  // replicate them
496  for (j = 0; j < mVariableSize; j++)
497  {
498  (*mIndividual[mPopulationSize + i])[j] = (*mIndividual[i])[j];
499  (*mVariance[mPopulationSize + i])[j] = (*mVariance[i])[j];
500  }
501 
502  mValue[mPopulationSize + i] = mValue[i];
503 
504  // possibly mutate the offspring
505  Continue = mutate(mPopulationSize + i);
506  }
507 
508  return Continue;
509 }
size_t mVariableSize
Definition: COptMethodEP.h:180
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
bool mutate(size_t i)
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
bool COptMethodEP::select ( )
private

Select surviving population

Returns
bool success

Definition at line 411 of file COptMethodEP.cpp.

References applyPartialPivot(), CVectorCore< CType >::array(), C_INT32, CRandom::getRandomU(), mLosses, mPivot, mPopulationSize, mpRandom, mValue, partialSortWithPivot(), and swap().

Referenced by optimise().

412 {
413  size_t i, j, nopp, opp;
414  size_t TotalPopulation = 2 * mPopulationSize;
415 
416  // tournament competition
417  mLosses = 0; // Set all losses to 0.
418 
419  // compete with ~ 20% of the TotalPopulation
420  nopp = std::max<size_t>(1, mPopulationSize / 5);
421 
422  // parents and offspring are all in competition
423  for (i = 0; i < TotalPopulation; i++)
424  for (j = 0; j < nopp; j++)
425  {
426  // get random opponent
427  do
428  {
429  opp = mpRandom->getRandomU((unsigned C_INT32)(TotalPopulation - 1));
430  }
431  while (i == opp);
432 
433  if (mValue[i] < mValue[opp])
434  mLosses[opp]++;
435  else
436  mLosses[i]++;
437  }
438 
441  mLosses.array() + TotalPopulation,
442  mPivot);
443 
446 
447  return true;
448 }
unsigned C_INT32 mPopulationSize
Definition: COptMethodEP.h:144
CRandom * mpRandom
Definition: COptMethodEP.h:149
bool applyPartialPivot(const CVector< size_t > &pivot, const size_t &ordered, SwapMethod swap)
Definition: CSort.h:375
#define C_INT32
Definition: copasi.h:90
CVector< size_t > mPivot
Definition: COptMethodEP.h:200
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
bool swap(size_t from, size_t to)
void partialSortWithPivot(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, CVector< size_t > &pivot)
Definition: CSort.h:149
virtual unsigned C_INT32 getRandomU()
Definition: CRandom.cpp:173
CType * array()
Definition: CVector.h:139
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175
bool COptMethodEP::swap ( size_t  from,
size_t  to 
)
private

Swap individuals from and to

Parameters
size_tfrom
size_tto
Returns
bool success

Definition at line 450 of file COptMethodEP.cpp.

References C_FLOAT64, mIndividual, mLosses, mValue, and mVariance.

Referenced by select().

451 {
452  CVector< C_FLOAT64 > * pTmp = mIndividual[to];
453  mIndividual[to] = mIndividual[from];
454  mIndividual[from] = pTmp;
455 
456  pTmp = mVariance[to];
457  mVariance[to] = mVariance[from];
458  mVariance[from] = pTmp;
459 
460  C_FLOAT64 dTmp = mValue[to];
461  mValue[to] = mValue[from];
462  mValue[from] = dTmp;
463 
464  size_t iTmp = mLosses[to];
465  mLosses[to] = mLosses[from];
466  mLosses[from] = iTmp;
467 
468  return true;
469 }
CVector< size_t > mLosses
Definition: COptMethodEP.h:160
std::vector< CVector< C_FLOAT64 > * > mVariance
Definition: COptMethodEP.h:190
#define C_FLOAT64
Definition: copasi.h:92
std::vector< CVector< C_FLOAT64 > * > mIndividual
Definition: COptMethodEP.h:185
CVector< C_FLOAT64 > mValue
Definition: COptMethodEP.h:175

Friends And Related Function Documentation

Member Data Documentation

size_t COptMethodEP::mBestIndex
private

Definition at line 151 of file COptMethodEP.h.

Referenced by optimise().

C_FLOAT64 COptMethodEP::mBestValue
private

The best value found so far.

Definition at line 165 of file COptMethodEP.h.

Referenced by optimise().

unsigned C_INT32 COptMethodEP::mCurrentIteration
private

The current iteration

Definition at line 195 of file COptMethodEP.h.

C_FLOAT64 COptMethodEP::mEvaluationValue
private

The value of the last evaluation.

Definition at line 170 of file COptMethodEP.h.

Referenced by creation(), evaluate(), and mutate().

unsigned C_INT32 COptMethodEP::mGeneration
private

size of the population

Definition at line 134 of file COptMethodEP.h.

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

unsigned C_INT32 COptMethodEP::mGenerations
private

number of generations

Definition at line 129 of file COptMethodEP.h.

Referenced by initialize(), and optimise().

size_t COptMethodEP::mhGenerations
private

Handle to the process report item "Current Generation"

Definition at line 139 of file COptMethodEP.h.

Referenced by initialize(), and optimise().

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

for array of individuals w/ candidate values for the parameters

Definition at line 185 of file COptMethodEP.h.

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

CVector< size_t > COptMethodEP::mLosses
private

number of wins of each individual in the tournament

Definition at line 160 of file COptMethodEP.h.

Referenced by fittest(), initialize(), select(), and swap().

CVector<size_t> COptMethodEP::mPivot
private

Pivot vector used for sorting

Definition at line 200 of file COptMethodEP.h.

Referenced by select().

unsigned C_INT32 COptMethodEP::mPopulationSize
private

size of the population

Definition at line 144 of file COptMethodEP.h.

Referenced by creation(), fittest(), initialize(), replicate(), and select().

CRandom* COptMethodEP::mpRandom
private

a pointer to the randomnumber generator.

Definition at line 149 of file COptMethodEP.h.

Referenced by cleanup(), creation(), initialize(), mutate(), and select().

CVector<C_FLOAT64> COptMethodEP::mValue
private

array of values of objective function f/ individuals

Definition at line 175 of file COptMethodEP.h.

Referenced by creation(), fittest(), initialize(), mutate(), optimise(), replicate(), select(), and swap().

size_t COptMethodEP::mVariableSize
private

number of parameters

Definition at line 180 of file COptMethodEP.h.

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

std::vector< CVector < C_FLOAT64 > * > COptMethodEP::mVariance
private

for array of variances w/ variance values for the parameters

Definition at line 190 of file COptMethodEP.h.

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

double COptMethodEP::tau1
private

Definition at line 153 of file COptMethodEP.h.

Referenced by initialize(), and mutate().

double COptMethodEP::tau2
private

Definition at line 155 of file COptMethodEP.h.

Referenced by initialize(), and mutate().


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