Condition When Creating a Macro
When you create a macro, you can specify a condition for each macro action. The macro action is executed only if the condition is true. In a condition to perform tests, you can use the predefined variables and the custom variables. You can import custom variables using the 'Macro variables' import interface. To disable a macro action temporarily, you can specify false in the Condition field of the macro action.
For example, a macro action is executed only if the number of selected process batches is greater than 100, using this condition:
SelectedProcessBatches>100
In macro condition, you can use the following comparators:
Comparison | Description |
---|---|
Var > x | True when the variable is greater than x |
Var < x | True when the variable is less than x |
Var = x | True when the variable is equal to x |
Var <> x | True when the variable is not equal to x |
Var >= x | True when the variable is greater than or equal to x |
Var <= x | True when the variable is less than or equal to x |
You can combine comparisons using "&" and "|" operators:
Operator | Description |
---|---|
& | And |
| | Or |
For example, the macro action is executed only if the number of selected process batches is greater than 100 and less than 200 using this condition:
SelectedProcessBatches>100 & SelectedProcessBatches<200
Predefined macro variables
Represents the result code of the last executed action. The value of this variable depends on the action.This table shows the value for each action:
Action | Value that is stored in the ActionResult variable |
---|---|
Schedule.Check Schedule | 1 in case of error, 0 otherwise |
Schedule.Run Solver | Value of SolutionCount. See the description of this variable. |
Inventory.Find Shortage.Below Minimum | Number of violating products |
Inventory.Find Shortage.Below Standard | Number of violating products |
Inventory.Find Overflow | Number of violating products |
Inventory.Batch Selection.Inflow Products | Number of selected products |
Inventory.Batch Selection.Outflow Products | Number of selected products |
Inventory.Batch Selection.All Products | Number of selected products |
For all the other actions, the ActionResult variable is reset to 0.
You can use this variable to check the result of a solver. However, the value is overwritten when another macro action is executed. It is recommended to use the SolutionCount variable instead.
SelectedProcessBatches
Represents the number of selected process batches.
SelectedTankBatches
Represents the number of selected tank batches.
SelectedProducts
Represents the number of selected products.
SelectedOrders
Represents the number of selected orders.
SolutionCount
Represents the number of solutions of the last solver. This table shows the possible values:
Solver result | Value of SolutionCount |
---|---|
No solution found | 0 |
Current solution only | 1 |
Current sequence only | 2 |
Current solution, plus current sequence | 3 |
First heuristic solution | 4 |
Second heuristic solution, and so on | 5 |
Tenth heuristic solution | 13 |
Partial solution with failed auxiliary constraints and all batches placed | Same as above |
Partial solution with failed inventory constraints and all batches placed (repair initial level, extra batches, etc.) | Same as above but negative |
Partial solution with failed critical constraints (for example, not all the batches are added) and all batches placed | 0 |
Partial solution with failed constraints and not all batches placed | 0 |
Partial solution without failed constraints but not all batches placed | 0 |
Condition | Action | Parameters | Description |
---|---|---|---|
Schedule.Run Solver | 2a - Multi-Stage Solver #1 | ||
SolutionCount=0 | Schedule.Run Solver | 3 - Multi-Stage Solver #2 | Run this solver only if no solution is provided by solver #1 |
The SolutionCount variable is useful to check the result of a solver. If no solution is found by a solver, the value of the SolutionCount variable is 0.
Because the SolutionCount variable is only set by the Schedule.Run Solver action, this can be used when calling a macro that calls a solver.
Example
Macro | Action | Result |
---|---|---|
RunSolver1 | Schedule.Run Solver "Solver1" | The ActionResult and SolutionCount variables are set to the result of the solver. |
RunTest | Automation.Run Macro "RunSolver1" | The SolutionCount value is still the result of Solver1, but the ActionResult variable is reset to 0. |