Some problems require multidimensional data. Alike some other traditional system dynamics tools, AnyLogic supports arrays. Array is a storage of numbers that may have any number of dimensions. Each dimension has finite number of indexes  subscripts.
Arrays are used when it is necessary to store a large set of
coefficients and access them or when there are multiple model layers.
The latter case is useful when you have defined a model for some
subsystem and there are other subsystems, which have the same
structure, as the first one, but other numerical parameters. One can
implement such multidimensional models making copies of the default
diagram and changing the parameters. Such approach has one great
disadvantage: if you want to change the model, you need do it so much
times, as many layers you have; the diagram grows and becomes
incomprehensive. Array allows you to create a single diagram for all
the layers. Therefore, model remains compact, and changes you make will
affect the whole model, but not a single layer.
For example, you create a model of a nation’s health, describing some social or health processes in respect to different groups of population. You may need to separate people by three characteristics: gender, age group, and social group. This example fits well in the array concept. Instead of dealing with multiple models describing different groups of people, you can just define an array with such enumerations: Gender(male, female), Age(child, teenager, adult, aged), and SocialGroup(wealthy, middleclass, deprived).
The following variables can be made arrays in AnyLogic: stock, flow, dynamic variable, parameter
Demo model: Bass Diffusion Arrays
Array variables in the graphical editor
Some system dynamics variables of type array (stock variables, parameters and constant flow and dynamic variables) need to be initialized.
AnyLogic provides easy and flexible tool for defining initial values of array elements. This is done because initialization of multidimensional arrays is nontrivial task, first of all as there is no way of intuitive visual representation of multidimensional data.
As arrays can have unlimited number of dimensions, each one possibly containing a great amount of elements, the sole convenient way of defining initial values of an array is layering this array (i.e. partitioning this array to layers) and successive initialization of each resulting layer.
You define a layer by fixing values in all but two dimensions of an array. When we say fix we mean that you select one particular element in the dimension. Thereby each fixation narrows the list of array dimensions by one dimension. Having finished narrowing dimensions to two ones, you get an ability to represent data of the resulting twodimensional layer in tabular form. To define initial values for all array elements you need to go over all combinations of elements of nonfixed dimensions.
To open the editor of array initial valuesTo make clear how to initialize array elements, let us illustrate it by a pair of simple examples.
To initialize all
array elements with one value
Assume you are creating a model studying population dynamics in LA and NY. Let's conditionally categorize people by three characteristics: gender, age and region. These characteristics are comfortably described using dimensions  enumerations: Gender(male, female), Age(child, teenager, adult, aged) and Region(LA, NY).
Let's study how to initialize threedimensional array Population[Region, Age, Gender] using our editor of array values:
To initialize all
array elements with one value
You can check whether you have defined initial values correctly by inspecting variable value at the model runtime:
The resulting array's initialization string is displayed in the text form in the Initial value field (or Default value, in the case of a parameterarray). If you need to initialize some another array with similar values, you can simply copy this string to the analogous property of that array and then modify the required values using the editor of array values.
There is a number of ways you can define the equation (or equations) for an array stock, flow or dynamic variable.
In the simplest case when the equation is the same for all elements
of the array,
you need only one equation field, where you type the expression,
possibly referencing the dimensions of
the array variable. For example, if the stock Population
is array with dimensions:
Region = {NORTH, SOUTH} and Gender = { MALE, FEMALE } the equation may look like:
d(Population[Gender,
Region])/dt = Births[Gender, Region]Deaths[Gender, Region]
To set the same
equation for all array elements
The equation above is mapped to a very simple loop construct looking
like:
for( r : Region )
for( g : Gender )
Population[ r, g ] = Births[ r ] – Deaths[
r, g ]
If birth rate is the same even in different regions, you can use a
scalar variable Births in the same
equation:
There
are cases however when equations are different for different elements
of the array or different element sets. Suppose in the population
example above people do intensively migrate out of NORTH region, but migration out of SOUTH region is negligible. Then there will be
two equations for the stock Population:
d(Population[Gender,
SOUTH])/dt = Births[SOUTH]  Deaths[Gender, SOUTH]
d(Population[Gender,
NORTH])/dt = Births[NORTH]  Deaths[Gender, NORTH] – OutMigration
To define several
equations for different subarrays of an array variable
In
some cases you need to refer to a different index of an array in the
equation. Suppose you are modeling an ageing chain and your stock Population is an array with one dimension Age = { 0 .. 99 }.
The inflow for an element of the array is the outflow of the element
with the previous index for all element but 0, and for the element 0
the inflow is Births. To implement this
you may define two subdimensions of Age:
Age0 = { 0 } and AgesAllBut0
= { 1 .. 99 } and write:
d( Population[ Age0 ] )/dt =
Births  Deaths[ Age0 ] – Ageing[ Age0 ]
d( Population[ AgesAllBut0 ] )/dt =
Ageing[ AgesAllBut0 – 1 ]  Deaths[ AgesAllBut0
] – Ageing[ AgesAllBut0 ]
To understand how it works it makes sense to map this into loop
construct:
for( a : 0 }
Population[ a ] = Births  Deaths[ a ] –
Ageing[ a ]
for( a : 1..99 }
Population[ a ] = Ageing[ a1 ]  Deaths[ a ] –
Ageing[ a ]
As you can see, the dimension names are simply substituted with loop
indexes in the equations. This gives you a high degree of flexibility
when you define equations. You can define the dependency of element
with a certain index on the element of same of another array having
arbitrary other index.
AnyLogic supports a set of functions you can use to perform operations over arrays.
Sometimes you need performing aggregation operations on elements of arrays. Aggregation functions over arrays are listed in the table below.
Function 
Description 
double average() 
The mean value of the aggregated elements:

boolean hasNegativeValues() 
Checks if there are any negative elements in the hyper array. Returns true if at least one element is negative, otherwise false. 
double max() 
Maximum value of the aggregated elements. 
double min() 
Minimum value of the aggregated elements. 
double prod() 
The product of the elements: 
int size() 
Returns the total number of elements in the hyper array. 
double stddev() 
Standard deviation: 
double sum() 
The sum of the aggregated elements:

You
can perform calculations on a subset of an array. In this case you
should enumerate the dimensions forming the subarray as function
arguments. For example, if you have an array people
with dimensions ( Region, Gender, AgeGroup ),
calling:
will calculate the number of adults of both genders in the north region.
The
following set of functions allows you to manage the values of elements
in a hyper array. You can use indexes to define to which elements a
value should be added or subtracted from and the parameters to define
how much exactly.
int INDEX_CAN_VARY
is a special constant that, being placed at an index position, tells
the methods that perform operation over subsets of hyper array elements
that they can vary the corresponding index. Other indexes are fixed.
INDEX_CAN_VARY can be used to increment,
to decrement, or to multiply across all the elements of a particular
dimension.
Parameters:
indexes  the array of indexes, INDEX_CAN_VARY for varying ones
value  the value to add to and to
subtract from array elements
factor  the factor to apply to array
elements
Function 
Description 
void increment(int... indexes) 
Increments ( 1) element(s) with the given index(es). 
void incrementBy(double value, int... indexes) 
Increments element(s) with the given index(es) by the given amount ( value). 
void decrement(int... indexes) 
Decrements (1) element(s) with the given index(es). 
void decrementBy(double value, int... indexes) 
Decrements element(s) with the given index(es) by the given amount (value). 
void multiply(double factor, int... indexes) 
Multiplies element(s) with the given index(es) by the given factor. 
Please refer to AnyLogic API Reference to find more information about functions syntax and parameters.