fixed checkstyle and findbugs warnings
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1069567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a59bf744d0
commit
987062a105
|
@ -20,6 +20,7 @@ package org.apache.commons.math.ode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -63,7 +64,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
||||||
private Collection<EventState> eventsStates;
|
private Collection<EventState> eventsStates;
|
||||||
|
|
||||||
/** Initialization indicator of events states. */
|
/** Initialization indicator of events states. */
|
||||||
protected boolean statesInitialized;
|
private boolean statesInitialized;
|
||||||
|
|
||||||
/** Name of the method. */
|
/** Name of the method. */
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -209,6 +210,16 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
||||||
equations.computeDerivatives(t, y, yDot);
|
equations.computeDerivatives(t, y, yDot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set the stateInitialized flag.
|
||||||
|
* <p>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.</p>
|
||||||
|
* @param stateInitialized new value for the flag
|
||||||
|
*/
|
||||||
|
protected void setStateInitialized(final boolean stateInitialized) {
|
||||||
|
this.statesInitialized = stateInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
/** Accept a step, triggering events and step handlers.
|
/** Accept a step, triggering events and step handlers.
|
||||||
* @param interpolator step interpolator
|
* @param interpolator step interpolator
|
||||||
* @param y state vector at step end time, must be reset if an event
|
* @param y state vector at step end time, must be reset if an event
|
||||||
|
@ -235,8 +246,16 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
||||||
statesInitialized = true;
|
statesInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SortedSet<EventState> occuringEvents = new TreeSet<EventState>(new Comparator<EventState>() {
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public int compare(EventState es0, EventState es1) {
|
||||||
|
return Double.compare(es0.getEventTime(), es1.getEventTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// find all events that occur during the step
|
// find all events that occur during the step
|
||||||
SortedSet<EventState> occuringEvents = new TreeSet<EventState>();
|
|
||||||
for (final EventState state : eventsStates) {
|
for (final EventState state : eventsStates) {
|
||||||
if (state.evaluateStep(interpolator)) {
|
if (state.evaluateStep(interpolator)) {
|
||||||
// the event occurs during the current step
|
// the event occurs during the current step
|
||||||
|
@ -249,7 +268,8 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
||||||
|
|
||||||
// restrict the interpolator to the first part of the step, up to the event
|
// restrict the interpolator to the first part of the step, up to the event
|
||||||
final double eventT = state.getEventTime();
|
final double eventT = state.getEventTime();
|
||||||
interpolator.setSoftBounds(previousT, eventT);
|
interpolator.setSoftPreviousTime(previousT);
|
||||||
|
interpolator.setSoftCurrentTime(eventT);
|
||||||
|
|
||||||
// trigger the event
|
// trigger the event
|
||||||
interpolator.setInterpolatedTime(eventT);
|
interpolator.setInterpolatedTime(eventT);
|
||||||
|
@ -279,7 +299,8 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
||||||
|
|
||||||
// prepare handling of the remaining part of the step
|
// prepare handling of the remaining part of the step
|
||||||
previousT = eventT;
|
previousT = eventT;
|
||||||
interpolator.setSoftBounds(eventT, currentT);
|
interpolator.setSoftPreviousTime(eventT);
|
||||||
|
interpolator.setSoftCurrentTime(currentT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.commons.math.util.FastMath;
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
public class EventState implements Comparable<EventState> {
|
public class EventState {
|
||||||
|
|
||||||
/** Event handler. */
|
/** Event handler. */
|
||||||
private final EventHandler handler;
|
private final EventHandler handler;
|
||||||
|
@ -301,13 +301,12 @@ public class EventState implements Comparable<EventState> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the occurrence time of the event triggered in the current
|
/** Get the occurrence time of the event triggered in the current step.
|
||||||
* step.
|
|
||||||
* @return occurrence time of the event triggered in the current
|
* @return occurrence time of the event triggered in the current
|
||||||
* step.
|
* step or positive infinity if no events are triggered
|
||||||
*/
|
*/
|
||||||
public double getEventTime() {
|
public double getEventTime() {
|
||||||
return pendingEventTime;
|
return pendingEvent ? pendingEventTime : Double.POSITIVE_INFINITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Acknowledge the fact the step has been accepted by the integrator.
|
/** Acknowledge the fact the step has been accepted by the integrator.
|
||||||
|
@ -370,21 +369,4 @@ public class EventState implements Comparable<EventState> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compare the instance with another event state.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* </p>
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator {
|
||||||
for (StepHandler handler : stepHandlers) {
|
for (StepHandler handler : stepHandlers) {
|
||||||
handler.reset();
|
handler.reset();
|
||||||
}
|
}
|
||||||
statesInitialized = false;
|
setStateInitialized(false);
|
||||||
|
|
||||||
// compute the initial Nordsieck vector using the configured starter integrator
|
// compute the initial Nordsieck vector using the configured starter integrator
|
||||||
start(t0, y, t);
|
start(t0, y, t);
|
||||||
|
|
|
@ -230,7 +230,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator {
|
||||||
for (StepHandler handler : stepHandlers) {
|
for (StepHandler handler : stepHandlers) {
|
||||||
handler.reset();
|
handler.reset();
|
||||||
}
|
}
|
||||||
statesInitialized = false;
|
setStateInitialized(false);
|
||||||
|
|
||||||
// compute the initial Nordsieck vector using the configured starter integrator
|
// compute the initial Nordsieck vector using the configured starter integrator
|
||||||
start(t0, y, t);
|
start(t0, y, t);
|
||||||
|
|
|
@ -226,7 +226,7 @@ public abstract class EmbeddedRungeKuttaIntegrator
|
||||||
for (StepHandler handler : stepHandlers) {
|
for (StepHandler handler : stepHandlers) {
|
||||||
handler.reset();
|
handler.reset();
|
||||||
}
|
}
|
||||||
statesInitialized = false;
|
setStateInitialized(false);
|
||||||
|
|
||||||
// main integration loop
|
// main integration loop
|
||||||
isLastStep = false;
|
isLastStep = false;
|
||||||
|
|
|
@ -632,7 +632,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
|
||||||
for (StepHandler handler : stepHandlers) {
|
for (StepHandler handler : stepHandlers) {
|
||||||
handler.reset();
|
handler.reset();
|
||||||
}
|
}
|
||||||
statesInitialized = false;
|
setStateInitialized(false);
|
||||||
costPerTimeUnit[0] = 0;
|
costPerTimeUnit[0] = 0;
|
||||||
isLastStep = false;
|
isLastStep = false;
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -131,7 +131,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator {
|
||||||
for (StepHandler handler : stepHandlers) {
|
for (StepHandler handler : stepHandlers) {
|
||||||
handler.reset();
|
handler.reset();
|
||||||
}
|
}
|
||||||
statesInitialized = false;
|
setStateInitialized(false);
|
||||||
|
|
||||||
// main integration loop
|
// main integration loop
|
||||||
isLastStep = false;
|
isLastStep = false;
|
||||||
|
|
|
@ -43,18 +43,6 @@ import org.apache.commons.math.exception.MathUserException;
|
||||||
public abstract class AbstractStepInterpolator
|
public abstract class AbstractStepInterpolator
|
||||||
implements StepInterpolator {
|
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 */
|
/** current time step */
|
||||||
protected double h;
|
protected double h;
|
||||||
|
|
||||||
|
@ -70,6 +58,18 @@ public abstract class AbstractStepInterpolator
|
||||||
/** interpolated derivatives */
|
/** interpolated derivatives */
|
||||||
protected double[] interpolatedDerivatives;
|
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. */
|
/** indicate if the step has been finalized or not. */
|
||||||
private boolean finalized;
|
private boolean finalized;
|
||||||
|
|
||||||
|
@ -245,15 +245,27 @@ public abstract class AbstractStepInterpolator
|
||||||
* <p>
|
* <p>
|
||||||
* This method can be used to restrict a step and make it appear
|
* This method can be used to restrict a step and make it appear
|
||||||
* as if the original step was smaller. Calling this method
|
* as if the original step was smaller. Calling this method
|
||||||
* <em>only</em> changes the value returned by {@link #getPreviousTime()}
|
* <em>only</em> changes the value returned by {@link #getPreviousTime()},
|
||||||
* and {@link #getCurrentTime()}, it does not change any
|
* it does not change any other property
|
||||||
* </p>
|
* </p>
|
||||||
* @param softPreviousTime start of the restricted step
|
* @param softPreviousTime start of the restricted step
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
public void setSoftPreviousTime(final double softPreviousTime) {
|
||||||
|
this.softPreviousTime = softPreviousTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Restrict step range to a limited part of the global step.
|
||||||
|
* <p>
|
||||||
|
* This method can be used to restrict a step and make it appear
|
||||||
|
* as if the original step was smaller. Calling this method
|
||||||
|
* <em>only</em> changes the value returned by {@link #getCurrentTime()},
|
||||||
|
* it does not change any other property
|
||||||
|
* </p>
|
||||||
* @param softCurrentTime end of the restricted step
|
* @param softCurrentTime end of the restricted step
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public void setSoftBounds(final double softPreviousTime, final double softCurrentTime) {
|
public void setSoftCurrentTime(final double softCurrentTime) {
|
||||||
this.softPreviousTime = softPreviousTime;
|
|
||||||
this.softCurrentTime = softCurrentTime;
|
this.softCurrentTime = softCurrentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +290,7 @@ public abstract class AbstractStepInterpolator
|
||||||
/**
|
/**
|
||||||
* Get the previous soft grid point time.
|
* Get the previous soft grid point time.
|
||||||
* @return previous soft grid point time
|
* @return previous soft grid point time
|
||||||
* @see #setSoftBounds(double, double)
|
* @see #setSoftPreviousTime(double)
|
||||||
*/
|
*/
|
||||||
public double getPreviousTime() {
|
public double getPreviousTime() {
|
||||||
return softPreviousTime;
|
return softPreviousTime;
|
||||||
|
@ -287,7 +299,7 @@ public abstract class AbstractStepInterpolator
|
||||||
/**
|
/**
|
||||||
* Get the current soft grid point time.
|
* Get the current soft grid point time.
|
||||||
* @return current soft grid point time
|
* @return current soft grid point time
|
||||||
* @see #setSoftBounds(double, double)
|
* @see #setSoftCurrentTime(double)
|
||||||
*/
|
*/
|
||||||
public double getCurrentTime() {
|
public double getCurrentTime() {
|
||||||
return softCurrentTime;
|
return softCurrentTime;
|
||||||
|
|
|
@ -148,7 +148,7 @@ public abstract class AbstractScalarDifferentiableOptimizer
|
||||||
* Compute the gradient vector.
|
* Compute the gradient vector.
|
||||||
* @param evaluationPoint point at which the gradient must be evaluated
|
* @param evaluationPoint point at which the gradient must be evaluated
|
||||||
* @return gradient at the specified point
|
* @return gradient at the specified point
|
||||||
* @exception MathUserException if the function gradient
|
* @exception FunctionEvaluationException if the function gradient
|
||||||
*/
|
*/
|
||||||
protected double[] computeObjectiveGradient(final double[] evaluationPoint)
|
protected double[] computeObjectiveGradient(final double[] evaluationPoint)
|
||||||
throws FunctionEvaluationException {
|
throws FunctionEvaluationException {
|
||||||
|
|
|
@ -1359,7 +1359,7 @@ public class FastMath {
|
||||||
double xb = ab;
|
double xb = ab;
|
||||||
|
|
||||||
/* Need a more accurate epsilon, so adjust the division. */
|
/* Need a more accurate epsilon, so adjust the division. */
|
||||||
double numer = (bits & 0x3ffffffffffL);
|
double numer = bits & 0x3ffffffffffL;
|
||||||
double denom = TWO_POWER_52 + (bits & 0x000ffc0000000000L);
|
double denom = TWO_POWER_52 + (bits & 0x000ffc0000000000L);
|
||||||
aa = numer - xa*denom - xb * denom;
|
aa = numer - xa*denom - xb * denom;
|
||||||
xb += aa / denom;
|
xb += aa / denom;
|
||||||
|
|
Loading…
Reference in New Issue