Phase 4. Defining Maintenance Center behavior

We will create an actionchart where the maintenance center decides what transport is needed, a truck or a helicopter, and checks if they are available to perform maintenance.

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. AnyLogic supports two types of variables – variables and collections.  

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

Define the logic of the transport management

  1. Open MC diagram. We will add the process diagram here using Actionchart palette elements.
  2. First drag the Action Chart  element from the palette into the graphical editor.

  3. Call it findTransport. This actionchart Returns value of type Transport. Its arguments should be specified in the table below: request argument of Type ServiceRequest:

  4. Next, insert the element For loop  in our findTransport actionchart. When working with actionchart elements, make sure you add them in the right place:

  5. The type of this for loop is Collection iterator. Specify Item and Collection as shown in the figure below - it depends on the request if a truck or a helicopter is needed. When finished, you can resize the element for the text to fit in the form.

  6. We need to add Decision  that will check if the transport is available. The condition says that the transport item should be in the AtCenter state from the statechart we have created on  Transport. Note that now the element displays the Label text in the diagram:

  7. Insert Return  element in the true branch. Tell it to return t. As the last step select the actionchart return statement for false and specify Return: null.

  8. This actionchart will check if there is an available truck or helicopter at the maintenance center.

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, we referred to the function getX() of the maintenance center when creating the actionchart on  Main: center.getX(). If the embedded object is replicated, you should say which one exactly you want to access. 

To access the object that shares the container with the current one, first get up to the container object and then get down to another agent.

To access the container of the current object you should call <its name>. Note that there is a special element,  Link to upper level agent, on every agent type diagram whose agents live in that agent type (here it is Main). The link is called after this upper level agent type and allows us to access it easily by simply referring to its name. For instance, to get to the element trucks[..], which is contained in  Main, from within  MC, we call main.trucks in MC

Reference model: Maintenance - Phase 4

Next let us configure  Turbine.


          Phase 3. Defining Transport agent behavior

          Phase 5. Defining Turbine behavior