Agent can contain variables. Variables are generally used to store the results of model simulation, to model some data or object characteristics, changing over time.
A collection represents a group of objects, known as its elements. They are used for defining data objects that group multiple elements into a single unit. Collections are used to store, retrieve, and manipulate aggregate data. Typically, they represent data items that form a natural group, such as a queue (in this case elements represent people waiting in a queue), or an autopark (elements are trucks), or a telephone directory (a collection performs mapping of names to phone numbers).
In the function body, we define the for loop. This loop does not always iterate through one agent population but analyzes the type of the service request and iterates through the trucks population if it is the request for the auto transport (by checking the condition request.type == AUTO ). If the condition is false, it means that a helicopter is required, so the loop iterates through another population: helicopters.
Inside the loop, we check whether the currently iterated agent is idle or not by using the agent's function inState(). If the control of the agent's statechart is currently in the AtCenter state, it means that we have found the idle transport. In this case the line return t; ends the function execution and returns the found value (idle vehicle). If there is no idle transport at all, this line will not be executed, so after the for loop the next line of code will be executed: return null; This way we tell the model that the truck was not found (the result is null, the idle transport does not exist).
In AnyLogic you enter pieces of code in numerous properties of various model elements. It is important to understand exactly where you are writing the code (which agent type and method it belongs to) and how you can access other model elements from there.
The elements of the same agent type are accessed simply by their names.
To access an element of an embedded object you should put a dot "." after the embedded object name and then write the element name. For example, to get to the state AtCenter that belongs to the statechart contained in Transport, from within Main, we call Transport.AtCenter in Main.
Reference model: Maintenance - Phase 4
Next let us configure Turbine.
Phase 3. Defining Transport agent behavior
Phase 5. Defining Turbine behavior