COPASI API  4.16.103
COptProblem.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * File name: COptProblem.cpp
17  *
18  * Programmer: Yongqun He
19  * Contact email: yohe@vt.edu
20  * Purpose: This is the source file of the COptProblem class.
21  * It specifies the optimization problem with its own members and
22  * functions. It's used by COptAlgorithm class and COptimization class
23  */
24 #include <cmath>
25 
26 #include "copasi.h"
27 #include "COptTask.h"
28 #include "COptProblem.h"
29 #include "COptItem.h"
30 
31 #include "function/CFunctionDB.h"
32 
35 
40 
41 #include "model/CModel.h"
42 #include "model/CCompartment.h"
43 
45 #include "report/CKeyFactory.h"
46 
49 
50 // static
51 const unsigned int COptProblem::ValidSubtasks[] =
52 {
64 };
65 
66 // Default constructor
68  const CCopasiContainer * pParent):
69  CCopasiProblem(type, pParent),
70  mWorstValue(0.0),
71  mpParmSubtaskCN(NULL),
72  mpParmObjectiveExpression(NULL),
73  mpParmMaximize(NULL),
74  mpParmRandomizeStartValues(NULL),
75  mpParmCalculateStatistics(NULL),
76  mpGrpItems(NULL),
77  mpGrpConstraints(NULL),
78  mpOptItems(NULL),
79  mpConstraintItems(NULL),
80  mpSubtask(NULL),
81  mpObjectiveExpression(NULL),
82  mUpdateMethods(),
83  mInitialRefreshMethods(),
84  mRefreshMethods(),
85  mRefreshConstraints(),
86  mCalculateValue(0),
87  mSolutionVariables(),
88  mOriginalVariables(),
89  mSolutionValue(0),
90  mCounter(0),
91  mFailedCounter(0),
92  mConstraintCounter(0),
93  mFailedConstraintCounter(0),
94  mCPUTime(CCopasiTimer::PROCESS, this),
95  mhSolutionValue(C_INVALID_INDEX),
96  mhCounter(C_INVALID_INDEX),
97  mStoreResults(false),
98  mHaveStatistics(false),
99  mGradient(0)
100 {
102  initObjects();
103 }
104 
105 // copy constructor
107  const CCopasiContainer * pParent):
108  CCopasiProblem(src, pParent),
109  mWorstValue(src.mWorstValue),
110  mpParmSubtaskCN(NULL),
111  mpParmObjectiveExpression(NULL),
112  mpParmMaximize(NULL),
113  mpParmRandomizeStartValues(NULL),
114  mpParmCalculateStatistics(NULL),
115  mpGrpItems(NULL),
116  mpGrpConstraints(NULL),
117  mpOptItems(NULL),
118  mpConstraintItems(NULL),
119  mpSubtask(NULL),
120  mpObjectiveExpression(NULL),
121  mUpdateMethods(),
122  mInitialRefreshMethods(),
123  mRefreshMethods(),
124  mRefreshConstraints(),
125  mCalculateValue(src.mCalculateValue),
126  mSolutionVariables(src.mSolutionVariables),
127  mOriginalVariables(src.mOriginalVariables),
128  mSolutionValue(src.mSolutionValue),
129  mCounter(0),
130  mFailedCounter(0),
131  mConstraintCounter(0),
132  mFailedConstraintCounter(0),
133  mCPUTime(CCopasiTimer::PROCESS, this),
134  mhSolutionValue(C_INVALID_INDEX),
135  mhCounter(C_INVALID_INDEX),
136  mStoreResults(src.mStoreResults),
137  mHaveStatistics(src.mHaveStatistics),
138  mGradient(src.mGradient)
139 {
141  initObjects();
142 }
143 
144 // Destructor
146 {}
147 
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 }
166 
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 }
262 
264 {
265  mpModel = pModel;
266  return true;
267 }
268 
270 {
271  mSolutionValue = (*mpParmMaximize ? - std::numeric_limits<C_FLOAT64>::infinity() : std::numeric_limits<C_FLOAT64>::infinity());
272  mCounter = 0;
273 }
274 
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 }
295 
297 {
298  addObjectReference("Function Evaluations", mCounter, CCopasiObject::ValueInt);
301 }
302 
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 }
327 
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 }
426 
427 void COptProblem::restoreModel(const bool & updateModel)
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 }
477 
478 bool COptProblem::restore(const bool & updateModel)
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 }
495 
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 }
506 
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 }
530 
531 /**
532  * calculate() decides whether the problem is a steady state problem or a
533  * trajectory problem based on whether the pointer to that type of problem
534  * is null or not. It then calls the process() method for that type of
535  * problem. Currently process takes ofstream& as a parameter but it will
536  * change so that process() takes no parameters.
537  */
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 }
608 
610  const C_FLOAT64 & resolution)
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 }
672 
674 {return mCalculateValue;}
675 
677 {return mSolutionVariables;}
678 
680 {return mGradient;}
681 
683  const CVector< C_FLOAT64 > & variables)
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 }
698 
700 {return mSolutionValue;}
701 
702 COptItem & COptProblem::getOptItem(const size_t & index)
703 {return *(*mpOptItems)[index];}
704 
706 {return mpGrpItems->size();}
707 
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 }
720 
721 bool COptProblem::removeOptItem(const size_t & index)
722 {return mpGrpItems->removeParameter(index);}
723 
724 bool COptProblem::swapOptItem(const size_t & iFrom,
725  const size_t & iTo)
726 {return mpGrpItems->swap(iFrom, iTo);}
727 
728 const std::vector< COptItem * > & COptProblem::getOptItemList() const
729 {return *mpOptItems;}
730 
731 const std::vector< COptItem * > & COptProblem::getConstraintList() const
732 {return *mpConstraintItems;}
733 
734 const std::vector< UpdateMethod * > & COptProblem::getCalculateVariableUpdateMethods() const
735 {return mUpdateMethods;}
736 
737 bool COptProblem::setObjectiveFunction(const std::string & infix)
738 {
739  *mpParmObjectiveExpression = infix;
740 
741  if (mpObjectiveExpression == NULL)
742  mpObjectiveExpression = new CExpression("Expression", this);
743 
744  return mpObjectiveExpression->setInfix(infix);
745 }
746 
748 {
750 }
751 
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 }
780 
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 }
793 
794 void COptProblem::setMaximize(const bool & maximize)
796 
797 const bool & COptProblem::maximize() const
798 {return *mpParmMaximize;}
799 
800 void COptProblem::setRandomizeStartValues(const bool & randomize)
801 {*mpParmRandomizeStartValues = randomize;}
802 
805 
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 }
821 
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 }
834 
835 void COptProblem::setCalculateStatistics(const bool & calculate)
837 
839 {return *mpParmCalculateStatistics;}
840 
842 {return mCounter;}
843 
845 {mCounter += increment;}
846 
848 {mCounter = 0;}
849 
851 {
853 }
854 
855 void COptProblem::print(std::ostream * ostream) const
856 {*ostream << *this;}
857 
858 void COptProblem::printResult(std::ostream * ostream) const
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 }
891 
892 std::ostream &operator<<(std::ostream &os, const COptProblem & o)
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 }
CCopasiDataModel * getObjectDataModel()
virtual Refresh * getRefresh() const
CCopasiParameterGroup * mpGrpItems
Definition: COptProblem.h:421
CCopasiContainer * getObjectAncestor(const std::string &type) const
CCopasiVectorN< CFunction > & loadedFunctions()
CCopasiTask::Type getSubtaskType() const
CVector< C_FLOAT64 > mSolutionVariables
Definition: COptProblem.h:479
virtual bool setInfix(const std::string &infix)
Definition: CExpression.cpp:63
#define pdelete(p)
Definition: copasi.h:215
C_FLOAT64 mSolutionValue
Definition: COptProblem.h:489
void incrementEvaluations(unsigned C_INT32 increment)
bool swap(const size_t &iFrom, const size_t &iTo)
std::vector< Refresh * > mInitialRefreshMethods
Definition: COptProblem.h:457
bool swapOptItem(const size_t &iFrom, const size_t &iTo)
COptItem & getOptItem(const size_t &index)
unsigned C_INT32 mCounter
Definition: COptProblem.h:494
CCopasiProblem * getProblem()
virtual CCopasiObjectName getCN() const
void restoreModel(const bool &updateModel)
bool * mpParmCalculateStatistics
Definition: COptProblem.h:416
virtual size_t size() const
CReport * mpReport
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
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 MCOptimization
const std::vector< COptItem * > & getConstraintList() const
virtual bool initialize()
size_t getOptItemSize() const
const CVector< C_FLOAT64 > & getVariableGradients() const
virtual bool setModel(CModel *pModel)
const std::vector< UpdateMethod * > & getCalculateVariableUpdateMethods() const
bool removeOptItem(const size_t &index)
bool setObjectCN(const CCopasiObjectName &objectCN)
Definition: COptItem.cpp:111
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
const std::set< const CCopasiObject * > & getUptoDateObjects() const
Definition: CModel.cpp:1178
const std::string & getDisplayString() const
#define C_INVALID_INDEX
Definition: copasi.h:222
const bool & getRandomizeStartValues() const
virtual bool calculateStatistics(const C_FLOAT64 &factor=1.0e-003, const C_FLOAT64 &resolution=1.0e-009)
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
virtual size_t getIndex(const std::string &name) const
#define C_INT32
Definition: copasi.h:90
std::ostream & operator<<(std::ostream &os, const COptProblem &o)
virtual bool progressItem(const size_t &handle)
bool mHaveStatistics
Definition: COptProblem.h:536
unsigned C_INT32 mConstraintCounter
Definition: COptProblem.h:504
CRegisteredObjectName * pCN
const CCopasiTimeVariable & getElapsedTime() const
virtual void print(std::ostream *ostream) const
const bool & maximize() const
void resetEvaluations()
unsigned C_INT32 mFailedConstraintCounter
Definition: COptProblem.h:509
virtual ~COptProblem()
size_t mhCounter
Definition: COptProblem.h:524
virtual bool restore(const bool &updateModel)
CTSSATask * pTask
virtual bool setCallBack(CProcessReport *pCallBack)
bool removeParameter(const std::string &name)
C_FLOAT64 mCalculateValue
Definition: COptProblem.h:474
const C_FLOAT64 & getSolutionValue() const
static std::string LL2String(const C_INT64 &value, const C_INT32 &digits=0)
Definition: CopasiTime.cpp:246
virtual bool calculate()
const CDescription & getDescription() const
std::vector< COptItem * > * mpOptItems
Definition: COptProblem.h:431
const C_FLOAT64 & getExecutionTime() const
std::vector< Refresh * > mRefreshConstraints
Definition: COptProblem.h:469
virtual const C_FLOAT64 & calcValue()
const std::vector< COptItem * > & getOptItemList() const
CCopasiTask * mpSubtask
Definition: COptProblem.h:441
void initializeParameter()
std::ostream * getStream() const
Definition: CReport.cpp:392
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
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
void rememberStartValues()
const Value & getValue() const
void randomizeStartValues()
const CVector< C_FLOAT64 > & getSolutionVariables() const
CCopasiTimer mCPUTime
Definition: COptProblem.h:514
std::vector< Refresh * > mRefreshMethods
Definition: COptProblem.h:463
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
CCopasiParameterGroup * assertGroup(const std::string &name)
std::string * mpParmObjectiveExpression
Definition: COptProblem.h:401
CCopasiParameter * getParameter(const std::string &name)
virtual void printResult(std::ostream *ostream) const
COptItem & addOptItem(const CCopasiObjectName &objectCN)
const C_FLOAT64 & getElapsedTimeSeconds() const
virtual bool initializeSubtaskBeforeOutput()
static CFunctionDB * getFunctionList()
virtual bool checkFunctionalConstraints()
virtual bool elevateChildren()
bool * mpParmMaximize
Definition: COptProblem.h:406
static const unsigned int ValidSubtasks[]
Definition: COptProblem.h:57
size_t size() const
Definition: CVector.h:100
virtual const DataObjectSet & getDirectDependencies(const DataObjectSet &context=DataObjectSet()) const
virtual bool process(const bool &useInitialValues)
void setRandomizeStartValues(const bool &randomize)
C_INT64 getSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:126
CReport & getReport()
#define C_FLOAT64
Definition: copasi.h:92
bool * mpParmRandomizeStartValues
Definition: COptProblem.h:411
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
const std::string getObjectiveFunction()
CType * array()
Definition: CVector.h:139
virtual void print(std::ostream *ostream) const
static CCopasiMessage getLastMessage()
bool addParameter(const CCopasiParameter &parameter)
Type getType() const
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
virtual bool checkParametricConstraints()
CCopasiParameter * assertParameter(const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
const bool & getCalculateStatistics() const
bool setSubtaskType(const CCopasiTask::Type &subtaskType)
CCopasiObject * addVectorReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
Definition: CModel.h:50
virtual bool setCallBack(CProcessReport *pCallBack)
CModel * mpModel
virtual bool restore()
void setMaximize(const bool &maximize)
const unsigned C_INT32 & getFunctionEvaluations() const
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
const C_FLOAT64 & getCalculateValue() const
COptProblem(const CCopasiTask::Type &type=CCopasiTask::optimization, const CCopasiContainer *pParent=NULL)
Definition: COptProblem.cpp:67
CProcessReport * mpCallBack
CExpression * mpObjectiveExpression
Definition: COptProblem.h:446
parameterGroup::iterator index_iterator
C_INT64 getMilliSeconds(const bool &bounded=false) const
Definition: CopasiTime.cpp:118
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
const CCopasiTask::Type & getType() const
const std::string & getInfix() const
void setCalculateStatistics(const bool &calculate)
CCopasiContainer * getObjectParent() const
std::vector< CObjectInterface * > UpdateSequence
bool setObjectiveFunction(const std::string &infix)
void initObjects()