Conditional Statements
ProModel allows you to use a variety of statements that add conditions to your Logic. Use these statements if you want an action to occur only in specific circumstances.
If Then Statements
If and Then are statements are used together and execute a particular action only when a specified Boolean expression is true.
To use an If Then statement, add the syntax...
If <Boolean expression> Then <statement>
...where Boolean expression
is the true or false condition to evaluate, and statement
is the action that is executed if the Boolean expression is found to be true.
You may also use the statements And
and Or
to include multiple Boolean expressions.
If <Boolean expression 1> And <Boolean expression 2> Then <statement>
If <Boolean expression 1> Or <Boolean expression 2> Then <statement>
To include multiple statements, use braces to improve code clarity.
{
If <Boolean expression> Then
<statement 1>
<statement 2>
<statement 3>
}
If Then Example
Suppose you have defined an Attribute for your Project Entity that indicates whether a particular Project Entity is long or short: if aProjectLength = 0, the Project is short, and if aProjectLength = 1, the Project is long. You also have a Location where Projects are inspected, InspectionTable, and its Time in the Flow is set to 5 min. However, you think it would be more realistic if long Projects took more time at InspectionTable, so you define the statement...
If aProjectLength = 1 Then Wait 10 min
...in the InspectionTable Logic. Now, the statement evaluates aProjectLength's value for each Entity that enters InspectionTable. If the Attribute aProjectLength = 1 for a particular Entity, the Entity waits at the InspectionTable for an additional 10 min on top of the 5 min defined in the Flow settings, for a total of 15 min. If the Attribute aProjectLength = 0 for a particular Entity, the statement is not executed and the Entity defaults to waiting 5 min, since that is the time defined in the Flow settings.
For more information on the statement used in this example, see Wait.
Else
The Else statement adds an additional action to an If…Then Statements statement that executes if the Boolean expression is false.
To add an Else statement to an If Then statement, add the syntax...
If <Boolean expression> Then <statement 1> Else <statement 2>
...where Boolean expression
is the true or false condition to evaluate, statement 1
is executed if the Boolean expression is found to be true, and statement 2
is executed if the Boolean expression is found to be false.
You may also use braces to improve the clarity of your Logic or to add additional statements.
{
If <Boolean expression>
Then
<statement 1>
<statement 2>
Else
<statement 3>
<statement 4>
}
Else Example
Suppose you have defined a Variable in your model to represent how many Entities have been completely processed by the system, vCompleted
.
To display a message every time an Entity is completed, and once 100 Entities have been completed, stop the simulation.
To achieve this outcome, define the statements...
Inc vCompleted
{
If vCompleted = 100 Then Stop
Else Display vCompleted “ Entities have been completed”
}
...in the final Location. Every time an Entity enters the final Location, the vCompleted value increments by 1. The value for vCompleted is evaluated by the If Then...Else statement. If vCompleted = 100, the simulation stops. If vCompleted is any value other than 100, a message displays showing the current vCompleted value, along with the text “Entities have been completed”.
For more information on the statements used in this example, see Inc.
While
The While statement repeatedly executes an action when a specified Boolean condition remains true.
To use the While statement, add the syntax...
While <Boolean expression> Do <statement>
...where Boolean expression
is the true or false condition and statement
is the executed action as long as the Boolean expression remains true.
The Boolean expression is evaluated for each statement iteration.
You may also use braces to improve the clarity of your Logic or to add additional statements.
{
While <Boolean expression> Do
<statement 1>
<statement 2>
<statement 3>
}
While Example
Suppose you have a Flow where the second half moves much faster than first half.
For this reason, you want to let 100 Entities pile up in the first part's last Location (a Storage Location) before allowing them to the second part, since you save money by not running the second half during that time.
You then want the Entities to pass through the Storage Location freely, since the model's second half is fast enough to process the 100 Entities and all the new Entities that come after without falling behind.
To achieve this result, start by defining a Variable to represent how many Entities are in your Storage Location, vStorage
.
Next, define the statements...
Inc vStorage
While vStorage < 100 Do Wait 10 min
...in the Storage Location Logic. Every time an Entity enters the Storage Location, the Inc statement increases the vStorage value. As long as vStorage is less than 100, the While loop continues to execute, keeping the Entities in the Storage Location due to the Wait statement. Once vStorage is 100 or greater, the While loop no longer executes and the Entities pass through the Storage Location directly after being processed.
Until
The Until statement repeatedly executes an action up to a point where a specified Boolean expression becomes true.
To use the Until statement, add the syntax...
Do <statement> Until <Boolean expression>
...where statement
is the executed action and Boolean expression
is the true or false condition to evaluate.
You may also use braces to improve the clarity of your Logic or to use additional statements.
{
Do
<statement 1>
<statement 2>
<statement 3>
Until
<Boolean expression>
}
Until Example
Suppose you have a Flow where the second half moves much faster than first half.
For this reason, you want to let 100 Entities pile up in the first part's last Location (a Storage Location) before allowing them to the second part, since you save money by not running the second half of your model during that time.
You then want the Entities to pass through the Storage Location freely, since the second half is fast enough to process the 100 Entities and all the new Entities that come after without falling behind.
To achieve this result, start by defining a Variable to represent how many Entities are in your Storage Location, vStorage
.
Next, define the statements...
Inc vStorage
Until vStorage > 100 Do Wait 10 min
...in the Storage Location Logic. Every time an Entity enters the Storage Location, the Inc statement increases the vStorage value. Up to the point where vStorage is greater than 100, the Until loop continues to execute, keeping the Entities in the Storage Location due to the Wait statement. Once the vStorage value is 100 or greater, the Until loop no longer executes and the Entities pass through the Storage Location directly after being processed.
Break
The Break statement interrupts a While loop or an Until loop when a specified condition is met. Use the Break statement when you want to define additional Boolean expressions that end a While loop or Until loop on top of the Boolean expression included in the initial While or Until Logic.
To use the Break statement, include it within a While loop or an Until loop. The Break statement is usually also inside an If Then statement.
{
While <Boolean expression 1> Do
<statement>
If <Boolean expression 2> Then Break
}
Once a Break statement is executed, the Logic moves on to the next statement defined after the While or Until loop. If a Break is encountered outside any loop, ProModel exits the entire Logic.
Break Example
Suppose the statements...
{
While Var1 > 5 Do
Wait 10 min
If Attr1 = 10 Then Break
}
Display “Loop has ended”
...are defined in the Location Logic. Because of how the While statement is defined, the statement within the While loop, Wait 10 min, continues to execute as long as the Var1 value is greater than 5. Once the Var1 value is less than 5, the While loop ends. Additionally, because of the Break statement, the While loop also ends if the Attr1 value is equal to 10. Once the While loop ends for either reason, the Logic moves on to the next statement after the loop, and so the message “Loop has ended” displays.
For more information on the statements used in this example, see Wait and If Then Statements.
BreakBlk
The BreakBlk statement exits from the innermost statement block. The next statement to execute immediately follows the End statement of the innermost statement block. If a BreakBlk is executed outside any statement block, ProModel exits the logic completely.
To use the BreakBlk statement, add the syntax...
BreakBlk
...to exit from the innermost statement block when the statement is invoked.
Begin and End
The Begin symbol { defines a statement block with a corresponding End symbol }. Begin and End are primarily used in conjunction with other control statements such as If Then and Do While. Every Begin symbol must pair with an End symbol.
To use the Begin and End symbols, add the following syntax...
{
<logic>
}
..where logic
is any logic statement collection that must be contained by the Begin and End symbols.
Route
The Route statement immediately executes a routing block for the processing Entity before finishing any remaining processing logic. The process does not continue until all Entities being routed for the particular block have begun executing their move logic and pass control back to the process. The processing logic may contain several Route statements. These statements may be selected individually using If Then statements, or they may be processed sequentially, with or without other process statements in between. If any Route statement appears in a process logic, then ProModel assumes all routing for that process are activated by the user and therefore does no automatic routing. If no Route statement appears in the processing logic, then all routing blocks are executed automatically once processing logic is complete.
The Route statement is most often the last statement in the process logic and is used with If Then statements to make routing decisions based on complex logic that is not available through other ProModel features (such as system functions or the User Condition routing rule). Route, when used with If Then properly, ensures that only one of the routing blocks is activated.
This statement can be used to route one or more Entities and leave behind a “ghost” Entity that processes the remaining logic after the route statement. The “ghost” Entity is also referred to as the parent Entity. The child Entity takes the route specified by the Route statement. If the child Entity cannot go to the next Location and is blocked, the parent Entity is also blocked and does not continue logic execution until the child Entity is no longer blocked.
To use the Route statement, add the syntax...
Route <expression>
...where expression
is a numerical expression, resulting in an integer, which determines the routing block that the Entity takes.
The expression is evaluated every time it is encountered, allowing the chosen block to vary during the simulation.
Return
The Return statement sends a value from a subroutine to the logic that called the subroutine. In the same way that parameters send information from the calling logic to the subroutine, Return sends information from the subroutine to the calling logic. After the Return statement executes, no more logic in the subroutine executes. When subroutines return values, the Return statement must be followed by an expression.
When used in logic that is not a subroutine, Return functions like a very powerful Break or BreakBlk statement. Where Break and BreakBlk exit only the innermost loop or statement block, Return exits the logic completely, no matter how deeply nested inside loops and statement blocks.
To use the Return statement, add the syntax...
RETURN {<expression>}
...where expression
is the value to return.
This expression must be on the same line as the Return statement.
If a subroutine was activated, then the return value is ignored.