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.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1165790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-09-06 19:16:05 +00:00
parent 67480f06e8
commit e751cc22b6
6 changed files with 16 additions and 91 deletions

View File

@ -1,68 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
* Error thrown when a numerical computation exceeds its allowed
* number of functions evaluations.
*
* @version $Id$
* @since 2.0
*/
public class MaxEvaluationsExceededException extends ConvergenceException {
/** Serializable version identifier. */
private static final long serialVersionUID = -5921271447220129118L;
/** Maximal number of evaluations allowed. */
private final int maxEvaluations;
/**
* Constructs an exception with a default detail message.
* @param maxEvaluations maximal number of evaluations allowed
*/
public MaxEvaluationsExceededException(final int maxEvaluations) {
super(LocalizedFormats.MAX_EVALUATIONS_EXCEEDED, maxEvaluations);
this.maxEvaluations = maxEvaluations;
}
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param maxEvaluations the exceeded maximal number of evaluations
* @param pattern format specifier
* @param arguments format arguments
* @since 2.2
*/
public MaxEvaluationsExceededException(final int maxEvaluations,
final Localizable pattern, final Object ... arguments) {
super(pattern, arguments);
this.maxEvaluations = maxEvaluations;
}
/** Get the maximal number of evaluations allowed.
* @return maximal number of evaluations allowed
*/
public int getMaxEvaluations() {
return maxEvaluations;
}
}

View File

@ -149,7 +149,6 @@ public enum LocalizedFormats implements Localizable {
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"),

View File

@ -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.events.EventState;
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 implements FirstOrderIntegrator {
/** 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 implements FirstOrderIntegrator {
stepSize = Double.NaN;
eventsStates = new ArrayList<EventState>();
statesInitialized = false;
evaluations = new Incrementor();
setMaxEvaluations(-1);
resetEvaluations();
}
@ -167,23 +165,23 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
/** {@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 implements FirstOrderIntegrator {
* @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);
}

View File

@ -120,7 +120,6 @@ LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT = la borne inf\u00e9rieure ({0}) devrait \u0
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

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.ode.nonstiff;
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 AdamsBashforthIntegratorTest {
}
@Test(expected = MathUserException.class)
@Test(expected = MaxCountExceededException.class)
public void exceedMaxEvaluations() {
TestProblem1 pb = new TestProblem1();

View File

@ -19,7 +19,7 @@ package org.apache.commons.math.ode.nonstiff;
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();