AnyLogic
Expand
Font size
  • java.lang.Object
    • com.anylogic.engine.TableFunction
All Implemented Interfaces:
java.io.Serializable

public class TableFunction
extends java.lang.Object
implements java.io.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.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Nested Class Summary

Nested Classes 
static class  TableFunction.InterpolationType  
static class  TableFunction.OutOfRangeAction  
Modifier and Type Class Description

Field Summary

Fields 
static TableFunction.InterpolationType INTERPOLATION_APPROXIMATION  
static TableFunction.InterpolationType INTERPOLATION_LINEAR  
static TableFunction.InterpolationType INTERPOLATION_NONE  
static TableFunction.InterpolationType INTERPOLATION_SPLINE  
static TableFunction.InterpolationType INTERPOLATION_STEP  
static TableFunction.OutOfRangeAction OUTOFRANGE_CUSTOM  
static TableFunction.OutOfRangeAction OUTOFRANGE_ERROR  
static TableFunction.OutOfRangeAction OUTOFRANGE_EXTRAPOLATE  
static TableFunction.OutOfRangeAction OUTOFRANGE_NEAREST  
static TableFunction.OutOfRangeAction OUTOFRANGE_REPEAT  
Modifier and Type Field Description

Constructor Summary

Constructors 
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.
TableFunction​(double[] arguments, double[] values, TableFunction.InterpolationType interpolationtype, TableFunction.OutOfRangeAction outofrangeaction, double outofrangevalue)
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods 
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.
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​(double x)
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.
void setApproximationOrder​(int order)
This method sets order of the approximation polynomial for the INTERPOLATION_APPROXIMATION mode.
void setArgumentsAndValues​(double[] arguments, double[] values)
Sets the new argument and value arrays for the table function.
void setInterpolationType​(TableFunction.InterpolationType type)
Sets the new interpolation type for the table function.
void setOutOfRangeAction​(TableFunction.OutOfRangeAction action)
Sets the new action performed in case the argument provided in get() is out of range.
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.
java.lang.String toString()
Returns the textual representation of the table function.
Modifier and Type Method Description

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail

INTERPOLATION_NONE

public static final TableFunction.InterpolationType INTERPOLATION_NONE

INTERPOLATION_STEP

public static final TableFunction.InterpolationType INTERPOLATION_STEP

INTERPOLATION_LINEAR

public static final TableFunction.InterpolationType INTERPOLATION_LINEAR

INTERPOLATION_SPLINE

public static final TableFunction.InterpolationType INTERPOLATION_SPLINE

INTERPOLATION_APPROXIMATION

public static final TableFunction.InterpolationType INTERPOLATION_APPROXIMATION

OUTOFRANGE_ERROR

public static final TableFunction.OutOfRangeAction OUTOFRANGE_ERROR

OUTOFRANGE_NEAREST

public static final TableFunction.OutOfRangeAction OUTOFRANGE_NEAREST

OUTOFRANGE_CUSTOM

public static final TableFunction.OutOfRangeAction OUTOFRANGE_CUSTOM

OUTOFRANGE_REPEAT

public static final TableFunction.OutOfRangeAction OUTOFRANGE_REPEAT

OUTOFRANGE_EXTRAPOLATE

public static final TableFunction.OutOfRangeAction OUTOFRANGE_EXTRAPOLATE

Constructor Detail

TableFunction

@Deprecated
public TableFunction​(double[] arguments,
                     double[] values,
                     TableFunction.InterpolationType interpolationtype,
                     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 type
outofrangeaction - the type of action performed for out of range arguments in get()
outofrangevalue - the value returned if argument is out of range

TableFunction

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 type
approximationOrder - the order (1, 2, 3...) of the approximation polynomial if the INTERPOLATION_APPROXIMATION mode is selected
outofrangeaction - the type of action performed for out of range arguments in get()
outofrangevalue - the value returned if argument is out of range

Method Detail

get

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

setArgumentsAndValues

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 arguments
values - the array of values

getArguments

public double[] getArguments()
Returns the (sorted) array of arguments.
Returns:
the array of arguments

getValues

public double[] getValues()
Returns the array of values corresponding to the (sorted) array of arguments.
Returns:
the array of values

getLength

public int getLength()
Returns the number of entries (rows) in the table function.
Returns:
the number of entries (rows) in the table function

getNextArgument

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

setInterpolationType

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 setApproximationOrder(int) or in the constructor) before calling this method
Parameters:
type - the new interpolation type

setApproximationOrder

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)

getApproximationOrder

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

getInterpolationType

public TableFunction.InterpolationType getInterpolationType()
Returns the current interpolation type of the table function.
Returns:
the current interpolation type

setOutOfRangeAction

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.
Parameters:
action - the type of action performed for out of range arguments

getOutOfRangeAction

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

setOutOfRangeDefaultValue

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

getOutOfRangeDefaultValue

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

toString

public java.lang.String toString()
Returns the textual representation of the table function.
Overrides:
toString in class java.lang.Object
Returns:
the textual representation of the table function
How can we improve this article?