Skip to content

Arrays

An array is a grid of values that belongs to the whole model, for when a single variable is not enough: a table of setup times, a matrix of travel distances between locations, a price list by product number. Like a variable an array is global; unlike a variable it holds many values that you reach by position.

Define arrays in the Logic Builder, on the Arrays tab.

The Arrays tab in the Logic Builder

  • Name: prefixed r_, for example r_SetupTime.
  • Type: Integer, Real, Date, or Descriptive.
  • Dimensions: an array can be one, two, or three dimensional. Set the size of each dimension you use and leave the others at zero: a single row of ten is 10, a ten-by-five grid is 10 × 5.
  • Initial: a starting value applied to every cell.
  • Statistics: track how the cells change during the run for the Arrays report.

You can also import an array’s contents from a file (Excel or CSV) instead of typing them in, which is the easy way to load a large lookup table.

Read or write a cell by its position in logic and expressions, for example a setup time looked up by the product number.

You can also step a single cell up or down in place with INC and DEC, the same way you would a counter variable. INC r_Array1[5] adds one to the fifth cell and DEC r_Array1[5] takes one away, so a running tally can live in an array indexed by type or by location without reading the cell, adding, and writing it back.

Stepping one array cell up with INC in the code editor

A single row indexed by product number returns a machine’s setup time without a chain of IF tests. Fill r_SetupTime once, then read the cell for the entity’s product:

SET a_Setup TO r_SetupTime[a_Product]
TIME a_Setup min

A two-dimensional array is a grid, so r_Distance[from, to] holds the distance between any two locations and one array covers every pair:

SET a_Miles TO r_Distance[a_From, a_To]
TIME a_Miles / v_Speed hr

Keep unit prices in r_Price and multiply by the quantity the entity carries. Editing the table reprices the model without touching any logic:

SET a_Price TO r_Price[a_Product]
SET a_LineTotal TO a_Price * a_Qty

Step one cell in place to keep a live count per location. Add on the way in and take away on the way out, and the array holds work in progress without reading, adding, and writing it back:

// as an entity enters a location
INC r_WIP[a_Loc]
// as it leaves
DEC r_WIP[a_Loc]

After a run, the Arrays report shows each array’s size, how many cells were used, and its value range, with a drill-down into the contents and their changes.