Class PiecewiseLinearRateFunction
- java.lang.Object
-
- jsl.modeling.elements.variable.nhpp.PiecewiseRateFunction
-
- jsl.modeling.elements.variable.nhpp.PiecewiseLinearRateFunction
-
- All Implemented Interfaces:
CumulativeRateFunctionIfc
,InvertibleCumulativeRateFunctionIfc
,RateFunctionIfc
public class PiecewiseLinearRateFunction extends PiecewiseRateFunction
Represents a piecewise linear rate function as a sequence of segments. The rate at the beginning of the segment can be different than the rate at the end of the segment, with a linear rate over the duration
-
-
Field Summary
-
Fields inherited from class jsl.modeling.elements.variable.nhpp.PiecewiseRateFunction
myMaxRate, myMinRate, myRateSegments
-
-
Constructor Summary
Constructors Constructor Description PiecewiseLinearRateFunction(double[] durations, double[] rates)
Uses the segments represented by the rate, duration pairs The rate array must be larger than the duration array, not null, and have at least 2 rates.PiecewiseLinearRateFunction(double duration, double secondRate)
Constructs a PiecewiseLinearRateFunction with the first rate specified for time zero as zeroPiecewiseLinearRateFunction(double firstRate, double duration, double secondRate)
Constructs a PiecewiseLinearRateFunction with the first rate specified for time zero
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFirstSegment(double firstRate, double duration, double secondRate)
void
addRateSegment(double duration, double rate)
Allows the construction of the piecewise linear rate function The user supplies the knot points on the piecewise linear function by supplying the rate at the end of the supplied duration via consecutive calls to addRateSegment().boolean
contains(double time)
Returns true if the supplied time is within the time range of the rate functionint
findTimeInterval(double time)
Searches for the interval that the supplied time falls within.double[]
getDurations()
Get the durations as an arraydouble[]
getRates()
Get the rates as an arrayPiecewiseLinearRateFunction
newInstance()
Returns a copy of the piecewise linear rate functionPiecewiseLinearRateFunction
newInstance(double factor)
Returns a copy of the piecewise linear rate function with each rate multiplied by the addFactor-
Methods inherited from class jsl.modeling.elements.variable.nhpp.PiecewiseRateFunction
findCumulativeRateInterval, getCumulativeRate, getCumulativeRateRangeLowerLimit, getCumulativeRateRangeUpperLimit, getInverseCumulativeRate, getMaximum, getMinimum, getNumberSegments, getRate, getRateSegment, getTimeRangeLowerLimit, getTimeRangeUpperLimit, toString
-
-
-
-
Constructor Detail
-
PiecewiseLinearRateFunction
public PiecewiseLinearRateFunction(double duration, double secondRate)
Constructs a PiecewiseLinearRateFunction with the first rate specified for time zero as zero- Parameters:
duration
- The duration until the second ratesecondRate
- The rate after the supplied duration
-
PiecewiseLinearRateFunction
public PiecewiseLinearRateFunction(double firstRate, double duration, double secondRate)
Constructs a PiecewiseLinearRateFunction with the first rate specified for time zero- Parameters:
firstRate
- The rate at time zeroduration
- The duration until the second ratesecondRate
- The rate after the supplied duration
-
PiecewiseLinearRateFunction
public PiecewiseLinearRateFunction(double[] durations, double[] rates)
Uses the segments represented by the rate, duration pairs The rate array must be larger than the duration array, not null, and have at least 2 rates. Any rates rate[0] beginning rate of segment 0, duration[0] duration of segment 0 i >=1 rate[i] ending rate of segment i-1, beginning rate of segment i, duration[i] duration of segment i- Parameters:
durations
- the durationsrates
- the rates
-
-
Method Detail
-
addFirstSegment
protected final void addFirstSegment(double firstRate, double duration, double secondRate)
-
newInstance
public PiecewiseLinearRateFunction newInstance()
Returns a copy of the piecewise linear rate function- Specified by:
newInstance
in classPiecewiseRateFunction
- Returns:
- a copy of the piecewise linear rate function
-
newInstance
public PiecewiseLinearRateFunction newInstance(double factor)
Returns a copy of the piecewise linear rate function with each rate multiplied by the addFactor- Specified by:
newInstance
in classPiecewiseRateFunction
- Parameters:
factor
- the addFactor to multiply- Returns:
- a copy of the piecewise linear rate function
-
addRateSegment
public final void addRateSegment(double duration, double rate)
Allows the construction of the piecewise linear rate function The user supplies the knot points on the piecewise linear function by supplying the rate at the end of the supplied duration via consecutive calls to addRateSegment().- Specified by:
addRateSegment
in classPiecewiseRateFunction
- Parameters:
duration
- must be > 0 and less than Double.POSITIVE_INFINITYrate
- must be >= 0, and less than Double.POSITIVE_INFINITY
-
getRates
public double[] getRates()
Get the rates as an array- Specified by:
getRates
in classPiecewiseRateFunction
- Returns:
- the rates as an array
-
getDurations
public double[] getDurations()
Get the durations as an array- Specified by:
getDurations
in classPiecewiseRateFunction
- Returns:
- the durations as an array
-
contains
public final boolean contains(double time)
Description copied from interface:RateFunctionIfc
Returns true if the supplied time is within the time range of the rate function- Parameters:
time
- the time to evaluate- Returns:
- true if the supplied time is within the time range
-
findTimeInterval
public final int findTimeInterval(double time)
Searches for the interval that the supplied time falls within. Returns -1 if no interval is found Interval indexing starts at index 0 (i.e. 0 is the first interval, silly Java zero based indexing)- Specified by:
findTimeInterval
in classPiecewiseRateFunction
- Parameters:
time
- the time to look up- Returns:
- an int representing the interval
-
-