diff --git a/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java index 16b9182d8..d28bc5900 100644 --- a/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java @@ -20,7 +20,7 @@ package org.apache.commons.math.optimization; import java.util.Arrays; import java.util.Comparator; -import org.apache.commons.math.exception.FunctionEvaluationException; +import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.exception.ConvergenceException; import org.apache.commons.math.analysis.MultivariateRealFunction; @@ -89,13 +89,14 @@ public class BaseMultiStartMultivariateRealOptimizer= 50); assertTrue(optimizer.getEvaluations() <= 100); } + + @Test(expected=MathUserException.class) + public void testBadFunction() { + UnivariateRealFunction f = new UnivariateRealFunction() { + public double value(double x) { + if (x < 0) { + throw new MathUserException(); + } + return 0; + } + }; + UnivariateRealOptimizer underlying = new BrentOptimizer(1e-9, 1e-14); + underlying.setMaxEvaluations(300); + JDKRandomGenerator g = new JDKRandomGenerator(); + g.setSeed(4312000053L); + MultiStartUnivariateRealOptimizer optimizer = + new MultiStartUnivariateRealOptimizer(underlying, 5, g); + + UnivariateRealPointValuePair optimum + = optimizer.optimize(f, GoalType.MINIMIZE, -0.3, -0.2); + } }