Skip to content

Commit

Permalink
Bug 3229: Terminate solution is found 100 times within the tolerance.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed May 23, 2024
1 parent 8ea6faa commit 6d4fd38
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 69 deletions.
22 changes: 21 additions & 1 deletion copasi/optimization/COptMethodPraxis.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -31,6 +31,7 @@

#include "copasi/parameterFitting/CFitProblem.h"
#include "copasi/core/CDataObjectReference.h"
#include "copasi/sbml/SBMLImporter.h"

COptMethodPraxis::COptMethodPraxis(const CDataContainer * pParent,
const CTaskEnum::Method & methodType,
Expand Down Expand Up @@ -133,6 +134,7 @@ bool COptMethodPraxis::optimise()
// Report the first value as the current best
mBestValue = evaluate();
mBest = mCurrent;
mCountWithinTolerance = 0;
mContinue = mProblemContext.master()->setSolution(mBestValue, mBest, true);

// We found a new best value lets report it.
Expand Down Expand Up @@ -211,11 +213,29 @@ const C_FLOAT64 & COptMethodPraxis::evaluateFunction(C_FLOAT64 *x, C_INT32 & n)
mBest[i] = x[i];

mBestValue = mEvaluationValue;
mCountWithinTolerance = 0;
mContinue = mProblemContext.master()->setSolution(mBestValue, mBest, true);

// We found a new best value lets report it.
mpParentTask->output(COutputInterface::DURING);
}
else if (SBMLImporter::areApproximatelyEqual(mBestValue, mEvaluationValue, mTolerance))
{
double Norm = 0;
double tmp;

for (i = 0; i < n; i++)
{
tmp = mBest[i] - x[i];
Norm += tmp * tmp;
}

if (sqrt(Norm) < mTolerance)
{
++mCountWithinTolerance;
mContinue &= (mCountWithinTolerance < 100);
}
}

mpParentTask->output(COutputInterface::MONITORING);

Expand Down
7 changes: 6 additions & 1 deletion copasi/optimization/COptMethodPraxis.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -116,6 +116,11 @@ class COptMethodPraxis: public COptMethod
*/
C_FLOAT64 mTolerance;

/**
* The count of tries within the tolerance of the best value
*/
size_t mCountWithinTolerance;

/**
* The number of iterations
*/
Expand Down
Loading

0 comments on commit 6d4fd38

Please sign in to comment.