Using For Loops
It is imperative that a user understand the difference between for() and loop()
when using the RASON modeling language. For() is an attribute to each formula in its block. Only
the determined formula (as a precedent in the dependency chain) and only a specific index combination is computed by
for().
Conversely, loop() behaves like a typical programming language loop. All formulas must execute in the listed
sequence for a given index combination. Indices are iterated as they appear as index columns in a table. The rightmost
(the last in the list) index changes more rapidly. The leftmost (the first in the list) index changes less rapidly.
When using a loop() statement, many dependencies are resolved at parse time which results in an easier solving model.
In the example below, there is only one index t, which is iterated from 2 to 10. For each index value, all
formulas in the loop block are evaluated in the sequence as they are entered.
formulas: {
"loop(t in 2..time)" : {
"direction[t]": { formula: "direction[t-1] + change[t]" },
"Vx[t]": { formula: "Vx[t-1] + COS(direction[t])*blast[t] + x1grav[t-1] + x2grav[t-1]" },
}
}
|