Author: erans
Date: Sat Dec  4 11:31:12 2010
New Revision: 1042151

URL: http://svn.apache.org/viewvc?rev=1042151&view=rev
Log:
MATH-451
In solvers, the maximum number of evaluations is passed as a parameter to the
method "solve". The "setMaxEvaluations" accessor is removed.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractDifferentiableUnivariateRealSolver.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractPolynomialSolver.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseAbstractUnivariateRealSolver.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractDifferentiableUnivariateRealSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractDifferentiableUnivariateRealSolver.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractDifferentiableUnivariateRealSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractDifferentiableUnivariateRealSolver.java
 Sat Dec  4 11:31:12 2010
@@ -72,10 +72,9 @@ public abstract class AbstractDifferenti
      * {...@inheritdoc}
      */
     @Override
-    protected void setup(DifferentiableUnivariateRealFunction f,
-                         double min, double max,
-                         double startValue) {
-        super.setup(f, min, max, startValue);
+    protected void setup(int maxEval, DifferentiableUnivariateRealFunction f,
+                         double min, double max, double startValue) {
+        super.setup(maxEval, f, min, max, startValue);
         functionDerivative = f.derivative();
     }
 }

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractPolynomialSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractPolynomialSolver.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractPolynomialSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AbstractPolynomialSolver.java
 Sat Dec  4 11:31:12 2010
@@ -66,10 +66,9 @@ public abstract class AbstractPolynomial
      * {...@inheritdoc}
      */
     @Override
-    protected void setup(PolynomialFunction f,
-                         double min, double max,
-                         double startValue) {
-        super.setup(f, min, max, startValue);
+    protected void setup(int maxEval, PolynomialFunction f,
+                             double min, double max, double startValue) {
+        super.setup(maxEval, f, min, max, startValue);
         polynomialFunction = f;
     }
 

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseAbstractUnivariateRealSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseAbstractUnivariateRealSolver.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseAbstractUnivariateRealSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseAbstractUnivariateRealSolver.java
 Sat Dec  4 11:31:12 2010
@@ -34,6 +34,8 @@ import org.apache.commons.math.analysis.
  */
 public abstract class BaseAbstractUnivariateRealSolver<FUNC extends 
UnivariateRealFunction>
     implements BaseUnivariateRealSolver<FUNC> {
+    /** Default maximum number of evaluations */
+    public static final int DEFAULT_MAX_EVALUATIONS = 100;
     /** Default absolute accuracy */
     public static final double DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
     /** Default relative accuracy. */
@@ -97,10 +99,6 @@ public abstract class BaseAbstractUnivar
     }
 
     /** {...@inheritdoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        evaluations.setMaximalCount(maxEvaluations);
-    }
-    /** {...@inheritdoc} */
     public int getMaxEvaluations() {
         return evaluations.getMaximalCount();
     }
@@ -167,8 +165,10 @@ public abstract class BaseAbstractUnivar
      * @param min Lower bound for the interval.
      * @param max Upper bound for the interval.
      * @param startValue Start value to use.
+     * @param maxEval Maximum number of evaluations.
      */
-    protected void setup(FUNC f,
+    protected void setup(int maxEval,
+                         FUNC f,
                          double min, double max,
                          double startValue) {
         // Checks.
@@ -181,26 +181,42 @@ public abstract class BaseAbstractUnivar
         searchMax = max;
         searchStart = startValue;
         function = f;
+        evaluations.setMaximalCount(maxEval);
         evaluations.resetCount();
     }
 
     /** {...@inheritdoc} */
     public double solve(FUNC f, double min, double max, double startValue) {
+        return solve(DEFAULT_MAX_EVALUATIONS, f, min, max, startValue);
+    }
+
+    /** {...@inheritdoc} */
+    public double solve(FUNC f, double min, double max) {
+        return solve(DEFAULT_MAX_EVALUATIONS, f, min, max);
+    }
+
+    /** {...@inheritdoc} */
+    public double solve(FUNC f, double startValue) {
+        return solve(DEFAULT_MAX_EVALUATIONS, f, startValue);
+    }
+
+    /** {...@inheritdoc} */
+    public double solve(int maxEval, FUNC f, double min, double max, double 
startValue) {
         // Initialization.
-        setup(f, min, max, startValue);
+        setup(maxEval, f, min, max, startValue);
 
         // Perform computation.
         return doSolve();
     }
 
     /** {...@inheritdoc} */
-    public double solve(FUNC f, double min, double max) {
-        return solve(f, min, max, min + 0.5 * (max - min));
+    public double solve(int maxEval, FUNC f, double min, double max) {
+        return solve(maxEval, f, min, max, min + 0.5 * (max - min));
     }
 
     /** {...@inheritdoc} */
-    public double solve(FUNC f, double startValue) {
-        return solve(f, Double.NaN, Double.NaN, startValue);
+    public double solve(int maxEval, FUNC f, double startValue) {
+        return solve(maxEval, f, Double.NaN, Double.NaN, startValue);
     }
 
     /**

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
 Sat Dec  4 11:31:12 2010
@@ -30,13 +30,6 @@ import org.apache.commons.math.analysis.
  */
 public interface BaseUnivariateRealSolver<FUNC extends UnivariateRealFunction> 
{
     /**
-     * Set the maximal number of function evaluations.
-     *
-     * @param maxEvaluations Maximal number of function evaluations.
-     */
-    void setMaxEvaluations(int maxEvaluations);
-
-    /**
      * Get the maximal number of function evaluations.
      *
      * @return the maximal number of function evaluations.
@@ -76,9 +69,10 @@ public interface BaseUnivariateRealSolve
      * @param min Lower bound for the interval.
      * @param max Upper bound for the interval.
      * @return a value where the function is zero.
-     * @throws IllegalArgumentException if {...@code min > max} or the 
endpoints
-     * do not satisfy the requirements specified by the solver.
-     * @since 2.0
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the default allowed number of evaluations is exceeded.
      */
     double solve(FUNC f, double min, double max);
 
@@ -93,22 +87,74 @@ public interface BaseUnivariateRealSolve
      * @param max Upper bound for the interval.
      * @param startValue Start value to use.
      * @return a value where the function is zero.
-     * @throws IllegalArgumentException if {...@code min > max} or the 
arguments
-     * do not satisfy the requirements specified by the solver.
-     * @since 2.0
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the default allowed number of evaluations is exceeded.
      */
     double solve(FUNC f, double min, double max, double startValue);
 
     /**
      * Solve for a zero in the vicinity of {...@code startValue}.
-     * A solver may require that the interval brackets a single zero root.
      *
      * @param f Function to solve.
      * @param startValue Start value to use.
      * @return a value where the function is zero.
-     * @throws IllegalArgumentException if {...@code min > max} or the 
arguments
-     * do not satisfy the requirements specified by the solver.
-     * @since 2.0
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the default allowed number of evaluations is exceeded.
      */
     double solve(FUNC f, double startValue);
+
+    /**
+     * Solve for a zero root in the given interval.
+     * A solver may require that the interval brackets a single zero root.
+     * Solvers that do require bracketing should be able to handle the case
+     * where one of the endpoints is itself a root.
+     *
+     * @param f Function to solve.
+     * @param min Lower bound for the interval.
+     * @param max Upper bound for the interval.
+     * @param maxEval Maximum number of evaluations.
+     * @return a value where the function is zero.
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the allowed number of evaluations is exceeded.
+     */
+    double solve(int maxEval, FUNC f, double min, double max);
+
+    /**
+     * Solve for a zero in the given interval, start at {...@code startValue}.
+     * A solver may require that the interval brackets a single zero root.
+     * Solvers that do require bracketing should be able to handle the case
+     * where one of the endpoints is itself a root.
+     *
+     * @param f Function to solve.
+     * @param min Lower bound for the interval.
+     * @param max Upper bound for the interval.
+     * @param startValue Start value to use.
+     * @param maxEval Maximum number of evaluations.
+     * @return a value where the function is zero.
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the allowed number of evaluations is exceeded.
+     */
+    double solve(int maxEval, FUNC f, double min, double max, double 
startValue);
+
+    /**
+     * Solve for a zero in the vicinity of {...@code startValue}.
+     *
+     * @param f Function to solve.
+     * @param startValue Start value to use.
+     * @return a value where the function is zero.
+     * @param maxEval Maximum number of evaluations.
+     * @throws org.apache.commons.math.exception.MathIllegalArgumentException
+     * if the arguments do not satisfy the requirements specified by the 
solver.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException if
+     * the allowed number of evaluations is exceeded.
+     */
+    double solve(int maxEval, FUNC f, double startValue);
 }

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
 Sat Dec  4 11:31:12 2010
@@ -51,8 +51,7 @@ public class UnivariateRealSolverUtils {
             throw new NullArgumentException(LocalizedFormats.FUNCTION);
         }
         final UnivariateRealSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(Integer.MAX_VALUE);
-        return solver.solve(function, x0, x1);
+        return solver.solve(Integer.MAX_VALUE, function, x0, x1);
     }
 
     /**
@@ -75,8 +74,7 @@ public class UnivariateRealSolverUtils {
             throw new NullArgumentException(LocalizedFormats.FUNCTION);
         }
         final UnivariateRealSolver solver = new BrentSolver(absoluteAccuracy);
-        solver.setMaxEvaluations(Integer.MAX_VALUE);
-        return solver.solve(function, x0, x1);
+        return solver.solve(Integer.MAX_VALUE, function, x0, x1);
     }
 
     /**

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/events/EventState.java
 Sat Dec  4 11:31:12 2010
@@ -253,8 +253,9 @@ public class EventState {
                         }
                     };
                     final BrentSolver solver = new BrentSolver(convergence);
-                    solver.setMaxEvaluations(maxIterationCount);
-                    final double root = (ta <= tb) ? solver.solve(f, ta, tb) : 
solver.solve(f, tb, ta);
+                    final double root = (ta <= tb) ?
+                        solver.solve(maxIterationCount, f, ta, tb) :
+                        solver.solve(maxIterationCount, f, tb, ta);
                     if ((FastMath.abs(root - ta) <= convergence) &&
                          (FastMath.abs(root - previousEventTime) <= 
convergence)) {
                         // we have either found nothing or found (again ?) a 
past event, we simply ignore it

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java
 Sat Dec  4 11:31:12 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization.general;
 
 import org.apache.commons.math.exception.MathIllegalStateException;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.analysis.solvers.BrentSolver;
 import org.apache.commons.math.analysis.solvers.UnivariateRealSolver;
@@ -85,7 +84,6 @@ public class NonLinearConjugateGradientO
      */
     public void setLineSearchSolver(final UnivariateRealSolver 
lineSearchSolver) {
         solver = lineSearchSolver;
-        solver.setMaxEvaluations(getMaxEvaluations());
     }
 
     /**
@@ -108,14 +106,13 @@ public class NonLinearConjugateGradientO
 
     /** {...@inheritdoc} */
     @Override
-    protected RealPointValuePair doOptimize() throws MathUserException {
+    protected RealPointValuePair doOptimize() {
         // Initialization.
         if (preconditioner == null) {
             preconditioner = new IdentityPreconditioner();
         }
         if (solver == null) {
             solver = new BrentSolver();
-            solver.setMaxEvaluations(getMaxEvaluations());
         }
         point = getStartPoint();
         final GoalType goal = getGoalType();
@@ -138,6 +135,7 @@ public class NonLinearConjugateGradientO
 
         RealPointValuePair current = null;
         int iter = 0;
+        int maxEval = getMaxEvaluations();
         while (true) {
             ++iter;
 
@@ -162,7 +160,8 @@ public class NonLinearConjugateGradientO
             // XXX Last parameters is set to a value clode to zero in order to
             // work around the divergence problem in the "testCircleFitting"
             // unit test (see MATH-439).
-            final double step = solver.solve(lsf, 0, uB, 1e-15);
+            final double step = solver.solve(maxEval, lsf, 0, uB, 1e-15);
+            maxEval -= solver.getEvaluations(); // Subtract used up 
evaluations.
 
             // Validate new point.
             for (int i = 0; i < point.length; ++i) {
@@ -217,12 +216,12 @@ public class NonLinearConjugateGradientO
      * @param a lower bound of the interval.
      * @param h initial step to try.
      * @return b such that f(a) and f(b) have opposite signs.
-     * @exception MathIllegalStateException if no bracket can be found.
-     * @exception MathUserException if function throws one.
+     * @throws MathIllegalStateException if no bracket can be found.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * function throws one.
      */
     private double findUpperBound(final UnivariateRealFunction f,
-                                  final double a, final double h)
-        throws MathUserException {
+                                  final double a, final double h) {
         final double yA = f.value(a);
         double yB = yA;
         for (double step = h; step < Double.MAX_VALUE; step *= FastMath.max(2, 
yA / yB)) {
@@ -265,7 +264,7 @@ public class NonLinearConjugateGradientO
         }
 
         /** {...@inheritdoc} */
-        public double value(double x) throws MathUserException {
+        public double value(double x) {
             // current point in the search direction
             final double[] shiftedPoint = point.clone();
             for (int i = 0; i < shiftedPoint.length; ++i) {

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Dec  4 11:31:12 2010
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-451">
+        For "solvers" (package "analysis.solvers"), the number of allowed 
function
+        evaluations is passed as a parameter to the "solve" method.
+      </action>
       <action dev="erans" type="fix" issue="MATH-447">
         Created a "MathRuntimeException" to serve as a base class for exception
         types that need to wrap another (lower-level) exception.

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BisectionSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -33,7 +33,6 @@ public final class BisectionSolverTest {
         double result;
 
         BisectionSolver solver = new BisectionSolver();
-        solver.setMaxEvaluations(50);
         result = solver.solve(f, 3, 4);
         Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
 
@@ -47,7 +46,6 @@ public final class BisectionSolverTest {
         double result;
 
         BisectionSolver solver = new BisectionSolver();
-        solver.setMaxEvaluations(50);
         result = solver.solve(f, -0.2, 0.2);
         Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 
@@ -85,21 +83,9 @@ public final class BisectionSolverTest {
     }
 
     @Test
-    public void testMath369() throws Exception {
+    public void testMath369() {
         UnivariateRealFunction f = new SinFunction();
         BisectionSolver solver = new BisectionSolver();
-        solver.setMaxEvaluations(40);
         Assert.assertEquals(FastMath.PI, solver.solve(f, 3.0, 3.2, 3.1), 
solver.getAbsoluteAccuracy());
     }
-
-    /**
-     *
-     */
-    @Test
-    public void testSetMaximalEvaluationCount(){
-        int expected = 100;
-        BisectionSolver solver = new BisectionSolver();
-        solver.setMaxEvaluations(expected);
-        Assert.assertEquals(expected, solver.getMaxEvaluations());
-    }
 }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BrentSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -21,6 +21,9 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
+import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -44,7 +47,6 @@ public final class BrentSolverTest {
         UnivariateRealFunction f = new SinFunction();
         double result;
         UnivariateRealSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(10);
         // Somewhat benign interval. The function is monotone.
         result = solver.solve(f, 3, 4);
         // System.out.println(
@@ -72,7 +74,6 @@ public final class BrentSolverTest {
         double result;
         // Brent-Dekker solver.
         UnivariateRealSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(20);
         // Symmetric bracket around 0. Test whether solvers can handle hitting
         // the root in the first iteration.
         result = solver.solve(f, -0.2, 0.2);
@@ -145,13 +146,18 @@ public final class BrentSolverTest {
        //     "Root: " + result + " Evaluations: " + solver.getEvaluations());
         Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
         Assert.assertTrue(solver.getEvaluations() <= 15);
+
+        try {
+            result = solver.solve(5, f, 0.85, 5);
+        } catch (TooManyEvaluationsException e) {
+            // Expected.
+        }
     }
 
     @Test
     public void testRootEndpoints() {
         UnivariateRealFunction f = new SinFunction();
         BrentSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(10);
 
         // endpoint is root
         double result = solver.solve(f, FastMath.PI, 4);
@@ -165,30 +171,28 @@ public final class BrentSolverTest {
 
         result = solver.solve(f, 3, FastMath.PI, 3.07);
         Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
-
     }
 
     @Test
     public void testBadEndpoints() {
         UnivariateRealFunction f = new SinFunction();
         BrentSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(10);
         try {  // bad interval
             solver.solve(f, 1, -1);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5);
-            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NoBracketingException - non-bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5, 1.2);
-            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NoBracketingException - non-bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
     }
@@ -197,7 +201,6 @@ public final class BrentSolverTest {
     public void testInitialGuess() {
         MonitoredFunction f = new MonitoredFunction(new QuinticFunction());
         BrentSolver solver = new BrentSolver();
-        solver.setMaxEvaluations(20);
         double result;
 
         // no guess
@@ -209,8 +212,8 @@ public final class BrentSolverTest {
         // invalid guess (it *is* a root, but outside of the range)
         try {
           result = solver.solve(f, 0.6, 7.0, 0.0);
-          Assert.fail("an IllegalArgumentException was expected");
-        } catch (IllegalArgumentException iae) {
+          Assert.fail("a NumberIsTooLargeException was expected");
+        } catch (NumberIsTooLargeException iae) {
             // expected behaviour
         }
 

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/LaguerreSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -21,6 +21,8 @@ import org.apache.commons.math.TestUtils
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
 import org.apache.commons.math.complex.Complex;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -48,7 +50,6 @@ public final class LaguerreSolverTest {
         double coefficients[] = { -1.0, 4.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
         LaguerreSolver solver = new LaguerreSolver();
-        solver.setMaxEvaluations(10);
 
         min = 0.0; max = 1.0; expected = 0.25;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
@@ -68,7 +69,6 @@ public final class LaguerreSolverTest {
         double coefficients[] = { -3.0, 5.0, 2.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
         LaguerreSolver solver = new LaguerreSolver();
-        solver.setMaxEvaluations(10);
 
         min = 0.0; max = 2.0; expected = 0.5;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
@@ -94,7 +94,6 @@ public final class LaguerreSolverTest {
         double coefficients[] = { -12.0, -1.0, 1.0, -12.0, -1.0, 1.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
         LaguerreSolver solver = new LaguerreSolver();
-        solver.setMaxEvaluations(10);
 
         min = -2.0; max = 2.0; expected = -1.0;
         tolerance = FastMath.max(solver.getAbsoluteAccuracy(),
@@ -162,20 +161,19 @@ public final class LaguerreSolverTest {
         double coefficients[] = { -3.0, 5.0, 2.0 };
         PolynomialFunction f = new PolynomialFunction(coefficients);
         LaguerreSolver solver = new LaguerreSolver();
-        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             solver.solve(f, 1, -1);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            Assert.fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NoBracketingException - no bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
     }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolver2Test.java
 Sat Dec  4 11:31:12 2010
@@ -47,7 +47,6 @@ public final class MullerSolver2Test {
     public void testSinFunction() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver2();
-        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = FastMath.PI;
@@ -70,7 +69,6 @@ public final class MullerSolver2Test {
     public void testQuinticFunction() {
         UnivariateRealFunction f = new QuinticFunction();
         UnivariateRealSolver solver = new MullerSolver2();
-        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
@@ -101,7 +99,6 @@ public final class MullerSolver2Test {
     public void testExpm1Function() {
         UnivariateRealFunction f = new Expm1Function();
         UnivariateRealSolver solver = new MullerSolver2();
-        solver.setMaxEvaluations(55);
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
@@ -130,19 +127,18 @@ public final class MullerSolver2Test {
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver2();
-        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             solver.solve(f, 1, -1);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
         } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+            Assert.fail("Expecting NoBracketingException - no bracketing");
         } catch (NoBracketingException ex) {
             // expected
         }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/MullerSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -47,7 +47,6 @@ public final class MullerSolverTest {
     public void testSinFunction() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver();
-        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = FastMath.PI;
@@ -70,7 +69,6 @@ public final class MullerSolverTest {
     public void testQuinticFunction() {
         UnivariateRealFunction f = new QuinticFunction();
         UnivariateRealSolver solver = new MullerSolver();
-        solver.setMaxEvaluations(15);
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
@@ -103,7 +101,6 @@ public final class MullerSolverTest {
     public void testExpm1Function() {
         UnivariateRealFunction f = new Expm1Function();
         UnivariateRealSolver solver = new MullerSolver();
-        solver.setMaxEvaluations(25);
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
@@ -132,20 +129,19 @@ public final class MullerSolverTest {
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new MullerSolver();
-        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             double root = solver.solve(f, 1, -1);
             System.out.println("root=" + root);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
         } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+            Assert.fail("Expecting NoBracketingException - no bracketing");
         } catch (NoBracketingException ex) {
             // expected
         }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/NewtonSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -37,7 +37,6 @@ public final class NewtonSolverTest {
         double result;
 
         NewtonSolver solver = new NewtonSolver();
-        solver.setMaxEvaluations(10);
         result = solver.solve(f, 3, 4);
         Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
 
@@ -56,7 +55,6 @@ public final class NewtonSolverTest {
         double result;
 
         NewtonSolver solver = new NewtonSolver();
-        solver.setMaxEvaluations(30);
         result = solver.solve(f, -0.2, 0.2);
         Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
 

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RiddersSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -45,7 +45,6 @@ public final class RiddersSolverTest {
     public void testSinFunction() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new RiddersSolver();
-        solver.setMaxEvaluations(10);
         double min, max, expected, result, tolerance;
 
         min = 3.0; max = 4.0; expected = FastMath.PI;
@@ -68,7 +67,6 @@ public final class RiddersSolverTest {
     public void testQuinticFunction() {
         UnivariateRealFunction f = new QuinticFunction();
         UnivariateRealSolver solver = new RiddersSolver();
-        solver.setMaxEvaluations(15);
         double min, max, expected, result, tolerance;
 
         min = -0.4; max = 0.2; expected = 0.0;
@@ -97,7 +95,6 @@ public final class RiddersSolverTest {
     public void testExpm1Function() {
         UnivariateRealFunction f = new Expm1Function();
         UnivariateRealSolver solver = new RiddersSolver();
-        solver.setMaxEvaluations(20);
         double min, max, expected, result, tolerance;
 
         min = -1.0; max = 2.0; expected = 0.0;
@@ -126,19 +123,18 @@ public final class RiddersSolverTest {
     public void testParameters() {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new RiddersSolver();
-        solver.setMaxEvaluations(10);
 
         try {
             // bad interval
             solver.solve(f, 1, -1);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
         } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {
             // no bracketing
             solver.solve(f, 2, 3);
-            Assert.fail("Expecting IllegalArgumentException - no bracketing");
+            Assert.fail("Expecting NoBracketingException - no bracketing");
         } catch (NoBracketingException ex) {
             // expected
         }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
 Sat Dec  4 11:31:12 2010
@@ -20,6 +20,8 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.QuinticFunction;
 import org.apache.commons.math.analysis.SinFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -38,7 +40,6 @@ public final class SecantSolverTest {
         UnivariateRealFunction f = new SinFunction();
         double result;
         UnivariateRealSolver solver = new SecantSolver();
-        solver.setMaxEvaluations(10);
 
         result = solver.solve(f, 3, 4);
         //System.out.println(
@@ -65,7 +66,6 @@ public final class SecantSolverTest {
         double result;
         // Brent-Dekker solver.
         UnivariateRealSolver solver = new SecantSolver();
-        solver.setMaxEvaluations(20);
         result = solver.solve(f, -0.2, 0.2);
         //System.out.println(
         //    "Root: " + result + " Evaluations: " + solver.getEvaluations());
@@ -129,7 +129,6 @@ public final class SecantSolverTest {
     public void testRootEndpoints() {
         UnivariateRealFunction f = new SinFunction();
         SecantSolver solver = new SecantSolver();
-        solver.setMaxEvaluations(10);
 
         // endpoint is root
         double result = solver.solve(f, FastMath.PI, 4);
@@ -150,23 +149,22 @@ public final class SecantSolverTest {
     public void testBadEndpoints() {
         UnivariateRealFunction f = new SinFunction();
         SecantSolver solver = new SecantSolver();
-        solver.setMaxEvaluations(10);
         try {  // bad interval
             solver.solve(f, 1, -1);
-            Assert.fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NumberIsTooLargeException - bad interval");
+        } catch (NumberIsTooLargeException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5);
-            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NoBracketingException - non-bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
         try {  // no bracket
             solver.solve(f, 1, 1.5, 1.2);
-            Assert.fail("Expecting IllegalArgumentException - non-bracketing");
-        } catch (IllegalArgumentException ex) {
+            Assert.fail("Expecting NoBracketingException - non-bracketing");
+        } catch (NoBracketingException ex) {
             // expected
         }
     }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
 Sat Dec  4 11:31:12 2010
@@ -55,8 +55,8 @@ public class MultiStartDifferentiableMul
                                                   new 
GaussianRandomGenerator(g));
         MultiStartDifferentiableMultivariateRealOptimizer optimizer =
             new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 
10, generator);
-        optimizer.setMaxEvaluations(100);
-        assertEquals(100, optimizer.getMaxEvaluations());
+        optimizer.setMaxEvaluations(200);
+        assertEquals(200, optimizer.getMaxEvaluations());
         optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 
1.0e-10));
         BrentSolver solver = new BrentSolver();
         RealPointValuePair optimum =

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java?rev=1042151&r1=1042150&r2=1042151&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
 Sat Dec  4 11:31:12 2010
@@ -235,7 +235,7 @@ public class NonLinearConjugateGradientO
         }, new double[] { 32, 23, 33, 31 });
         NonLinearConjugateGradientOptimizer optimizer =
             new 
NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
-        optimizer.setMaxEvaluations(100);
+        optimizer.setMaxEvaluations(200);
         optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-13, 
1.0e-13));
         BrentSolver solver = new BrentSolver(1e-15, 1e-15);
         optimizer.setLineSearchSolver(solver);


Reply via email to