Introduction to RASON
About RASON Models and the RASON Server
Rason Subscriptions
Rason Web IDE
Creating and Running a Decision Flow
Defining Your Optimization Model
Defining Your Simulation Model
Performing Sensitivity Analysis
Defining Your Stochastic Optimization Model
Defining Your Data Science Model
Defining Custom Types
Defining Custom Functions
Defining Your Decision Table
Defining Contexts
Supported FEEL Functions
Using the REST API
REST API Quick Call Endpoints
REST API Endpoints
Decision Flow REST API Endpoints
OData Endpoints
OData Service for Decision Flows
Creating Your Own Application
Using Arrays, For Loops and Tables
Organization Accounts

Indexed array formulas (For Statements)

The purpose of indexed array formulas is to enable more flexible and scalable model definitions. In the RASON modeling language, the for() construct is not executed as a procedural loop as it would be in a typical programming language. Instead, for() is a declarative construct that defines how an indexed array formula is computed. The sequence of formulas inside a for does not matter; the construct simply specifies how to compute the array formula across its indices.

The main purpose of for is to define model functions in a compact form. Each formula in the body of a for is an independent array formula, similiar to an array formula in Excel. If a function in the model depends on an array formula defined with for, that array formula is computed in its entirety by iterating overs its indices, without regard to any other formula in the section.

An indexed array formula may also depend on other formulas, just as in Excel. In this case, the system first determines the dependency tree, computes all precedent formulas, and then evaluates the array formula itself. As a result, formulas defined with for() behave like Excel array formulas, which are evaluated based on dependencies rather than execution order.

The primary advantage of indexed array formulas is that they support reverse-mode evaluation, which is significantly faster than forward evaluation. The following example introduces the basic concepts of indexed array formulas.

  
    ...
    "for(p in 'part')" : {
      "cons[p]":{ 
        "formula":"sumproduct(parts[p, ], x) - inventory[p]", 
        "upper":0
      }
    },
    ...
}

Code snippet taken from the example, Using For (Indexed Arrays). Click RASON Examples -- Example Models using Arrays Loops and Tables to open.

Depending on the formula, the evaluation result may be a 1-D array (horizontal or vertical), 2-D array, or a multi-dimensional table.

Indexed arrays do not behave the same way as parallel arrays. A parallel array is evaluated only once and produces values for all result elements simultaneously. In contrast, an indexed array is evaluated only for the specific index values that are explicitly defined, rather than automatically for every element of the array. In the example above, the formula uses a single index [p], but in general, indexed array formulas often involve more than one index.

As mentioned above, the "for (p in 'part')" statement in the RASON modeling language does not behave like a "for" loop in a traditional programming language. In RASON, for() is a declarative construct that defines the indices and their index sets associated with an array formula; it does not assign or iterate over index values. Although for() defines all valid index values, RASON evaluates an indexed array formula only for the specific index values that are actually needed. The model does not evaluate formulas sequentially; instead, it starts from the requested result and computes only the formulas required to produce that result. In indexed array formulas, each evaluation is identified not just by the formula itself, but also by the specific index value being requested.

This example is intentionally simple. It does not depend on any other formulas. Because the indexed array includes an upper bound, the code belongs in the constraints section. One constraint is created for each value of p in the part index set. A for() definition can also appear in the formulas section. To evaluate the constraint for a specific part, such as "tube", set p = "tube". RASON then evaluates the formula only for that part and ignores all other parts.

Back to Non-Parallel Array Formulas