You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/09/06 21:16:05 UTC

svn commit: r1165790 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ main/java/org/apache/commons/math/exception/util/ main/java/org/apache/commons/math/ode/ main/resources/META-INF/localization/ test/java/org/apache/commons/mat...

Author: luc
Date: Tue Sep  6 19:16:05 2011
New Revision: 1165790

URL: http://svn.apache.org/viewvc?rev=1165790&view=rev
Log:
Removed last use of MaxEvaluationsExceededException.

This exception was now used only in ODE. It has been replaced by
MaxCountExceededException, triggered by an Incrementor instance just as
what is done in root solvers.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/MaxEvaluationsExceededException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java
    commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1165790&r1=1165789&r2=1165790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Tue Sep  6 19:16:05 2011
@@ -149,7 +149,6 @@ public enum LocalizedFormats implements 
     MAP_MODIFIED_WHILE_ITERATING("map has been modified while iterating"),
     EVALUATIONS("evaluations"), /* keep */
     MAX_COUNT_EXCEEDED("maximal count ({0}) exceeded"), /* keep */
-    MAX_EVALUATIONS_EXCEEDED("maximal number of evaluations ({0}) exceeded"),
     MAX_ITERATIONS_EXCEEDED("maximal number of iterations ({0}) exceeded"),
     MINIMAL_STEPSIZE_REACHED_DURING_INTEGRATION("minimal step size ({1,number,0.00E00}) reached, integration needs {0,number,0.00E00}"),
     MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS("Loess expects the abscissa and ordinate arrays to be of the same size, but got {0} abscissae and {1} ordinatae"),

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java?rev=1165790&r1=1165789&r2=1165790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java Tue Sep  6 19:16:05 2011
@@ -26,12 +26,11 @@ import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import org.apache.commons.math.MaxEvaluationsExceededException;
 import org.apache.commons.math.analysis.solvers.BracketingNthOrderBrentSolver;
 import org.apache.commons.math.analysis.solvers.UnivariateRealSolver;
 import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.exception.MathIllegalStateException;
-import org.apache.commons.math.exception.MathUserException;
+import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.ode.events.EventHandler;
@@ -39,6 +38,7 @@ import org.apache.commons.math.ode.event
 import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
 import org.apache.commons.math.ode.sampling.StepHandler;
 import org.apache.commons.math.util.FastMath;
+import org.apache.commons.math.util.Incrementor;
 import org.apache.commons.math.util.MathUtils;
 
 /**
@@ -72,11 +72,8 @@ public abstract class AbstractIntegrator
     /** Name of the method. */
     private final String name;
 
-    /** Maximal number of evaluations allowed. */
-    private int maxEvaluations;
-
-    /** Number of evaluations already performed. */
-    private int evaluations;
+    /** Counter for number of evaluations. */
+    private Incrementor evaluations;
 
     /** Differential equations to integrate. */
     private transient FirstOrderDifferentialEquations equations;
@@ -91,6 +88,7 @@ public abstract class AbstractIntegrator
         stepSize  = Double.NaN;
         eventsStates = new ArrayList<EventState>();
         statesInitialized = false;
+        evaluations = new Incrementor();
         setMaxEvaluations(-1);
         resetEvaluations();
     }
@@ -167,23 +165,23 @@ public abstract class AbstractIntegrator
 
     /** {@inheritDoc} */
     public void setMaxEvaluations(int maxEvaluations) {
-        this.maxEvaluations = (maxEvaluations < 0) ? Integer.MAX_VALUE : maxEvaluations;
+        evaluations.setMaximalCount((maxEvaluations < 0) ? Integer.MAX_VALUE : maxEvaluations);
     }
 
     /** {@inheritDoc} */
     public int getMaxEvaluations() {
-        return maxEvaluations;
+        return evaluations.getMaximalCount();
     }
 
     /** {@inheritDoc} */
     public int getEvaluations() {
-        return evaluations;
+        return evaluations.getCount();
     }
 
     /** Reset the number of evaluations to zero.
      */
     protected void resetEvaluations() {
-        evaluations = 0;
+        evaluations.resetCount();
     }
 
     /** Set the differential equations.
@@ -198,14 +196,11 @@ public abstract class AbstractIntegrator
      * @param t current value of the independent <I>time</I> variable
      * @param y array containing the current value of the state vector
      * @param yDot placeholder array where to put the time derivative of the state vector
-     * @throws MathUserException this user-defined exception should be used if an error is
-     * is triggered by user code
+     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
      */
     public void computeDerivatives(final double t, final double[] y, final double[] yDot)
-        throws MathUserException {
-        if (++evaluations > maxEvaluations) {
-            throw new MathUserException(new MaxEvaluationsExceededException(maxEvaluations));
-        }
+        throws MaxCountExceededException {
+        evaluations.incrementCount();
         equations.computeDerivatives(t, y, yDot);
     }
 

Modified: commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties?rev=1165790&r1=1165789&r2=1165790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties (original)
+++ commons/proper/math/trunk/src/main/resources/META-INF/localization/LocalizedFormats_fr.properties Tue Sep  6 19:16:05 2011
@@ -120,7 +120,6 @@ LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT = la
 MAP_MODIFIED_WHILE_ITERATING = la table d''adressage a \u00e9t\u00e9 modifi\u00e9e pendant l''it\u00e9ration
 EVALUATIONS = \u00e9valuations
 MAX_COUNT_EXCEEDED = limite ({0}) d\u00e9pass\u00e9
-MAX_EVALUATIONS_EXCEEDED = nombre maximal d''\u00e9valuations ({0}) d\u00e9pass\u00e9
 MAX_ITERATIONS_EXCEEDED = nombre maximal d''it\u00e9rations ({0}) d\u00e9pass\u00e9
 MINIMAL_STEPSIZE_REACHED_DURING_INTEGRATION = pas minimal ({1,number,0.00E00}) atteint, l''int\u00e9gration n\u00e9cessite {0,number,0.00E00}
 MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS = Loess a besoin de tableaux d'abscisses et d'oordonn\u00e9es de m\u00eame taille, mais il y a {0} points en abscisse et {1} en ordonn\u00e9e

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java?rev=1165790&r1=1165789&r2=1165790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java Tue Sep  6 19:16:05 2011
@@ -19,7 +19,7 @@ package org.apache.commons.math.ode.nons
 
 
 import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.MathUserException;
+import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
 import org.apache.commons.math.ode.FirstOrderIntegrator;
 import org.apache.commons.math.ode.TestProblem1;
@@ -99,7 +99,7 @@ public class AdamsBashforthIntegratorTes
 
     }
 
-    @Test(expected = MathUserException.class)
+    @Test(expected = MaxCountExceededException.class)
     public void exceedMaxEvaluations() {
 
         TestProblem1 pb  = new TestProblem1();

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java?rev=1165790&r1=1165789&r2=1165790&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java Tue Sep  6 19:16:05 2011
@@ -19,7 +19,7 @@ package org.apache.commons.math.ode.nons
 
 
 import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.MathUserException;
+import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
 import org.apache.commons.math.ode.FirstOrderIntegrator;
 import org.apache.commons.math.ode.TestProblem1;
@@ -99,7 +99,7 @@ public class AdamsMoultonIntegratorTest 
 
     }
 
-    @Test(expected = MathUserException.class)
+    @Test(expected = MaxCountExceededException.class)
     public void exceedMaxEvaluations() {
 
         TestProblem1 pb  = new TestProblem1();