Skip to content

Commit

Permalink
MultiStart: Handle constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 6, 2023
1 parent ff3141e commit c683d22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
24 changes: 8 additions & 16 deletions lib/src/Base/Optim/MultiStart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ void MultiStart::run()
// run the solver with each starting point
OptimizationAlgorithm solver(solver_);
resultCollection_.clear();
Scalar bestValue = getProblem().isMinimization() ? SpecFunc::MaxScalar : SpecFunc::LowestScalar;
result_ = OptimizationResult(getProblem());
const UnsignedInteger size = startingSample_.getSize();
const UnsignedInteger initialEvaluationNumber = getProblem().getObjective().getEvaluationCallsNumber();
UnsignedInteger evaluationNumber = 0;
UnsignedInteger successNumber = 0;
UnsignedInteger improvementNumber = 0;
for (UnsignedInteger i = 0; i < size; ++ i)
{
solver.setStartingPoint(startingSample_[i]);
Expand All @@ -112,7 +111,7 @@ void MultiStart::run()
try
{
solver.run();
++successNumber;
++ successNumber;
}
catch (const Exception & ex)
{
Expand All @@ -122,15 +121,10 @@ void MultiStart::run()

const OptimizationResult result(solver.getResult());
if (keepResults_) resultCollection_.add(result);
Scalar currentValue = result.getOptimalValue()[0];
if ((getProblem().isMinimization() && (currentValue < bestValue))
|| (!getProblem().isMinimization() && (currentValue > bestValue)))
{
bestValue = currentValue;
setResult(result);
LOGINFO(OSS() << "Best initial point so far=" << result.getOptimalPoint() << " value=" << result.getOptimalValue());
++improvementNumber;
}

result_.store(result.getOptimalPoint(), result.getOptimalValue(),
result.getAbsoluteError(), result.getRelativeError(), result.getResidualError(), result.getConstraintError(),
solver.getMaximumConstraintError());

evaluationNumber += getProblem().getObjective().getEvaluationCallsNumber() - initialEvaluationNumber;
LOGDEBUG(OSS() << "Number of evaluations so far=" << evaluationNumber);
Expand All @@ -154,12 +148,10 @@ void MultiStart::run()
}
}
}
LOGINFO(OSS() << successNumber << " out of " << size << " local searches succeeded, " << improvementNumber << " improvements");

if (!(successNumber > 0))
{
throw InternalException(HERE) << "None of the local searches succeeded.";
}
LOGINFO(OSS() << successNumber << " out of " << size << " local searches succeeded");
result_.setEvaluationNumber(evaluationNumber);
}


Expand Down
12 changes: 7 additions & 5 deletions python/src/MultiStart_doc.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ startingSample : 2-d sequence of float

Notes
-----
A global number of evaluations can be explicitly set,
The starting point of the internal solver is ignored.
If you want to use it, add it to *startingSample*.

Stopping criteria used are the ones set in the internal solver.

A global number of evaluations can be set,
in that case all starting points might not be used depending on the number
of evaluations allocated to the internal solver.

The starting point of *solver* is ignored.
If you want to use it, add it to *startingSample*.

Starting points provided through the *startingSample* parameter
should be within the bounds of the
:class:`~openturns.OptimizationProblem`, but this is not checked.
:class:`~openturns.OptimizationProblem`, but this is not enforced.

Examples
--------
Expand Down

0 comments on commit c683d22

Please sign in to comment.