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

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 used to assign attributes across indexed array formulas. The biggest advantage of indexed arrays 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')" : {
      "constraint[p]":{ 
        "formula":"sumproduct(parts[p, ], x) - inventory[p]", 
        "upper":0
      }
    },
    ...
}

Code snippet taken from the example, indexedArray.json. Click RASON Examples -- Example Models using Arrays Loops and Tables -- Using a For Statement 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 constrast, 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.

Introducing indexed elements into array formulas enables more advanced evaluation strategies. The following example illustrates an array in which each element is evaluated using the value of the previous element.

  formulas: {
      "for(t in 2..time)": {
        "coordX[t]": { 
          dimensions: ['time'], 
          value: 1.570796, 
          formula: "coordX[t-1] + change[t]" 
        }
      }
    },
    constraints: {
      cx: { 
        formula: "abs(coordX[time] - TargetX)", 
        upper: 100
      }
    },

Code snippet taken from the example, recursiveArray.json. Click RASON Examples -- Example Models using Arrays Loops and Tables -- Using a For statement with recursive formulas.

In this example, the cx constraint is evaluated first. This constraint depends only on the final element, coordX[10] (where time = 10). As a result, RASON begins dependency tracking with coordX[10]. During that evaluation, RASON detects that coordX[10] depends on coordX[9]. When evaluating coordX[9], it finds a further dependency on coordX[8]. This backward dependency tracking continues until coordX[1] is reached.

Once coordX[1] has been evaluated, RASON can then evaluate coordX[2], followed by coordX[3], and so on, until coordX[10] is computed. At that point, all required values are available, and the constraint cx can be fully evaluated.

Back to Non-Parallel Array Formulas