Array and Agent Functions

Use these functions and selectors to work with model arrays and Agent Modules in ordinary model equations.

Start with an array reference

An array reference can select one element, a range, a saved element set, or all elements of a dimension.

GoalSyntaxExample
One elementVariable[Dimension=Element]Sales[Region=East]
Inclusive rangeVariable[Dimension=Start:End]Sales[Region=East:West]
Saved element setVariable[Dimension in SetName]Sales[Region in Domestic]
All elementsVariable[Dimension!]Sales[Region!]
Current target elementVariable[Dimension]Sales[Region]

Select ranges and neighbors

The compact range form is required. Write State[Dimension="1":"2"], not State[Dimension="1":Dimension="2"].

Aggregate selected elements

Use Dimension! or a range when an aggregate must receive multiple elements.

SUM(State[Region!])
MEAN(Converter_1[Dimension_1, Dimension_2!])
SUM(Converter_1[Dimension_1!, Dimension_2!])

In an array target that shares a source dimension, the bare dimension name follows the current target element. Dimension! still selects every element. A selector that resolves to multiple values must be inside an aggregate; a scalar equation cannot hold a group of values.

Conditional aggregates

SUMIF, COUNTIF, and MEANIF test each selected element against a condition.

SUMIF(Sales[Region in Domestic], Sales > 15)
SUMIF(Sales[Region!], Active[Region] > 0)
MEANIF(Sales[Region!], Sales > 15)

Within the condition, the aggregated variable name is the current selected element. Aligned selectors, such as Active[Region], refer to the matching dimension value. MEANIF returns 0 when no elements match.

Build and reuse array values

Assign an array equation

Use a top-level ARRAY(a, b, c, ...) equation to assign values in dimension order. The argument count must equal the target element count.

ARRAY(10, 20, 40)
INTEG(0, ARRAY(5, 6, 7))

The second form supplies array Stock initial values.

Broadcast a lower-dimensional value

Use BROADCAST(array_selector) to intentionally repeat a single selected value across extra target dimensions.

BROADCAST("2_Dimension"[Dimension_1, Dimension_2=Element_1])

Without BROADCAST, a lower-dimensional source reference remains invalid rather than repeating silently.

Canonical array functions

FunctionUseExample
SELFCurrent array-element context.SELF * Growth_Rate
SIZE(array_or_dimension)Whole-array size; scalar values are clamped to at least 0.SIZE(Regional_Sales)
PREVIOUS(value)Previous-step state boundary; uses value when no prior state exists.PREVIOUS(Inventory)
ENDVAL(value)End/previous-value boundary with the same native behavior as PREVIOUS.ENDVAL(Inventory)
ARRAY(a, b, ...)Top-level array assignment, or sum of arguments in a scalar expression.ARRAY(10, 20, 40)
BROADCAST(array_selector)Explicitly repeat one lower-dimensional selected value.BROADCAST(Source[Region])
ARRAYSUM, ARRAYMEAN, ARRAYMIN, ARRAYMAXAggregate arguments or a normalized whole-array value.ARRAYMEAN(Regional_Sales)
COUNTCount arguments or selected elements. Alias: ARRAYCOUNT.COUNT(Sales[Region=East:West])
SUMIF, COUNTIF, MEANIFConditionally aggregate selected elements.COUNTIF(Sales[Region!], Sales >= 40)
MEDIAN, PRODUCT, ANY, ALL, STDEVAggregate arguments or selected array elements.STDEV(Sales[Region=East:West])
ARRAYELEMENT(index, a, b, ...)Select a one-based value argument. Aliases: ELEMENT, ELM, AT.ARRAYELEMENT(2, North, South, West)

Query an Agent Module

Use AGENT* functions in ordinary model variables to expose scalar values from a managed Agent Module. Quote the Agent Module and field labels.

FunctionReturnsExample
AGENTINDEXCurrent one-based array element index; 0 outside array context.AGENTINDEX
AGENTCOUNT("Agent Module")Active managed-agent count.AGENTCOUNT("Households")
AGENTSUM("Agent Module", "Field" [, "Element"])Sum of a scalar field or selected element.AGENTSUM("Households", "Moved")
AGENTMEAN("Agent Module", "Field" [, "Element"])Mean field value.AGENTMEAN("Households", "Similar Fraction")
AGENTMIN("Agent Module", "Field" [, "Element"])Minimum active-agent field value.AGENTMIN("Households", "Wealth")
AGENTMAX("Agent Module", "Field" [, "Element"])Maximum active-agent field value.AGENTMAX("Households", "Wealth")

POPULATIONCOUNT, POPULATIONSUM, POPULATIONMEAN, POPULATIONMIN, and POPULATIONMAX remain compatibility aliases for older projects. They do not create a second population system.


Yano Simulator Help — Version 0.2.0, Build 20260809