myFunc = theFunc;
myC = theC;
+ myIsFindSingleSolution = Standard_False;
myZ = -1;
mySolCount = 0;
//purpose : Compute Global extremum point
//=======================================================================
// In this algo indexes started from 1, not from 0.
-void math_GlobOptMin::Perform()
+void math_GlobOptMin::Perform(const Standard_Boolean isFindSingleSolution)
{
Standard_Integer i;
myE1 = minLength * myTol;
myE2 = maxLength * myTol;
- if (myC > 1.0)
- myE3 = - maxLength * myTol / 4.0;
+
+ myIsFindSingleSolution = isFindSingleSolution;
+ if (isFindSingleSolution)
+ {
+ // Run local optimization
+ // if current value better than optimal.
+ myE3 = 0.0;
+ }
else
- myE3 = - maxLength * myTol * myC / 4.0;
+ {
+ if (myC > 1.0)
+ myE3 = - maxLength * myTol / 4.0;
+ else
+ myE3 = - maxLength * myTol * myC / 4.0;
+ }
computeGlobalExtremum(myN);
aStepBestValue = (isInside && (val < d))? val : d;
aStepBestPoint = (isInside && (val < d))? myTmp : myX;
- // Solutions are close to each other.
- if (Abs(aStepBestValue - myF) < mySameTol * 0.01)
+ // Solutions are close to each other
+ // and it is allowed to have more than one solution.
+ if (Abs(aStepBestValue - myF) < mySameTol * 0.01 &&
+ !myIsFindSingleSolution)
{
if (!isStored(aStepBestPoint))
{
}
}
- // New best solution.
- if ((aStepBestValue - myF) * myZ > mySameTol * 0.01)
+ // New best solution:
+ // new point is out of (mySameTol * 0.01) surrounding or
+ // new point is better than old + single point search.
+ Standard_Real aFunctionalDelta = (aStepBestValue - myF) * myZ;
+ if (aFunctionalDelta > mySameTol * 0.01 ||
+ (aFunctionalDelta > 0.0 && myIsFindSingleSolution))
{
mySolCount = 0;
myF = aStepBestValue;
Standard_EXPORT ~math_GlobOptMin();
- Standard_EXPORT void Perform();
+ //! @param isFindSingleSolution - defines whether to find single solution or all solutions.
+ Standard_EXPORT void Perform(const Standard_Boolean isFindSingleSolution = Standard_False);
//! Get best functional value.
Standard_EXPORT Standard_Real GetF();
// function values |val1 - val2| * 0.01 < mySameTol is equal,
// default value is 1.0e-7.
Standard_Real myC; //Lipschitz constant, default 9
+ Standard_Boolean myIsFindSingleSolution; // Default value is false.
// Output.
Standard_Boolean myDone;