From 42f7447d5c43b2ec4bf5ff16ce8bc60dadeee51f Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Thu, 28 Mar 2024 12:46:31 -0400 Subject: [PATCH 1/7] Bug 3224: The sub task source is now updated on task type changes. --- copasi/CopasiDataModel/CDataModel.cpp | 37 +++++++--------- copasi/CopasiDataModel/CDataModel.h | 10 ----- copasi/UI/CQBrowserPaneDM.cpp | 2 +- copasi/UI/CQFittingItemWidget.cpp | 36 +++++++-------- copasi/analytics/CAnalyticsProblem.cpp | 2 +- .../cpp_examples/example5/example5.cpp | 6 +-- .../cpp_examples/example6/example6.cpp | 15 ++++--- .../compareExpressions/compare_utilities.cpp | 11 +++-- copasi/core/CObjectInterface.cpp | 17 +++++++ copasi/core/CObjectInterface.h | 3 ++ copasi/core/CRegisteredCommonName.cpp | 21 ++++++++- copasi/core/CRegisteredCommonName.h | 8 ++++ copasi/crosssection/CCrossSectionProblem.cpp | 14 +++--- copasi/crosssection/CCrossSectionProblem.h | 6 +-- copasi/math/CMathContainer.cpp | 2 +- copasi/model/CEvent.cpp | 6 +-- copasi/model/CEvent.h | 10 ++--- copasi/optimization/COptItem.cpp | 38 +++++++++++----- copasi/optimization/COptItem.h | 44 ++++++++++++------- copasi/optimization/COptProblem.cpp | 31 +++++++------ copasi/optimization/COptProblem.h | 14 +++--- copasi/parameterFitting/CFitProblem.cpp | 20 ++++----- copasi/parameterFitting/CFitProblem.h | 16 +++---- copasi/sensitivities/CSensProblem.cpp | 4 +- copasi/utilities/CCopasiParameter.cpp | 3 +- copasi/utilities/CCopasiParameter.h | 2 +- tests/test_CDataHandler.cpp | 36 +++++++-------- 27 files changed, 241 insertions(+), 173 deletions(-) diff --git a/copasi/CopasiDataModel/CDataModel.cpp b/copasi/CopasiDataModel/CDataModel.cpp index c25fdaa112..d7aa77ecaa 100644 --- a/copasi/CopasiDataModel/CDataModel.cpp +++ b/copasi/CopasiDataModel/CDataModel.cpp @@ -82,12 +82,12 @@ LIBCOMBINE_CPP_NAMESPACE_USE // static const CEnumAnnotation< std::string, CDataModel::ContentType > -CDataModel::ContentTypeNames( {"COPASI", - "GEPASI", - "SBML", - "SED-ML", - "OMEX" -}); +CDataModel::ContentTypeNames({"COPASI", + "GEPASI", + "SBML", + "SED-ML", + "OMEX" + }); // static CDataModel::ContentType CDataModel::contentType(std::istream & content) @@ -257,11 +257,6 @@ CDataModel::~CDataModel() CRegisteredCommonName::setEnabled(true); } -CRegisteredCommonName CDataModel::registeredCN(const std::string & CN) const -{ - return CRegisteredCommonName(CN, this); -} - bool CDataModel::loadFromString(const std::string & content, std::string referenceDir, CProcessReport * pProcessReport, @@ -717,9 +712,9 @@ bool CDataModel::loadModelParameterSets(const std::string & fileName, CDataVectorN< CModelParameterSet > & loadedSet = parameterSetModel->getModelParameterSets(); CCommonName loadedModelCn = parameterSetModel->getStringCN(); -for (CModelParameterSet & set : loadedSet) + for (CModelParameterSet & set : loadedSet) { -for (CModelParameter * current : dynamic_cast< CModelParameterGroup & >(set)) + for (CModelParameter * current : dynamic_cast< CModelParameterGroup & >(set)) { replaceCnInGroup(current, loadedModelCn, thisModelsCn); } @@ -762,7 +757,7 @@ void CDataModel::replaceCnInGroup(CModelParameter * pParam, if (!group) return; -for (CModelParameter * element : *group) + for (CModelParameter * element : *group) { CModelParameterGroup * inside = dynamic_cast< CModelParameterGroup * >(element); @@ -2047,7 +2042,7 @@ void addMessages(const std::string & title, std::stringstream & messageStream, c messageStream << "\n"; -for (auto & message : messages) + for (auto & message : messages) { auto startPos = message.getText().find_first_of("\n"); auto text = message.getText().substr(startPos + 1); @@ -2783,7 +2778,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Optimization],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::parameterFitting: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); @@ -2812,7 +2807,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Parameter Estimation],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::lyap: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); @@ -2829,7 +2824,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Lyapunov Exponents],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::mca: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); @@ -2846,7 +2841,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Metabolic Control Analysis],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::lna: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); @@ -2863,7 +2858,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Linear Noise Approximation],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::sens: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); @@ -2880,7 +2875,7 @@ CReportDefinition * CDataModel::addReport(const CTaskEnum::Task & taskType) pReport->getFooterAddr()->push_back(CRegisteredCommonName("CN=Root,Vector=TaskList[Sensitivities],Object=Result", this)); break; - //************************************************************************** + //************************************************************************** case CTaskEnum::Task::tssAnalysis: pReport = new CReportDefinition(CTaskEnum::TaskName[taskType]); pReport->setTaskType(taskType); diff --git a/copasi/CopasiDataModel/CDataModel.h b/copasi/CopasiDataModel/CDataModel.h index 1e61234040..d685b1e96d 100644 --- a/copasi/CopasiDataModel/CDataModel.h +++ b/copasi/CopasiDataModel/CDataModel.h @@ -191,16 +191,6 @@ class CDataModel: public CDataContainer, public COutputHandler virtual ~CDataModel(); - /** - * resolves the given CN string in this dataModel to a - * registered common name - * - * @param CN the CN to resolve - * - * @return a registered common name for the CN - */ - CRegisteredCommonName registeredCN(const std::string & CN) const; - /** * Load the model from the content which may be any supported type * @param const std::string & content diff --git a/copasi/UI/CQBrowserPaneDM.cpp b/copasi/UI/CQBrowserPaneDM.cpp index 4b6780be72..9b19d2c9f3 100644 --- a/copasi/UI/CQBrowserPaneDM.cpp +++ b/copasi/UI/CQBrowserPaneDM.cpp @@ -738,7 +738,7 @@ bool CQBrowserPaneDM::slotNotify(ListViews::ObjectType objectType, ListViews::Ac pNode = findNodeFromCN(cn); } - std::string NewCN = pNode != NULL ? pNode->getCN() : cn; + CRegisteredCommonName NewCN = pNode != NULL ? pNode->getCN() : cn; if (cn != NewCN) { diff --git a/copasi/UI/CQFittingItemWidget.cpp b/copasi/UI/CQFittingItemWidget.cpp index aeb43926ea..86b3b8efe6 100644 --- a/copasi/UI/CQFittingItemWidget.cpp +++ b/copasi/UI/CQFittingItemWidget.cpp @@ -149,14 +149,14 @@ void CQFittingItemWidget::slotCheckLowerInf(bool checked) mpCheckLowerInf->setStyleSheet(QString(mpCheckLowerInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}"); } - std::string Number; + CRegisteredCommonName Number; if (checked) - Number = "-inf"; + Number = CRegisteredCommonName("-inf", nullptr); else if (isNumber(TO_UTF8(mpEditLower->text()))) - Number = TO_UTF8(mpEditLower->text()); + Number = CRegisteredCommonName(TO_UTF8(mpEditLower->text()), nullptr); else if (mpLowerObject) - Number = mpLowerObject->getStringCN(); + Number = mpLowerObject->getCN(); else return; std::set< size_t >::const_iterator it = mSelection.begin(); @@ -185,14 +185,14 @@ void CQFittingItemWidget::slotCheckUpperInf(bool checked) mpCheckUpperInf->setStyleSheet(QString(mpCheckUpperInf->metaObject()->className()) + " {background-color:" + mSavedColor.name() + ";}"); } - std::string Number; + CRegisteredCommonName Number; if (checked) - Number = "inf"; + Number = CRegisteredCommonName("inf", nullptr); else if (isNumber(TO_UTF8(mpEditUpper->text()))) - Number = TO_UTF8(mpEditUpper->text()); + Number = CRegisteredCommonName(TO_UTF8(mpEditUpper->text()), nullptr); else if (mpUpperObject) - Number = mpUpperObject->getStringCN(); + Number = mpUpperObject->getCN(); else return; std::set< size_t >::const_iterator it = mSelection.begin(); @@ -245,7 +245,7 @@ void CQFittingItemWidget::slotLowerEdit() std::set< size_t >::const_iterator it = mSelection.begin(); std::set< size_t >::const_iterator end = mSelection.end(); mpLowerObject = pObject; - CCommonName CN = mpLowerObject->getStringCN(); + CRegisteredCommonName CN = mpLowerObject->getCN(); for (; it != end; ++it) { @@ -299,7 +299,7 @@ void CQFittingItemWidget::slotUpperEdit() std::set< size_t >::const_iterator it = mSelection.begin(); std::set< size_t >::const_iterator end = mSelection.end(); mpUpperObject = pObject; - CCommonName CN = mpUpperObject->getStringCN(); + CRegisteredCommonName CN = mpUpperObject->getCN(); for (; it != end; ++it) { @@ -419,7 +419,7 @@ void CQFittingItemWidget::slotParamEdit() for (; it != end; ++it) { - (*mpItemsCopy)[*it]->setObjectCN(Selection[0]->getStringCN()); + (*mpItemsCopy)[*it]->setObjectCN(Selection[0]->getCN()); setTableText((int) *it, (*mpItemsCopy)[*it]); } @@ -449,7 +449,7 @@ void CQFittingItemWidget::slotParamEdit() break; } - pItem->setObjectCN(Selection[i]->getStringCN()); + pItem->setObjectCN(Selection[i]->getCN()); // Add the new item to the list. mpItemsCopy->insert(mpItemsCopy->begin() + current + i, pItem); // Update the table @@ -1430,14 +1430,14 @@ void CQFittingItemWidget::saveSelection() pItem = (*mpItemsCopy)[*it]; if (mpCheckLowerInf->isChecked()) - pItem->setLowerBound(CCommonName("-inf")); + pItem->setLowerBound(CRegisteredCommonName("-inf", nullptr)); else if (isNumber(TO_UTF8(mpEditLower->text()))) - pItem->setLowerBound(CCommonName(TO_UTF8(mpEditLower->text()))); + pItem->setLowerBound(CRegisteredCommonName(TO_UTF8(mpEditLower->text()), nullptr)); if (mpCheckUpperInf->isChecked()) - pItem->setUpperBound(CCommonName("inf")); + pItem->setUpperBound(CRegisteredCommonName("inf", nullptr)); else if (isNumber(TO_UTF8(mpEditUpper->text()))) - pItem->setUpperBound(CCommonName(TO_UTF8(mpEditUpper->text()))); + pItem->setUpperBound(CRegisteredCommonName(TO_UTF8(mpEditUpper->text()), nullptr)); if (isNumber(TO_UTF8(mpEditStart->text()))) pItem->setStartValue(mpEditStart->text().toDouble()); @@ -1508,7 +1508,7 @@ void CQFittingItemWidget::slotLowerLostFocus() for (; it != end; ++it) { - (*mpItemsCopy)[*it]->setLowerBound(Number); + (*mpItemsCopy)[*it]->setLowerBound(CRegisteredCommonName(Number, nullptr)); if (first) { @@ -1541,7 +1541,7 @@ void CQFittingItemWidget::slotUpperLostFocus() for (; it != end; ++it) { - (*mpItemsCopy)[*it]->setUpperBound(Number); + (*mpItemsCopy)[*it]->setUpperBound(CRegisteredCommonName(Number, nullptr)); if (first) { diff --git a/copasi/analytics/CAnalyticsProblem.cpp b/copasi/analytics/CAnalyticsProblem.cpp index 1a485381c2..651eb1e627 100644 --- a/copasi/analytics/CAnalyticsProblem.cpp +++ b/copasi/analytics/CAnalyticsProblem.cpp @@ -77,7 +77,7 @@ void CAnalyticsProblem::initializeParameter() mpFlagLimitOutConvergence = assertParameter("DelayOutputUntilConvergence", CCopasiParameter::Type::BOOL, false); mpConvergenceOutTolerance = assertParameter("OutputConvergenceTolerance", CCopasiParameter::Type::DOUBLE, (C_FLOAT64)1E-6); mpTriggerExpression = assertParameter("TriggerExpression", CCopasiParameter::Type::EXPRESSION, std::string("")); - mpSingleObjectCN = assertParameter("SingleVariable", CCopasiParameter::Type::CN, CRegisteredCommonName("")); + mpSingleObjectCN = assertParameter("SingleVariable", CCopasiParameter::Type::CN, CRegisteredCommonName()); setOutputEvent(false); } diff --git a/copasi/bindings/cpp_examples/example5/example5.cpp b/copasi/bindings/cpp_examples/example5/example5.cpp index 8ff8fb1b86..9d9a09dc47 100644 --- a/copasi/bindings/cpp_examples/example5/example5.cpp +++ b/copasi/bindings/cpp_examples/example5/example5.cpp @@ -141,12 +141,12 @@ int main() // now we create the optimization items // i.e. the model elements that have to be changed during the optimization // in order to get to the optimal solution - COptItem* pOptItem = &pOptProblem->addOptItem(CCommonName(pFixedModelValue->getObject(CCommonName("Reference=InitialValue"))->getCN())); + COptItem* pOptItem = &pOptProblem->addOptItem(pFixedModelValue->getObject(CCommonName("Reference=InitialValue"))->getCN()); // we want to change the fixed model value from -100 to +100 with a start // value of 50 pOptItem->setStartValue(50.0); - pOptItem->setLowerBound(CCommonName("-100")); - pOptItem->setUpperBound(CCommonName("100")); + pOptItem->setLowerBound(-100); + pOptItem->setUpperBound(100); // now we set some parameters on the method // these parameters are specific to the method type we set above diff --git a/copasi/bindings/cpp_examples/example6/example6.cpp b/copasi/bindings/cpp_examples/example6/example6.cpp index 7bf6edc903..79e76a78e0 100644 --- a/copasi/bindings/cpp_examples/example6/example6.cpp +++ b/copasi/bindings/cpp_examples/example6/example6.cpp @@ -1,4 +1,9 @@ -// Copyright (C) 2017 by Pedro Mendes, Virginia Tech Intellectual +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the +// University of Virginia, University of Heidelberg, and University +// of Connecticut School of Medicine. +// All rights reserved. + +// Copyright (C) 2017 - 2018 by Pedro Mendes, Virginia Tech Intellectual // Properties, Inc., University of Heidelberg, and University of // of Connecticut School of Medicine. // All rights reserved. @@ -367,8 +372,8 @@ int main() pFitItem1->setObjectCN(pParameterReference->getCN()); assert(pFitItem1 != NULL); pFitItem1->setStartValue(4.0); - pFitItem1->setLowerBound(CCommonName("0.00001")); - pFitItem1->setUpperBound(CCommonName("10")); + pFitItem1->setLowerBound(0.00001); + pFitItem1->setUpperBound(10); // add the fit item pOptimizationItemGroup->addParameter(pFitItem1); @@ -385,8 +390,8 @@ int main() pFitItem2->setObjectCN(pParameterReference->getCN()); assert(pFitItem2 != NULL); pFitItem2->setStartValue(4.0); - pFitItem2->setLowerBound(CCommonName("0.00001")); - pFitItem2->setUpperBound(CCommonName("10")); + pFitItem2->setLowerBound(0.00001); + pFitItem2->setUpperBound(10); // add the fit item pOptimizationItemGroup->addParameter(pFitItem2); diff --git a/copasi/compareExpressions/compare_utilities.cpp b/copasi/compareExpressions/compare_utilities.cpp index b4d395e42e..2d591548f0 100644 --- a/copasi/compareExpressions/compare_utilities.cpp +++ b/copasi/compareExpressions/compare_utilities.cpp @@ -1,4 +1,9 @@ -// Copyright (C) 2017 by Pedro Mendes, Virginia Tech Intellectual +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the +// University of Virginia, University of Heidelberg, and University +// of Connecticut School of Medicine. +// All rights reserved. + +// Copyright (C) 2017 - 2018 by Pedro Mendes, Virginia Tech Intellectual // Properties, Inc., University of Heidelberg, and University of // of Connecticut School of Medicine. // All rights reserved. @@ -431,7 +436,7 @@ void normalize_variable_names(CNormalBase* pBase, std::map& if (pItem != NULL && pItem->getType() == CNormalItem::VARIABLE) { - std::string cn = pItem->getName(); + CCommonName cn = pItem->getName(); pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(listOfContainers, cn)); if (pObject != NULL) diff --git a/copasi/core/CObjectInterface.cpp b/copasi/core/CObjectInterface.cpp index 0cf23c7f92..47ab26a74e 100644 --- a/copasi/core/CObjectInterface.cpp +++ b/copasi/core/CObjectInterface.cpp @@ -110,6 +110,23 @@ CObjectInterface * CObjectInterface::GetObjectFromCN(const CObjectInterface::Con return const_cast< CObjectInterface * >(pObject); } +// static +CObjectInterface * CObjectInterface::GetObjectFromCN(const CObjectInterface::ContainerList & listOfContainer, + const CRegisteredCommonName & objName) +{ + const CDataModel * pDataModel = objName.getDataModel(); + + if (pDataModel != nullptr) + { + CObjectInterface::ContainerList ListOfContainer = listOfContainer; + ListOfContainer.push_back(pDataModel); + + return GetObjectFromCN(ListOfContainer, CCommonName(objName)); + } + + return GetObjectFromCN(listOfContainer, CCommonName(objName)); +} + CObjectInterface::CObjectInterface(): mValidity(this) {} diff --git a/copasi/core/CObjectInterface.h b/copasi/core/CObjectInterface.h index 9549a481be..1b5eb35f5e 100644 --- a/copasi/core/CObjectInterface.h +++ b/copasi/core/CObjectInterface.h @@ -36,6 +36,9 @@ class CObjectInterface static CObjectInterface * GetObjectFromCN(const ContainerList & listOfContainer, const CCommonName & objName); + static CObjectInterface * GetObjectFromCN(const ContainerList & listOfContainer, + const CRegisteredCommonName & objName); + /** * Constructor */ diff --git a/copasi/core/CRegisteredCommonName.cpp b/copasi/core/CRegisteredCommonName.cpp index 7dcbb08def..ea6810dd97 100644 --- a/copasi/core/CRegisteredCommonName.cpp +++ b/copasi/core/CRegisteredCommonName.cpp @@ -16,6 +16,7 @@ #include "copasi/core/CDataObject.h" #include "copasi/core/CDataContainer.h" #include "copasi/CopasiDataModel/CDataModel.h" +#include "copasi/core/CRootContainer.h" using std::string; @@ -53,10 +54,21 @@ CRegisteredCommonName::CRegisteredCommonName() mSet.insert(this); } +CRegisteredCommonName::CRegisteredCommonName(const std::string & name) + : CCommonName(name) + , mpDataModel(nullptr) +{ + const CDataObject * pObject = CObjectInterface::DataObject(CRootContainer::getRoot()->getObject(name)); + + if (pObject != nullptr) + mpDataModel = pObject->getObjectDataModel(); + + mSet.insert(this); +} + CRegisteredCommonName::CRegisteredCommonName(const std::string & name, const CObjectInterface * pObject) : CCommonName(name) - , mpDataModel((pObject != nullptr - && CObjectInterface::DataObject(pObject) != nullptr) + , mpDataModel(CObjectInterface::DataObject(pObject) != nullptr ? CObjectInterface::DataObject(pObject)->getObjectDataModel() : nullptr) { mSet.insert(this); @@ -74,6 +86,11 @@ CRegisteredCommonName::~CRegisteredCommonName() mSet.erase(this); } +const CDataModel * CRegisteredCommonName::getDataModel() const +{ + return mpDataModel; +} + // static void CRegisteredCommonName::handle(const std::string & oldCN, const CRegisteredCommonName & newCN) { diff --git a/copasi/core/CRegisteredCommonName.h b/copasi/core/CRegisteredCommonName.h index 41ab1982e9..f8d0edd96c 100644 --- a/copasi/core/CRegisteredCommonName.h +++ b/copasi/core/CRegisteredCommonName.h @@ -77,6 +77,12 @@ class CRegisteredCommonName: public CCommonName */ CRegisteredCommonName(); + /** + * Constructor from base class + * @param const std::string & name + */ + CRegisteredCommonName(const std::string & name); + /** * Constructor from base class * @param const std::string & name @@ -95,6 +101,8 @@ class CRegisteredCommonName: public CCommonName */ ~CRegisteredCommonName(); + const CDataModel * getDataModel() const; + /** * Enable and disable the rename handler * @param const bool & enabled diff --git a/copasi/crosssection/CCrossSectionProblem.cpp b/copasi/crosssection/CCrossSectionProblem.cpp index f965373249..c623d81849 100644 --- a/copasi/crosssection/CCrossSectionProblem.cpp +++ b/copasi/crosssection/CCrossSectionProblem.cpp @@ -30,7 +30,7 @@ CCrossSectionProblem::CCrossSectionProblem(const CDataContainer * pParent) mpFlagLimitOutCrossings(NULL), mpOutCrossingsLimit(NULL), mpFlagLimitOutTime(NULL), - mSingleObjectCN(NULL), + mpSingleObjectCN(NULL), mpFlagPositiveDirection(NULL), mpThreshold(NULL) { @@ -51,7 +51,7 @@ CCrossSectionProblem::CCrossSectionProblem(const CCrossSectionProblem & src, mpFlagLimitOutCrossings(NULL), mpOutCrossingsLimit(NULL), mpFlagLimitOutTime(NULL), - mSingleObjectCN(NULL), + mpSingleObjectCN(NULL), mpFlagPositiveDirection(NULL), mpThreshold(NULL) { @@ -74,7 +74,7 @@ void CCrossSectionProblem::initializeParameter() mpFlagLimitOutConvergence = assertParameter("DelayOutputUntilConvergence", CCopasiParameter::Type::BOOL, false); mpConvergenceOutTolerance = assertParameter("OutputConvergenceTolerance", CCopasiParameter::Type::DOUBLE, (C_FLOAT64)1E-6); mpTriggerExpression = assertParameter("TriggerExpression", CCopasiParameter::Type::EXPRESSION, std::string("")); - mSingleObjectCN = assertParameter("SingleVariable", CCopasiParameter::Type::CN, CCommonName("")); + mpSingleObjectCN = assertParameter("SingleVariable", CCopasiParameter::Type::CN, CRegisteredCommonName()); setOutputEvent(false); } @@ -151,14 +151,14 @@ void CCrossSectionProblem::setTimeLimit(const C_FLOAT64 &timeLimit) */ const std::string& CCrossSectionProblem::getSingleObjectCN() const { - return *mSingleObjectCN; + return *mpSingleObjectCN; } void CCrossSectionProblem::setSingleObjectCN(const CDataObject* pObject) { if (pObject == NULL) return; - setSingleObjectCN(pObject->getStringCN()); + setSingleObjectCN(pObject->getCN()); } const C_FLOAT64& CCrossSectionProblem::getThreshold() const @@ -173,9 +173,9 @@ void CCrossSectionProblem::setThreshold(const C_FLOAT64 &threshold) /* * set the variable */ -void CCrossSectionProblem::setSingleObjectCN(const std::string& cn) +void CCrossSectionProblem::setSingleObjectCN(const CRegisteredCommonName & cn) { - *mSingleObjectCN = cn; + *mpSingleObjectCN = cn; } bool CCrossSectionProblem::getFlagLimitConvergence() const diff --git a/copasi/crosssection/CCrossSectionProblem.h b/copasi/crosssection/CCrossSectionProblem.h index cf9be50d16..4beb6371f2 100644 --- a/copasi/crosssection/CCrossSectionProblem.h +++ b/copasi/crosssection/CCrossSectionProblem.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -80,7 +80,7 @@ class CCrossSectionProblem : public CTrajectoryProblem /* * set the variable */ - void setSingleObjectCN(const std::string& cn); + void setSingleObjectCN(const CRegisteredCommonName & cn); void setSingleObjectCN(const CDataObject* pObject); const C_FLOAT64& getThreshold() const; void setThreshold(const C_FLOAT64 &threshold); @@ -270,7 +270,7 @@ class CCrossSectionProblem : public CTrajectoryProblem * this member variable is mapped to a CCopasiParameter */ std::string * mpTriggerExpression; - std::string * mSingleObjectCN; + CRegisteredCommonName * mpSingleObjectCN; bool * mpFlagPositiveDirection; C_FLOAT64 * mpThreshold; }; diff --git a/copasi/math/CMathContainer.cpp b/copasi/math/CMathContainer.cpp index 25148cde55..1ae8c2096a 100644 --- a/copasi/math/CMathContainer.cpp +++ b/copasi/math/CMathContainer.cpp @@ -1365,7 +1365,7 @@ const CObjectInterface * CMathContainer::getObject(const CCommonName & cn) const if (cn.getPrimary() != ModelCN.getPrimary()) { - pObject = CObjectInterface::GetObjectFromCN(ListOfContainer, ModelCN + "," + cn); + pObject = CObjectInterface::GetObjectFromCN(ListOfContainer, CCommonName(ModelCN + "," + cn)); } else { diff --git a/copasi/model/CEvent.cpp b/copasi/model/CEvent.cpp index 2ea80ebc98..71b68b2596 100644 --- a/copasi/model/CEvent.cpp +++ b/copasi/model/CEvent.cpp @@ -259,7 +259,7 @@ const CDataObject * CEventAssignment::getTargetObject() const return mpTarget; } -bool CEventAssignment::setTargetCN(const std::string & targetCN) +bool CEventAssignment::setTargetCN(const CRegisteredCommonName & targetCN) { if (targetCN != getTargetCN() && mpModel != nullptr) @@ -267,11 +267,11 @@ bool CEventAssignment::setTargetCN(const std::string & targetCN) mpModel->setCompileFlag(true); } - mTargetCN = CRegisteredCommonName(targetCN, this); + mTargetCN = targetCN; return setObjectName(targetCN); } -const std::string & CEventAssignment::getTargetCN() const +const CRegisteredCommonName & CEventAssignment::getTargetCN() const { //if (mTargetCN != getObjectName()) // setObjectName(mTargetCN); diff --git a/copasi/model/CEvent.h b/copasi/model/CEvent.h index e10d83a545..763eab8f26 100644 --- a/copasi/model/CEvent.h +++ b/copasi/model/CEvent.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -129,16 +129,16 @@ class CEventAssignment : public CDataContainer /** * Set the CN of the target - * @param const std::string & targetCN + * @param const CRegisteredCommonName & targetCN * @return bool success; */ - bool setTargetCN(const std::string & targetCN); + bool setTargetCN(const CRegisteredCommonName & targetCN); /** * Retrieve the target CN - * @return const std::string & targetCN + * @return CRegisteredCommonName & targetCN */ - const std::string & getTargetCN() const; + const CRegisteredCommonName & getTargetCN() const; /** * Retrieve the target CN for saving CopasiML diff --git a/copasi/optimization/COptItem.cpp b/copasi/optimization/COptItem.cpp index d62d0ac135..9303311e65 100644 --- a/copasi/optimization/COptItem.cpp +++ b/copasi/optimization/COptItem.cpp @@ -131,13 +131,13 @@ void * COptItem::getValuePointer() const void COptItem::initializeParameter() { - mpParmObjectCN = assertParameter("ObjectCN", CCopasiParameter::Type::CN, CCommonName("")); - mpParmLowerBound = assertParameter("LowerBound", CCopasiParameter::Type::CN, CCommonName("1e-06")); - mpParmUpperBound = assertParameter("UpperBound", CCopasiParameter::Type::CN, CCommonName("1e+06")); + mpParmObjectCN = assertParameter("ObjectCN", CCopasiParameter::Type::CN, CRegisteredCommonName()); + mpParmLowerBound = assertParameter("LowerBound", CCopasiParameter::Type::CN, CRegisteredCommonName("1e-06", nullptr)); + mpParmUpperBound = assertParameter("UpperBound", CCopasiParameter::Type::CN, CRegisteredCommonName("1e+06", nullptr)); mpParmStartValue = assertParameter("StartValue", CCopasiParameter::Type::DOUBLE, NaN); } -bool COptItem::setObjectCN(const CCommonName & objectCN) +bool COptItem::setObjectCN(const CRegisteredCommonName & objectCN) { const CDataObject * pObject = CObjectInterface::DataObject(getObjectFromCN(objectCN)); @@ -154,7 +154,7 @@ bool COptItem::setObjectCN(const CCommonName & objectCN) const CObjectInterface * COptItem::getObject() const {return mpObject;} -const CCommonName COptItem::getObjectCN() const +const CRegisteredCommonName & COptItem::getObjectCN() const {return *mpParmObjectCN;} std::string COptItem::getObjectDisplayName() const @@ -173,7 +173,7 @@ std::string COptItem::getObjectDisplayName() const return mpObject->getObjectDisplayName(); } -bool COptItem::setLowerBound(const CCommonName & lowerBound) +bool COptItem::setLowerBound(const CRegisteredCommonName & lowerBound) { if (lowerBound[0] == '-' && lowerBound[lowerBound.length() - 1] == '%' && @@ -183,7 +183,7 @@ bool COptItem::setLowerBound(const CCommonName & lowerBound) C_FLOAT64 StartValue = getStartValue(); LowerBound << StartValue + fabs(StartValue) * strToDouble(lowerBound.c_str(), NULL) / 100.0; - *mpParmLowerBound = LowerBound.str(); + *mpParmLowerBound = CRegisteredCommonName(LowerBound.str(), nullptr); return true; } @@ -195,10 +195,18 @@ bool COptItem::setLowerBound(const CCommonName & lowerBound) return compileLowerBound(CDataContainer::EmptyList); } -const std::string COptItem::getLowerBound() const +bool COptItem::setLowerBound(const C_FLOAT64 & lowerBound) +{ + std::stringstream LowerBound; + LowerBound << lowerBound; + + return setLowerBound(CRegisteredCommonName(LowerBound.str(), nullptr)); +} + +const CRegisteredCommonName & COptItem::getLowerBound() const {return *mpParmLowerBound;} -bool COptItem::setUpperBound(const CCommonName & upperBound) +bool COptItem::setUpperBound(const CRegisteredCommonName & upperBound) { if (upperBound[0] == '+' && upperBound[upperBound.length() - 1] == '%' && @@ -208,7 +216,7 @@ bool COptItem::setUpperBound(const CCommonName & upperBound) C_FLOAT64 StartValue = getStartValue(); UpperBound << StartValue + fabs(StartValue) * strToDouble(upperBound.c_str(), NULL) / 100.0; - *mpParmUpperBound = UpperBound.str(); + *mpParmUpperBound = CRegisteredCommonName(UpperBound.str(), nullptr); return true; } @@ -220,7 +228,15 @@ bool COptItem::setUpperBound(const CCommonName & upperBound) return compileUpperBound(CDataContainer::EmptyList); } -const std::string COptItem::getUpperBound() const +bool COptItem::setUpperBound(const C_FLOAT64 & upperBound) +{ + std::stringstream UpperBound; + UpperBound << upperBound; + + return setUpperBound(CRegisteredCommonName(UpperBound.str(), nullptr)); +} + +const CRegisteredCommonName & COptItem::getUpperBound() const {return *mpParmUpperBound;} bool COptItem::setStartValue(const C_FLOAT64 & value) diff --git a/copasi/optimization/COptItem.h b/copasi/optimization/COptItem.h index a7fddf37fb..23a68ac657 100644 --- a/copasi/optimization/COptItem.h +++ b/copasi/optimization/COptItem.h @@ -87,16 +87,16 @@ class COptItem: public CCopasiParameterGroup /** * Set the object of the optimization item. - * @param const CCommonName & objectCN + * @param const CRegisteredCommonName & objectCN * @return bool success */ - bool setObjectCN(const CCommonName & objectCN); + bool setObjectCN(const CRegisteredCommonName & objectCN); /** * Retrieve the object of the optimization item. - * @return const CCommonName objectCN + * @return const CRegisteredCommonName & objectCN */ - const CCommonName getObjectCN() const; + const CRegisteredCommonName & getObjectCN() const; /** * Retrieve the item object. This may only be called after compile @@ -112,29 +112,43 @@ class COptItem: public CCopasiParameterGroup /** * Set the lower bound. - * @param const CCommonName & lowerBound + * @param const CRegisteredCommonName & lowerBound * @return bool success */ - bool setLowerBound(const CCommonName & lowerBound); + bool setLowerBound(const CRegisteredCommonName & lowerBound); + + /** + * Set the lower bound. + * @param const C_FLOAT64 & upperBound + * @return bool success + */ + bool setLowerBound(const C_FLOAT64 & upperBound); /** * Retrieve the lower bound. - * @return const std::string lowerBound + * @return const CRegisteredCommonName & lowerBound + */ + const CRegisteredCommonName & getLowerBound() const; + + /** + * Set the upper bound. + * @param const CRegisteredCommonName & upperBound + * @return bool success */ - const std::string getLowerBound() const; + bool setUpperBound(const CRegisteredCommonName & upperBound); /** * Set the upper bound. - * @param const CCommonName & upperBound + * @param const C_FLOAT64 & upperBound * @return bool success */ - bool setUpperBound(const CCommonName & upperBound); + bool setUpperBound(const C_FLOAT64 & upperBound); /** * Retrieve the upper bound. - * @return const std::string upperBound + * @return const CRegisteredCommonName & upperBound */ - const std::string getUpperBound() const; + const CRegisteredCommonName & getUpperBound() const; /** * Check the validity of the optimization item. @@ -311,17 +325,17 @@ class COptItem: public CCopasiParameterGroup /** * A pointer to the value of the CCopasiParameter holding the ObjectCN */ - std::string * mpParmObjectCN; + CRegisteredCommonName * mpParmObjectCN; /** * A pointer to the value of the CCopasiParameter holding the LowerBound */ - std::string * mpParmLowerBound; + CRegisteredCommonName * mpParmLowerBound; /** * A pointer to the value of the CCopasiParameter holding the UpperBound */ - std::string * mpParmUpperBound; + CRegisteredCommonName * mpParmUpperBound; /** * A pointer to the value of the CCopasiParameter holding the start value diff --git a/copasi/optimization/COptProblem.cpp b/copasi/optimization/COptProblem.cpp index ed34c7fdfd..4bec0f7902 100644 --- a/copasi/optimization/COptProblem.cpp +++ b/copasi/optimization/COptProblem.cpp @@ -199,7 +199,7 @@ void * COptProblem::getValuePointer() const void COptProblem::initializeParameter() { - mpParmSubTaskCN = assertParameter("Subtask", CCopasiParameter::Type::CN, CCommonName("")); + mpParmSubTaskCN = assertParameter("Subtask", CCopasiParameter::Type::CN, CRegisteredCommonName()); mpParmObjectiveExpression = assertParameter("ObjectiveExpression", CCopasiParameter::Type::EXPRESSION, std::string("")); mpParmMaximize = assertParameter("Maximize", CCopasiParameter::Type::BOOL, false); mpParmRandomizeStartValues = assertParameter("Randomize Start Values", CCopasiParameter::Type::BOOL, false); @@ -370,6 +370,7 @@ bool COptProblem::initializeSubtaskBeforeOutput() { mpSubTask->setMathContainer(mpContainer); mpSubTask->setCallBack(mProcessReport); + return mpSubTask->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL); } } @@ -1060,7 +1061,7 @@ size_t COptProblem::getOptConstraintSize() const return mpGrpConstraints->size(); } -COptItem & COptProblem::addOptConstraint(const CCommonName & objectCN) +COptItem & COptProblem::addOptConstraint(const CRegisteredCommonName & objectCN) { CDataModel * pDataModel = getObjectDataModel(); assert(pDataModel != NULL); @@ -1084,7 +1085,7 @@ COptItem & COptProblem::getOptItem(const size_t & index) size_t COptProblem::getOptItemSize() const {return mpGrpItems->size();} -COptItem & COptProblem::addOptItem(const CCommonName & objectCN) +COptItem & COptProblem::addOptItem(const CRegisteredCommonName & objectCN) { CDataModel* pDataModel = getObjectDataModel(); assert(pDataModel != NULL); @@ -1155,10 +1156,8 @@ const std::string COptProblem::getObjectiveFunction() return *mpParmObjectiveExpression; } -CCommonName COptProblem::setSubtaskType(const CTaskEnum::Task & subtaskType) +CRegisteredCommonName COptProblem::setSubtaskType(const CTaskEnum::Task & subtaskType) { - CCommonName SubTaskCN; - CDataVectorN< CCopasiTask > * pTasks = dynamic_cast< CDataVectorN< CCopasiTask > *>(getObjectAncestor("Vector")); @@ -1175,23 +1174,23 @@ CCommonName COptProblem::setSubtaskType(const CTaskEnum::Task & subtaskType) for (; it != end; ++it) if (it->getType() == subtaskType) { - SubTaskCN = it->getStringCN(); - break; - } - } + if (mpParmSubTaskCN != NULL) + { + *mpParmSubTaskCN = it->getCN(); + mpSubTaskSrc = getSubTask(); + } - if (mpParmSubTaskCN != NULL) - { - *mpParmSubTaskCN = SubTaskCN; + return it->getCN(); + } } - return SubTaskCN; + return CRegisteredCommonName(); } CTaskEnum::Task COptProblem::getSubtaskType() const { - if (mpSubTask != NULL) - return mpSubTask->getType(); + if (mpSubTaskSrc != NULL) + return mpSubTaskSrc->getType(); return CTaskEnum::Task::UnsetTask; } diff --git a/copasi/optimization/COptProblem.h b/copasi/optimization/COptProblem.h index 060f1980d7..a348b2e1dc 100644 --- a/copasi/optimization/COptProblem.h +++ b/copasi/optimization/COptProblem.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -324,10 +324,10 @@ class COptProblem : public CCopasiProblem /** * Add an optimization constraint to the problem. - * @param const CCommonName & objectCN + * @param const CRegisteredCommonName & objectCN * @return COptItem optItemAdded */ - COptItem & addOptConstraint(const CCommonName & objectCN); + COptItem & addOptConstraint(const CRegisteredCommonName & objectCN); /** * Remove an optimization constraint. @@ -351,10 +351,10 @@ class COptProblem : public CCopasiProblem /** * Add an optimization item to the problem. - * @param const CCommonName & objectCN + * @param const CRegisteredCommonName & objectCN * @return COptItem optItemAdded */ - COptItem & addOptItem(const CCommonName & objectCN); + COptItem & addOptItem(const CRegisteredCommonName & objectCN); /** * Remove an optimization items. @@ -390,7 +390,7 @@ class COptProblem : public CCopasiProblem * @param const CTaskEnum::Task & subtaskType * @return CCommonName */ - CCommonName setSubtaskType(const CTaskEnum::Task & subtaskType); + CRegisteredCommonName setSubtaskType(const CTaskEnum::Task & subtaskType); /** * Retrieve the subtask type @@ -552,7 +552,7 @@ class COptProblem : public CCopasiProblem /** * A pointer to the value of the CCopasiParameter holding the CN for the subtask */ - std::string * mpParmSubTaskCN; + CRegisteredCommonName * mpParmSubTaskCN; /** * A pointer to the value of the CCopasiParameter holding the infix expression diff --git a/copasi/parameterFitting/CFitProblem.cpp b/copasi/parameterFitting/CFitProblem.cpp index 8f1f7fc900..18ffaa3514 100644 --- a/copasi/parameterFitting/CFitProblem.cpp +++ b/copasi/parameterFitting/CFitProblem.cpp @@ -288,11 +288,11 @@ void CFitProblem::initializeParameter() mpParmObjectiveExpression = NULL; *mpParmMaximize = false; - mpParmSteadyStateCN = assertParameter("Steady-State", CCopasiParameter::Type::CN, CCommonName("")); - mpParmTimeCourseCN = assertParameter("Time-Course", CCopasiParameter::Type::CN, CCommonName("")); + mpParmSteadyStateCN = assertParameter("Steady-State", CCopasiParameter::Type::CN, CRegisteredCommonName()); + mpParmTimeCourseCN = assertParameter("Time-Course", CCopasiParameter::Type::CN, CRegisteredCommonName()); mpCreateParameterSets = assertParameter("Create Parameter Sets", CCopasiParameter::Type::BOOL, false); mpUseTimeSens = assertParameter("Use Time Sens", CCopasiParameter::Type::BOOL, false); - mpParmTimeSensCN = assertParameter("Time-Sens", CCopasiParameter::Type::CN, CCommonName(""));; + mpParmTimeSensCN = assertParameter("Time-Sens", CCopasiParameter::Type::CN, CRegisteredCommonName());; assertGroup("Experiment Set"); @@ -333,9 +333,9 @@ bool CFitProblem::elevateChildren() // Due to a naming conflict the following parameters may have been overwritten during // the load of a CopasiML file we replace them with default values if that was the case. - mpParmSteadyStateCN = assertParameter("Steady-State", CCopasiParameter::Type::CN, CCommonName("")); - mpParmTimeCourseCN = assertParameter("Time-Course", CCopasiParameter::Type::CN, CCommonName("")); - mpParmTimeSensCN = assertParameter("Time-Sens", CCopasiParameter::Type::CN, CCommonName("")); + mpParmSteadyStateCN = assertParameter("Steady-State", CCopasiParameter::Type::CN, CRegisteredCommonName()); + mpParmTimeCourseCN = assertParameter("Time-Course", CCopasiParameter::Type::CN, CRegisteredCommonName()); + mpParmTimeSensCN = assertParameter("Time-Sens", CCopasiParameter::Type::CN, CRegisteredCommonName()); CDataVectorN< CCopasiTask > * pTasks = NULL; CDataModel* pDataModel = getObjectDataModel(); @@ -355,7 +355,7 @@ bool CFitProblem::elevateChildren() for (i = 0; i < imax; i++) if (pTasks->operator[](i).getType() == CTaskEnum::Task::steadyState) { - *mpParmSteadyStateCN = pTasks->operator[](i).getStringCN(); + *mpParmSteadyStateCN = pTasks->operator[](i).getCN(); break; } @@ -364,7 +364,7 @@ bool CFitProblem::elevateChildren() for (i = 0; i < imax; i++) if (pTasks->operator[](i).getType() == CTaskEnum::Task::timeCourse) { - *mpParmTimeCourseCN = pTasks->operator[](i).getStringCN(); + *mpParmTimeCourseCN = pTasks->operator[](i).getCN(); break; } } @@ -918,7 +918,7 @@ bool CFitProblem::checkFunctionalConstraints() return true; } -CFitItem & CFitProblem::addFitItem(const CCommonName & objectCN) +CFitItem & CFitProblem::addFitItem(const CRegisteredCommonName & objectCN) { CDataModel* pDataModel = getObjectDataModel(); assert(pDataModel != NULL); @@ -931,7 +931,7 @@ CFitItem & CFitProblem::addFitItem(const CCommonName & objectCN) return *pItem; } -CFitConstraint & CFitProblem::addFitConstraint(const CCommonName & objectCN) +CFitConstraint & CFitProblem::addFitConstraint(const CRegisteredCommonName & objectCN) { CDataModel * pDataModel = getObjectDataModel(); assert(pDataModel != NULL); diff --git a/copasi/parameterFitting/CFitProblem.h b/copasi/parameterFitting/CFitProblem.h index 0801a2f912..241cd44897 100644 --- a/copasi/parameterFitting/CFitProblem.h +++ b/copasi/parameterFitting/CFitProblem.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -284,17 +284,17 @@ class CFitProblem : public COptProblem /** * Add a fit item to the problem. - * @param const CCommonName & objectCN + * @param const CRegisteredCommonName & objectCN * @return CFitItem optItemAdded */ - CFitItem & addFitItem(const CCommonName & objectCN); + CFitItem & addFitItem(const CRegisteredCommonName & objectCN); /** * Add a fit constraint to the problem. - * @param const CCommonName & objectCN + * @param const CRegisteredCommonName & objectCN * @return CFitConstraint optItemAdded */ - CFitConstraint & addFitConstraint(const CCommonName & objectCN); + CFitConstraint & addFitConstraint(const CRegisteredCommonName & objectCN); /** * Set the solution. @@ -396,12 +396,12 @@ class CFitProblem : public COptProblem /** * A pointer to the value of the CCopasiParameter holding the Steady-State CN */ - std::string * mpParmSteadyStateCN; + CRegisteredCommonName * mpParmSteadyStateCN; /** * A pointer to the value of the CCopasiParameter holding the Time Course CN */ - std::string * mpParmTimeCourseCN; + CRegisteredCommonName * mpParmTimeCourseCN; /** * The experiment set to which the model is fitted. @@ -607,7 +607,7 @@ class CFitProblem : public COptProblem CMatrix< C_FLOAT64 > mJacTimeSens; - std::string* mpParmTimeSensCN; + CRegisteredCommonName * mpParmTimeSensCN; }; #endif // COPASI_CFitProblem diff --git a/copasi/sensitivities/CSensProblem.cpp b/copasi/sensitivities/CSensProblem.cpp index 680f7c560a..f98ca946b6 100644 --- a/copasi/sensitivities/CSensProblem.cpp +++ b/copasi/sensitivities/CSensProblem.cpp @@ -182,7 +182,7 @@ void CSensProblem::createParametersInGroup(CCopasiParameterGroup * pg) if (!pg) return; - pg->assertParameter("SingleObject", CCopasiParameter::Type::CN, CCommonName("")); + pg->assertParameter("SingleObject", CCopasiParameter::Type::CN, CRegisteredCommonName()); pg->assertParameter("ObjectListType", CCopasiParameter::Type::UINT, (unsigned C_INT32) 0); } @@ -680,7 +680,7 @@ std::ostream & operator<<(std::ostream & os, const CSensProblem & o) << std::endl; os << "Calculation to perform: " - << CSensProblem::SubTaskName[o.getSubTaskType()] << std::endl + << CTaskEnum::TaskName[CSensProblem::SubTaskTypeToTask[o.getSubTaskType()]] << std::endl << std::endl; size_t i, imax = o.getNumberOfVariables(); diff --git a/copasi/utilities/CCopasiParameter.cpp b/copasi/utilities/CCopasiParameter.cpp index af443dff63..bf5c65f23b 100644 --- a/copasi/utilities/CCopasiParameter.cpp +++ b/copasi/utilities/CCopasiParameter.cpp @@ -385,13 +385,12 @@ bool CCopasiParameter::isValidValue(const std::string & value) const if (mType != CCopasiParameter::Type::STRING && mType != CCopasiParameter::Type::FILE && - mType != CCopasiParameter::Type::CN && mType != CCopasiParameter::Type::EXPRESSION) return false; return inValidValues(value); } -bool CCopasiParameter::isValidValue(const CCommonName & /* value */) const +bool CCopasiParameter::isValidValue(const CRegisteredCommonName & /* value */) const { if (mType != CCopasiParameter::Type::CN) return false; diff --git a/copasi/utilities/CCopasiParameter.h b/copasi/utilities/CCopasiParameter.h index d798c0df7b..87274c5537 100644 --- a/copasi/utilities/CCopasiParameter.h +++ b/copasi/utilities/CCopasiParameter.h @@ -316,7 +316,7 @@ class CCopasiParameter: public CDataContainer * @param const CRegisteredCommonName & value * @return bool isValidValue */ - bool isValidValue(const CCommonName & value) const; + bool isValidValue(const CRegisteredCommonName & value) const; /** * Check whether the value corresponds to the type diff --git a/tests/test_CDataHandler.cpp b/tests/test_CDataHandler.cpp index 6f08ff526f..56f503c48f 100644 --- a/tests/test_CDataHandler.cpp +++ b/tests/test_CDataHandler.cpp @@ -30,9 +30,9 @@ TEST_CASE("1: load model, simulate, collect data", "[copasi][datahandler]") CCopasiMessage::clearDeque(); CDataHandler inv_handler; - inv_handler.addDuringName( {"CN=Root,Model=The Brusselator", dm}); // this should not work and give a warning during compile, and stop it + inv_handler.addDuringName({"CN=Root,Model=The Brusselator", dm}); // this should not work and give a warning during compile, and stop it - REQUIRE(inv_handler.compile( {dm}) == false); + REQUIRE(inv_handler.compile({dm}) == false); auto text = CCopasiMessage::getAllMessageText(); REQUIRE(text.find("CN=Root,Model=The Brusselator") != std::string::npos); @@ -40,13 +40,13 @@ TEST_CASE("1: load model, simulate, collect data", "[copasi][datahandler]") CCopasiMessage::clearDeque(); CDataHandler handler; - handler.addDuringName(dm->registeredCN("CN=Root,Model=The Brusselator,Reference=Time")); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=Concentration", dm}); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[Y],Reference=Concentration", dm}); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Reactions[R1],Reference=Flux", dm}); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Reactions[R2],Reference=Flux", dm}); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Reactions[R3],Reference=Flux", dm}); - handler.addDuringName( {"CN=Root,Model=The Brusselator,Vector=Reactions[R4],Reference=Flux", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Reference=Time", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[X],Reference=Concentration", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[Y],Reference=Concentration", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Reactions[R1],Reference=Flux", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Reactions[R2],Reference=Flux", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Reactions[R3],Reference=Flux", dm}); + handler.addDuringName({"CN=Root,Model=The Brusselator,Vector=Reactions[R4],Reference=Flux", dm}); auto& task = dynamic_cast((*dm->getTaskList())["Time-Course"]); REQUIRE(task.initialize(CCopasiTask::OUTPUT_DURING, &handler, NULL) == true); @@ -80,10 +80,10 @@ TEST_CASE("ensure that data handler with function evaluations can be compiled", REQUIRE(dm->loadModel(getTestFile("test-data/brusselator.cps"), NULL) == true); CDataHandler handler; - handler.addDuringName( {"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Function Evaluations", dm}); - handler.addDuringName( {"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Value", dm}); + handler.addDuringName({"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Function Evaluations", dm}); + handler.addDuringName({"CN=Root,Vector=TaskList[Optimization],Problem=Optimization,Reference=Best Value", dm}); - REQUIRE(handler.compile( {dm}) == true); + REQUIRE(handler.compile({dm}) == true); // lets try whether it works now @@ -94,16 +94,16 @@ TEST_CASE("ensure that data handler with function evaluations can be compiled", { auto & item = problem->addOptItem( - {"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=InitialConcentration"}); - item.setLowerBound( {"0.0001"}); - item.setUpperBound( {"100"}); + {"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[A],Reference=InitialConcentration", dm}); + item.setLowerBound(0.0001); + item.setUpperBound(100); item.setStartValue(0.5); } { - auto & item = problem->addOptItem( {"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[B],Reference=InitialConcentration"}); - item.setLowerBound( {"0.0001"}); - item.setUpperBound( {"100"}); + auto & item = problem->addOptItem({"CN=Root,Model=The Brusselator,Vector=Compartments[compartment],Vector=Metabolites[B],Reference=InitialConcentration", dm}); + item.setLowerBound(0.0001); + item.setUpperBound(100); item.setStartValue(3); } From 0e8a2445ea80de42ab6995043c3d70d47044733f Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Thu, 28 Mar 2024 12:48:47 -0400 Subject: [PATCH 2/7] Bug 3223: Sub task names are now based on CTaskEnum. --- copasi/UI/SensitivitiesWidget.cpp | 5 ++--- copasi/sensitivities/CSensProblem.cpp | 24 ------------------------ copasi/sensitivities/CSensProblem.h | 6 +----- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/copasi/UI/SensitivitiesWidget.cpp b/copasi/UI/SensitivitiesWidget.cpp index a10acfa3fc..707b7b021c 100644 --- a/copasi/UI/SensitivitiesWidget.cpp +++ b/copasi/UI/SensitivitiesWidget.cpp @@ -323,10 +323,9 @@ SensitivitiesWidget::initCombos() // SubTaskChooser combo int i = 0; - while (CSensProblem::SubTaskName[i].length() > 0) + for (int i = 0; i < CSensProblem::SubTaskType::__SIZE; ++i) { - StringList.append(FROM_UTF8(CSensProblem::SubTaskName[i])); - ++i; + StringList.append(FROM_UTF8(CTaskEnum::TaskName[CSensProblem::SubTaskTypeToTask[i]])); } SubTaskChooser->insertItems(SubTaskChooser->count(), StringList); diff --git a/copasi/sensitivities/CSensProblem.cpp b/copasi/sensitivities/CSensProblem.cpp index f98ca946b6..68800ad6c2 100644 --- a/copasi/sensitivities/CSensProblem.cpp +++ b/copasi/sensitivities/CSensProblem.cpp @@ -152,30 +152,6 @@ const CEnumAnnotation< CTaskEnum::Task, CSensProblem::SubTaskType > CSensProblem CTaskEnum::Task::crosssection // CrossSection }); -const std::string CSensProblem::SubTaskName[] = -{ - "Evaluation", - "Steady State", - "Time Series", - "Parameter Estimation", - "Optimization", - "Cross Section", - //"Lyapunov Exponents", - "" -}; - -const char * CSensProblem::XMLSubTask[] = -{ - "Evaluation", - "SteadyState", - "TimeSeries", - "ParameterEstimation", - "Optimization", - "CrossSection", - //"LyapunovExponents", - NULL -}; - //static void CSensProblem::createParametersInGroup(CCopasiParameterGroup * pg) { diff --git a/copasi/sensitivities/CSensProblem.h b/copasi/sensitivities/CSensProblem.h index 996c8cfc1b..909dce7771 100644 --- a/copasi/sensitivities/CSensProblem.h +++ b/copasi/sensitivities/CSensProblem.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -93,10 +93,6 @@ class CSensProblem : public CCopasiProblem static const CEnumAnnotation< CTaskEnum::Task, SubTaskType > SubTaskTypeToTask; - static const std::string SubTaskName[]; - - static const char * XMLSubTask[]; - static std::vector< CObjectLists::ListType > getPossibleTargetFunctions(CSensProblem::SubTaskType); static std::vector< CObjectLists::ListType > getPossibleVariables(CSensProblem::SubTaskType); From 8fd1a60891cb37199ffd5f3d2d0beb72efdaacf3 Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Mon, 1 Apr 2024 15:49:42 -0400 Subject: [PATCH 3/7] Bug 3221: Fixed UI problems in experiment data and event widgets. --- copasi/UI/CQEventWidget1.cpp | 2 +- copasi/UI/CQExperimentData.cpp | 2 +- copasi/UI/CQParameterGroupView.cpp | 2 +- copasi/core/CRegisteredCommonName.cpp | 2 + copasi/core/CRegisteredCommonName.h | 5 +++ copasi/model/CEvent.cpp | 4 +- copasi/model/CModelExpansion.cpp | 2 +- .../parameterFitting/CExperimentObjectMap.cpp | 18 ++++----- .../parameterFitting/CExperimentObjectMap.h | 14 +++---- copasi/scan/CScanMethod.cpp | 2 +- copasi/scan/CScanProblem.cpp | 4 +- copasi/timesens/CTimeSensProblem.cpp | 39 ++++++++----------- copasi/timesens/CTimeSensProblem.h | 15 ++++--- copasi/xml/parser/TaskHandler.cpp | 8 ++-- 14 files changed, 59 insertions(+), 60 deletions(-) diff --git a/copasi/UI/CQEventWidget1.cpp b/copasi/UI/CQEventWidget1.cpp index c737f74486..8bbc44a67a 100644 --- a/copasi/UI/CQEventWidget1.cpp +++ b/copasi/UI/CQEventWidget1.cpp @@ -501,7 +501,7 @@ void CQEventWidget1::slotSelectObject() if (pObject == NULL) return; - if (mAssignments[mCurrentTarget].setTargetCN(pObject->getStringCN())) + if (mAssignments[mCurrentTarget].setTargetCN(pObject->getCN())) { // If the target key change was successful we need to update the label. mpLBTarget->item((int) mCurrentTarget)->setText(FROM_UTF8(pObject->getObjectDisplayName())); diff --git a/copasi/UI/CQExperimentData.cpp b/copasi/UI/CQExperimentData.cpp index 016b0d8e71..070c831f1d 100644 --- a/copasi/UI/CQExperimentData.cpp +++ b/copasi/UI/CQExperimentData.cpp @@ -1554,7 +1554,7 @@ bool CQExperimentData::saveTable(CExperiment * pExperiment) if (ObjectMap.getObjectCN(i) != TO_UTF8(mpTable->item((int) i, COL_OBJECT_HIDDEN)->text())) { - ObjectMap.setObjectCN(i, TO_UTF8(mpTable->item((int) i, COL_OBJECT_HIDDEN)->text())); + ObjectMap.setObjectCN(i, CRegisteredCommonName(TO_UTF8(mpTable->item((int) i, COL_OBJECT_HIDDEN)->text()), mpDataModel)); Changed = true; } diff --git a/copasi/UI/CQParameterGroupView.cpp b/copasi/UI/CQParameterGroupView.cpp index 0b1fda8b70..4f5e15f977 100644 --- a/copasi/UI/CQParameterGroupView.cpp +++ b/copasi/UI/CQParameterGroupView.cpp @@ -240,7 +240,7 @@ void CQParameterGroupView::modifySelectCNs(CCopasiParameterGroup & group, const for (; itNew != endNew; ++itNew) { - group.addParameter("Reaction", CCopasiParameter::Type::CN, (*itNew)->getStringCN()); + group.addParameter("Reaction", CCopasiParameter::Type::CN, (*itNew)->getCN()); } mpParameterGroupDM->endResetModel(); diff --git a/copasi/core/CRegisteredCommonName.cpp b/copasi/core/CRegisteredCommonName.cpp index ea6810dd97..b555ace70f 100644 --- a/copasi/core/CRegisteredCommonName.cpp +++ b/copasi/core/CRegisteredCommonName.cpp @@ -54,6 +54,7 @@ CRegisteredCommonName::CRegisteredCommonName() mSet.insert(this); } +#ifndef DEPRECATE_CONSTRUCTOR CRegisteredCommonName::CRegisteredCommonName(const std::string & name) : CCommonName(name) , mpDataModel(nullptr) @@ -65,6 +66,7 @@ CRegisteredCommonName::CRegisteredCommonName(const std::string & name) mSet.insert(this); } +#endif // DEPRECATE_CONSTRUCTOR CRegisteredCommonName::CRegisteredCommonName(const std::string & name, const CObjectInterface * pObject) : CCommonName(name) diff --git a/copasi/core/CRegisteredCommonName.h b/copasi/core/CRegisteredCommonName.h index f8d0edd96c..6b3e54ab67 100644 --- a/copasi/core/CRegisteredCommonName.h +++ b/copasi/core/CRegisteredCommonName.h @@ -13,6 +13,9 @@ #include "copasi/core/CCommonName.h" +// Uncomment to disable the deprecated construct from std::string +// #define DEPRECATE_CONSTRUCTOR 1 + class CDataModel; class CObjectInterface; @@ -77,11 +80,13 @@ class CRegisteredCommonName: public CCommonName */ CRegisteredCommonName(); +#ifndef DEPRECATE_CONSTRUCTOR /** * Constructor from base class * @param const std::string & name */ CRegisteredCommonName(const std::string & name); +#endif // DEPRECATE_CONSTRUCTOR /** * Constructor from base class diff --git a/copasi/model/CEvent.cpp b/copasi/model/CEvent.cpp index 71b68b2596..6948e37882 100644 --- a/copasi/model/CEvent.cpp +++ b/copasi/model/CEvent.cpp @@ -71,7 +71,7 @@ bool CEventAssignment::applyData(const CData & data, CUndoData::CChangeSet & cha if (data.isSetProperty(CData::OBJECT_REFERENCE_CN)) { - setTargetCN(data.getProperty(CData::OBJECT_REFERENCE_CN).toString()); + setTargetCN(CRegisteredCommonName(data.getProperty(CData::OBJECT_REFERENCE_CN).toString(), this)); compileModel = true; } @@ -211,7 +211,7 @@ CIssue CEventAssignment::compile(CObjectInterface::ContainerList listOfContainer if (pEntity != nullptr) { mpTarget = pEntity->getValueObject(); - setTargetCN(mpTarget->getStringCN()); + setTargetCN(mpTarget->getCN()); } else pEntity = dynamic_cast< const CModelEntity * >(mpTarget->getObjectParent()); diff --git a/copasi/model/CModelExpansion.cpp b/copasi/model/CModelExpansion.cpp index 17fe14492e..29ed6a2127 100644 --- a/copasi/model/CModelExpansion.cpp +++ b/copasi/model/CModelExpansion.cpp @@ -1566,7 +1566,7 @@ void CModelExpansion::replaceInEvent(CEvent* pX, const ElementsMap & emap) const CDataObject * pObject = emap.getDuplicateFromObject(pAssignment->getTargetObject()); if (pObject != NULL) - pAssignment->setTargetCN(pObject->getStringCN()); + pAssignment->setTargetCN(pObject->getCN()); } } diff --git a/copasi/parameterFitting/CExperimentObjectMap.cpp b/copasi/parameterFitting/CExperimentObjectMap.cpp index 9f0395cbc9..b76b58f1c6 100644 --- a/copasi/parameterFitting/CExperimentObjectMap.cpp +++ b/copasi/parameterFitting/CExperimentObjectMap.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -200,18 +200,18 @@ CExperiment::Type CExperimentObjectMap::getRole(const size_t & index) const } bool CExperimentObjectMap::setObjectCN(const size_t & index, - const std::string & CN) + const CRegisteredCommonName & CN) { CDataColumn * pColumn = dynamic_cast< CDataColumn * >(getGroup(StringPrint("%d", index))); if (pColumn) - return pColumn->setObjectCN((CCommonName) CN); + return pColumn->setObjectCN(CN); else return false; } -std::string CExperimentObjectMap::getObjectCN(const size_t & index) const +CRegisteredCommonName CExperimentObjectMap::getObjectCN(const size_t & index) const { const CDataColumn * pColumn = dynamic_cast< const CDataColumn * >(getGroup(StringPrint("%d", index))); @@ -219,7 +219,7 @@ std::string CExperimentObjectMap::getObjectCN(const size_t & index) const if (pColumn) return pColumn->getObjectCN(); else - return ""; + return CRegisteredCommonName(); } bool CExperimentObjectMap::setScale(const size_t & index, @@ -393,7 +393,7 @@ bool CExperimentObjectMap::CDataColumn::setRole(const CExperiment::Type & role) const CExperiment::Type & CExperimentObjectMap::CDataColumn::getRole() const {return *mpRole;} -bool CExperimentObjectMap::CDataColumn::setObjectCN(const std::string & objectCN) +bool CExperimentObjectMap::CDataColumn::setObjectCN(const CRegisteredCommonName & objectCN) { if (objectCN == "") { @@ -409,18 +409,18 @@ bool CExperimentObjectMap::CDataColumn::setObjectCN(const std::string & objectCN *mpObjectCN = objectCN; else mpObjectCN = - assertParameter("Object CN", CCopasiParameter::Type::CN, (CCommonName) objectCN); + assertParameter("Object CN", CCopasiParameter::Type::CN, objectCN); } return true; } -std::string CExperimentObjectMap::CDataColumn::getObjectCN() const +CRegisteredCommonName CExperimentObjectMap::CDataColumn::getObjectCN() const { if (mpObjectCN != NULL) return *mpObjectCN; else - return ""; + return CRegisteredCommonName(); } bool CExperimentObjectMap::CDataColumn::setScale(const C_FLOAT64 & weight) diff --git a/copasi/parameterFitting/CExperimentObjectMap.h b/copasi/parameterFitting/CExperimentObjectMap.h index 4a2238fa37..95b33b033f 100644 --- a/copasi/parameterFitting/CExperimentObjectMap.h +++ b/copasi/parameterFitting/CExperimentObjectMap.h @@ -105,16 +105,16 @@ class CExperimentObjectMap: public CCopasiParameterGroup /** * Set the object CN of the object mapped to the column - * @param const std::string & objectCN + * @param const CRegisteredCommonName & objectCN * @return bool success */ - bool setObjectCN(const std::string & objectCN); + bool setObjectCN(const CRegisteredCommonName & objectCN); /** * Retrieve the object CN of the object mapped to the column * @return std::string objctCN */ - std::string getObjectCN() const; + CRegisteredCommonName getObjectCN() const; /** * Set the scaling factor for the column @@ -145,7 +145,7 @@ class CExperimentObjectMap: public CCopasiParameterGroup private: CExperiment::Type *mpRole; - CCommonName *mpObjectCN; + CRegisteredCommonName *mpObjectCN; C_FLOAT64 *mpScale; }; @@ -249,18 +249,18 @@ class CExperimentObjectMap: public CCopasiParameterGroup /** * Set the object CN of the object mapped to the indexed column * @param const size_t & index - * @param const std::string & objectCN + * @param const CRegisteredCommonName & objectCN * @return bool success */ bool setObjectCN(const size_t & index, - const std::string & objectCN); + const CRegisteredCommonName & objectCN); /** * Retrieve the object CN of the object mapped to the indexed column * @param const size_t & index * @return std::stringobjctCN */ - std::string getObjectCN(const size_t & index) const; + CRegisteredCommonName getObjectCN(const size_t & index) const; /** * Set the scaling factor for the indexed column diff --git a/copasi/scan/CScanMethod.cpp b/copasi/scan/CScanMethod.cpp index 17f2f280a4..94ab9abd6d 100644 --- a/copasi/scan/CScanMethod.cpp +++ b/copasi/scan/CScanMethod.cpp @@ -127,7 +127,7 @@ CScanItem::CScanItem(CCopasiParameterGroup* si): void CScanItem::ensureParameterGroupHasAllElements(CCopasiParameterGroup* pg) { pg->assertParameter("Number of steps", CCopasiParameter::Type::UINT, 0); - pg->assertParameter("Object", CCopasiParameter::Type::CN, std::string()); + pg->assertParameter("Object", CCopasiParameter::Type::CN, CRegisteredCommonName()); } size_t CScanItem::getNumSteps() const {return mNumSteps;} diff --git a/copasi/scan/CScanProblem.cpp b/copasi/scan/CScanProblem.cpp index ae127b5d91..a569febc24 100644 --- a/copasi/scan/CScanProblem.cpp +++ b/copasi/scan/CScanProblem.cpp @@ -292,9 +292,9 @@ CCopasiParameterGroup* CScanProblem::createScanItem(CScanProblem::Type type, siz tmp->addParameter("Type", CCopasiParameter::Type::UINT, (unsigned C_INT32) type); if (obj) - tmp->addParameter("Object", CCopasiParameter::Type::CN, obj->getStringCN()); + tmp->addParameter("Object", CCopasiParameter::Type::CN, obj->getCN()); else - tmp->addParameter("Object", CCopasiParameter::Type::CN, CCommonName("")); + tmp->addParameter("Object", CCopasiParameter::Type::CN, CRegisteredCommonName()); //create specific parameters if ((type == SCAN_LINEAR) || (type == SCAN_RANDOM)) diff --git a/copasi/timesens/CTimeSensProblem.cpp b/copasi/timesens/CTimeSensProblem.cpp index a4a8463e9c..9e95e64c7a 100644 --- a/copasi/timesens/CTimeSensProblem.cpp +++ b/copasi/timesens/CTimeSensProblem.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -99,22 +99,22 @@ bool CTimeSensProblem::elevateChildren() //********************************** -CCommonName CTimeSensProblem::getParameterCN(size_t index) +CRegisteredCommonName CTimeSensProblem::getParameterCN(size_t index) { if (mpParametersGroup == NULL) - return CCommonName(); + return CRegisteredCommonName(); size_t numParameters = getNumParameters(); if (index >= numParameters) - return CCommonName(); + return CRegisteredCommonName(); CCopasiParameter* current = mpParametersGroup->getParameter(index); if (current == NULL) - return CCommonName(); + return CRegisteredCommonName(); - return current->getValue(); + return current->getValue< CRegisteredCommonName >(); } void CTimeSensProblem::removeParameterCN(size_t index) @@ -129,7 +129,7 @@ void CTimeSensProblem::removeParameterCN(size_t index) mpParametersGroup->removeParameter(index); } -void CTimeSensProblem::removeParameterCN(const CCommonName & cn) +void CTimeSensProblem::removeParameterCN(const std::string & cn) { if (mpParametersGroup == NULL) return; @@ -138,10 +138,9 @@ void CTimeSensProblem::removeParameterCN(const CCommonName & cn) for (int i = numParameters - 1; i >= 0 ; --i) { - CCommonName currentCn = getParameterCN(i); CCopasiParameter* current = mpParametersGroup->getParameter(i); - if (current && current->getValue() == cn) + if (current && current->getValue< CRegisteredCommonName >() == cn) mpParametersGroup->removeParameter(i); } } @@ -154,7 +153,7 @@ size_t CTimeSensProblem::getNumParameters() return mpParametersGroup->size(); } -void CTimeSensProblem::addParameterCN(const CCommonName & cn) +void CTimeSensProblem::addParameterCN(const CRegisteredCommonName & cn) { if (mpParametersGroup == NULL) return; @@ -162,7 +161,6 @@ void CTimeSensProblem::addParameterCN(const CCommonName & cn) mpParametersGroup->addParameter("ParameterCN", CCopasiParameter::Type::CN, cn); } - void CTimeSensProblem::clearParameterCNs() { if (mpParametersGroup == NULL) @@ -173,22 +171,22 @@ void CTimeSensProblem::clearParameterCNs() //*********************************** -CCommonName CTimeSensProblem::getTargetCN(size_t index) +CRegisteredCommonName CTimeSensProblem::getTargetCN(size_t index) { if (mpTargetsGroup == NULL) - return CCommonName(); + return CRegisteredCommonName(); size_t numTargets = getNumTargets(); if (index >= numTargets) - return CCommonName(); + return CRegisteredCommonName(); CCopasiParameter* current = mpTargetsGroup->getParameter(index); if (current == NULL) - return CCommonName(); + return CRegisteredCommonName(); - return current->getValue(); + return current->getValue< CRegisteredCommonName> (); } void CTimeSensProblem::removeTargetCN(size_t index) @@ -203,7 +201,7 @@ void CTimeSensProblem::removeTargetCN(size_t index) mpTargetsGroup->removeParameter(index); } -void CTimeSensProblem::removeTargetCN(const CCommonName & cn) +void CTimeSensProblem::removeTargetCN(const std::string & cn) { if (mpTargetsGroup == NULL) return; @@ -212,10 +210,9 @@ void CTimeSensProblem::removeTargetCN(const CCommonName & cn) for (int i = numTargets - 1; i >= 0 ; --i) { - CCommonName currentCn = getTargetCN(i); CCopasiParameter* current = mpTargetsGroup->getParameter(i); - if (current && current->getValue() == cn) + if (current && current->getValue< CRegisteredCommonName >() == cn) mpTargetsGroup->removeParameter(i); } } @@ -228,7 +225,7 @@ size_t CTimeSensProblem::getNumTargets() return mpTargetsGroup->size(); } -void CTimeSensProblem::addTargetCN(const CCommonName & cn) +void CTimeSensProblem::addTargetCN(const CRegisteredCommonName & cn) { if (mpTargetsGroup == NULL) return; @@ -236,7 +233,6 @@ void CTimeSensProblem::addTargetCN(const CCommonName & cn) mpTargetsGroup->addParameter("TargetCN", CCopasiParameter::Type::CN, cn); } - void CTimeSensProblem::clearTargetCNs() { if (mpTargetsGroup == NULL) @@ -326,4 +322,3 @@ const CDataArray * CTimeSensProblem::getScaledTargetsResultAnnotated() const { return mpScaledTargetsResultAnnotation; } - diff --git a/copasi/timesens/CTimeSensProblem.h b/copasi/timesens/CTimeSensProblem.h index 0fd519f3ec..d3e075cf42 100644 --- a/copasi/timesens/CTimeSensProblem.h +++ b/copasi/timesens/CTimeSensProblem.h @@ -1,4 +1,4 @@ -// Copyright (C) 2019 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -60,13 +60,13 @@ class CTimeSensProblem : public CTrajectoryProblem size_t getNumParameters(); - void addParameterCN(const CCommonName& cn); + void addParameterCN(const CRegisteredCommonName& cn); - CCommonName getParameterCN(size_t index); + CRegisteredCommonName getParameterCN(size_t index); void removeParameterCN(size_t index); - void removeParameterCN(const CCommonName& cn); + void removeParameterCN(const std::string & cn); void clearParameterCNs(); @@ -76,13 +76,13 @@ class CTimeSensProblem : public CTrajectoryProblem size_t getNumTargets(); - void addTargetCN(const CCommonName& cn); + void addTargetCN(const CRegisteredCommonName& cn); - CCommonName getTargetCN(size_t index); + CRegisteredCommonName getTargetCN(size_t index); void removeTargetCN(size_t index); - void removeTargetCN(const CCommonName& cn); + void removeTargetCN(const std::string & cn); void clearTargetCNs(); @@ -142,7 +142,6 @@ class CTimeSensProblem : public CTrajectoryProblem //the targets for the sensitivities CCopasiParameterGroup * mpTargetsGroup; - }; #endif // COPASI_CTimeSensProblem diff --git a/copasi/xml/parser/TaskHandler.cpp b/copasi/xml/parser/TaskHandler.cpp index e3c2ca2987..5588ce206d 100644 --- a/copasi/xml/parser/TaskHandler.cpp +++ b/copasi/xml/parser/TaskHandler.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -232,7 +232,7 @@ bool TaskHandler::processEnd(const XML_Char * pszName) pObjMap->clear(); // add map in new format: -for (auto entry : map) + for (auto entry : map) { pObjMap->addGroup(entry.first); CCopasiParameterGroup * pGroup = pObjMap->getGroup(entry.first); @@ -241,11 +241,9 @@ for (auto entry : map) continue; pGroup->addParameter("Role", CCopasiParameter::Type::UINT, entry.second.first); - pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, entry.second.second); + pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, pGroup)); } - } - } mpData->pCurrentTask->getProblem()->elevateChildren(); From 3780d32237173c47b205fc64a8dbae77ee634181 Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Wed, 3 Apr 2024 17:17:50 -0400 Subject: [PATCH 4/7] Fixed setCNValue in CCopasiParameter.i. --- copasi/bindings/swig/CCopasiParameter.i | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/copasi/bindings/swig/CCopasiParameter.i b/copasi/bindings/swig/CCopasiParameter.i index c3d52abf23..394d4ea6cb 100644 --- a/copasi/bindings/swig/CCopasiParameter.i +++ b/copasi/bindings/swig/CCopasiParameter.i @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -194,14 +194,14 @@ return self->setValue(v); } - bool setCNValue(const CCommonName& v) + bool setCNValue(const CRegisteredCommonName & v) { return self->setValue(v); } - bool setCNValue(const std::string& v) + bool setCNValue(const std::string & v) { - return self->setValue(CCommonName(v)); + return self->setValue(CRegisteredCommonName(v)); } bool setKeyValue(const std::string& v) From cf13c1afe9bc91dfc1beaedf1bb2bd44f318c018 Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Fri, 5 Apr 2024 17:02:56 -0400 Subject: [PATCH 5/7] Bug 3226: CCopasiParameter of type CN are correctly loaded in CopasiML. --- copasi/xml/CCopasiXMLInterface.cpp | 4 ++-- copasi/xml/parser/ParameterHandler.cpp | 32 ++++++++++++++------------ copasi/xml/parser/TaskHandler.cpp | 3 ++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/copasi/xml/CCopasiXMLInterface.cpp b/copasi/xml/CCopasiXMLInterface.cpp index cb55955a92..62458b65d5 100644 --- a/copasi/xml/CCopasiXMLInterface.cpp +++ b/copasi/xml/CCopasiXMLInterface.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -463,7 +463,7 @@ bool CCopasiXMLInterface::saveParameter(const CCopasiParameter & parameter) break; case CCopasiParameter::Type::CN: - Attributes.add("value", parameter.getValue< CCommonName >()); + Attributes.add("value", parameter.getValue< CRegisteredCommonName >()); if (!saveElement("Parameter", Attributes)) success = false; diff --git a/copasi/xml/parser/ParameterHandler.cpp b/copasi/xml/parser/ParameterHandler.cpp index cb1b6b6343..141c5009f0 100644 --- a/copasi/xml/parser/ParameterHandler.cpp +++ b/copasi/xml/parser/ParameterHandler.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -18,6 +18,8 @@ #include "ParameterHandler.h" #include "CXMLParser.h" +#include "copasi/CopasiDataModel/CDataModel.h" +#include "copasi/core/CRegisteredCommonName.h" #include "copasi/utilities/CCopasiParameter.h" /** @@ -47,7 +49,6 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, std::string sValue(""); bool UnmappedKey = false; - void * pValue = NULL; CCopasiParameter::Type type; C_FLOAT64 d; @@ -69,26 +70,28 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, sValue = cValue; } + mpData->pCurrentParameter = new CCopasiParameter(name, type); + switch (type) { case CCopasiParameter::Type::DOUBLE: d = CCopasiXMLInterface::DBL(sValue.c_str()); - pValue = &d; + mpData->pCurrentParameter->setValue(d); break; case CCopasiParameter::Type::UDOUBLE: d = CCopasiXMLInterface::DBL(sValue.c_str()); - pValue = &d; + mpData->pCurrentParameter->setValue(d); break; case CCopasiParameter::Type::INT: i = strToInt(sValue.c_str()); - pValue = &i; + mpData->pCurrentParameter->setValue(i); break; case CCopasiParameter::Type::UINT: ui = strToUnsignedInt(sValue.c_str()); - pValue = &ui; + mpData->pCurrentParameter->setValue(ui); break; case CCopasiParameter::Type::BOOL: @@ -102,19 +105,17 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, b = true; } - pValue = &b; + mpData->pCurrentParameter->setValue(b); break; case CCopasiParameter::Type::STRING: case CCopasiParameter::Type::FILE: - case CCopasiParameter::Type::CN: - pValue = &sValue; + mpData->pCurrentParameter->setValue(sValue); break; case CCopasiParameter::Type::KEY: { - if (sValue != "" && - CKeyFactory::isValidKey(sValue)) + if (sValue != "" && CKeyFactory::isValidKey(sValue)) { CDataObject * pObject = mpData->mKeyMap.get(sValue); @@ -128,20 +129,21 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, } } - pValue = &sValue; + mpData->pCurrentParameter->setValue(sValue); } break; + case CCopasiParameter::Type::CN: + mpData->pCurrentParameter->setValue(CRegisteredCommonName(sValue, mpData->pDataModel)); + break; + default: if (cType != NULL) // otherwise missing attribute will have been logged CCopasiMessage(CCopasiMessage::ERROR, MCXML + 16, name.c_str(), cType, mpParser->getCurrentLineNumber()); - pValue = NULL; break; } - mpData->pCurrentParameter = new CCopasiParameter(name, type, pValue); - if (UnmappedKey) { mpData->UnmappedKeyParameters.push_back(mpData->pCurrentParameter->getKey()); diff --git a/copasi/xml/parser/TaskHandler.cpp b/copasi/xml/parser/TaskHandler.cpp index 5588ce206d..a6551b0162 100644 --- a/copasi/xml/parser/TaskHandler.cpp +++ b/copasi/xml/parser/TaskHandler.cpp @@ -26,6 +26,7 @@ #include "copasi/utilities/CTaskFactory.h" #include "copasi/model/CModel.h" #include "copasi/function/CExpression.h" +#include "copasi/CopasiDataModel/CDataModel.h" /** * Replace Task with the name type of the handler and implement the @@ -241,7 +242,7 @@ bool TaskHandler::processEnd(const XML_Char * pszName) continue; pGroup->addParameter("Role", CCopasiParameter::Type::UINT, entry.second.first); - pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, pGroup)); + pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, mpData->pDataModel)); } } } From 62872bbd44ce6d35022b5fb991bc480e4ea43c8f Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Mon, 8 Apr 2024 11:17:30 -0400 Subject: [PATCH 6/7] Fixed reading parameter of type unsigned C_INT32. --- copasi/utilities/CCopasiParameter.cpp | 6 ++++++ copasi/xml/parser/ParameterHandler.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/copasi/utilities/CCopasiParameter.cpp b/copasi/utilities/CCopasiParameter.cpp index bf5c65f23b..e5cb33c050 100644 --- a/copasi/utilities/CCopasiParameter.cpp +++ b/copasi/utilities/CCopasiParameter.cpp @@ -577,6 +577,12 @@ void CCopasiParameter::assignValue(const void * pValue) } assignValue(mType, mpValue, pValue); + + CDataContainer * pParent = getObjectParent(); + + if (pParent != nullptr + && dynamic_cast< CCopasiParameterGroup * >(pParent) != nullptr) + static_cast< CCopasiParameterGroup * >(pParent)->signalChanged(this); } void CCopasiParameter::assignValidValues(const void * pValidValues) diff --git a/copasi/xml/parser/ParameterHandler.cpp b/copasi/xml/parser/ParameterHandler.cpp index 141c5009f0..8e9a8652ac 100644 --- a/copasi/xml/parser/ParameterHandler.cpp +++ b/copasi/xml/parser/ParameterHandler.cpp @@ -53,7 +53,7 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName, C_FLOAT64 d; C_INT32 i; - size_t ui; + unsigned C_INT32 ui; bool b; switch (mCurrentElement.first) From 1647e3df206dc03deb9e9ffcc15043f60db1e6b9 Mon Sep 17 00:00:00 2001 From: Stefan Hoops Date: Mon, 8 Apr 2024 12:44:58 -0400 Subject: [PATCH 7/7] Added overloaded methods for setLowerBoud and setUpperBound. --- copasi/bindings/swig/COptItem.i | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/copasi/bindings/swig/COptItem.i b/copasi/bindings/swig/COptItem.i index f4a9fc0dc9..866e01ab47 100644 --- a/copasi/bindings/swig/COptItem.i +++ b/copasi/bindings/swig/COptItem.i @@ -1,4 +1,4 @@ -// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the +// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the // University of Virginia, University of Heidelberg, and University // of Connecticut School of Medicine. // All rights reserved. @@ -71,6 +71,16 @@ return v; } + bool setLowerBound(const std::string & v) + { + return self->setLowerBound(CRegisteredCommonName(v)); + } + + bool setUpperBound(const std::string & v) + { + return self->setUpperBound(CRegisteredCommonName(v)); + } + CFitItem* asFitItem() { return dynamic_cast($self);