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

#include <COptProblem.h>

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

Public Member Functions

COptItemaddOptItem (const CCopasiObjectName &objectCN)
 
virtual bool calculate ()
 
virtual bool calculateStatistics (const C_FLOAT64 &factor=1.0e-003, const C_FLOAT64 &resolution=1.0e-009)
 
virtual bool checkFunctionalConstraints ()
 
virtual bool checkParametricConstraints ()
 
 COptProblem (const CCopasiTask::Type &type=CCopasiTask::optimization, const CCopasiContainer *pParent=NULL)
 
 COptProblem (const COptProblem &src, const CCopasiContainer *pParent=NULL)
 
virtual bool elevateChildren ()
 
const bool & getCalculateStatistics () const
 
const C_FLOAT64getCalculateValue () const
 
const std::vector
< UpdateMethod * > & 
getCalculateVariableUpdateMethods () const
 
const std::vector< COptItem * > & getConstraintList () const
 
const C_FLOAT64getExecutionTime () const
 
const unsigned C_INT32getFunctionEvaluations () const
 
const std::string getObjectiveFunction ()
 
COptItemgetOptItem (const size_t &index)
 
const std::vector< COptItem * > & getOptItemList () const
 
size_t getOptItemSize () const
 
const bool & getRandomizeStartValues () const
 
const C_FLOAT64getSolutionValue () const
 
const CVector< C_FLOAT64 > & getSolutionVariables () const
 
CCopasiTask::Type getSubtaskType () const
 
const CVector< C_FLOAT64 > & getVariableGradients () const
 
size_t getVariableSize () const
 
void incrementEvaluations (unsigned C_INT32 increment)
 
virtual bool initialize ()
 
virtual bool initializeSubtaskBeforeOutput ()
 
const bool & maximize () const
 
virtual void print (std::ostream *ostream) const
 
virtual void printResult (std::ostream *ostream) const
 
void randomizeStartValues ()
 
void rememberStartValues ()
 
bool removeOptItem (const size_t &index)
 
void reset ()
 
void resetEvaluations ()
 
virtual bool restore (const bool &updateModel)
 
void restoreModel (const bool &updateModel)
 
void setCalculateStatistics (const bool &calculate)
 
virtual bool setCallBack (CProcessReport *pCallBack)
 
void setMaximize (const bool &maximize)
 
virtual bool setModel (CModel *pModel)
 
bool setObjectiveFunction (const std::string &infix)
 
void setRandomizeStartValues (const bool &randomize)
 
virtual bool setSolution (const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
 
bool setSubtaskType (const CCopasiTask::Type &subtaskType)
 
bool swapOptItem (const size_t &iFrom, const size_t &iTo)
 
virtual ~COptProblem ()
 
- Public Member Functions inherited from CCopasiProblem
 CCopasiProblem (const CCopasiProblem &src, const CCopasiContainer *pParent=NULL)
 
CModelgetModel () const
 
const CCopasiTask::TypegetType () const
 
virtual ~CCopasiProblem ()
 
- 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 ()
 
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 ()
 

Static Public Attributes

static const unsigned int ValidSubtasks []
 
- 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 Attributes

C_FLOAT64 mCalculateValue
 
unsigned C_INT32 mConstraintCounter
 
unsigned C_INT32 mCounter
 
CCopasiTimer mCPUTime
 
unsigned C_INT32 mFailedConstraintCounter
 
unsigned C_INT32 mFailedCounter
 
CVector< C_FLOAT64mGradient
 
bool mHaveStatistics
 
size_t mhCounter
 
size_t mhSolutionValue
 
std::vector< Refresh * > mInitialRefreshMethods
 
CVector< C_FLOAT64mOriginalVariables
 
std::vector< COptItem * > * mpConstraintItems
 
CCopasiParameterGroupmpGrpConstraints
 
CCopasiParameterGroupmpGrpItems
 
CExpressionmpObjectiveExpression
 
std::vector< COptItem * > * mpOptItems
 
bool * mpParmCalculateStatistics
 
bool * mpParmMaximize
 
std::string * mpParmObjectiveExpression
 
bool * mpParmRandomizeStartValues
 
std::string * mpParmSubtaskCN
 
CCopasiTaskmpSubtask
 
std::vector< Refresh * > mRefreshConstraints
 
std::vector< Refresh * > mRefreshMethods
 
C_FLOAT64 mSolutionValue
 
CVector< C_FLOAT64mSolutionVariables
 
bool mStoreResults
 
std::vector< UpdateMethod * > mUpdateMethods
 
C_FLOAT64 mWorstValue
 
- Protected Attributes inherited from CCopasiProblem
CProcessReportmpCallBack
 
CModelmpModel
 
CReportmpReport
 
- Protected Attributes inherited from CCopasiParameter
std::string mKey
 
CCopasiObjectmpValueReference
 
size_t mSize
 
Value mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 

Private Member Functions

void initializeParameter ()
 
void initObjects ()
 

Friends

std::ostream & operator<< (std::ostream &os, const COptProblem &o)
 

Additional Inherited Members

- 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 CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- 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 CCopasiProblem
 CCopasiProblem (const CCopasiTask::Type &type, 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)
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 49 of file COptProblem.h.

Constructor & Destructor Documentation

COptProblem::COptProblem ( const CCopasiTask::Type type = CCopasiTask::optimization,
const CCopasiContainer pParent = NULL 
)

Default constructor

Parameters
constCCopasiTask::Type & type (default: optimization)
constCCopasiContainer * pParent (default: NULL)

Definition at line 67 of file COptProblem.cpp.

References initializeParameter(), and initObjects().

68  :
69  CCopasiProblem(type, pParent),
70  mWorstValue(0.0),
71  mpParmSubtaskCN(NULL),
73  mpParmMaximize(NULL),
76  mpGrpItems(NULL),
77  mpGrpConstraints(NULL),
78  mpOptItems(NULL),
79  mpConstraintItems(NULL),
80  mpSubtask(NULL),
86  mCalculateValue(0),
89  mSolutionValue(0),
90  mCounter(0),
91  mFailedCounter(0),
97  mStoreResults(false),
98  mHaveStatistics(false),
99  mGradient(0)
100 {
102  initObjects();
103 }
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
std::vector< Refresh * > mInitialRefreshMethods
Definition: COptProblem.h:457
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
std::vector< UpdateMethod * > mUpdateMethods
Definition: COptProblem.h:451
CVector< C_FLOAT64 > mGradient
Definition: COptProblem.h:541
unsigned C_INT32 mFailedCounter
Definition: COptProblem.h:499
#define C_INVALID_INDEX
Definition: copasi.h:222
bool mHaveStatistics
Definition: COptProblem.h:536
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
size_t mhCounter
Definition: COptProblem.h:524
C_FLOAT64 mCalculateValue
Definition: COptProblem.h:474
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
std::vector< Refresh * > mRefreshConstraints
Definition: COptProblem.h:469
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
void initializeParameter()
bool mStoreResults
Definition: COptProblem.h:530
CCopasiParameterGroup * mpGrpConstraints
Definition: COptProblem.h:426
size_t mhSolutionValue
Definition: COptProblem.h:519
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
std::vector< Refresh * > mRefreshMethods
Definition: COptProblem.h:463
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
bool * mpParmMaximize
Definition: COptProblem.h:406
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
C_FLOAT64 mWorstValue
Definition: COptProblem.h:385
CVector< C_FLOAT64 > mOriginalVariables
Definition: COptProblem.h:484
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
void initObjects()
COptProblem::COptProblem ( const COptProblem src,
const CCopasiContainer pParent = NULL 
)

Copy constructor.

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

Definition at line 106 of file COptProblem.cpp.

References initializeParameter(), and initObjects().

107  :
108  CCopasiProblem(src, pParent),
110  mpParmSubtaskCN(NULL),
112  mpParmMaximize(NULL),
115  mpGrpItems(NULL),
116  mpGrpConstraints(NULL),
117  mpOptItems(NULL),
118  mpConstraintItems(NULL),
119  mpSubtask(NULL),
120  mpObjectiveExpression(NULL),
121  mUpdateMethods(),
123  mRefreshMethods(),
129  mCounter(0),
130  mFailedCounter(0),
138  mGradient(src.mGradient)
139 {
141  initObjects();
142 }
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
std::vector< Refresh * > mInitialRefreshMethods
Definition: COptProblem.h:457
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
std::vector< UpdateMethod * > mUpdateMethods
Definition: COptProblem.h:451
CVector< C_FLOAT64 > mGradient
Definition: COptProblem.h:541
unsigned C_INT32 mFailedCounter
Definition: COptProblem.h:499
#define C_INVALID_INDEX
Definition: copasi.h:222
bool mHaveStatistics
Definition: COptProblem.h:536
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
size_t mhCounter
Definition: COptProblem.h:524
C_FLOAT64 mCalculateValue
Definition: COptProblem.h:474
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
std::vector< Refresh * > mRefreshConstraints
Definition: COptProblem.h:469
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
void initializeParameter()
bool mStoreResults
Definition: COptProblem.h:530
CCopasiParameterGroup * mpGrpConstraints
Definition: COptProblem.h:426
size_t mhSolutionValue
Definition: COptProblem.h:519
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
std::vector< Refresh * > mRefreshMethods
Definition: COptProblem.h:463
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
bool * mpParmMaximize
Definition: COptProblem.h:406
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
C_FLOAT64 mWorstValue
Definition: COptProblem.h:385
CVector< C_FLOAT64 > mOriginalVariables
Definition: COptProblem.h:484
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
void initObjects()
COptProblem::~COptProblem ( )
virtual

Destructor

Definition at line 145 of file COptProblem.cpp.

146 {}

Member Function Documentation

COptItem & COptProblem::addOptItem ( const CCopasiObjectName objectCN)

Add an optimization item to the problem.

Parameters
constCCopasiObjectName & objectCN
Returns
COptItem optItemAdded

Definition at line 708 of file COptProblem.cpp.

References CCopasiParameterGroup::addParameter(), CCopasiObject::getObjectDataModel(), mpGrpItems, and COptItem::setObjectCN().

709 {
710  CCopasiDataModel* pDataModel = getObjectDataModel();
711  assert(pDataModel != NULL);
712 
713  COptItem * pItem = new COptItem(pDataModel);
714  pItem->setObjectCN(objectCN);
715 
716  mpGrpItems->addParameter(pItem);
717 
718  return *pItem;
719 }
CCopasiDataModel * getObjectDataModel()
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
bool setObjectCN(const CCopasiObjectName &objectCN)
Definition: COptItem.cpp:111
bool addParameter(const CCopasiParameter &parameter)
bool COptProblem::calculate ( void  )
virtual

Do the calculating based on CalculateVariables and fill CalculateResults with the results.

Returns
bool continue

calculate() decides whether the problem is a steady state problem or a trajectory problem based on whether the pointer to that type of problem is null or not. It then calls the process() method for that type of problem. Currently process takes ofstream& as a parameter but it will change so that process() takes no parameters.

Reimplemented in CFitProblem, and CRealProblem.

Definition at line 538 of file COptProblem.cpp.

References CExpression::calcValue(), CCopasiMessage::getLastMessage(), CCopasiTask::getProblem(), CCopasiTask::getType(), CCopasiTask::initialize(), mCalculateValue, mCounter, mFailedCounter, mhCounter, mInitialRefreshMethods, CCopasiProblem::mpCallBack, mpObjectiveExpression, mpParmMaximize, mpSubtask, mRefreshMethods, mStoreResults, CCopasiTask::NO_OUTPUT, CCopasiTask::ONLY_TIME_SERIES, pdelete, CCopasiTask::process(), CProcessReport::progressItem(), and CCopasiTask::timeCourse.

Referenced by calculateStatistics(), COptMethodEP::evaluate(), COptMethodStatistics::evaluate(), COptMethodSteepestDescent::evaluate(), CRandomSearch::evaluate(), COptMethodDE::evaluate(), COptMethodSRES::evaluate(), COptMethodPS::evaluate(), COptMethodGA::evaluate(), COptMethodHookeJeeves::evaluate(), COptMethodGASR::evaluate(), COptMethodLevenbergMarquardt::evaluate(), COptMethodNelderMead::evaluate(), COptMethodCoranaWalk::evaluate(), COptMethodSA::evaluate(), COptMethodSS::evaluate(), COptMethodPraxis::evaluate(), COptMethodTruncatedNewton::evaluate(), COptMethodEP2::optimise(), and setCalculateStatistics().

539 {
540  mCounter++;
541  bool success = false;
542  COutputHandler * pOutputHandler = NULL;
543 
544  if (mpSubtask == NULL)
545  return false;
546 
547  if (mStoreResults &&
549  {
550  static_cast< CTrajectoryProblem * >(mpSubtask->getProblem())->setTimeSeriesRequested(true);
551 
552  pOutputHandler = new COutputHandler();
553  mpSubtask->initialize(CCopasiTask::ONLY_TIME_SERIES, pOutputHandler, NULL);
554  }
555 
556  try
557  {
558  // Update all initial values which depend on the optimization items.
559  std::vector< Refresh * >::const_iterator it = mInitialRefreshMethods.begin();
560  std::vector< Refresh * >::const_iterator end = mInitialRefreshMethods.end();
561 
562  for (; it != end; ++it)
563  (**it)();
564 
565  success = mpSubtask->process(true);
566 
567  // Refresh all values needed to calculate the objective function.
568  it = mRefreshMethods.begin();
569  end = mRefreshMethods.end();
570 
571  for (; it != end; ++it)
572  (**it)();
573 
575  }
576 
577  catch (CCopasiException & /*Exception*/)
578  {
579  // We do not want to clog the message cue.
581 
582  success = false;
583  }
584 
585  catch (...)
586  {
587  success = false;
588  }
589 
590  if (mStoreResults &&
592  {
593  mStoreResults = false;
595  pdelete(pOutputHandler);
596  }
597 
598  if (!success || isnan(mCalculateValue))
599  {
600  mFailedCounter++;
601  mCalculateValue = std::numeric_limits< C_FLOAT64 >::infinity();
602  }
603 
605 
606  return true;
607 }
#define pdelete(p)
Definition: copasi.h:215
std::vector< Refresh * > mInitialRefreshMethods
Definition: COptProblem.h:457
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
CCopasiProblem * getProblem()
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
unsigned C_INT32 mFailedCounter
Definition: COptProblem.h:499
virtual bool progressItem(const size_t &handle)
size_t mhCounter
Definition: COptProblem.h:524
C_FLOAT64 mCalculateValue
Definition: COptProblem.h:474
virtual const C_FLOAT64 & calcValue()
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
bool mStoreResults
Definition: COptProblem.h:530
std::vector< Refresh * > mRefreshMethods
Definition: COptProblem.h:463
bool * mpParmMaximize
Definition: COptProblem.h:406
virtual bool process(const bool &useInitialValues)
static CCopasiMessage getLastMessage()
Type getType() const
CProcessReport * mpCallBack
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
bool COptProblem::calculateStatistics ( const C_FLOAT64 factor = 1.0e-003,
const C_FLOAT64 resolution = 1.0e-009 
)
virtual

Calculate the statistics for the problem

Parameters
constC_FLOAT64 & factor (Default: 1.0e-003)
constC_FLOAT64 & resolution (Default: 1.0e-009)

Reimplemented in CFitProblem.

Definition at line 609 of file COptProblem.cpp.

References C_FLOAT64, calculate(), CCopasiObject::getRefresh(), mCalculateValue, mCPUTime, mGradient, mHaveStatistics, mpParmCalculateStatistics, mpParmMaximize, mSolutionValue, mSolutionVariables, mStoreResults, mUpdateMethods, mWorstValue, CVector< CType >::resize(), and CVectorCore< CType >::size().

Referenced by COptTask::process().

611 {
612  // Set the current values to the solution values.
613  size_t i, imax = mSolutionVariables.size();
614 
615  mGradient.resize(imax);
616  mGradient = std::numeric_limits<C_FLOAT64>::quiet_NaN();
617 
618  // Recalculate the best solution.
619  for (i = 0; i < imax; i++)
621 
622  // This is necessary so that the result can be displayed.
623  mStoreResults = true;
624  calculate();
625  mStoreResults = false;
626 
627  // Make sure the timer is accurate.
629 
631  return false;
632 
634  {
635  mHaveStatistics = true;
636 
637  C_FLOAT64 Current;
638  C_FLOAT64 Delta;
639 
640  // Calculate the gradient
641  for (i = 0; i < imax; i++)
642  {
643  Current = mSolutionVariables[i];
644 
645  if (fabs(Current) > resolution)
646  {
647  (*mUpdateMethods[i])(Current * (1.0 + factor));
648  Delta = 1.0 / (Current * factor);
649  }
650  else
651  {
652  (*mUpdateMethods[i])(resolution);
653  Delta = 1.0 / resolution;
654  }
655 
656  calculate();
657 
659 
660  // Restore the value
661  (*mUpdateMethods[i])(Current);
662  }
663 
664  calculate();
665 
666  // Make sure the timer is accurate.
667  (*mCPUTime.getRefresh())();
668  }
669 
670  return true;
671 }
virtual Refresh * getRefresh() const
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
std::vector< UpdateMethod * > mUpdateMethods
Definition: COptProblem.h:451
CVector< C_FLOAT64 > mGradient
Definition: COptProblem.h:541
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
bool mHaveStatistics
Definition: COptProblem.h:536
C_FLOAT64 mCalculateValue
Definition: COptProblem.h:474
virtual bool calculate()
bool mStoreResults
Definition: COptProblem.h:530
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
bool * mpParmMaximize
Definition: COptProblem.h:406
size_t size() const
Definition: CVector.h:100
#define C_FLOAT64
Definition: copasi.h:92
C_FLOAT64 mWorstValue
Definition: COptProblem.h:385
bool COptProblem::checkFunctionalConstraints ( )
virtual

Check whether all functional constraints are fulfilled.

Returns
bool fulfilled

Reimplemented in CFitProblem.

Definition at line 507 of file COptProblem.cpp.

References mConstraintCounter, mFailedConstraintCounter, mpConstraintItems, and mRefreshConstraints.

Referenced by COptMethodEP::evaluate(), COptMethodStatistics::evaluate(), COptMethodSteepestDescent::evaluate(), CRandomSearch::evaluate(), COptMethodDE::evaluate(), COptMethodPS::evaluate(), COptMethodGA::evaluate(), COptMethodHookeJeeves::evaluate(), COptMethodSA::evaluate(), COptMethodNelderMead::evaluate(), COptMethodCoranaWalk::evaluate(), COptMethodLevenbergMarquardt::evaluate(), COptMethodSS::evaluate(), COptMethodPraxis::evaluate(), COptMethodTruncatedNewton::evaluate(), COptMethodSA::optimise(), and COptMethodCoranaWalk::optimise().

508 {
509  // Make sure the constraint values are up to date.
510  std::vector< Refresh *>::const_iterator itRefresh = mRefreshConstraints.begin();
511  std::vector< Refresh *>::const_iterator endRefresh = mRefreshConstraints.end();
512 
513  for (; itRefresh != endRefresh; ++itRefresh)
514  (**itRefresh)();
515 
516  std::vector< COptItem * >::const_iterator it = mpConstraintItems->begin();
517  std::vector< COptItem * >::const_iterator end = mpConstraintItems->end();
518 
520 
521  for (; it != end; ++it)
522  if ((*it)->checkConstraint())
523  {
525  return false;
526  }
527 
528  return true;
529 }
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
std::vector< Refresh * > mRefreshConstraints
Definition: COptProblem.h:469
bool COptProblem::checkParametricConstraints ( )
virtual

Check whether all parameters are within their boundaries.

Returns
bool within

Definition at line 496 of file COptProblem.cpp.

References mpOptItems.

Referenced by COptMethodSteepestDescent::evaluate(), COptMethodHookeJeeves::evaluate(), COptMethodNelderMead::evaluate(), COptMethodLevenbergMarquardt::evaluate(), COptMethodPraxis::evaluate(), COptMethodTruncatedNewton::evaluate(), COptMethodSA::optimise(), and COptMethodCoranaWalk::optimise().

497 {
498  std::vector< COptItem * >::const_iterator it = mpOptItems->begin();
499  std::vector< COptItem * >::const_iterator end = mpOptItems->end();
500 
501  for (; it != end; ++it)
502  if ((*it)->checkConstraint()) return false;
503 
504  return true;
505 }
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
bool COptProblem::elevateChildren ( )
virtual

This methods must be called to elevate subgroups to derived objects. The default implementation does nothing.

Returns
bool success

Reimplemented from CCopasiParameterGroup.

Reimplemented in CFitProblem.

Definition at line 167 of file COptProblem.cpp.

References C_INVALID_INDEX, CCopasiRootContainer::getFunctionList(), CCopasiVectorN< CType >::getIndex(), CEvaluationTree::getInfix(), CCopasiParameterGroup::getParameter(), CCopasiParameter::getValue(), CFunctionDB::loadedFunctions(), mpConstraintItems, mpGrpConstraints, mpGrpItems, mpOptItems, mpParmObjectiveExpression, mpParmSubtaskCN, CCopasiParameter::Value::pSTRING, CCopasiParameterGroup::removeParameter(), setObjectiveFunction(), setSubtaskType(), CCopasiTask::steadyState, and CCopasiTask::timeCourse.

Referenced by CFitProblem::elevateChildren(), and initializeParameter().

168 {
169  // We need to handle the old file format which had two different task keys
170  if (mpParmSubtaskCN != NULL)
171  {
172  CCopasiParameter * pParameter;
173 
174  if ((pParameter = getParameter("Steady-State")) != NULL)
175  {
176  if (*pParameter->getValue().pSTRING != "")
177  {
179  }
180 
181  removeParameter("Steady-State");
182  }
183 
184  if ((pParameter = getParameter("Time-Course")) != NULL)
185  {
186  if (*pParameter->getValue().pSTRING != "")
187  {
189  }
190 
191  removeParameter("Time-Course");
192  }
193 
194  // If no subtask is defined we default to steady-state
195  if (*mpParmSubtaskCN == "")
197  }
198 
199  // Handle old file format in which the objective expression was stored in the function DB
200  if (mpParmObjectiveExpression != NULL)
201  {
202  CCopasiParameter * pParameter = getParameter("ObjectiveFunction");
203  CExpression * pObjectiveFunction = NULL;
204 
205  // We do not use the key to find the objective function because keys are not re-mapped
206  // for unknown parameters, instead we rely on the uniqueness of the name and the fact that
207  // this is the only expression in the list.
208  size_t Index = CCopasiRootContainer::getFunctionList()->loadedFunctions().getIndex("Objective Function");
209 
210  if (Index != C_INVALID_INDEX)
211  {
212  pObjectiveFunction =
214  }
215 
216  if (pObjectiveFunction != NULL &&
217  pParameter != NULL)
218  {
219  *mpParmObjectiveExpression = pObjectiveFunction->getInfix();
220 
221  removeParameter("ObjectiveFunction");
222  }
223 
225  }
226 
227  mpGrpItems =
228  elevate<CCopasiParameterGroup, CCopasiParameterGroup>(mpGrpItems);
229 
230  if (!mpGrpItems) return false;
231 
232  std::vector<CCopasiParameter *> * pValue =
233  mpGrpItems->CCopasiParameter::getValue().pGROUP;
234 
235  index_iterator it = pValue->begin();
236  index_iterator end = pValue->end();
237 
238  for (; it != end; ++it)
239  if (!elevate<COptItem, CCopasiParameterGroup>(*it)) return false;
240 
241  mpOptItems =
242  static_cast<std::vector<COptItem * > * >(mpGrpItems->CCopasiParameter::getValue().pVOID);
243 
245  elevate<CCopasiParameterGroup, CCopasiParameterGroup>(mpGrpConstraints);
246 
247  if (!mpGrpConstraints) return false;
248 
249  pValue = mpGrpConstraints->CCopasiParameter::getValue().pGROUP;
250 
251  it = pValue->begin();
252  end = pValue->end();
253 
254  for (; it != end; ++it)
255  if (!elevate<COptItem, CCopasiParameterGroup>(*it)) return false;
256 
258  static_cast<std::vector<COptItem * > * >(mpGrpConstraints->CCopasiParameter::getValue().pVOID);
259 
260  return true;
261 }
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
CCopasiVectorN< CFunction > & loadedFunctions()
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
bool removeParameter(const std::string &name)
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
CCopasiParameterGroup * mpGrpConstraints
Definition: COptProblem.h:426
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
const Value & getValue() const
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
CCopasiParameter * getParameter(const std::string &name)
static CFunctionDB * getFunctionList()
bool setSubtaskType(const CCopasiTask::Type &subtaskType)
parameterGroup::iterator index_iterator
const std::string & getInfix() const
bool setObjectiveFunction(const std::string &infix)
const bool & COptProblem::getCalculateStatistics ( ) const

Retrieve whether we have to calculate statistics

Returns
const bool & maximize

Definition at line 838 of file COptProblem.cpp.

References mpParmCalculateStatistics.

Referenced by CQFittingResult::enterProtected(), CQFittingWidget::loadTask(), CQOptimizationWidget::loadTask(), CQFittingWidget::saveTask(), and CQOptimizationWidget::saveTask().

839 {return *mpParmCalculateStatistics;}
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
const C_FLOAT64 & COptProblem::getCalculateValue ( ) const
const std::vector< UpdateMethod * > & COptProblem::getCalculateVariableUpdateMethods ( ) const

Retrieve the update methods for the variables for calculation.

Returns
const std::vector< UpdateMethod * > & updateMethods

Definition at line 734 of file COptProblem.cpp.

References mUpdateMethods.

Referenced by COptMethod::initialize(), and COptMethodEP2::optimise().

735 {return mUpdateMethods;}
std::vector< UpdateMethod * > mUpdateMethods
Definition: COptProblem.h:451
const std::vector< COptItem * > & COptProblem::getConstraintList ( ) const

Retrieve the list of constraints.

Returns
const std::vector< COptItem * > & constraintList

Definition at line 731 of file COptProblem.cpp.

References mpConstraintItems.

Referenced by COptMethod::initialize().

732 {return *mpConstraintItems;}
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
const C_FLOAT64 & COptProblem::getExecutionTime ( ) const

Retrieve the objective function.

Returns
const C_FLOAT64 & executionTime

Definition at line 850 of file COptProblem.cpp.

References CCopasiTimer::getElapsedTimeSeconds(), and mCPUTime.

Referenced by CQOptimizationResult::enterProtected(), CQFittingResultTab1::load(), CQOptimizationResult::slotSave(), and CQFittingResult::slotSave().

851 {
853 }
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
const C_FLOAT64 & getElapsedTimeSeconds() const
const unsigned C_INT32 & COptProblem::getFunctionEvaluations ( ) const

Retrieve the evaluation counter.

Returns
const unsigned C_INT32 & functionEvaluations

Definition at line 841 of file COptProblem.cpp.

References mCounter.

Referenced by CQOptimizationResult::enterProtected(), CQFittingResult::enterProtected(), CQFittingResultTab1::load(), COptMethodSS::localmin(), CQOptimizationResult::slotSave(), and CQFittingResult::slotSave().

842 {return mCounter;}
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
const std::string COptProblem::getObjectiveFunction ( )

Retrieve the objective function.

Returns
const std::string infix.

Definition at line 747 of file COptProblem.cpp.

References mpParmObjectiveExpression.

Referenced by CQOptimizationWidget::loadTask(), and CQOptimizationWidget::saveTask().

748 {
750 }
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
COptItem & COptProblem::getOptItem ( const size_t &  index)

Retrieve the 'index' optimization item.

Parameters
constsize_t & index
Returns
COptItem optItem

Definition at line 702 of file COptProblem.cpp.

703 {return *(*mpOptItems)[index];}
const std::vector< COptItem * > & COptProblem::getOptItemList ( ) const

Retrieve the list of optimization parameters.

Returns
const std::vector< COptItem * > & optItemList

Definition at line 728 of file COptProblem.cpp.

References mpOptItems.

Referenced by CQOptimizationResult::enterProtected(), CQFittingResult::enterProtected(), COptMethod::initialize(), and COptMethodSS::localmin().

729 {return *mpOptItems;}
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
size_t COptProblem::getOptItemSize ( ) const

Retrieve the number of optimization items.

Returns
const size_t size

Definition at line 705 of file COptProblem.cpp.

References mpGrpItems, and CCopasiParameterGroup::size().

706 {return mpGrpItems->size();}
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
const bool & COptProblem::getRandomizeStartValues ( ) const

Retrieve whether we have to calculate statistics

Returns
const bool & randomize

Definition at line 803 of file COptProblem.cpp.

References mpParmRandomizeStartValues.

Referenced by CQFittingWidget::loadTask(), CQOptimizationWidget::loadTask(), CQFittingWidget::saveTask(), and CQOptimizationWidget::saveTask().

bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
const C_FLOAT64 & COptProblem::getSolutionValue ( ) const

Retrieve the result for the solution

Definition at line 699 of file COptProblem.cpp.

References mSolutionValue.

Referenced by CQOptimizationResult::enterProtected(), CQFittingResultTab1::load(), COptMethodSS::localmin(), CQOptimizationResult::slotSave(), and CQFittingResult::slotSave().

700 {return mSolutionValue;}
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
const CVector< C_FLOAT64 > & COptProblem::getSolutionVariables ( ) const
CCopasiTask::Type COptProblem::getSubtaskType ( ) const

Retrieve the subtask type

Returns
CCopasiTask::Type subtaskType

Definition at line 781 of file COptProblem.cpp.

References CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDataModel(), CCopasiTask::getType(), mpParmSubtaskCN, mpSubtask, CCopasiDataModel::ObjectFromName(), and CCopasiTask::unset.

Referenced by CQOptimizationWidget::loadTask(), and CQOptimizationWidget::saveTask().

782 {
783  std::vector< CCopasiContainer * > ListOfContainer;
784  ListOfContainer.push_back(getObjectAncestor("Vector"));
785  mpSubtask =
786  dynamic_cast< CCopasiTask * >(const_cast< CCopasiObject *>(getObjectDataModel()->ObjectFromName(ListOfContainer, *mpParmSubtaskCN)));
787 
788  if (mpSubtask == NULL)
789  return CCopasiTask::unset;
790 
791  return mpSubtask->getType();
792 }
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
Type getType() const
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
const CVector< C_FLOAT64 > & COptProblem::getVariableGradients ( ) const

Retrieve the gradients for each solution variable.

Returns
const CVector< C_FLOAT64 > & variableGradients

Definition at line 679 of file COptProblem.cpp.

References mGradient.

Referenced by CQOptimizationResult::enterProtected(), and CQFittingResult::enterProtected().

680 {return mGradient;}
CVector< C_FLOAT64 > mGradient
Definition: COptProblem.h:541
size_t COptProblem::getVariableSize ( ) const

Retrieve the size of the variable vectors.

Returns
size_t VariableSize

Referenced by COptMethodEP2::optimise().

void COptProblem::incrementEvaluations ( unsigned C_INT32  increment)

Adds increment to the function evaluation counter

Parameters
unsignedC_INT32 increment

Definition at line 844 of file COptProblem.cpp.

References mCounter.

Referenced by COptMethodSS::localmin().

845 {mCounter += increment;}
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
bool COptProblem::initialize ( )
virtual

Do all necessary initialization so that calls to calculate will be successful. This is called once from CCopasiTask::process()

Returns
bool success

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 328 of file COptProblem.cpp.

References CModel::buildInitialRefreshSequence(), CCopasiObject::buildUpdateSequence(), CExpression::compile(), CModel::compileIfNecessary(), CCopasiMessage::ERROR, CCopasiObject::getDirectDependencies(), CEvaluationTree::getInfix(), CCopasiObject::getObjectParent(), CCopasiTask::getReport(), CReport::getStream(), CModel::getUptoDateObjects(), mConstraintCounter, MCOptimization, mCounter, mCPUTime, mFailedConstraintCounter, mFailedCounter, mInitialRefreshMethods, mOriginalVariables, CCopasiProblem::mpCallBack, mpConstraintItems, CCopasiProblem::mpModel, mpObjectiveExpression, mpOptItems, mpParmMaximize, CCopasiProblem::mpReport, mpSubtask, mRefreshConstraints, mRefreshMethods, mSolutionValue, mSolutionVariables, mUpdateMethods, mWorstValue, pTask, CVector< CType >::resize(), and CCopasiTimer::start().

Referenced by CFitProblem::initialize(), COptTask::initialize(), and COptMethodSS::initialize().

329 {
330  mWorstValue = (*mpParmMaximize ? - std::numeric_limits<C_FLOAT64>::infinity() : std::numeric_limits<C_FLOAT64>::infinity());
331 
332  if (!mpModel) return false;
333 
335 
336  bool success = true;
337 
338  mpReport = NULL;
339  mCounter = 0;
340  mFailedCounter = 0;
341  mConstraintCounter = 0;
343 
345 
346  std::vector< CCopasiContainer * > ContainerList;
347  ContainerList.push_back(mpModel);
348 
349  COptTask * pTask = dynamic_cast<COptTask *>(getObjectParent());
350 
351  if (pTask)
352  {
353  ContainerList.push_back(pTask);
354  mpReport = &pTask->getReport();
355 
356  if (!mpReport->getStream()) mpReport = NULL;
357  }
358 
359  if (mpSubtask != NULL)
360  ContainerList.push_back(mpSubtask);
361 
362  size_t i;
363  size_t Size = mpOptItems->size();
364 
365  mUpdateMethods.resize(Size);
368 
369  mSolutionVariables = std::numeric_limits<C_FLOAT64>::quiet_NaN();
370  mOriginalVariables = std::numeric_limits<C_FLOAT64>::quiet_NaN();
371 
372  std::vector< COptItem * >::iterator it = mpOptItems->begin();
373  std::vector< COptItem * >::iterator end = mpOptItems->end();
374 
375  if (it == end)
376  {
378  return false;
379  }
380 
381  std::set< const CCopasiObject * > changedObjects;
382 
383  for (i = 0; it != end; ++it, i++)
384  {
385  success &= (*it)->compile(ContainerList);
386 
387  mUpdateMethods[i] = (*it)->getUpdateMethod();
388  changedObjects.insert((*it)->getObject());
389  mOriginalVariables[i] = *(*it)->COptItem::getObjectValue();
390  }
391 
392  changedObjects.erase(NULL);
394 
395  it = mpConstraintItems->begin();
396  end = mpConstraintItems->end();
397 
398  // We need to build a refresh sequence so the constraint values are updated
399  std::set< const CCopasiObject * > Objects;
400 
401  for (i = 0; it != end; ++it, i++)
402  {
403  success &= (*it)->compile(ContainerList);
404 
405  Objects.insert((*it)->getDirectDependencies().begin(),
406  (*it)->getDirectDependencies().end());
407  }
408 
410 
411  mCPUTime.start();
412 
413  if (mpObjectiveExpression == NULL ||
414  mpObjectiveExpression->getInfix() == "" ||
415  !mpObjectiveExpression->compile(ContainerList))
416  {
417  mRefreshMethods.clear();
419  return false;
420  }
421 
423 
424  return success;
425 }
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
std::vector< Refresh * > mInitialRefreshMethods
Definition: COptProblem.h:457
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
CReport * mpReport
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
std::vector< UpdateMethod * > mUpdateMethods
Definition: COptProblem.h:451
unsigned C_INT32 mFailedCounter
Definition: COptProblem.h:499
#define MCOptimization
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
const std::set< const CCopasiObject * > & getUptoDateObjects() const
Definition: CModel.cpp:1178
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
CTSSATask * pTask
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
std::vector< Refresh * > mRefreshConstraints
Definition: COptProblem.h:469
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
std::ostream * getStream() const
Definition: CReport.cpp:392
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
std::vector< Refresh * > mRefreshMethods
Definition: COptProblem.h:463
bool * mpParmMaximize
Definition: COptProblem.h:406
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
CReport & getReport()
#define C_FLOAT64
Definition: copasi.h:92
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
C_FLOAT64 mWorstValue
Definition: COptProblem.h:385
CVector< C_FLOAT64 > mOriginalVariables
Definition: COptProblem.h:484
CModel * mpModel
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
CProcessReport * mpCallBack
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
const std::string & getInfix() const
CCopasiContainer * getObjectParent() const
void COptProblem::initializeParameter ( )
private

Allocates all group parameters and assures that they are properly initialized.

Definition at line 148 of file COptProblem.cpp.

References CCopasiParameterGroup::assertGroup(), CCopasiParameterGroup::assertParameter(), CCopasiParameter::BOOL, CCopasiParameter::CN, elevateChildren(), CCopasiParameter::EXPRESSION, CCopasiParameter::getValue(), mpGrpConstraints, mpGrpItems, mpParmCalculateStatistics, mpParmMaximize, mpParmObjectiveExpression, mpParmRandomizeStartValues, mpParmSubtaskCN, CCopasiParameter::Value::pBOOL, CCopasiParameter::Value::pCN, and CCopasiParameter::Value::pEXPRESSION.

Referenced by COptProblem().

149 {
153  assertParameter("ObjectiveExpression", CCopasiParameter::EXPRESSION, std::string(""))->getValue().pEXPRESSION;
155  assertParameter("Maximize", CCopasiParameter::BOOL, false)-> getValue().pBOOL;
157  assertParameter("Randomize Start Values", CCopasiParameter::BOOL, false)-> getValue().pBOOL;
159  assertParameter("Calculate Statistics", CCopasiParameter::BOOL, true)-> getValue().pBOOL;
160 
161  mpGrpItems = assertGroup("OptimizationItemList");
162  mpGrpConstraints = assertGroup("OptimizationConstraintList");
163 
164  elevateChildren();
165 }
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
CRegisteredObjectName * pCN
CCopasiParameterGroup * mpGrpConstraints
Definition: COptProblem.h:426
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
const Value & getValue() const
CCopasiParameterGroup * assertGroup(const std::string &name)
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
virtual bool elevateChildren()
bool * mpParmMaximize
Definition: COptProblem.h:406
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
CCopasiParameter * assertParameter(const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
bool COptProblem::initializeSubtaskBeforeOutput ( )
virtual

perform at least the initializations of the subtask that must be done before the output is initialized.

Definition at line 303 of file COptProblem.cpp.

References CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDataModel(), CCopasiTask::initialize(), mpParmSubtaskCN, mpSubtask, CCopasiTask::NO_OUTPUT, and CCopasiDataModel::ObjectFromName().

Referenced by COptTask::initialize(), and COptMethodSS::initialize().

304 {
305  if (mpParmSubtaskCN != NULL)
306  {
307  std::vector< CCopasiContainer * > ListOfContainer;
308  ListOfContainer.push_back(getObjectAncestor("Vector"));
309  mpSubtask =
310  dynamic_cast< CCopasiTask * >(getObjectDataModel()->ObjectFromName(ListOfContainer, *mpParmSubtaskCN));
311 
312  try
313  {
314  if (mpSubtask != NULL)
315  return mpSubtask->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
316  }
317 
318  catch (...) {}
319 
320  return false;
321  }
322 
323  // We have a CFitProblem for which it is OK not to have a subtask.
324  mpSubtask = NULL;
325  return true;
326 }
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
void COptProblem::initObjects ( )
private

Definition at line 296 of file COptProblem.cpp.

References CCopasiContainer::addObjectReference(), CCopasiContainer::addVectorReference(), mCounter, mSolutionValue, mSolutionVariables, CCopasiObject::ValueDbl, and CCopasiObject::ValueInt.

Referenced by COptProblem().

297 {
298  addObjectReference("Function Evaluations", mCounter, CCopasiObject::ValueInt);
301 }
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
CCopasiObject * addVectorReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
const bool & COptProblem::maximize ( ) const

Check whether we have to maximize

Returns
const bool & maximize

Definition at line 797 of file COptProblem.cpp.

References mpParmMaximize.

Referenced by CQOptimizationWidget::loadTask(), CQOptimizationWidget::saveTask(), and setMaximize().

798 {return *mpParmMaximize;}
bool * mpParmMaximize
Definition: COptProblem.h:406
void COptProblem::print ( std::ostream *  ostream) const
virtual

This is the output method for any object. The default implementation provided with CCopasiObject uses the ostream operator<< of the object to print the object.To override this default behavior one needs to reimplement the virtual print function.

Parameters
std::ostream* ostream

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 855 of file COptProblem.cpp.

856 {*ostream << *this;}
void COptProblem::printResult ( std::ostream *  ostream) const
virtual

This is the output method for any result of a problem. The default implementation provided with CCopasiProblem. Does only print "Not implemented." To override this default behavior one needs to reimplement the virtual printResult function.

Parameters
std::ostream* ostream

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 858 of file COptProblem.cpp.

References C_FLOAT64, CCopasiTimer::getElapsedTime(), CCopasiTimeVariable::getMilliSeconds(), CCopasiTimeVariable::getSeconds(), CCopasiTimeVariable::LL2String(), mCounter, mCPUTime, mpOptItems, mSolutionValue, mSolutionVariables, and CVectorCore< CType >::size().

859 {
860  std::ostream & os = *ostream;
861 
862  if (mSolutionVariables.size() == 0)
863  {
864  return;
865  }
866 
867  os << " Objective Function Value:\t" << mSolutionValue << std::endl;
868 
869  CCopasiTimeVariable CPUTime = const_cast<COptProblem *>(this)->mCPUTime.getElapsedTime();
870 
871  os << " Function Evaluations:\t" << mCounter << std::endl;
872  os << " CPU Time [s]:\t"
873  << CCopasiTimeVariable::LL2String(CPUTime.getSeconds(), 1) << "."
874  << CCopasiTimeVariable::LL2String(CPUTime.getMilliSeconds(true), 3) << std::endl;
875  os << " Evaluations/Second [1/s]:\t" << mCounter / (C_FLOAT64)(CPUTime.getMilliSeconds() / 1e3) << std::endl;
876  os << std::endl;
877 
878  std::vector< COptItem * >::const_iterator itItem =
879  mpOptItems->begin();
880  std::vector< COptItem * >::const_iterator endItem =
881  mpOptItems->end();
882 
883  size_t i;
884 
885  for (i = 0; itItem != endItem; ++itItem, i++)
886  {
887  os << " " << (*itItem)->getObjectDisplayName() << ": "
888  << mSolutionVariables[i] << std::endl;
889  }
890 }
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
const CCopasiTimeVariable & getElapsedTime() const
static std::string LL2String(const C_INT64 &value, const C_INT32 &digits=0)
Definition: CopasiTime.cpp:246
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
size_t size() const
Definition: CVector.h:100
C_INT64 getSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:126
#define C_FLOAT64
Definition: copasi.h:92
C_INT64 getMilliSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:118
void COptProblem::randomizeStartValues ( )

Randomize the start values if requested

Definition at line 806 of file COptProblem.cpp.

References mpOptItems, and mpParmRandomizeStartValues.

Referenced by CFitTask::process(), and COptTask::process().

807 {
809  {
810  std::vector< COptItem * >::iterator it = mpOptItems->begin();
811  std::vector< COptItem * >::iterator end = mpOptItems->end();
812 
813  for (; it != end; ++it)
814  {
815  (*it)->setStartValue((*it)->getRandomValue());
816  }
817  }
818 
819  return;
820 }
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
void COptProblem::rememberStartValues ( )

Remember the start values;

Definition at line 822 of file COptProblem.cpp.

References mpOptItems.

Referenced by CFitTask::process(), and COptTask::process().

823 {
824  std::vector< COptItem * >::iterator it = mpOptItems->begin();
825  std::vector< COptItem * >::iterator end = mpOptItems->end();
826 
827  for (; it != end; ++it)
828  {
829  (*it)->rememberStartValue();
830  }
831 
832  return;
833 }
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
bool COptProblem::removeOptItem ( const size_t &  index)

Remove an optimization items.

Parameters
constsize_t & index
Returns
bool success

Definition at line 721 of file COptProblem.cpp.

References mpGrpItems, and CCopasiParameterGroup::removeParameter().

722 {return mpGrpItems->removeParameter(index);}
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
bool removeParameter(const std::string &name)
void COptProblem::reset ( )

Reset counters and objective value.

Definition at line 269 of file COptProblem.cpp.

References mCounter, mpParmMaximize, and mSolutionValue.

Referenced by COptMethodSS::localmin(), and setCallBack().

270 {
271  mSolutionValue = (*mpParmMaximize ? - std::numeric_limits<C_FLOAT64>::infinity() : std::numeric_limits<C_FLOAT64>::infinity());
272  mCounter = 0;
273 }
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
bool * mpParmMaximize
Definition: COptProblem.h:406
#define C_FLOAT64
Definition: copasi.h:92
void COptProblem::resetEvaluations ( )

Resets the function evaluation counter

Definition at line 847 of file COptProblem.cpp.

References mCounter.

Referenced by COptMethodSS::localmin(), and COptTask::process().

848 {mCounter = 0;}
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
bool COptProblem::restore ( const bool &  updateModel)
virtual

Do all necessary restore procedures so that the model and task are in the same state as before.

Parameters
constbool & updateModel
Returns
bool success

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 478 of file COptProblem.cpp.

References mConstraintCounter, MCOptimization, mCounter, mFailedConstraintCounter, mFailedCounter, mpSubtask, CCopasiTask::restore(), restoreModel(), and CCopasiMessage::WARNING.

Referenced by CFitProblem::restore().

479 {
480  bool success = true;
481 
482  if (mpSubtask != NULL)
483  success &= mpSubtask->restore();
484 
485  restoreModel(updateModel);
486 
487  if (mFailedCounter * 20 > mCounter) // > 5% failure rate
489 
490  if (10 * mFailedConstraintCounter > 8 * mConstraintCounter) // > 80 % failure rate
492 
493  return success;
494 }
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
void restoreModel(const bool &updateModel)
unsigned C_INT32 mFailedCounter
Definition: COptProblem.h:499
#define MCOptimization
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
virtual bool restore()
void COptProblem::restoreModel ( const bool &  updateModel)

Do all necessary restore procedures for the model is in the same state as before.

Parameters
constbool & updateModel

Definition at line 427 of file COptProblem.cpp.

References CVectorCore< CType >::array(), CModel::buildInitialRefreshSequence(), C_FLOAT64, mOriginalVariables, CCopasiProblem::mpModel, mpOptItems, mSolutionValue, mSolutionVariables, and mWorstValue.

Referenced by CScanTask::processCallback(), and restore().

428 {
429  std::vector<COptItem * >::iterator it = mpOptItems->begin();
430  std::vector<COptItem * >::iterator end = mpOptItems->end();
431  const C_FLOAT64 * pTmp;
432  std::set< const CCopasiObject * > ChangedObjects;
433 
434  if (updateModel && mSolutionValue != mWorstValue)
435  {
436  // Set the model values and start values to the solution values
437  pTmp = mSolutionVariables.array();
438 
439  for (; it != end; ++it, pTmp++)
440  {
441  if ((*it)->getObject())
442  {
443  (*(*it)->COptItem::getUpdateMethod())(*pTmp);
444  (*it)->setStartValue(*pTmp);
445 
446  ChangedObjects.insert((*it)->getObject());
447  }
448  }
449  }
450  else
451  {
452  // Reset the model values to the original values
453  pTmp = mOriginalVariables.array();
454 
455  for (; it != end; ++it, pTmp++)
456  {
457  if ((*it)->getObject())
458  {
459  if (!isnan(*pTmp))
460  (*(*it)->COptItem::getUpdateMethod())(*pTmp);
461 
462  ChangedObjects.insert((*it)->getObject());
463  }
464  }
465  }
466 
467  // We need to update the dependent initial values
468  std::vector< Refresh * > UpdateSequence = mpModel->buildInitialRefreshSequence(ChangedObjects);
469  std::vector< Refresh * >::iterator itUpdate = UpdateSequence.begin();
470  std::vector< Refresh * >::iterator endUpdate = UpdateSequence.end();
471 
472  for (; itUpdate != endUpdate; ++itUpdate)
473  {
474  (**itUpdate)();
475  }
476 }
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
#define C_FLOAT64
Definition: copasi.h:92
CType * array()
Definition: CVector.h:139
C_FLOAT64 mWorstValue
Definition: COptProblem.h:385
CVector< C_FLOAT64 > mOriginalVariables
Definition: COptProblem.h:484
CModel * mpModel
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
std::vector< CObjectInterface * > UpdateSequence
void COptProblem::setCalculateStatistics ( const bool &  calculate)

Set whether we have to calculate statistics

Parameters
constbool & calculate

Definition at line 835 of file COptProblem.cpp.

References calculate(), and mpParmCalculateStatistics.

Referenced by COptMethodSS::initialize(), Arguments::prepareModel(), CQFittingWidget::saveTask(), and CQOptimizationWidget::saveTask().

bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
virtual bool calculate()
bool COptProblem::setCallBack ( CProcessReport pCallBack)
virtual

Set the call back of the problem

Parameters
CProcessReport* pCallBack
Returns
bool success

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 275 of file COptProblem.cpp.

References CProcessReport::addItem(), mCounter, mhCounter, mhSolutionValue, CCopasiProblem::mpCallBack, mSolutionValue, reset(), and CCopasiProblem::setCallBack().

Referenced by COptMethodSS::initialize(), and CFitProblem::setCallBack().

276 {
277  CCopasiProblem::setCallBack(pCallBack);
278 
279  if (pCallBack)
280  {
281  reset();
282 
283  // We need to reset mSolutionValue to correctly initialize the progress item.
285  mpCallBack->addItem("Best Value",
287  // We need to reset mCounter to correctly initialize the progress item.
288  mhCounter =
289  mpCallBack->addItem("Function Evaluations",
290  mCounter);
291  }
292 
293  return true;
294 }
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
size_t mhCounter
Definition: COptProblem.h:524
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
size_t mhSolutionValue
Definition: COptProblem.h:519
virtual bool setCallBack(CProcessReport *pCallBack)
CProcessReport * mpCallBack
void COptProblem::setMaximize ( const bool &  maximize)

Set whether we have to maximize the objective function

Parameters
constbool & maximize

Definition at line 794 of file COptProblem.cpp.

References maximize(), and mpParmMaximize.

Referenced by CQOptimizationWidget::saveTask().

const bool & maximize() const
bool * mpParmMaximize
Definition: COptProblem.h:406
bool COptProblem::setModel ( CModel pModel)
virtual

Set the model of the problem

Parameters
CModel* pModel
Returns
bool success

Reimplemented from CCopasiProblem.

Reimplemented in CFitProblem.

Definition at line 263 of file COptProblem.cpp.

References CCopasiProblem::mpModel.

Referenced by CFitProblem::setModel().

264 {
265  mpModel = pModel;
266  return true;
267 }
CModel * mpModel
bool COptProblem::setObjectiveFunction ( const std::string &  infix)

Set optimization function

Parameters
conststd::string & infix
Returns
bool success

Definition at line 737 of file COptProblem.cpp.

References mpObjectiveExpression, mpParmObjectiveExpression, and CExpression::setInfix().

Referenced by elevateChildren(), and CQOptimizationWidget::saveTask().

738 {
739  *mpParmObjectiveExpression = infix;
740 
741  if (mpObjectiveExpression == NULL)
742  mpObjectiveExpression = new CExpression("Expression", this);
743 
744  return mpObjectiveExpression->setInfix(infix);
745 }
virtual bool setInfix(const std::string &infix)
Definition: CExpression.cpp:63
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
void COptProblem::setRandomizeStartValues ( const bool &  randomize)

Set whether we have to randomize start values

Parameters
constbool & randomize

Definition at line 800 of file COptProblem.cpp.

References mpParmRandomizeStartValues.

Referenced by COptMethodSS::initialize(), Arguments::prepareModel(), CQFittingWidget::saveTask(), and CQOptimizationWidget::saveTask().

801 {*mpParmRandomizeStartValues = randomize;}
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
bool COptProblem::setSolution ( const C_FLOAT64 value,
const CVector< C_FLOAT64 > &  variables 
)
virtual

Set the solution.

Parameters
constC_FLOAT64 & value
constCVector< C_FLOAT64 > & variables
Returns
bool continue;

Reimplemented in CFitProblem.

Definition at line 682 of file COptProblem.cpp.

References mhSolutionValue, CCopasiProblem::mpCallBack, mpParmMaximize, mSolutionValue, mSolutionVariables, and CProcessReport::progressItem().

Referenced by COptMethodPS::create(), COptMethodPraxis::evaluateFunction(), COptMethodPS::move(), COptMethodDE::optimise(), COptMethodSRES::optimise(), COptMethodSS::optimise(), COptMethodGA::optimise(), COptMethodPS::optimise(), COptMethodGASR::optimise(), COptMethodHookeJeeves::optimise(), COptMethodLevenbergMarquardt::optimise(), COptMethodNelderMead::optimise(), COptMethodCoranaWalk::optimise(), COptMethodSA::optimise(), COptMethodTruncatedNewton::optimise(), COptMethodPraxis::optimise(), COptMethodStatistics::optimise(), COptMethodSteepestDescent::optimise(), COptMethodEP::optimise(), CRandomSearch::optimise(), CFitProblem::setSolution(), and COptMethodTruncatedNewton::sFun().

684 {
685  mSolutionValue = *mpParmMaximize ? -value : value;
686  mSolutionVariables = variables;
687 
688  bool Continue = true;
689 
690  if (value == -std::numeric_limits< C_FLOAT64 >::infinity())
691  Continue = false;
692 
693  if (mpCallBack)
695 
696  return Continue;
697 }
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
virtual bool progressItem(const size_t &handle)
size_t mhSolutionValue
Definition: COptProblem.h:519
bool * mpParmMaximize
Definition: COptProblem.h:406
CProcessReport * mpCallBack
bool COptProblem::setSubtaskType ( const CCopasiTask::Type subtaskType)

Set subtask type

Parameters
constCCopasiTask::Type & subtaskType
Returns
success

Definition at line 752 of file COptProblem.cpp.

References CCopasiObject::getCN(), CCopasiObject::getObjectAncestor(), CCopasiObject::getObjectDataModel(), CCopasiProblem::getType(), mpParmSubtaskCN, mpSubtask, and CCopasiVector< T >::size().

Referenced by elevateChildren(), and CQOptimizationWidget::saveTask().

753 {
754  mpSubtask = NULL;
755  *mpParmSubtaskCN = "";
756 
758  dynamic_cast< CCopasiVectorN< CCopasiTask > *>(getObjectAncestor("Vector"));
759 
760  CCopasiDataModel* pDataModel = getObjectDataModel();
761 
762  if (pTasks == NULL && pDataModel)
763  pTasks = pDataModel->getTaskList();
764 
765  if (pTasks)
766  {
767  size_t i, imax = pTasks->size();
768 
769  for (i = 0; i < imax; i++)
770  if ((*pTasks)[i]->getType() == subtaskType)
771  {
772  mpSubtask = (*pTasks)[i];
774  return true;
775  }
776  }
777 
778  return false;
779 }
CCopasiDataModel * getObjectDataModel()
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual CCopasiObjectName getCN() const
virtual size_t size() const
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
std::string * mpParmSubtaskCN
Definition: COptProblem.h:390
const CCopasiTask::Type & getType() const
bool COptProblem::swapOptItem ( const size_t &  iFrom,
const size_t &  iTo 
)

Swap two optimization items.

Parameters
constsize_t & iFrom
constsize_t & iTo
Returns
bool success

Definition at line 724 of file COptProblem.cpp.

References mpGrpItems, and CCopasiParameterGroup::swap().

726 {return mpGrpItems->swap(iFrom, iTo);}
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
bool swap(const size_t &iFrom, const size_t &iTo)

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const COptProblem o 
)
friend

Output stream operator

Parameters
ostream& os
constCOptProblem & A
Returns
ostream & os

Definition at line 892 of file COptProblem.cpp.

893 {
894  os << "Problem Description:" << std::endl;
895 
896  os << "Subtask: " << std::endl;
897 
898  if (o.mpSubtask)
899  o.mpSubtask->getDescription().print(&os);
900  else
901  os << "No Subtask specified.";
902 
903  os << std::endl;
904 
905  if (o.mpObjectiveExpression)
906  {
907  os << "Objective Function:" << std::endl;
908  os << " " << o.mpObjectiveExpression->getDisplayString() << std::endl;
909  os << std:: endl;
910  }
911 
912  os << "List of Optimization Items:" << std::endl;
913 
914  std::vector< COptItem * >::const_iterator itItem =
915  o.mpOptItems->begin();
916  std::vector< COptItem * >::const_iterator endItem =
917  o.mpOptItems->end();
918 
919  for (; itItem != endItem; ++itItem)
920  os << " " << **itItem << std::endl;
921 
922  itItem = o.mpConstraintItems->begin();
923  endItem = o.mpConstraintItems->end();
924 
925  for (; itItem != endItem; ++itItem)
926  os << " " << **itItem << std::endl;
927 
928  return os;
929 }
std::vector< COptItem * > * mpConstraintItems
Definition: COptProblem.h:436
const std::string & getDisplayString() const
const CDescription & getDescription() const
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
virtual void print(std::ostream *ostream) const
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446

Member Data Documentation

C_FLOAT64 COptProblem::mCalculateValue
protected

A vector of results for calculate

Definition at line 474 of file COptProblem.h.

Referenced by CFitProblem::calculate(), calculate(), CFitProblem::calculateStatistics(), calculateStatistics(), and getCalculateValue().

unsigned C_INT32 COptProblem::mConstraintCounter
protected

Counter of constraint checks

Definition at line 504 of file COptProblem.h.

Referenced by CFitProblem::checkFunctionalConstraints(), checkFunctionalConstraints(), initialize(), and restore().

unsigned C_INT32 COptProblem::mCounter
protected
CCopasiTimer COptProblem::mCPUTime
protected
unsigned C_INT32 COptProblem::mFailedConstraintCounter
protected

Counter of failed constraint checks

Definition at line 509 of file COptProblem.h.

Referenced by CFitProblem::checkFunctionalConstraints(), checkFunctionalConstraints(), initialize(), and restore().

unsigned C_INT32 COptProblem::mFailedCounter
protected

Counter of failed evaluations

Definition at line 499 of file COptProblem.h.

Referenced by CFitProblem::calculate(), calculate(), CFitProblem::calculateCrossValidation(), initialize(), and restore().

CVector< C_FLOAT64 > COptProblem::mGradient
protected

The gradient vector for the parameters

Definition at line 541 of file COptProblem.h.

Referenced by CFitProblem::calculateStatistics(), calculateStatistics(), getVariableGradients(), and CFitProblem::printResult().

bool COptProblem::mHaveStatistics
protected

Indicates whether the statistics have been calculated for the current result

Definition at line 536 of file COptProblem.h.

Referenced by CFitProblem::calculateStatistics(), calculateStatistics(), CFitProblem::initialize(), and CFitProblem::printResult().

size_t COptProblem::mhCounter
protected

Handle of "Function Evaluations" process report item

Definition at line 524 of file COptProblem.h.

Referenced by CFitProblem::calculate(), calculate(), CFitProblem::calculateCrossValidation(), and setCallBack().

size_t COptProblem::mhSolutionValue
protected

Handle of "Best Value" process report item

Definition at line 519 of file COptProblem.h.

Referenced by setCallBack(), and setSolution().

std::vector< Refresh * > COptProblem::mInitialRefreshMethods
protected

A vector of refresh methods which need to be called update all initial values which depend on the optimization items.

Definition at line 457 of file COptProblem.h.

Referenced by calculate(), and initialize().

CVector< C_FLOAT64 > COptProblem::mOriginalVariables
protected

A vector of solution variables

Definition at line 484 of file COptProblem.h.

Referenced by CFitProblem::calculate(), CFitProblem::calculateCrossValidation(), initialize(), and restoreModel().

std::vector<COptItem *>* COptProblem::mpConstraintItems
protected
CCopasiParameterGroup* COptProblem::mpGrpConstraints
protected

A pointer to the value of the CCopasiParameter holding the OptimizationConstraints

Definition at line 426 of file COptProblem.h.

Referenced by elevateChildren(), and initializeParameter().

CCopasiParameterGroup* COptProblem::mpGrpItems
protected

A pointer to the value of the CCopasiParameterGroup holding the OptimizationItems

Definition at line 421 of file COptProblem.h.

Referenced by addOptItem(), elevateChildren(), getOptItemSize(), initializeParameter(), removeOptItem(), and swapOptItem().

CExpression* COptProblem::mpObjectiveExpression
protected

The objective function which should be minimized or maximized.

Definition at line 446 of file COptProblem.h.

Referenced by calculate(), initialize(), operator<<(), and setObjectiveFunction().

std::vector<COptItem *>* COptProblem::mpOptItems
protected
bool* COptProblem::mpParmCalculateStatistics
protected
bool* COptProblem::mpParmMaximize
protected
std::string* COptProblem::mpParmObjectiveExpression
protected

A pointer to the value of the CCopasiParameter holding the ObjectiveFunctionKey A pointer to the value of the CCopasiParameter holding the infix expression of the objective function

Definition at line 401 of file COptProblem.h.

Referenced by elevateChildren(), getObjectiveFunction(), CFitProblem::initializeParameter(), initializeParameter(), and setObjectiveFunction().

bool* COptProblem::mpParmRandomizeStartValues
protected

A pointer to the value of the CCopasiParameter holding Randomize Start Values

Definition at line 411 of file COptProblem.h.

Referenced by getRandomizeStartValues(), initializeParameter(), randomizeStartValues(), and setRandomizeStartValues().

std::string* COptProblem::mpParmSubtaskCN
protected

A pointer to the value of the CCopasiParameter holding the CN for the subtask

Definition at line 390 of file COptProblem.h.

Referenced by elevateChildren(), getSubtaskType(), CFitProblem::initializeParameter(), initializeParameter(), initializeSubtaskBeforeOutput(), and setSubtaskType().

CCopasiTask* COptProblem::mpSubtask
mutableprotected

Pointer to the subtask to be used in the optimization

Definition at line 441 of file COptProblem.h.

Referenced by calculate(), getSubtaskType(), initialize(), initializeSubtaskBeforeOutput(), operator<<(), restore(), and setSubtaskType().

std::vector< Refresh * > COptProblem::mRefreshConstraints
protected

A vector of refresh methods which need to be called retrieve the values of constraints.

Definition at line 469 of file COptProblem.h.

Referenced by checkFunctionalConstraints(), and initialize().

std::vector< Refresh * > COptProblem::mRefreshMethods
protected

A vector of refresh methods which need to be called retrieve the value of the objective function.

Definition at line 463 of file COptProblem.h.

Referenced by calculate(), and initialize().

C_FLOAT64 COptProblem::mSolutionValue
protected
CVector< C_FLOAT64 > COptProblem::mSolutionVariables
protected
bool COptProblem::mStoreResults
protected

Indicates whether the results shall be stored. The default is false.

Definition at line 530 of file COptProblem.h.

Referenced by CFitProblem::calculate(), calculate(), CFitProblem::calculateCrossValidation(), CFitProblem::calculateStatistics(), calculateStatistics(), and CFitProblem::initialize().

std::vector< UpdateMethod * > COptProblem::mUpdateMethods
protected

A vector of update method to the values of the optimization items.

Definition at line 451 of file COptProblem.h.

Referenced by CFitProblem::calculateStatistics(), calculateStatistics(), getCalculateVariableUpdateMethods(), and initialize().

C_FLOAT64 COptProblem::mWorstValue
protected
const unsigned int COptProblem::ValidSubtasks
static
Initial value:

The methods which can be selected for performing this task.

File name: COptProblem.cpp

Programmer: Yongqun He Contact email: yohe@.nosp@m.vt.e.nosp@m.du Purpose: This is the source file of the COptProblem class. It specifies the optimization problem with its own members and functions. It's used by COptAlgorithm class and COptimization class

Definition at line 57 of file COptProblem.h.

Referenced by CQOptimizationWidget::init().


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