Iterating through sub-scenarios
To iterate through the sub-scenarios that a particular scenario block manages, you can do something like the following:
1. In State 1, call the iterate operation to start an iteration. After you call iterate, the first sub-scenario that the block created becomes the context instance.
2. Move to State 2.
3. In State 2, determine whether you are done iterating through the sub-scenarios.
a. If the value of the complete field in the iteration ended output feed is true, then you are done iterating. Move to State 3.
b. If there are no sub-scenarios, the value of the complete field is true immediately after calling the iterate operation.
c. If the value of the complete field in the iteration ended output feed is false, then you are not done iterating. Do the following:
Do something. For example, aggregate some quantity.
Call the
next operation to make the next sub-scenario the context instance. The
iterate operation visits the sub-scenarios in the order in which they were created.
Move to
State 2.
Following are rules that perform these steps:
State 1
When true
Then iterate [MyScenarioBlock]
Then move to State 2
State 2
When complete from MyScenarioBlock(iteration ended)
Then move to State 3
When true
Then Quantity = Quantity + Quantity from MyScenarioBlock(output)
Then next [MyScenarioBlock]
Then Move to State 2
In your main scenario, you might want to start the iteration and perform the iteration in a single state. One way to do this is to use a Boolean variable that indicates whether an iteration is in progress. In the following example, iterating is a Boolean variable:
Iterate State
When not iterating
Then iterating = true
Then iterate [MyScenarioBlock]
Then continue
When complete from MyScenarioBlock(iteration ended)
Then iterating = false
Then Move to AnotherState
When true
Then Quantity = Quantity + Quantity from MyScenarioBlock(output)
Then next [MyScenarioBlock]
Then Move to Iterate State
There is no significant performance advantage of using one of the above iteration techniques rather than the other. Choose the simplest approach for your Scenario. To restart an iteration, call the iterate operation.
Note: You might find it convenient to use the Filtered Summary block instead of an iteration. The Filtered Summary block can calculate totals and averages across sub-scenarios. For any other calculations, you would need to iterate through sub-scenarios. See the
Filtered Summary v2.0 for details.