AnyLogic 9
Expand
Font size

Data set

Data Set is able to store 2D (X,Y) data of the double type and keep the current minimum and maximum of the stored data for each dimension. The data set keeps a limited number of the latest data items.

You can use time as an X value of the data set, that is, associate an observed value with a time moment when it was sampled. A queue length, a vehicle coordinate, a fluid level are the examples of such values. Such a data set is called timed. Alternatively, you can record the dependence of one value on another — such data sets are called phased.

Demo model: Dataset for Cost Data Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).
Adding a new item when the dataset is full will cause the oldest sample to be lost and, if the lost item contained a minimum or maximum, will initiate a new min/max search, which can be time consuming for large data sets.
Therefore, for large data sets, it is recommended that the size is not less than the number of items you plan to add.

While the model is running, you can view and optionally copy the collected data to the clipboard so that later on you can paste it into another application (such as Microsoft Excel) to perform statistical analysis.

To create a data set

  1. Drag the  Data Set element from the  Analysis palette into the graphical editor.
  2. Go to the Properties view.
  3. To make the data set timed, select the Use time as horizontal axis value check box and specify the dynamically evaluated expression to obtain the current data set value in the Vertical axis value box, or
    To make the data set phased, clear this check box and specify expressions that evaluate both Horizontal axis value and Vertical axis value.
  4. A data set may have a limitation on a maximum number of points it can store. Set the tail size in the Maximum number of samples property.
  5. Finally, choose how you want this data set to be updated.

Properties

General

Name — The name of the data set. The name is used to identify and access the data set.

Show name — If selected, the name of the data set is displayed on a presentation diagram.

Ignore — If selected, the data set is excluded from the model.

Use time as horizontal axis value — If selected, the data set is timed, that is, when new samples are added to the data set, the Y-value is evaluated using the specified Vertical axis value expression, while the X-value takes the current model time value.
Otherwise, the data set is phased, that is, both the X- and Y-values of the data set are evaluated using the specified expressions (Horizontal axis value and Vertical axis value, respectively).

Horizontal axis value — [Enabled if Use time as horizontal axis value is not selected] The expression that is dynamically evaluated to obtain the current X-value of the phased data set.

Vertical axis value — The expression that is dynamically evaluated to obtain the current Y-value of the data set.

Maximum number of samples — A “tail size” of the data set. Defines a number of the latest data items this data set will keep.

Data update

Update data automatically — If selected, new data samples are added automatically starting at the exact time (select the option Use model time) or date (select Use calendar date) specified below and repeating with the specified Recurrence time. Otherwise, you should add new samples by yourself dynamically.

Expert

Visible — If selected, the data set is visible on a presentation at runtime.

Functions

Populating the data set
Function Description
void add(double x, double y) Adds a new data item to the data set.

x — the X-value of the data item.
y — the Y-value of the data item.
void add(double y) Adds a new value to the data set. This function is supported only by datasets with the option Use time (run number) as horizontal axis value selected. Calling this function for other datasets will throw runtime error.

y — the Y-value of the data item.
void fillFrom(DataSet ds) Makes this dataset an exact copy of the given original dataset.

ds — the dataset to copy.

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

tf — the table function.
Retrieving data
Function Description
double getXMin() Returns the minimum of all X values of all stored data items, or infinity in case there are no items.
double getXMax() Returns the maximum of all X values of all stored items, or -infinity in case there are no items.
double getXMedian() Returns the median value of all X values of all stored items, or 0 in case there are no items.
double getXMean() Returns the mean value of all X values of all stored items, or 0 in case there are no items.
double getYMax() Returns the maximum of all Y values of all stored items, or -infinity in case there are no items.
double getYMin() Returns the minimum of all Y values of all stored items, or infinity in case there are no items.
double getYMedian() Returns the median value of all Y values of all stored items, or 0 in case there are no items.
double getYMean() Returns the mean value of all Y values of all stored items, or 0 in case there are no items.
double getX(int i) Returns the x of the data items with a given index (which must be in the range 0..size()-1).

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

i — the index in the range 0..size()-1.
int size() Returns the number of items stored in the data set.
Resetting data
Function Description
void reset() Discards all stored data and their minimum/maximum.
Capacity
Function Description
int getCapacity() Returns the capacity of the data set.
void setCapacity(int newcapacity) Resizes the data set according to the new capacity.

newcapacity — the new size of the data set.
Duplicating values
Function Description
void allowDuplicateX(boolean yes) Sets the way of handling two subsequent calls of add() with identical X-values.

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

yes — if true, two entries in the dataset will be created, otherwise second item will override the last one.
boolean duplicateXAllowed() Tests if subsequent data items with same X-values are allowed in this dataset. Returns true if yes, otherwise false.
boolean duplicateYAllowed() Tests if subsequent data items with same Y-values are allowed in this dataset. Returns true if yes, otherwise false.
Textual representation
Function Description
String toString() Returns a tab-separated multi-line textual representation of the data set containing not more than 1000 data items.
How can we improve this article?