Using Arrays, For, Loops and Tables
The following topics demonstrate how to use for-loops with both 2D arrays and tables in the RASON modeling language.
Arrays, for-loops, and tables can be used throughout a RASON model to compute intermediate results, define constraints and objectives in optimization and
simulation optimization models, and define uncertain functions in simulation and simulation optimization models. These constructs may appear in sections
such as formulas (for intermediate calculations), constraints (to define optimization constraints), uncertainFunction
(to define uncertainty in simulation models), or anywhere else where tables, array formulas, and for-loops improve efficiency, readability, and structure.
Internally, RASON stores data as scalars or 2D arrays. Arrays are iterated using numeric index ranges such as 1..dim_size.
Tables are a distinct data structure from arrays. A table is defined using one or more index columns based on index sets and a single value column.
Tables are iterated using index-set values rather than numeric positions. Tables may be defined manually in the data section using index sets, or populated from data sources.
When tables are created from data sources, their index sets are derived from the data-source index columns, and because a table supports only one value column, a specific value column must be selected.
A Loop is a sequential construct: all formulas inside it are executed in the order they are written. In contrast, a For statement is declarative and vectorized,
similar to Excel array formulas. RASON first analyzes dependency (precedent) relationships and then evaluates the formulas inside a For statement across all indices as an array.
Loops and For statements are supported in the following sections (using the formulas property): preprocessor, formulas, constraints,
uncertainFunctions, and objective. They are not supported in the uncertainVariables section or in any box definition section.
In the objective section, only a single objective expression is allowed; therefore, only aggregation constructs such as sum may be used. General loops and For statements are not
permitted. In addition, Loop and For statements cannot be used in sections that define model structure.
|