Phase 4. Defining Maintenance Center behavior

Define the transport requests to the maintenance center

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).

  1. Open Main diagram. Add two Collection elements from the Agent palette.
  2. The collections called aviaRequests and autoRequests are both of LinkedList Collection class and ServiceRequest Element class.

We will define a function which will search for the idle transport to fulfill the maintenance task.

Define the logic of the transport management

  1. Drag the Function element from Agent palette into Main diagram.
  2. Name the function findTransport.
  3. This function searches for an idle transport. If the transport is found, the function should return it. So select the Returns value option and set the function to return the value of Type Transport.
  4. The function should analyze the type of the incoming service request. This requires adding one function argument - we need it to pass the service request to the function. Expand the Arguments section of the function properties and define the request argument of Type ServiceRequest in the table.
  5. Finally, define the function algorithm itself. Expand the Function body section of the properties and type the Java code there as shown in the figure below.

    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