Package com.anylogic.engine
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- get
- setArgumentsAndValues
- getArguments
- getValues
- getLength
- getNextArgument
- setInterpolationType
- setApproximationOrder
- getApproximationOrder
- getInterpolationType
- setOutOfRangeAction
- getOutOfRangeAction
- setOutOfRangeDefaultValue
- getOutOfRangeDefaultValue
- toString
- indexOf
- createCustomDistribution
- createCustomDistribution
- java.lang.Object
- com.anylogic.engine.TableFunction
- All Implemented Interfaces:
Serializable
public class TableFunction extends Object implements Serializable
Table function enables the user to define functions by giving a number of
(argument, value) pairs, i.e. a number of base points on a plot. Supports
various interpolation types. A call of get(x) will return a (possibly,
interpolated) value of the function. A number of behaviors are supported
for the case x is out of original argument range.
In case the function only supports discrete values (that were provided as the argument set), and no interpolation is allowed, a call of get(x) with x not matching any argument entry would result in exception thrown.
In case the function only supports discrete values (that were provided as the argument set), and no interpolation is allowed, a call of get(x) with x not matching any argument entry would result in exception thrown.
- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Modifier and Type | Class | Description |
---|---|---|
static enum | TableFunction.InterpolationType | |
static enum | TableFunction.OutOfRangeAction |
Modifier and Type | Field | Description |
---|---|---|
static final TableFunction.InterpolationType | INTERPOLATION_APPROXIMATION | |
static final TableFunction.InterpolationType | INTERPOLATION_LINEAR | |
static final TableFunction.InterpolationType | INTERPOLATION_NONE | |
static final TableFunction.InterpolationType | INTERPOLATION_SPLINE | |
static final TableFunction.InterpolationType | INTERPOLATION_STEP | |
static final TableFunction.OutOfRangeAction | OUTOFRANGE_CUSTOM | |
static final TableFunction.OutOfRangeAction | OUTOFRANGE_ERROR | |
static final TableFunction.OutOfRangeAction | OUTOFRANGE_EXTRAPOLATE | |
static final TableFunction.OutOfRangeAction | OUTOFRANGE_NEAREST | |
static final TableFunction.OutOfRangeAction | OUTOFRANGE_REPEAT |
Constructor | Description |
---|---|
TableFunction |
Creates a new table function with the given arguments, values, interpolation
type and out of range behavior type.
|
TableFunction |
Deprecated.
|
Modifier and Type | Method | Description |
---|---|---|
CustomDistributionAbstract<Double> | createCustomDistribution() |
Constructs a custom distribution from the TableFunction.
|
CustomDistributionAbstract<Double> | createCustomDistribution |
Constructs a custom distribution from the TableFunction.
|
double | get |
Returns the table function value corresponding to the given argument,
subject to the currently set interpolation type and out of range handling.
|
int | getApproximationOrder() |
The method returns the currently set order of the approximation polynomial
used in the approximation mode.
|
double[] | getArguments() |
Returns the (sorted) array of arguments.
|
TableFunction.InterpolationType | getInterpolationType() |
Returns the current interpolation type of the table function.
|
int | getLength() |
Returns the number of entries (rows) in the table function.
|
double | getNextArgument |
Returns the value of the nearest argument that is strictly greater
than x, respecting the possible table repeating.
|
TableFunction.OutOfRangeAction | getOutOfRangeAction() |
Returns the current type of action performed for out of range arguments.
|
double | getOutOfRangeDefaultValue() |
Returns the value that is returned by get(x) in case x is out of range
when out of range action type is OUTOFRANGE_CUSTOM.
|
double[] | getValues() |
Returns the array of values corresponding to the (sorted) array of arguments.
|
int | indexOf |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. Finds the interval between the two points on the argument axis [a,b[ where x belongs to and returns the index of the left point a. |
void | setApproximationOrder |
This method sets order of the approximation polynomial for the
INTERPOLATION_APPROXIMATION mode.
|
void | setArgumentsAndValues |
Sets the new argument and value arrays for the table function.
|
void | setInterpolationType |
Sets the new interpolation type for the table function.
|
void | setOutOfRangeAction |
Sets the new action performed in case the argument provided in get()
is out of range.
|
void | setOutOfRangeDefaultValue |
Sets the value to be returned by get(x) in case x is out of range AND
out of range action type is OUTOFRANGE_CUSTOM.
|
String | toString() |
Returns the textual representation of the table function.
|
public static final TableFunction.InterpolationType INTERPOLATION_NONE
public static final TableFunction.InterpolationType INTERPOLATION_STEP
public static final TableFunction.InterpolationType INTERPOLATION_LINEAR
public static final TableFunction.InterpolationType INTERPOLATION_SPLINE
public static final TableFunction.InterpolationType INTERPOLATION_APPROXIMATION
public static final TableFunction.OutOfRangeAction OUTOFRANGE_ERROR
public static final TableFunction.OutOfRangeAction OUTOFRANGE_NEAREST
public static final TableFunction.OutOfRangeAction OUTOFRANGE_CUSTOM
public static final TableFunction.OutOfRangeAction OUTOFRANGE_REPEAT
public static final TableFunction.OutOfRangeAction OUTOFRANGE_EXTRAPOLATE
@Deprecated public TableFunction(double[] arguments, double[] values, TableFunction.InterpolationType interpolationtype, TableFunction.OutOfRangeAction outofrangeaction, double outofrangevalue)
Deprecated.
please use
TableFunction(double[], double[], InterpolationType, int, OutOfRangeAction, double)
constructor insteadCreates a new table function with the given arguments, values, interpolation
type and out of range behavior type. Note that arrays are not copied; they are
used by reference and can be modified.
- Parameters:
arguments
- the array of arguments (2 or more - recommended, no duplicates, can be sorted or not)values
- the array of values (same size as arguments)interpolationtype
- the interpolation typeoutofrangeaction
- the type of action performed for out of range arguments in get()outofrangevalue
- the value returned if argument is out of range
public TableFunction(double[] arguments, double[] values, TableFunction.InterpolationType interpolationtype, int approximationOrder, TableFunction.OutOfRangeAction outofrangeaction, double outofrangevalue)
Creates a new table function with the given arguments, values, interpolation
type and out of range behavior type. Note that arrays are not copied; they are
used by reference and can be modified.
- Parameters:
arguments
- the array of arguments (2 or more - recommended, no duplicates, can be sorted or not)values
- the array of values (same size as arguments)interpolationtype
- the interpolation typeapproximationOrder
- the order (1, 2, 3...) of the approximation polynomial if the INTERPOLATION_APPROXIMATION mode is selectedoutofrangeaction
- the type of action performed for out of range arguments in get()outofrangevalue
- the value returned if argument is out of range
public double get(double x)
Returns the table function value corresponding to the given argument,
subject to the currently set interpolation type and out of range handling.
- Parameters:
x
- the argument- Returns:
- the table function value
public void setArgumentsAndValues(double[] arguments, double[] values)
Sets the new argument and value arrays for the table function. The following
checks are performed: arrays must be of the same length, there cannot be duplicate arguments.
The arguments will be sorted if they are not
- Parameters:
arguments
- the array of argumentsvalues
- the array of values
public double[] getArguments()
Returns the (sorted) array of arguments.
- Returns:
- the array of arguments
public double[] getValues()
Returns the array of values corresponding to the (sorted) array of arguments.
- Returns:
- the array of values
public int getLength()
Returns the number of entries (rows) in the table function.
- Returns:
- the number of entries (rows) in the table function
public double getNextArgument(double x)
Returns the value of the nearest argument that is strictly greater
than x, respecting the possible table repeating. If the table is
not repeating and there is no such argument, returns
+infinity
.- Returns:
- the index of the nearest argument that is greater than x, or
+infinity
public void setInterpolationType(TableFunction.InterpolationType type)
Sets the new interpolation type for the table function. Valid types are:
INTERPOLATION_NONE, INTERPOLATION_STEP, INTERPOLATION_LINEAR,
INTERPOLATION_SPLINE, INTERPOLATION_APPROXIMATION.
In case of approximation please ensure that correct approximation order is specified (using
In case of approximation please ensure that correct approximation order is specified (using
setApproximationOrder(int)
or in the
constructor) before calling this method- Parameters:
type
- the new interpolation type
public void setApproximationOrder(int order)
This method sets order of the approximation polynomial for the
INTERPOLATION_APPROXIMATION mode. The method doesn't change
interpolation type (see
setInterpolationType(InterpolationType)
)- Parameters:
order
- order of the approximation (polynomial order)
public int getApproximationOrder()
The method returns the currently set order of the approximation polynomial
used in the approximation mode.
- Returns:
- order of the approximation polynomial
public TableFunction.InterpolationType getInterpolationType()
Returns the current interpolation type of the table function.
- Returns:
- the current interpolation type
public void setOutOfRangeAction(TableFunction.OutOfRangeAction action)
Sets the new action performed in case the argument provided in get()
is out of range. The valid actions are:
OUTOFRANGE_ERROR - raise error (throw exception)
OUTOFRANGE_NEAREST - use nearest value
OUTOFRANGE_CUSTOM - use specific value
OUTOFRANGE_REPEAT - treat the table as repeated pattern
In case interpolation type is INTERPOLATION_NONE, the only possible behavior is to raise error.
OUTOFRANGE_ERROR - raise error (throw exception)
OUTOFRANGE_NEAREST - use nearest value
OUTOFRANGE_CUSTOM - use specific value
OUTOFRANGE_REPEAT - treat the table as repeated pattern
In case interpolation type is INTERPOLATION_NONE, the only possible behavior is to raise error.
- Parameters:
action
- the type of action performed for out of range arguments
public TableFunction.OutOfRangeAction getOutOfRangeAction()
Returns the current type of action performed for out of range arguments.
- Returns:
- the current type of action performed for out of range arguments
public void setOutOfRangeDefaultValue(double value)
Sets the value to be returned by get(x) in case x is out of range AND
out of range action type is OUTOFRANGE_CUSTOM.
- Parameters:
value
- the value to be returned by get(x) in case x is out of range
public double getOutOfRangeDefaultValue()
Returns the value that is returned by get(x) in case x is out of range
when out of range action type is OUTOFRANGE_CUSTOM.
- Returns:
- the value that is returned by get(x) in case x is out of range
public String toString()
Returns the textual representation of the table function.
@AnyLogicInternalAPI public int indexOf(double x)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Finds the interval between the two points on the argument axis [a,b[ where x belongs to and returns the index of the left point a. The index of the last point is returned only if x equals the last point. If x isn't in the range, nearest index is returned
it may be removed/renamed in future.
Finds the interval between the two points on the argument axis [a,b[ where x belongs to and returns the index of the left point a. The index of the last point is returned only if x equals the last point. If x isn't in the range, nearest index is returned
public CustomDistributionAbstract<Double> createCustomDistribution()
Constructs a custom distribution from the TableFunction. Takes table function's
interpolation type and check if it can be supported.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.
- Returns:
- CustomDistribution matching tableFunction
public CustomDistributionAbstract<Double> createCustomDistribution(Random random)
Constructs a custom distribution from the TableFunction. Takes table function's
interpolation type and check if it can be supported.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from an
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from an
Agent
or an Experiment
.- Parameters:
random
- the random number generator that will be used- Returns:
- CustomDistribution matching tableFunction
TableFunction(double[], double[], InterpolationType, int, OutOfRangeAction, double)
constructor instead