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

#include <COptMethodSRES.h>

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

Public Member Functions

 COptMethodSRES (const COptMethodSRES &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodSRES ()
 
- 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 ()
 
 COptMethodSRES (const CCopasiContainer *pParent=NULL)
 
bool creation (size_t first)
 
bool evaluate (const CVector< C_FLOAT64 > &individual)
 
size_t fittest ()
 
virtual bool initialize ()
 
void initObjects ()
 
bool mutate ()
 
C_FLOAT64 phi (size_t indvNum)
 
bool replicate ()
 
void select ()
 
bool swap (size_t from, size_t to)
 

Private Attributes

C_FLOAT64 mBestValue
 
C_FLOAT64 mEvaluationValue
 
unsigned C_INT32 mGeneration
 
unsigned C_INT32 mGenerations
 
size_t mhGenerations
 
std::vector< CVector
< C_FLOAT64 > * > 
mIndividual
 
CVector< C_FLOAT64mMaxVariance
 
C_FLOAT64 mPf
 
CVector< C_FLOAT64mPhi
 
unsigned C_INT32 mPopulationSize
 
CRandommpRandom
 
double mTau
 
double mTauPrime
 
CVector< C_FLOAT64mValue
 
size_t mVariableSize
 
std::vector< CVector
< C_FLOAT64 > * > 
mVariance
 

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

COptMethodSRES class

Definition at line 27 of file COptMethodSRES.h.

Constructor & Destructor Documentation

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

Copy Constructor

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

Definition at line 57 of file COptMethodSRES.cpp.

References initObjects().

58  :
59  COptMethod(src, pParent),
60  mGenerations(0),
61  mPopulationSize(0),
62  mpRandom(NULL),
63  mVariableSize(0),
64  mIndividual(0),
66  mValue(0),
68  mGeneration(0)
69 {initObjects();}
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
C_FLOAT64 mEvaluationValue
unsigned C_INT32 mGenerations
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
C_FLOAT64 mBestValue
unsigned C_INT32 mGeneration
#define max(a, b)
Definition: f2c.h:176
COptMethodSRES::~COptMethodSRES ( )
virtual

Destructor

Definition at line 71 of file COptMethodSRES.cpp.

References cleanup().

72 {cleanup();}
virtual bool cleanup()
COptMethodSRES::COptMethodSRES ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 35 of file COptMethodSRES.cpp.

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

35  :
37  mGenerations(0),
38  mPopulationSize(0),
39  mpRandom(NULL),
40  mVariableSize(0),
41  mIndividual(0),
43  mValue(0),
45  mGeneration(0)
46 
47 {
48  addParameter("Number of Generations", CCopasiParameter::UINT, (unsigned C_INT32) 200);
49  addParameter("Population Size", CCopasiParameter::UINT, (unsigned C_INT32) 20);
50  addParameter("Random Number Generator", CCopasiParameter::UINT, (unsigned C_INT32) CRandom::mt19937);
51  addParameter("Seed", CCopasiParameter::UINT, (unsigned C_INT32) 0);
52  addParameter("Pf", CCopasiParameter::DOUBLE, (C_FLOAT64) 0.475); //*****ADDED for SR
53 
54  initObjects();
55 }
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
C_FLOAT64 mEvaluationValue
unsigned C_INT32 mGenerations
CRandom * mpRandom
#define C_INT32
Definition: copasi.h:90
std::vector< CVector< C_FLOAT64 > * > mIndividual
C_FLOAT64 mBestValue
unsigned C_INT32 mGeneration
#define C_FLOAT64
Definition: copasi.h:92
bool addParameter(const CCopasiParameter &parameter)
#define max(a, b)
Definition: f2c.h:176

Member Function Documentation

bool COptMethodSRES::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 586 of file COptMethodSRES.cpp.

References mIndividual, mpRandom, mVariance, and pdelete.

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

587 {
588  size_t i;
589 
590  pdelete(mpRandom);
591 
592  for (i = 0; i < mIndividual.size(); i++)
593  {
594  pdelete(mIndividual[i]);
595  pdelete(mVariance[i]);
596  }
597 
598  return true;
599 }
#define pdelete(p)
Definition: copasi.h:215
std::vector< CVector< C_FLOAT64 > * > mVariance
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
bool COptMethodSRES::creation ( size_t  first)
private

Initialise the population

Parameters
size_tfirst
Returns
bool continue

Definition at line 293 of file COptMethodSRES.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, COptItem::checkConstraint(), COptItem::checkLowerBound(), COptItem::checkUpperBound(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), CRandom::getRandomNormal(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), max, mEvaluationValue, min, mIndividual, mMaxVariance, mPhi, mPopulationSize, mpRandom, mValue, mVariableSize, mVariance, and phi().

Referenced by optimise().

294 {
295  size_t i;
296  size_t j;
297 
298  C_FLOAT64 mn;
299  C_FLOAT64 mx;
300  C_FLOAT64 la;
301 
302  bool Continue = true;
303 
304  std::vector< CVector < C_FLOAT64 > * >::iterator it =
305  mIndividual.begin() + first;
306  std::vector< CVector < C_FLOAT64 > * >::iterator end =
307  mIndividual.begin() + mPopulationSize;
308  std::vector< CVector < C_FLOAT64 > * >::iterator itVariance =
309  mVariance.begin() + first;
310 
311  C_FLOAT64 * pVariable, * pVariableEnd, * pVariance, * pMaxVariance;
312  C_FLOAT64 * pPhi = mPhi.array() + first;
313  C_FLOAT64 * pValue = mValue.array() + first;
314 
315  // set the first individual to the initial guess
316  if (it == mIndividual.begin())
317  {
318  pVariable = (*it)->array();
319  pVariableEnd = pVariable + mVariableSize;
320  pVariance = (*itVariance)->array();
321  pMaxVariance = mMaxVariance.array();
322 
323  for (j = 0; pVariable != pVariableEnd; ++pVariable, ++pVariance, ++pMaxVariance, ++j)
324  {
325  C_FLOAT64 & mut = *pVariable;
326  COptItem & OptItem = *(*mpOptItem)[j];
327 
328  mut = OptItem.getStartValue();
329 
330  // force it to be within the bounds
331  switch (OptItem.checkConstraint(mut))
332  {
333  case - 1:
334  mut = *OptItem.getLowerBoundValue();
335 
336  if (!OptItem.checkLowerBound(mut)) // Inequality
337  {
338  if (mut == 0.0)
340  else
341  mut += mut * std::numeric_limits< C_FLOAT64 >::epsilon();
342  }
343 
344  break;
345 
346  case 1:
347  mut = *OptItem.getUpperBoundValue();
348 
349  if (!OptItem.checkUpperBound(mut)) // Inequality
350  {
351  if (mut == 0.0)
353  else
354  mut -= mut * std::numeric_limits< C_FLOAT64 >::epsilon();
355  }
356 
357  break;
358  }
359 
360  // We need to set the value here so that further checks take
361  // account of the value.
362  (*(*mpSetCalculateVariable)[j])(mut);
363 
364  // Set the variance for this parameter.
365  *pVariance = std::min(*OptItem.getUpperBoundValue() - mut, mut - *OptItem.getLowerBoundValue()) / sqrt(double(mVariableSize));
366  }
367 
368  Continue = evaluate(**it);
369  *pValue++ = mEvaluationValue;
370  *pPhi++ = phi(0);
371 
372  ++it;
373  ++itVariance;
374  ++first;
375  }
376 
377  for (i = first; it < end ; ++it, ++itVariance, ++i)
378  {
379  pVariable = (*it)->array();
380  pVariableEnd = pVariable + mVariableSize;
381  pVariance = (*itVariance)->array();
382  pMaxVariance = mMaxVariance.array();
383 
384  for (j = 0; pVariable != pVariableEnd; ++pVariable, ++pVariance, ++pMaxVariance, ++j)
385  {
386  C_FLOAT64 & mut = *pVariable;
387  COptItem & OptItem = *(*mpOptItem)[j];
388 
389  // calculate lower and upper bounds
390  mn = *OptItem.getLowerBoundValue();
391  mx = *OptItem.getUpperBoundValue();
392 
393  try
394  {
395  // First determine the location of the intervall
396  // Secondly determine whether to distribute the parameter linearly or not
397  // depending on the location and act uppon it.
398  if (0.0 <= mn) // the interval [mn, mx) is in [0, inf)
399  {
400  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
401 
402  if (la < 1.8 || !(mn > 0.0)) // linear
403  mut = mn + mpRandom->getRandomCC() * (mx - mn);
404  else
405  mut = pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
406  }
407  else if (mx > 0) // 0 is in the interval (mn, mx)
408  {
409  la = log10(mx) + log10(-mn);
410 
411  if (la < 3.6) // linear
412  mut = mn + mpRandom->getRandomCC() * (mx - mn);
413  else
414  {
415  C_FLOAT64 mean = (mx + mn) * 0.5;
416  C_FLOAT64 sigma = mean * 0.01;
417 
418  do
419  {
420  mut = mpRandom->getRandomNormal(mean, sigma);
421  }
422  while ((mut < mn) || (mut > mx));
423  }
424  }
425  else // the interval (mn, mx] is in (-inf, 0]
426  {
427  // Switch lower and upper bound and change sign, i.e.,
428  // we can treat it similarly as location 1:
429  mx = - *OptItem.getLowerBoundValue();
430  mn = - *OptItem.getUpperBoundValue();
431 
432  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
433 
434  if (la < 1.8 || !(mn > 0.0)) // linear
435  mut = - (mn + mpRandom->getRandomCC() * (mx - mn));
436  else
437  mut = - pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
438  }
439  }
440 
441  catch (...)
442  {
443  mut = (mx + mn) * 0.5;
444  }
445 
446  // force it to be within the bounds
447  switch (OptItem.checkConstraint(mut))
448  {
449  case - 1:
450  mut = *OptItem.getLowerBoundValue();
451 
452  if (!OptItem.checkLowerBound(mut)) // Inequality
453  {
454  if (mut == 0.0)
456  else
457  mut += mut * std::numeric_limits< C_FLOAT64 >::epsilon();
458  }
459 
460  break;
461 
462  case 1:
463  mut = *OptItem.getUpperBoundValue();
464 
465  if (!OptItem.checkUpperBound(mut)) // Inequality
466  {
467  if (mut == 0.0)
469  else
470  mut -= mut * std::numeric_limits< C_FLOAT64 >::epsilon();
471  }
472 
473  break;
474  }
475 
476  // We need to set the value here so that further checks take
477  // account of the value.
478  (*(*mpSetCalculateVariable)[j])(mut);
479 
480  // Set the variance for this parameter.
481  *pVariance = std::min(*OptItem.getUpperBoundValue() - mut, mut - *OptItem.getLowerBoundValue()) / sqrt(double(mVariableSize));
482  }
483 
484  // calculate its fitness
485  Continue = evaluate(**it);
486  *pValue++ = mEvaluationValue;
487  *pPhi++ = phi(i);
488  }
489 
490  return Continue;
491 }
C_FLOAT64 phi(size_t indvNum)
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
std::vector< CVector< C_FLOAT64 > * > mVariance
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
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
bool checkUpperBound(const C_FLOAT64 &value) const
Definition: COptItem.cpp:438
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
CVector< C_FLOAT64 > mMaxVariance
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CVector< C_FLOAT64 > mPhi
bool evaluate(const CVector< C_FLOAT64 > &individual)
#define min(a, b)
Definition: f2c.h:175
#define max(a, b)
Definition: f2c.h:176
bool COptMethodSRES::evaluate ( const CVector< C_FLOAT64 > &  individual)
private

Evaluate the fitness of one individual

Parameters
constCVector< C_FLOAT64 > & individual
Returns
bool continue

Definition at line 75 of file COptMethodSRES.cpp.

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

Referenced by creation(), and mutate().

76 {
77  bool Continue = true;
78 
79  // We do not need to check whether the parametric constraints are fulfilled
80  // since this method allows for parameters outside the bounds
81 
82  // evaluate the fitness
83  Continue = mpOptProblem->calculate();
84 
85  // We do not need to check whether the functional constraints are fulfilled
86  // since this method allows for solutions outside the bounds.
87 
89 
90  return Continue;
91 }
C_FLOAT64 mEvaluationValue
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
const C_FLOAT64 & getCalculateValue() const
size_t COptMethodSRES::fittest ( void  )
private

Find the best individual at this generation

Returns
size_t fittest

Definition at line 277 of file COptMethodSRES.cpp.

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

Referenced by optimise().

278 {
279  size_t i, BestIndex = C_INVALID_INDEX;
281 
282  for (i = 0; i < mPopulationSize; i++)
283  if (mValue[i] < BestValue && mPhi[i] == 0)
284  {
285  BestIndex = i;
286  BestValue = mValue[i];
287  }
288 
289  return BestIndex;
290 }
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_FLOAT64
Definition: copasi.h:92
CVector< C_FLOAT64 > mPhi
#define max(a, b)
Definition: f2c.h:176
bool COptMethodSRES::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 498 of file COptMethodSRES.cpp.

References CProcessReport::addItem(), C_FLOAT64, childrate, cleanup(), CRandom::createGenerator(), COptItem::getLowerBoundValue(), COptItem::getUpperBoundValue(), CCopasiParameter::getValue(), COptMethod::initialize(), mBestValue, mGeneration, mGenerations, mhGenerations, mIndividual, mMaxVariance, CCopasiMethod::mpCallBack, mPf, mPhi, COptMethod::mpOptItem, mPopulationSize, mpRandom, mTau, mTauPrime, mValue, mVariableSize, mVariance, CCopasiParameter::Value::pDOUBLE, CCopasiParameter::Value::pUINT, CVector< CType >::resize(), and CCopasiParameterGroup::setValue().

Referenced by optimise().

499 {
500  cleanup();
501 
502  size_t i;
503 
504  if (!COptMethod::initialize()) return false;
505 
506  mGenerations = * getValue("Number of Generations").pUINT;
507  mGeneration = 0;
508 
509  if (mpCallBack)
510  mhGenerations =
511  mpCallBack->addItem("Current Generation",
512  mGeneration,
513  & mGenerations);
514 
515  mGeneration++;
516 
517  mPopulationSize = * getValue("Population Size").pUINT;
518 
519  mPf = *(C_FLOAT64*) getValue("Pf").pDOUBLE;
520 
521  if (mPf < 0.0 || 1.0 < mPf)
522  {
523  mPf = 0.475;
524  setValue("Pf", mPf);
525  }
526 
527  mpRandom =
528  CRandom::createGenerator(* (CRandom::Type *) getValue("Random Number Generator").pUINT,
529  * getValue("Seed").pUINT);
530 
531  mVariableSize = mpOptItem->size();
532 
534 
535  for (i = 0; i < childrate * mPopulationSize; i++)
537 
538  mVariance.resize(childrate * mPopulationSize);
539 
540  for (i = 0; i < childrate * mPopulationSize; i++)
542 
544 
545  for (i = 0; i < mVariableSize; i++)
546  {
547  COptItem & OptItem = *(*mpOptItem)[i];
548 
549  try
550  {
551  mMaxVariance[i] =
552  (*OptItem.getUpperBoundValue() - *OptItem.getLowerBoundValue()) / sqrt(double(mVariableSize));
553  }
554  catch (...)
555  {
556  mMaxVariance[i] = 1.0e3;
557  }
558  }
559 
560  mValue.resize(childrate * mPopulationSize);
561  mValue = std::numeric_limits<C_FLOAT64>::infinity();
562  mBestValue = std::numeric_limits<C_FLOAT64>::infinity();
563 
564  mPhi.resize(childrate * mPopulationSize);
565 
566  try
567  {
568  /*
569  C_FLOAT64 alpha = 0.2;
570  C_FLOAT64 chi = 1 / (2 * sqrt(double(mVariableSize))) + 1 / (2 * double(mVariableSize));
571  C_FLOAT64 varphi = sqrt(2/chi * log(1/alpha) *exp(chi/2 -(1-alpha)));
572  */
573 
574  C_FLOAT64 varphi = 1;
575  mTau = varphi / sqrt(2 * sqrt(double(mVariableSize)));
576  mTauPrime = varphi / sqrt(2 * double(mVariableSize));
577  }
578  catch (...)
579  {
580  mTau = mTauPrime = 1;
581  }
582 
583  return true;
584 }
CVector< C_FLOAT64 > mValue
virtual bool initialize()
Definition: COptMethod.cpp:189
unsigned C_INT32 mPopulationSize
std::vector< CVector< C_FLOAT64 > * > mVariance
#define childrate
virtual bool cleanup()
unsigned C_INT32 mGenerations
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
C_FLOAT64 mBestValue
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)
CVector< C_FLOAT64 > mMaxVariance
const Value & getValue() const
bool setValue(const std::string &name, const CType &value)
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
unsigned C_INT32 mGeneration
unsigned C_INT32 * pUINT
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
CVector< C_FLOAT64 > mPhi
CProcessReport * mpCallBack
void COptMethodSRES::initObjects ( )
private

Initialize contained objects.

Definition at line 493 of file COptMethodSRES.cpp.

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

Referenced by COptMethodSRES().

494 {
496 }
unsigned C_INT32 mGeneration
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodSRES::mutate ( )
private

Mutate the new generation

Definition at line 161 of file COptMethodSRES.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, C_INVALID_INDEX, COptItem::checkConstraint(), evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomNormal01(), COptItem::getUpperBoundValue(), mEvaluationValue, min, mIndividual, mMaxVariance, mPhi, mPopulationSize, mpRandom, mTau, mTauPrime, mValue, mVariableSize, mVariance, and phi().

Referenced by replicate().

162 {
163  std::vector< CVector < C_FLOAT64 > * >::iterator it = mIndividual.begin() + mPopulationSize;
164  std::vector< CVector < C_FLOAT64 > * >::iterator end = mIndividual.end();
165  std::vector< CVector < C_FLOAT64 > * >::iterator itVariance = mVariance.begin() + mPopulationSize;
166 
167  C_FLOAT64 * pVariable, * pVariableEnd, * pVariance, * pMaxVariance;
168  C_FLOAT64 * pPhi = mPhi.array() + mPopulationSize;
169  C_FLOAT64 * pValue = mValue.array() + mPopulationSize;
170 
171  bool Continue = true;
172  size_t i, j;
173  C_FLOAT64 v1;
174 
175  // Mutate each new individual
176  for (i = mPopulationSize; it != end && Continue; ++it, ++itVariance, ++i)
177  {
178  pVariable = (*it)->array();
179  pVariableEnd = pVariable + mVariableSize;
180  pVariance = (*itVariance)->array();
181  pMaxVariance = mMaxVariance.array();
182 
183  v1 = mpRandom->getRandomNormal01();
184 
185  for (j = 0; pVariable != pVariableEnd; ++pVariable, ++pVariance, ++pMaxVariance, ++j)
186  {
187  C_FLOAT64 & mut = *pVariable;
188  C_FLOAT64 Store = mut;
189 
190  COptItem & OptItem = *(*mpOptItem)[j];
191 
192  size_t l = C_INVALID_INDEX;
193 
194  try
195  {
196  // update the parameter for the variances
197  *pVariance =
198  std::min(*pVariance * exp(mTauPrime * v1 + mTau * mpRandom->getRandomNormal01()), *pMaxVariance);
199 
200  for (l = 0; l < 10; l++)
201  {
202  // calculate the mutated parameter
203  mut = Store + *pVariance * mpRandom->getRandomNormal01();
204 
205  if (OptItem.checkConstraint(mut) == 0)
206  break;
207  }
208  }
209 
210  catch (...)
211  {
212  mut = (*OptItem.getUpperBoundValue() + *OptItem.getLowerBoundValue()) * 0.5;
213  }
214 
215  if (l == 10)
216  mut = Store;
217 
218  // We need to set the value here so that further checks take
219  // account of the value.
220  (*(*mpSetCalculateVariable)[j])(mut);
221  }
222 
223  // calculate its fitness
224  Continue = evaluate(**it);
225  *pValue++ = mEvaluationValue;
226  *pPhi++ = phi(i);
227  }
228 
229  return Continue;
230 }
C_FLOAT64 phi(size_t indvNum)
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
std::vector< CVector< C_FLOAT64 > * > mVariance
C_FLOAT64 mEvaluationValue
#define C_INVALID_INDEX
Definition: copasi.h:222
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
virtual C_FLOAT64 getRandomNormal01()
Definition: CRandom.cpp:261
CVector< C_FLOAT64 > mMaxVariance
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CVector< C_FLOAT64 > mPhi
bool evaluate(const CVector< C_FLOAT64 > &individual)
#define min(a, b)
Definition: f2c.h:175
bool COptMethodSRES::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 641 of file COptMethodSRES.cpp.

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

642 {
643  bool Continue = true;
644  size_t BestIndex = C_INVALID_INDEX;
645 
646 #ifdef RANDOMIZE
647  // Counters to determine whether the optimization process has stalled
648  // They count the number of generations without advances.
649  size_t Stalled10, Stalled20, Stalled40, Stalled80;
650  Stalled10 = Stalled20 = Stalled40 = Stalled80 = 0;
651 #endif // RANDOMIZE
652 
653  if (!initialize())
654  {
655  if (mpCallBack)
657 
658  return false;
659  }
660 
661  // initialise the population
662  Continue = creation(0);
663 
664  // get the index of the fittest
665  BestIndex = fittest();
666 
667  if (BestIndex != C_INVALID_INDEX)
668  {
669  // and store that value
670  mBestValue = mValue[BestIndex];
671  Continue = mpOptProblem->setSolution(mBestValue, *mIndividual[BestIndex]);
672 
673  // We found a new best value lets report it.
675  }
676 
677  if (!Continue)
678  {
679  if (mpCallBack)
681 
682  cleanup();
683  return true;
684  }
685 
686  // ITERATE FOR gener GENERATIONS
687 #ifdef RANDOMIZE
688 
689  for (mGeneration = 2;
690  mGeneration <= mGenerations && Continue;
691  mGeneration++, Stalled10++, Stalled20++, Stalled40++, Stalled80++)
692  {
693  // perturb the population if we have stalled for a while
694  if (Stalled80 > 80)
695  {
696  Continue = creation((size_t)(mPopulationSize * 0.2));
697  Stalled10 = Stalled20 = Stalled40 = Stalled80 = 0;
698  }
699  else if (Stalled40 > 40)
700  {
701  Continue = creation((size_t)(mPopulationSize * 0.6));
702  Stalled10 = Stalled20 = Stalled40 = 0;
703  }
704  else if (Stalled20 > 20)
705  {
706  Continue = creation((size_t)(mPopulationSize * 0.8));
707  Stalled10 = Stalled20 = 0;
708  }
709  else if (Stalled10 > 10)
710  {
711  Continue = creation((size_t)(mPopulationSize * 0.9));
712  Stalled10 = 0;
713  }
714 
715 #else
716 
717  for (mGeneration = 2;
718  mGeneration <= mGenerations && Continue;
719  mGeneration++)
720  {
721 #endif // RANDOMIZE
722  Continue = replicate();
723 
724  // select the most fit
725  select();
726 
727  // get the index of the fittest
728  BestIndex = fittest();
729 
730  if (BestIndex != C_INVALID_INDEX &&
731  mValue[BestIndex] < mBestValue)
732  {
733 #ifdef RANDOMIZE
734  Stalled10 = Stalled20 = Stalled40 = Stalled80 = 0;
735 #endif // RANDOMIZE
736  mBestValue = mValue[BestIndex];
737 
738  Continue = mpOptProblem->setSolution(mBestValue, *mIndividual[BestIndex]);
739 
740  // We found a new best value lets report it.
742  }
743 
744  if (mpCallBack)
746  }
747 
748  if (mpCallBack)
750 
751  return true;
752 }
COptTask * mpParentTask
Definition: COptMethod.h:58
CVector< C_FLOAT64 > mValue
unsigned C_INT32 mPopulationSize
virtual bool cleanup()
unsigned C_INT32 mGenerations
#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)
std::vector< CVector< C_FLOAT64 > * > mIndividual
C_FLOAT64 mBestValue
unsigned C_INT32 mGeneration
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool finishItem(const size_t &handle)
virtual bool initialize()
bool creation(size_t first)
CProcessReport * mpCallBack
C_FLOAT64 COptMethodSRES::phi ( size_t  indvNum)
private

For Stochastic Ranking, evaluate the distance ofparameters to boundaries

Returns
C_FLOAT64 phiVal

Definition at line 602 of file COptMethodSRES.cpp.

References C_FLOAT64, mIndividual, COptMethod::mpOptContraints, and COptMethod::mpOptItem.

Referenced by creation(), and mutate().

603 {
604  C_FLOAT64 phiVal = 0.0;
605  C_FLOAT64 phiCalc;
606 
607  std::vector< COptItem * >::const_iterator it = mpOptItem->begin();
608  std::vector< COptItem * >::const_iterator end = mpOptItem->end();
609  C_FLOAT64 * pValue = mIndividual[indivNum]->array();
610 
611  for (; it != end; ++it, pValue++)
612  {
613  switch ((*it)->checkConstraint())
614  {
615  case - 1:
616  phiCalc = *(*it)->getLowerBoundValue() - *pValue;
617  phiVal += phiCalc * phiCalc;
618  break;
619 
620  case 1:
621  phiCalc = *pValue - *(*it)->getUpperBoundValue();
622  phiVal += phiCalc * phiCalc;
623  break;
624  }
625  }
626 
627  it = mpOptContraints->begin();
628  end = mpOptContraints->end();
629 
630  for (; it != end; ++it)
631  {
632  phiCalc = (*it)->getConstraintViolation();
633 
634  if (phiCalc > 0.0)
635  phiVal += phiCalc * phiCalc;
636  }
637 
638  return phiVal;
639 }
const std::vector< COptItem * > * mpOptContraints
Definition: COptMethod.h:75
std::vector< CVector< C_FLOAT64 > * > mIndividual
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
#define C_FLOAT64
Definition: copasi.h:92
bool COptMethodSRES::replicate ( void  )
private

Replicate the individuals with crossover

Returns
bool continue

Definition at line 114 of file COptMethodSRES.cpp.

References C_FLOAT64, childrate, CRandom::getRandomU(), mIndividual, mPopulationSize, mpRandom, mutate(), mVariableSize, and mVariance.

Referenced by optimise().

115 {
116  bool Continue = true;
117 
118  size_t Parent;
119  size_t i, j;
120 
121  std::vector< CVector < C_FLOAT64 > * >::iterator itSrc = mIndividual.begin();
122  std::vector< CVector < C_FLOAT64 > * >::iterator endSrc = itSrc + mPopulationSize;
123  std::vector< CVector < C_FLOAT64 > * >::iterator itTarget = endSrc;
124 
125  std::vector< CVector < C_FLOAT64 > * >::iterator itSrcVariance = mVariance.begin();
126  std::vector< CVector < C_FLOAT64 > * >::iterator itTargetVariance = itSrcVariance + mPopulationSize;
127 
128  C_FLOAT64 * pVariance, * pVarianceEnd, * pParentVariance;
129 
130  // iterate over parents
131  for (i = 0; itSrc != endSrc && Continue; ++itSrc, ++itSrcVariance, ++i)
132  {
133  // iterate over the child rate - 1 since the first child is the
134  // parent.
135  for (j = 1; j < childrate; ++j, ++itTarget, ++itTargetVariance)
136  {
137  // first just copy the individuals
138  **itTarget = **itSrc;
139  **itTargetVariance = **itSrcVariance;
140 
141  // do recombination on the sigma
142  // since sigmas already have one parent's component
143  // need only average with the sigmas of the other parent
144  Parent = (i + mpRandom->getRandomU(mPopulationSize - 1)) % mPopulationSize;
145 
146  pVariance = (*itTargetVariance)->array();
147  pVarianceEnd = pVariance + mVariableSize;
148  pParentVariance = mVariance[Parent]->array();
149 
150  for (; pVariance != pVarianceEnd; ++pVariance, ++pParentVariance)
151  *pVariance = (*pVariance + *pParentVariance) * .5;
152  }
153  }
154 
155  Continue &= mutate();
156 
157  return Continue;
158 }
unsigned C_INT32 mPopulationSize
std::vector< CVector< C_FLOAT64 > * > mVariance
#define childrate
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
virtual unsigned C_INT32 getRandomU()
Definition: CRandom.cpp:173
#define C_FLOAT64
Definition: copasi.h:92
void COptMethodSRES::select ( )
private

Select surviving population

Returns
success

Definition at line 233 of file COptMethodSRES.cpp.

References CRandom::getRandomOO(), mIndividual, mPf, mPhi, mpRandom, mValue, and swap().

Referenced by optimise().

234 {
235  size_t i, j;
236  size_t TotalPopulation = mIndividual.size();
237  bool wasSwapped;
238  size_t sweepNum = TotalPopulation; // This is default based on paper
239 
240  // Selection Method for Stochastic Ranking
241  // stochastic ranking "bubble sort"
242 
243  for (i = 0; i < sweepNum; i++) // Here sweepNum is optimal number of sweeps from paper
244  {
245  wasSwapped = false;
246 
247  // :TODO: since we are only interested in mPopulationSize highest ranked
248  // individuals the upper limit of the loop can be improved.
249  for (j = 0; j < TotalPopulation - 1; j++) // lambda is number of individuals
250  {
251  if ((mPhi[j] == 0 && mPhi[j + 1] == 0) || // within bounds
252  (mpRandom->getRandomOO() < mPf)) // random chance to compare values outside bounds
253  {
254  // compare obj fcn using mValue alternative code
255  if (mValue[j] > mValue[j + 1])
256  {
257  swap(j, j + 1);
258  wasSwapped = true;
259  }
260  }
261  else
262  {
263  if (mPhi[j] > mPhi[j + 1]) // j further outside then j+1
264  {
265  swap(j, j + 1);
266  wasSwapped = true;
267  }
268  }
269  }
270 
271  // if nothing was swapped, then they're ordered!
272  if (wasSwapped == false) break;
273  }
274 }
CVector< C_FLOAT64 > mValue
virtual C_FLOAT64 getRandomOO()
Definition: CRandom.cpp:254
CRandom * mpRandom
std::vector< CVector< C_FLOAT64 > * > mIndividual
bool swap(size_t from, size_t to)
CVector< C_FLOAT64 > mPhi
bool COptMethodSRES::swap ( size_t  from,
size_t  to 
)
private

Swap individuals from and to

Parameters
size_tfrom
size_tto
Returns
bool success

Definition at line 93 of file COptMethodSRES.cpp.

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

Referenced by select().

94 {
95  CVector< C_FLOAT64 > * pTmp = mIndividual[to];
96  mIndividual[to] = mIndividual[from];
97  mIndividual[from] = pTmp;
98 
99  pTmp = mVariance[to];
100  mVariance[to] = mVariance[from];
101  mVariance[from] = pTmp;
102 
103  C_FLOAT64 dTmp = mValue[to];
104  mValue[to] = mValue[from];
105  mValue[from] = dTmp;
106 
107  dTmp = mPhi[to];
108  mPhi[to] = mPhi[from];
109  mPhi[from] = dTmp;
110 
111  return true;
112 }
CVector< C_FLOAT64 > mValue
std::vector< CVector< C_FLOAT64 > * > mVariance
std::vector< CVector< C_FLOAT64 > * > mIndividual
#define C_FLOAT64
Definition: copasi.h:92
CVector< C_FLOAT64 > mPhi

Friends And Related Function Documentation

Member Data Documentation

C_FLOAT64 COptMethodSRES::mBestValue
private

Definition at line 191 of file COptMethodSRES.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodSRES::mEvaluationValue
private

The value of the last evaluation.

Definition at line 184 of file COptMethodSRES.h.

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

unsigned C_INT32 COptMethodSRES::mGeneration
private

Definition at line 193 of file COptMethodSRES.h.

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

unsigned C_INT32 COptMethodSRES::mGenerations
private

number of generations

Definition at line 134 of file COptMethodSRES.h.

Referenced by initialize(), and optimise().

size_t COptMethodSRES::mhGenerations
private

Handle to the process report item "Current Generation"

Definition at line 139 of file COptMethodSRES.h.

Referenced by initialize(), and optimise().

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

for array of individuals w/ candidate values for the parameters

Definition at line 164 of file COptMethodSRES.h.

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

CVector< C_FLOAT64 > COptMethodSRES::mMaxVariance
private

A vector of maximal variances

Definition at line 179 of file COptMethodSRES.h.

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

C_FLOAT64 COptMethodSRES::mPf
private

Probability value used for SR ****

Definition at line 154 of file COptMethodSRES.h.

Referenced by initialize(), and select().

CVector< C_FLOAT64 > COptMethodSRES::mPhi
private

For Stochastic Ranking. Used for array of Phi values for the individuals

Definition at line 169 of file COptMethodSRES.h.

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

unsigned C_INT32 COptMethodSRES::mPopulationSize
private

size of the population

Definition at line 144 of file COptMethodSRES.h.

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

CRandom* COptMethodSRES::mpRandom
private

a pointer to the randomnumber generator.

Definition at line 149 of file COptMethodSRES.h.

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

double COptMethodSRES::mTau
private

Definition at line 195 of file COptMethodSRES.h.

Referenced by initialize(), and mutate().

double COptMethodSRES::mTauPrime
private

Definition at line 197 of file COptMethodSRES.h.

Referenced by initialize(), and mutate().

CVector< C_FLOAT64 > COptMethodSRES::mValue
private

array of values of objective function f/ individuals

Definition at line 189 of file COptMethodSRES.h.

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

size_t COptMethodSRES::mVariableSize
private

number of parameters

Definition at line 159 of file COptMethodSRES.h.

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

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

for array of variances w/ variance values for the parameters

Definition at line 174 of file COptMethodSRES.h.

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


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