Complex simulation modeling cannot go without algorithms that usually perform some data processing or calculations. AnyLogic supports action charts - structured block charts allowing defining algorithms graphically in the style of structured programming. We use widely known extension of an approach suggested by Dijkstra that splits algorithms into sub-sections with a single point of entry. It states that three ways of combining programs—sequencing, selection, and iteration—are sufficient to express any computable algorithm. The style reduces understanding an algorithm to understanding each structure on its own.
Action charts are very helpful since using them you can define algorithms even if you are not familiar with syntax of Java operators.
In fact, action chart visually defines a function and you can
use ordinary AnyLogic functions as before. However, using action charts gives
you one more evident benefit: it visualizes the
implemented algorithm, making it more intuitive to another
Action chart is constructed from the following blocks located on the Actionchart page of the Palette view:
Action Chart creates the basic action chart consisting of a starting point and "return" block. Defines the general action chart properties.
Code block allows inserting a code snippet performing some action into your action chart.
Decision block is the simpliest way to route the algorithm flow depending on the condition. The block has two exit branches - true and false. When the control reaches the "decision" block, it decides which branch to take. If the condition defined for this block is met, true branch is taken. Otherwise, false branch is taken.
Is used to declare local variable into an action chart. The local variable is visible only down the action chart starting from the declaration point.
Iteration loop. Loop actions are executed if the condition defined for this loop evaluates to true. The condition is evaluated once at the beginning of the loop and again before each
further iteration of the action.
|Do While Loop||
Iteration loop. Loop actions are executed if the condition defined for this loop evaluates to true. The condition is evaluated once at the beginning of the loop and again before each further iteration of the action.
Iteration loop. There are two forms of a "for loop".
Return block plays two roles: it specifies the value the action chart will return (if it's return type is not void) and also causes that value to be returned immediately.
Break block controls the flow of the loop. It stops the current iteration of the loop (and optionally quits the loop without executing the rest of the iterations).
Action charts are called in the same way as functions - you write the action chart name followed by parentheses. In the case action chart has some arguments, you should pass argument values separated by commas inside the parentheses. The values should be provided in the order they are defined in the Action Chart.