AnyLogic
Expand
Font size
All Implemented Interfaces:
Serializable

public class DataSet
extends ChartItem
A data set capable of storing 2D (X,Y) data of type double and maintaining the up-to-date minimum and maximum of the stored data for each dimension. The data set keeps a given limited number of the latest data items.
Please note that adding a new item when the dataset is full will cause loss of the oldest sample and, if the lost item contained minimum or maximum, will initiate a new search for min/max, which may be quite time consuming for large datasets. Therefore for large datasets it is recommended to have the size not less than the number of items yoiu plan to add.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Constructor Summary

ConstructorDescription
DataSet(int capacity)
Constructs a 2D data set with data of type double with a given capacity.
DataSet(int capacity, DataUpdater_xjal updater)
Constructs a 2D data set with data of type double with a given capacity.
Registers the given updater so that dataset uses it while being updated.

Method Summary

Modifier and TypeMethodDescription
voidadd(double y)
Adds a new data item to the data set.
voidadd(double x, double y)
Adds a new data item to the data set.
voidadd(double x, IStatechartState<?,?> state)
Adds a new statechart state data item to the data set.
voidallowDuplicateX(boolean yes)
Sets the way of handling two subsequent calls of add() with identical X values.
voidallowDuplicateY(boolean yes)
Sets the way of handling two subsequent calls of add() with identical Y values.
voiddestroyUpdater_xjal()
This method is used to 'disconnect' this data class from the agent/experiment this object was defined in.
It is usually called on agent destroy so that experiment could use this data object e.g.
booleanduplicateXAllowed()
Tests if subsequent data items with same X values are allowed in this dataset.
booleanduplicateYAllowed()
Tests if subsequent data items with same Y values are allowed in this dataset.
voidfillFrom(DataSet ds)
Makes this dataset an exact copy of the given original dataset.
voidfillFrom(TableFunction tf)
Discards all existing data, sets the capacity to equal to the number of entries in the given table function and fills the dataset from the given table function.
intgetCapacity()
Returns the capacity of the data set.
List<List<Object>>getPlainDataTable() 
StringgetSVGDeltaAndMarkSynced(boolean deltaonly) 
doublegetX(int i)
Returns the x of the data items with a given index (which must be in the range 0..size()-1).
doublegetXMax()
Returns the maximum of all x values of all stored items, or -infinity in case there are no items.
doublegetXMean()
Returns the average of all x values of all stored items, or 0 in case there are no items.
doublegetXMedian()
Returns the median of all x values of all stored items, or 0 in case there are no items.
Note that this median calculation is time consuming
doublegetXMin()
Returns the minimum of all x values of all stored data items, or +infinity in case there are no items.
doublegetY(int i)
Returns the y of the data items with a given index (which must be in the range 0..size()-1).
doublegetYMax()
Returns the maximum of all y values of all stored items, or -infinity in case there are no items.
doublegetYMean()
Returns the average of all y values of all stored items, or 0 in case there are no items.
doublegetYMedian()
Returns the median of all y values of all stored items, or 0 in case there are no items.
Note that this median calculation is time consuming
doublegetYMin()
Returns the minimum of all y values of all stored items, or +infinity in case there are no items.
voidreset()
Discards all stored data and their minimum/maximum.
voidsetCapacity(int newcapacity)
Resizes the data set according to the new capacity.
intsize()
Returns the number of items stored in the data set.
StringtoString()
Returns a tab-separated multi-line textual representation of the data set containing not more than 1000 data items.
voidupdate()
Should be overridden and call add( x, y ) if the user has specified the values for horizontal and/or vertical axes.

Methods inherited from class com.anylogic.engine.analysis.ChartItem

getVersion

Methods inherited from class java.lang.Object

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

Constructor Details

DataSet

public DataSet(int capacity)
Constructs a 2D data set with data of type double with a given capacity.
Parameters:
capacity - the maximum number of (x,y) items the data set can store

DataSet

public DataSet(int capacity,
 DataUpdater_xjal updater)
Constructs a 2D data set with data of type double with a given capacity.
Registers the given updater so that dataset uses it while being updated. Updater may be destroyUpdater_xjal() dropped off when no more needed, in order to improve memory performance.
Parameters:
capacity - the maximum number of (x,y) items the data set can store
updater - updater which may be used instead of overriding update() method

Method Details

destroyUpdater_xjal

@AnyLogicInternalCodegenAPI
public void destroyUpdater_xjal()
This method is used to 'disconnect' this data class from the agent/experiment this object was defined in.
It is usually called on agent destroy so that experiment could use this data object e.g. in its charts.

reset

public void reset()
Discards all stored data and their minimum/maximum.

setCapacity

public void setCapacity(int newcapacity)
Resizes the data set according to the new capacity. As many as possible of old data items will be kept. The minimum/maximum are recalculated.
Parameters:
newcapacity - the new size of the data set

getCapacity

public int getCapacity()
Returns the capacity of the data set. The actual number of stored items may be smaller and can be retrieved by size().
Returns:
the capacity of the data set

allowDuplicateY

public void allowDuplicateY(boolean yes)
Sets the way of handling two subsequent calls of add() with identical Y values.
Parameters:
yes - if true, two entries in the dataset will be created, otherwise second item will override the last one.

duplicateYAllowed

public boolean duplicateYAllowed()
Tests if subsequent data items with same Y values are allowed in this dataset. By default they are allowed.
Returns:
true if yes, otherwise false

allowDuplicateX

public void allowDuplicateX(boolean yes)
Sets the way of handling two subsequent calls of add() with identical X values.
Parameters:
yes - if true, two entries in the dataset will be created, otherwise second item will override the last one.

duplicateXAllowed

public boolean duplicateXAllowed()
Tests if subsequent data items with same X values are allowed in this dataset. By default they are allowed.
Returns:
true if yes, otherwise false

add

public void add(double x,
 IStatechartState<?,?> state)
Adds a new statechart state data item to the data set. If the data set is full, the oldest item will be pushed out and lost. The minimum/maximum may change as a result of both adding new and discarding old values and are recalculated.
Parameters:
x - the x value of the data item, usually time
state - the y value of the data item, the state (ordinal number of the state will be used)

add

public void add(double x,
 double y)
Adds a new data item to the data set. If the data set is full, the oldest item will be pushed out and lost. The minimum/maximum may change as a result of both adding new and discarding old values and are recalculated.
Parameters:
x - the x value of the data item
y - the y value of the data item

add

public void add(double y)
Adds a new data item to the data set. This method is supported only by datasets with enabled "Use time (run number) as horizontal axis value" option (see General Properties page of DataSet in the AnyLogic IDE).
If the data set is full, the oldest item will be pushed out and lost. The minimum/maximum may change as a result of both adding new and discarding old values and are recalculated.
Parameters:
y - the y value of the data item

fillFrom

public void fillFrom(DataSet ds)
Makes this dataset an exact copy of the given original dataset.
Parameters:
ds - the original dataset

fillFrom

public void fillFrom(TableFunction tf)
Discards all existing data, sets the capacity to equal to the number of entries in the given table function and fills the dataset from the given table function.
Parameters:
tf - the table function to copy data from

update

public void update()
Should be overridden and call add( x, y ) if the user has specified the values for horizontal and/or vertical axes. By default does nothing or uses updater if was created with appropriate constructor.
Overrides:
update in class ChartItem

getXMin

public double getXMin()
Returns the minimum of all x values of all stored data items, or +infinity in case there are no items.
Returns:
the minimum of the x values or +infinity

getXMax

public double getXMax()
Returns the maximum of all x values of all stored items, or -infinity in case there are no items.
Returns:
the maximum of the x values or -infinity

getXMean

public double getXMean()
Returns the average of all x values of all stored items, or 0 in case there are no items.
Returns:
the average of all x values or 0
Since:
7.2

getXMedian

public double getXMedian()
Returns the median of all x values of all stored items, or 0 in case there are no items.
Note that this median calculation is time consuming
Returns:
the median of the x values or 0
Since:
7.0

getYMin

public double getYMin()
Returns the minimum of all y values of all stored items, or +infinity in case there are no items.
Returns:
the minimum of the y values or +infinity

getYMax

public double getYMax()
Returns the maximum of all y values of all stored items, or -infinity in case there are no items.
Returns:
the maximum of the y values or -infinity

getYMean

public double getYMean()
Returns the average of all y values of all stored items, or 0 in case there are no items.
Returns:
the average of all y values or 0
Since:
7.2

getYMedian

public double getYMedian()
Returns the median of all y values of all stored items, or 0 in case there are no items.
Note that this median calculation is time consuming
Returns:
the median of the y values or 0
Since:
7.0

size

public int size()
Returns the number of items stored in the data set.
Returns:
the number of items stored

getX

public double getX(int i)
Returns the x of the data items with a given index (which must be in the range 0..size()-1).
Parameters:
i - the index of the data items
Returns:
the x of the data items

getY

public double getY(int i)
Returns the y of the data items with a given index (which must be in the range 0..size()-1).
Parameters:
i - the index of the data items
Returns:
the y of the data items

toString

public String toString()
Returns a tab-separated multi-line textual representation of the data set containing not more than 1000 data items. If there are more items, the very last line says "... xxx more items".
Overrides:
toString in class Object
Returns:
the textual representation of the data set

getPlainDataTable

@AnyLogicInternalAPI
public List<List<Object>> getPlainDataTable()

getSVGDeltaAndMarkSynced

@AnyLogicInternalAPI
public String getSVGDeltaAndMarkSynced(boolean deltaonly)