Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 93684 invoked from network); 10 Feb 2011 21:07:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Feb 2011 21:07:51 -0000 Received: (qmail 76072 invoked by uid 500); 10 Feb 2011 21:07:51 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 75998 invoked by uid 500); 10 Feb 2011 21:07:50 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 75991 invoked by uid 99); 10 Feb 2011 21:07:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Feb 2011 21:07:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Feb 2011 21:07:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EF47D2388A66; Thu, 10 Feb 2011 21:07:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1069567 - in /commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math: ode/ ode/events/ ode/nonstiff/ ode/sampling/ optimization/general/ util/ Date: Thu, 10 Feb 2011 21:07:26 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110210210726.EF47D2388A66@eris.apache.org> Author: luc Date: Thu Feb 10 21:07:26 2011 New Revision: 1069567 URL: http://svn.apache.org/viewvc?rev=1069567&view=rev Log: fixed checkstyle and findbugs warnings Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/events/EventState.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java Thu Feb 10 21:07:26 2011 @@ -20,6 +20,7 @@ package org.apache.commons.math.ode; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -63,7 +64,7 @@ public abstract class AbstractIntegrator private Collection eventsStates; /** Initialization indicator of events states. */ - protected boolean statesInitialized; + private boolean statesInitialized; /** Name of the method. */ private final String name; @@ -209,6 +210,16 @@ public abstract class AbstractIntegrator equations.computeDerivatives(t, y, yDot); } + /** Set the stateInitialized flag. + *

This method must be called by integrators with the value + * {@code false} before they start integration, so a proper lazy + * initialization is done automatically on the first step.

+ * @param stateInitialized new value for the flag + */ + protected void setStateInitialized(final boolean stateInitialized) { + this.statesInitialized = stateInitialized; + } + /** Accept a step, triggering events and step handlers. * @param interpolator step interpolator * @param y state vector at step end time, must be reset if an event @@ -235,8 +246,16 @@ public abstract class AbstractIntegrator statesInitialized = true; } + SortedSet occuringEvents = new TreeSet(new Comparator() { + + /** {@inheritDoc} */ + public int compare(EventState es0, EventState es1) { + return Double.compare(es0.getEventTime(), es1.getEventTime()); + } + + }); + // find all events that occur during the step - SortedSet occuringEvents = new TreeSet(); for (final EventState state : eventsStates) { if (state.evaluateStep(interpolator)) { // the event occurs during the current step @@ -249,7 +268,8 @@ public abstract class AbstractIntegrator // restrict the interpolator to the first part of the step, up to the event final double eventT = state.getEventTime(); - interpolator.setSoftBounds(previousT, eventT); + interpolator.setSoftPreviousTime(previousT); + interpolator.setSoftCurrentTime(eventT); // trigger the event interpolator.setInterpolatedTime(eventT); @@ -279,7 +299,8 @@ public abstract class AbstractIntegrator // prepare handling of the remaining part of the step previousT = eventT; - interpolator.setSoftBounds(eventT, currentT); + interpolator.setSoftPreviousTime(eventT); + interpolator.setSoftCurrentTime(currentT); } Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/events/EventState.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/events/EventState.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/events/EventState.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/events/EventState.java Thu Feb 10 21:07:26 2011 @@ -39,7 +39,7 @@ import org.apache.commons.math.util.Fast * @version $Revision$ $Date$ * @since 1.2 */ -public class EventState implements Comparable { +public class EventState { /** Event handler. */ private final EventHandler handler; @@ -301,13 +301,12 @@ public class EventState implements Compa } - /** Get the occurrence time of the event triggered in the current - * step. + /** Get the occurrence time of the event triggered in the current step. * @return occurrence time of the event triggered in the current - * step. + * step or positive infinity if no events are triggered */ public double getEventTime() { - return pendingEventTime; + return pendingEvent ? pendingEventTime : Double.POSITIVE_INFINITY; } /** Acknowledge the fact the step has been accepted by the integrator. @@ -370,21 +369,4 @@ public class EventState implements Compa } - /** Compare the instance with another event state. - *

- * Event state ordering is based on occurrence time within the last - * evaluated step. If no event occurs during the step, a time arbitrarily - * set to positive infinity is used. - *

- * @param state other event state to compare the instance to - * @return a negative integer, zero, or a positive integer as the event - * occurs before, simultaneous, or after the specified event of the - * specified state. - */ - public int compareTo(final EventState state) { - final double instanceTime = pendingEvent ? pendingEventTime : Double.POSITIVE_INFINITY; - final double otherTime = state.pendingEvent ? state.pendingEventTime : Double.POSITIVE_INFINITY; - return Double.compare(instanceTime, otherTime); - } - } Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java Thu Feb 10 21:07:26 2011 @@ -210,7 +210,7 @@ public class AdamsBashforthIntegrator ex for (StepHandler handler : stepHandlers) { handler.reset(); } - statesInitialized = false; + setStateInitialized(false); // compute the initial Nordsieck vector using the configured starter integrator start(t0, y, t); Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java Thu Feb 10 21:07:26 2011 @@ -230,7 +230,7 @@ public class AdamsMoultonIntegrator exte for (StepHandler handler : stepHandlers) { handler.reset(); } - statesInitialized = false; + setStateInitialized(false); // compute the initial Nordsieck vector using the configured starter integrator start(t0, y, t); Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java Thu Feb 10 21:07:26 2011 @@ -226,7 +226,7 @@ public abstract class EmbeddedRungeKutta for (StepHandler handler : stepHandlers) { handler.reset(); } - statesInitialized = false; + setStateInitialized(false); // main integration loop isLastStep = false; Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java Thu Feb 10 21:07:26 2011 @@ -632,7 +632,7 @@ public class GraggBulirschStoerIntegrato for (StepHandler handler : stepHandlers) { handler.reset(); } - statesInitialized = false; + setStateInitialized(false); costPerTimeUnit[0] = 0; isLastStep = false; do { Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java Thu Feb 10 21:07:26 2011 @@ -131,7 +131,7 @@ public abstract class RungeKuttaIntegrat for (StepHandler handler : stepHandlers) { handler.reset(); } - statesInitialized = false; + setStateInitialized(false); // main integration loop isLastStep = false; Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java Thu Feb 10 21:07:26 2011 @@ -43,18 +43,6 @@ import org.apache.commons.math.exception public abstract class AbstractStepInterpolator implements StepInterpolator { - /** global previous time */ - private double globalPreviousTime; - - /** global current time */ - private double globalCurrentTime; - - /** soft previous time */ - private double softPreviousTime; - - /** soft current time */ - private double softCurrentTime; - /** current time step */ protected double h; @@ -70,6 +58,18 @@ public abstract class AbstractStepInterp /** interpolated derivatives */ protected double[] interpolatedDerivatives; + /** global previous time */ + private double globalPreviousTime; + + /** global current time */ + private double globalCurrentTime; + + /** soft previous time */ + private double softPreviousTime; + + /** soft current time */ + private double softCurrentTime; + /** indicate if the step has been finalized or not. */ private boolean finalized; @@ -245,15 +245,27 @@ public abstract class AbstractStepInterp *

* This method can be used to restrict a step and make it appear * as if the original step was smaller. Calling this method - * only changes the value returned by {@link #getPreviousTime()} - * and {@link #getCurrentTime()}, it does not change any + * only changes the value returned by {@link #getPreviousTime()}, + * it does not change any other property *

* @param softPreviousTime start of the restricted step - * @param softCurrentTime end of the restricted step * @since 2.2 */ - public void setSoftBounds(final double softPreviousTime, final double softCurrentTime) { + public void setSoftPreviousTime(final double softPreviousTime) { this.softPreviousTime = softPreviousTime; + } + + /** Restrict step range to a limited part of the global step. + *

+ * This method can be used to restrict a step and make it appear + * as if the original step was smaller. Calling this method + * only changes the value returned by {@link #getCurrentTime()}, + * it does not change any other property + *

+ * @param softCurrentTime end of the restricted step + * @since 2.2 + */ + public void setSoftCurrentTime(final double softCurrentTime) { this.softCurrentTime = softCurrentTime; } @@ -278,7 +290,7 @@ public abstract class AbstractStepInterp /** * Get the previous soft grid point time. * @return previous soft grid point time - * @see #setSoftBounds(double, double) + * @see #setSoftPreviousTime(double) */ public double getPreviousTime() { return softPreviousTime; @@ -287,7 +299,7 @@ public abstract class AbstractStepInterp /** * Get the current soft grid point time. * @return current soft grid point time - * @see #setSoftBounds(double, double) + * @see #setSoftCurrentTime(double) */ public double getCurrentTime() { return softCurrentTime; Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java Thu Feb 10 21:07:26 2011 @@ -148,7 +148,7 @@ public abstract class AbstractScalarDiff * Compute the gradient vector. * @param evaluationPoint point at which the gradient must be evaluated * @return gradient at the specified point - * @exception MathUserException if the function gradient + * @exception FunctionEvaluationException if the function gradient */ protected double[] computeObjectiveGradient(final double[] evaluationPoint) throws FunctionEvaluationException { Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1069567&r1=1069566&r2=1069567&view=diff ============================================================================== --- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java (original) +++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java Thu Feb 10 21:07:26 2011 @@ -1359,7 +1359,7 @@ public class FastMath { double xb = ab; /* Need a more accurate epsilon, so adjust the division. */ - double numer = (bits & 0x3ffffffffffL); + double numer = bits & 0x3ffffffffffL; double denom = TWO_POWER_52 + (bits & 0x000ffc0000000000L); aa = numer - xa*denom - xb * denom; xb += aa / denom;