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

#include <COptMethodSA.h>

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

Public Member Functions

 COptMethodSA (const COptMethodSA &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodSA ()
 
- 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 ()
 
 COptMethodSA (const CCopasiContainer *pParent=NULL)
 
const C_FLOAT64evaluate ()
 
virtual bool initialize ()
 
void initObjects ()
 

Private Attributes

CVector< size_t > mAccepted
 
C_FLOAT64 mBestValue
 
bool mContinue
 
C_FLOAT64 mCoolingFactor
 
CVector< C_FLOAT64mCurrent
 
C_FLOAT64 mCurrentValue
 
C_FLOAT64 mEvaluationValue
 
size_t mhTemperature
 
CRandommpRandom
 
CVector< C_FLOAT64mStep
 
C_FLOAT64 mTemperature
 
C_FLOAT64 mTolerance
 
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 31 of file COptMethodSA.h.

Constructor & Destructor Documentation

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

Copy Constructor

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

Definition at line 47 of file COptMethodSA.cpp.

References initObjects().

48  :
49  COptMethod(src, pParent)
50 {initObjects();}
void initObjects()
COptMethodSA::~COptMethodSA ( )
virtual

Destructor

Definition at line 52 of file COptMethodSA.cpp.

References cleanup().

53 {cleanup();}
virtual bool cleanup()
COptMethodSA::COptMethodSA ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 35 of file COptMethodSA.cpp.

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

35  :
37 {
38  addParameter("Start Temperature", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0);
39  addParameter("Cooling Factor", CCopasiParameter::UDOUBLE, (C_FLOAT64) 0.85);
40  addParameter("Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.e-006);
41  addParameter("Random Number Generator", CCopasiParameter::UINT, (unsigned C_INT32) CRandom::mt19937);
42  addParameter("Seed", CCopasiParameter::UINT, (unsigned C_INT32) 0);
43 
44  initObjects();
45 }
#define C_INT32
Definition: copasi.h:90
#define C_FLOAT64
Definition: copasi.h:92
bool addParameter(const CCopasiParameter &parameter)
void initObjects()

Member Function Documentation

bool COptMethodSA::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 275 of file COptMethodSA.cpp.

Referenced by initialize(), and ~COptMethodSA().

276 {
277  return true;
278 }
const C_FLOAT64 & COptMethodSA::evaluate ( )
private

Evaluate the objective function

Returns
bool continue

Definition at line 280 of file COptMethodSA.cpp.

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

Referenced by optimise().

281 {
282  // We do not need to check whether the parametric constraints are fulfilled
283  // since the parameters are created within the bounds.
284 
287 
288  // When we leave the either functional domain
289  // we set the objective value +Inf
291  mEvaluationValue = std::numeric_limits<C_FLOAT64>::infinity();
292 
293  return mEvaluationValue;
294 }
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
virtual bool checkFunctionalConstraints()
C_FLOAT64 mEvaluationValue
Definition: COptMethodSA.h:129
const C_FLOAT64 & getCalculateValue() const
bool COptMethodSA::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 296 of file COptMethodSA.cpp.

References CProcessReport::addItem(), cleanup(), CRandom::createGenerator(), CCopasiParameter::getValue(), COptMethod::initialize(), mAccepted, mBestValue, mContinue, mCoolingFactor, mCurrent, mhTemperature, CCopasiMethod::mpCallBack, COptMethod::mpOptItem, mpRandom, mStep, mTemperature, mTolerance, mVariableSize, CCopasiParameter::Value::pUDOUBLE, and CVector< CType >::resize().

Referenced by optimise().

297 {
298  cleanup();
299 
300  if (!COptMethod::initialize()) return false;
301 
302  mTemperature = * getValue("Start Temperature").pUDOUBLE;
303  mCoolingFactor = * getValue("Cooling Factor").pUDOUBLE;
304  mTolerance = * getValue("Tolerance").pUDOUBLE;
305  mpRandom =
306  CRandom::createGenerator(* (CRandom::Type *) getValue("Random Number Generator").pUINT,
307  * getValue("Seed").pUINT);
308 
309  if (mpCallBack)
310  mhTemperature =
311  mpCallBack->addItem("Current Temperature",
312  mTemperature);
313 
314  mBestValue = std::numeric_limits<C_FLOAT64>::infinity();
315  mContinue = true;
316 
317  mVariableSize = mpOptItem->size();
318 
322 
323  return true;
324 }
C_FLOAT64 mTolerance
Definition: COptMethodSA.h:109
virtual bool cleanup()
virtual bool initialize()
Definition: COptMethod.cpp:189
CVector< C_FLOAT64 > mCurrent
Definition: COptMethodSA.h:139
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
size_t mVariableSize
Definition: COptMethodSA.h:119
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
C_FLOAT64 mCoolingFactor
Definition: COptMethodSA.h:104
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
C_FLOAT64 mTemperature
Definition: COptMethodSA.h:94
const Value & getValue() const
CVector< size_t > mAccepted
Definition: COptMethodSA.h:154
CVector< C_FLOAT64 > mStep
Definition: COptMethodSA.h:149
size_t mhTemperature
Definition: COptMethodSA.h:99
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
CProcessReport * mpCallBack
C_FLOAT64 mBestValue
Definition: COptMethodSA.h:124
CRandom * mpRandom
Definition: COptMethodSA.h:114
void COptMethodSA::initObjects ( )
private

Initialize contained objects.

Definition at line 55 of file COptMethodSA.cpp.

References CCopasiContainer::addObjectReference(), mTemperature, and CCopasiObject::ValueDbl.

Referenced by COptMethodSA().

56 {
58 }
C_FLOAT64 mTemperature
Definition: COptMethodSA.h:94
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodSA::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 60 of file COptMethodSA.cpp.

References C_FLOAT64, COptItem::checkConstraint(), COptProblem::checkFunctionalConstraints(), COptProblem::checkParametricConstraints(), COutputInterface::DURING, evaluate(), CProcessReport::finishItem(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), CRandom::getRandomCO(), COptProblem::getSolutionVariables(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), initialize(), K, mAccepted, max, mBestValue, mContinue, mCoolingFactor, mCurrent, mCurrentValue, mEvaluationValue, mhTemperature, CCopasiMethod::mpCallBack, COptMethod::mpOptProblem, COptMethod::mpParentTask, mpRandom, COptMethod::mpSetCalculateVariable, mStep, mTemperature, mTolerance, mVariableSize, NS, CCopasiTask::output(), CProcessReport::progressItem(), COptProblem::setSolution(), and STORED.

61 {
62  if (!initialize())
63  {
64  if (mpCallBack)
66 
67  return false;
68  }
69 
70  size_t i, j, k, m;
71 
72  size_t h, a;
73  C_FLOAT64 xc, p, c, nt, New;
74  C_FLOAT64 fk[STORED];
75  bool ready;
76 
77  // initial point is first guess but we have to make sure that we
78  // are within the parameter domain
79  for (i = 0; i < mVariableSize; i++)
80  {
81  const COptItem & OptItem = *(*mpOptItem)[i];
82 
83  switch (OptItem.checkConstraint(OptItem.getStartValue()))
84  {
85  case - 1:
86  mCurrent[i] = *OptItem.getLowerBoundValue();
87  break;
88 
89  case 1:
90  mCurrent[i] = *OptItem.getUpperBoundValue();
91  break;
92 
93  case 0:
94  mCurrent[i] = OptItem.getStartValue();
95  break;
96  }
97 
98  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
99 
100  // The step must not contain any zeroes
101  mStep[i] = std::max(fabs(mCurrent[i]), 1.0);
102  }
103 
105 
106  if (!isnan(mEvaluationValue))
107  {
108  // and store that value
111 
112  // We found a new best value lets report it.
114  }
115 
116  // store this in all positions
117  for (a = 0; a < STORED; a++)
118  fk[a] = mCurrentValue;
119 
120  mAccepted = 0;
121 
122  // set the number of steps at one single temperature
123  nt = (C_FLOAT64)(5 * mVariableSize);
124 
125  if (nt < 100) nt = 100;
126 
127  // no temperature reductions yet
128  k = 0;
129 
130  do // number of internal cycles: max(5*mVariableSize, 100) * NS * mVariableSize
131  {
132  for (m = 0; m < nt && mContinue; m++) // step adjustments
133  {
134  for (j = 0; j < NS && mContinue; j++) // adjustment in all directions
135  {
136  for (h = 0; h < mVariableSize && mContinue; h++) // adjustment in one direction
137  {
138  // Calculate the step
139  xc = (2.0 * mpRandom->getRandomCC() - 1) * mStep[h];
140  New = mCurrent[h] + xc;
141 
142  // Set the new parameter value
143  (*(*mpSetCalculateVariable)[h])(New);
144 
145  // Check all parametric constraints
147  {
148  // Undo since not accepted
149  (*(*mpSetCalculateVariable)[h])(mCurrent[h]);
150  continue;
151  }
152 
153  // evaluate the function
154  evaluate();
155 
156  // Check all functional constraints
158  {
159  // Undo since not accepted
160  (*(*mpSetCalculateVariable)[h])(mCurrent[h]);
161  continue;
162  }
163 
164  // here we have a completely feasible point
165  // keep if energy is reduced
167  {
168  // only one value has changed...
169  mCurrent[h] = New;
171  i++; // a new point
172  mAccepted[h]++; // a new point in this coordinate
173 
175  {
176  // and store that value
179 
180  // We found a new best value lets report it.
182  }
183  }
184  else
185  {
186  // keep with probability p, if energy is increased
187  p = exp((mCurrentValue - mEvaluationValue) / (K * mTemperature));
188 
189  if (p > mpRandom->getRandomCO())
190  {
191  // only one value has changed...
192  mCurrent[h] = New;
194  i++; // a new point
195  mAccepted[h]++; // a new point in this coordinate
196  }
197  else
198  // Undo since not accepted
199  (*(*mpSetCalculateVariable)[h])(mCurrent[h]);
200  }
201  }
202  }
203 
204  // update the step sizes
205  for (a = 0; a < mVariableSize; a++)
206  {
207  c = (C_FLOAT64) mAccepted[a] / (C_FLOAT64) NS;
208 
209  if (c > 0.6)
210  mStep[a] *= 1 + 5 * (c - 0.6);
211  else if (c < 0.4)
212  mStep[a] /= 1 + 5 * (0.4 - c);
213 
214  mAccepted[a] = 0;
215  }
216  }
217 
218  // the equilibrium energy
219 
220  k++;
221 
222  // if this is the first cycle ignore the convergence tests
223  if (k == 1)
224  ready = false;
225  else
226  {
227  ready = true;
228 
229  // check termination criterion of not much change since last STORED times
230  for (a = 0; a < STORED; a++)
231  if (fabs(fk[a] - mCurrentValue) > mTolerance)
232  {
233  ready = false;
234  break;
235  }
236 
237  if (!ready)
238  {
239  for (a = 0; a < STORED - 1; a++)
240  fk[a] = fk[a + 1];
241 
242  fk[STORED - 1] = mCurrentValue;
243  }
244  // check the termination criterion of not much larger than last optimal
245  else if (fabs(mCurrentValue - mBestValue) > mTolerance)
246  ready = false;
247  }
248 
249  if (!ready)
250  {
251  i++;
252 
254 
255  for (a = 0; a < mVariableSize; a++)
256  (*(*mpSetCalculateVariable)[a])(mCurrent[a]);
257 
259  }
260 
261  // update the temperature
263 
264  if (mpCallBack)
265  mContinue &= mpCallBack->progressItem(mhTemperature);
266  }
267  while (!ready && mContinue);
268 
269  if (mpCallBack)
271 
272  return true;
273 }
C_FLOAT64 mTolerance
Definition: COptMethodSA.h:109
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
CVector< C_FLOAT64 > mCurrent
Definition: COptMethodSA.h:139
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
virtual bool initialize()
virtual bool progressItem(const size_t &handle)
size_t mVariableSize
Definition: COptMethodSA.h:119
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
C_FLOAT64 mCoolingFactor
Definition: COptMethodSA.h:104
C_FLOAT64 mTemperature
Definition: COptMethodSA.h:94
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
CVector< size_t > mAccepted
Definition: COptMethodSA.h:154
const CVector< C_FLOAT64 > & getSolutionVariables() const
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool finishItem(const size_t &handle)
virtual bool checkFunctionalConstraints()
#define NS
CVector< C_FLOAT64 > mStep
Definition: COptMethodSA.h:149
size_t mhTemperature
Definition: COptMethodSA.h:99
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
virtual C_FLOAT64 getRandomCO()
Definition: CRandom.cpp:245
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 mCurrentValue
Definition: COptMethodSA.h:144
#define STORED
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
virtual bool checkParametricConstraints()
C_FLOAT64 mEvaluationValue
Definition: COptMethodSA.h:129
const C_FLOAT64 & evaluate()
CProcessReport * mpCallBack
C_FLOAT64 mBestValue
Definition: COptMethodSA.h:124
CRandom * mpRandom
Definition: COptMethodSA.h:114
#define K
#define max(a, b)
Definition: f2c.h:176

Friends And Related Function Documentation

Member Data Documentation

CVector< size_t > COptMethodSA::mAccepted
private

The number of accepted steps

Definition at line 154 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodSA::mBestValue
private

The best value found so far

Definition at line 124 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

bool COptMethodSA::mContinue
private

Flag indicating whether the computation shall continue

Definition at line 134 of file COptMethodSA.h.

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

C_FLOAT64 COptMethodSA::mCoolingFactor
private

The cooling factor

Definition at line 104 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

CVector< C_FLOAT64 > COptMethodSA::mCurrent
private

The current solution guess

Definition at line 139 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodSA::mCurrentValue
private

The result of a function evaluation for mCurrent

Definition at line 144 of file COptMethodSA.h.

Referenced by optimise().

C_FLOAT64 COptMethodSA::mEvaluationValue
private

The result of a function evaluation

Definition at line 129 of file COptMethodSA.h.

Referenced by evaluate(), and optimise().

size_t COptMethodSA::mhTemperature
private

Handle to the process report item "Current Temperature"

Definition at line 99 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

CRandom* COptMethodSA::mpRandom
private

a pointer to the randomnumber generator.

Definition at line 114 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

CVector< C_FLOAT64 > COptMethodSA::mStep
private

The step taken

Definition at line 149 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodSA::mTemperature
private

The current temperature

Definition at line 94 of file COptMethodSA.h.

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

C_FLOAT64 COptMethodSA::mTolerance
private

The tolerance

Definition at line 109 of file COptMethodSA.h.

Referenced by initialize(), and optimise().

size_t COptMethodSA::mVariableSize
private

number of parameters

Definition at line 119 of file COptMethodSA.h.

Referenced by initialize(), and optimise().


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