Phase 1. Creating different types of agents

Agents are the main building blocks of this AnyLogic model. Agent is a unit of model design that can have behavior, memory (history), timing, contacts, etc. You can define as many agent types in your model as you need. We will create and define a single agent, an agent type and three agent populations in this model. 

The agent internal state and behavior can be implemented in a number of ways. The state of the agent can be represented by a number of variables, by the statechart state, etc. The behavior can be so to say passive (e.g. there are agents that only react to message arrivals or to function calls and do not have their own timing), or active, when internal dynamics (timeouts or system dynamics processes) of the agent causes it to act. In the latter case agents most probably would have event and/or statechart objects inside.

In our model we will define agents's behaviour using parameters, variables, collections, functions, events, option lists and also actioncharts and statecharts.

Creating a model

 Create a new model
  1. Click the New  toolbar button. The New Model dialog box is displayed.
  2. Specify the name of the model. Type Maintenance in the Model name edit box.

  3. Specify the location where you want to store your model files. Browse for the existing folder using the Browse button, or type the name of the folder you want to create in the Location edit box.
  4. Select the Model time units: hours.
  5. Click Finish to complete the process.

New model is created. It already has one agent type called  Main and experiment called  Simulation

In the center of the workspace you will see the graphical editor. It shows the diagram of the  Main agent type. The blue frame on the diagram is the model frame that defines the size of the model window and the part of the graphical diagram that is shown in the window at the model runtime.


To the left of the graphical editor you can see the Projects view and the Palette view sharing the same area. The Projects view provides access to AnyLogic models currently opened in the workspace. The workspace tree provides easy navigation throughout the models. The Palette view contains all graphical elements you can add onto the graphical editor of your agent just by drag'n'drop. Model elements are grouped by categories in a number of stencils (palettes).

On the right side of the workspace you can see the Properties view. The Properties view is used to view and modify the properties of a currently selected model element(s). When you select something – e.g., in the Projects view or in the graphical editor – the Properties view displays the properties of the selection.

Now we can continue developing our model created by AnyLogic model creation wizard.

Creating agents

First we need to create a single agent - the maintenance center, then an empty population for maintenance transport, three populations for the wind turbines, trucks and helicopters, and an agent type to represent service requests. Then we will be able to define the processes inside the types of agents - on their diagrams.

Add a maintenance center

  1. In the Palette view, hover your mouse over the vertical navigation bar and select Agent there to open the Agent palette.

  2. Drag the Agent  element from the Agent palette into  Main diagram. The New agent wizard will pop up automatically.

  3. Select A single agent option on Step 1. We need only one maintenance center that will send transport to turbines for scheduled maintenance and any failures/repairs. 

  4. We are creating a new type of agent and do not need to use any templates. Specify the Agent type name: MC and the Agent name: center. Click Next to proceed.

  5. Choose the 3D animation figure Hangar from the Buildings section and click Next.

  6. Skip step 4 where you can add parameters, simply click Next.
  7. We want all our agents to live in a continuous space, 1000x600, in a random network with a random layout. The agent populations that we will add on Main will also live in the same environment.

  8. Click Finish

Now you can find the new agent type  MC in the model tree on the same level as  Main and the agent  center itself under Main Agents.

The agent animation is shown on the agent type diagram as well as on  Main. We need to change the scale of the model and of this agent's animation.

  1. Double-click Main in the model tree and pan the agent's diagram down.
  2. Above the X axis, you will find the Scale element. Open its Properties view.
  3. Set the Scale is property to be Specified explicitly. Then specify the Scale5 pixels per kilometer.  

If we will keep the animations of our objects resized corresponding to the model scale, it will be rather impossible to see these objects (maintenance center, wind turbines, trucks and helicopters) in our model's animation scene. So we will use greater scales for the objects to make them visible on animation. 

  1. Double-click MC in the model tree.
  2. In the graphical editor, select the maintenance center animation shape, and in its properties, clear the Resize automatically to match agent scale option.
  1. Pan the agent's diagram downand for the agent's scale, set the option Scale is: Specified explicitly. Then specify the Scale20 pixels per kilometer.  

Add the wind turbines

  1. Drag the Agent  element from the Agent palette onto  Main diagram. 
  2. This time, select Population of agents. Click Next on Step 2 ( the default setting I want to create a new agent type). On the next wizard page type the name of the new type: Turbine and agent population name will autofill as turbines. Click Next.


  3. Choose 3D animation figure Wind Turbine Rotating from the Energy section of the list. 

  4. We do not need to add here any parameters, so skip that Step 5. 
  5. On Step 6, set up to create 25 agents in this population. 
  6. You can click Finish on step 6. Step 7, Configure new environment, is prefilled with the correct settings because we are adding the new population into  Main where there already is a configured environment.
  7. Open the Turbine agent diagram and set the agent's Scale to 10 pixels per kilometer the same way we did for the MC agent.

Add the transport

  1. Drag the Agent  element from the Agent palette onto  Main diagram. 
  2. One more time select Population of agents. Click Next on Step 2 (I want to create a new agent type). On the next wizard page (step 3) define the Agent type name:Transport, and the Agent population name: transport. Click Next.
  3. This is an empty population that does not need animation. We will use this agent type to define the logic of our model. Select None for animation type, skip the parameters step, choose to Create initially empty population and click Finish.

Add trucks and helicopters to the model

  1. Drag the Agent  element from the Agent palette onto  Main diagram. 
  2. Again, select Population of agents. Click Next on Step 2 (I want to create a new agent type). On the next wizard page (step 3) define the Agent type name: Truck, and the agent population name will autofill as trucks. Click Next.
  3. Select the Lorry 3D animation figure from the section Road transport on the next step. We do not need to add any parameters here in the wizard. There are 5 agents in this population and the environment settings should be pre-filled as we set them up the first time. 
  4. After you create the Truck agent type, select it the model tree and go to its Properties view. First expand the Dimensions and movement section. We suppose that the average truck's speed equals 70 kilometers per hour.
  5. Expand the Advanced section and make Truck inherit Transport configuration by setting up the parameter Extends other agent: Transport.

  6. Select the truck animation shape, and in its properties, clear the Resize automatically to match agent scale option.
  7. Modify the Truck scale. In the scale element properties, clear the Inherited from parent option and set the scale to 10 pixels per kilometer.
  8. Now  Truck agent is fully set up. We need to add one more population for helicopters. Go back to  Main and drag the Agent  element from the Agent palette again and select Population on the first step.
  9. Type the new agent type name Helicopter and the population name helicopters will autofill. You can find the Helicopter 3D animation figure in the section Military. We want to use 2 helicopters for the turbine maintenance. This population lives in the same environment.
  10. Helicopter also Extends other agent: Transport. We suppose that helicopters move with the speed 200 kilometers per hour.
  11. Select the helicopter animation shape, and in its properties, clear the Resize automatically to match agent scale option.
  12. Modify the Helicopter scale. In the scale element properties, clear the Inherited from parent option and set the scale to 5 pixels per kilometer.

Add the service requests

  1. Drag the Agent  element from the Agent palette into Main diagram. 
  2. Select Agent type only. We need to add an agent type to define logic of the model with the parameters we will set up on its diagram. 


  3. Type its name ServiceRequest in the corresponding field and click Next. Select None for the animation type and proceed to the next step.
  4. On step 4 we will create a parameter and an option list.

    Option List is the element for defining agent attributes that have limited choice of alternative options. In our case, we need to differentiate between trucks and helicopters which are both used by the maintenance center and respond to the service requests. The parameter is called type and its type is the Option List. Since there are no option lists in the model yet, the wizard suggests that you Create new option list: TransportType. Type the options in the table, one in a line: AUTO, AVIA.

  5. Click Finish. The option lists do not have any graphical icons that you can click to select them in the graphical editor. You can find Option Lists in the model elements tree:

  6. After you click Finish, AnyLogic will open the  ServiceRequest agent type diagram. There you can find the parameter type that we have created. Add one more Parameter  from the Agent palette. Call it turbine and select its Type from the drop-down list: Turbine. Now  ServiceRequest is fully set up.

The agent elements will appear on  Main. You can notice that the populations are marked with the [..]. Move the agents beyond the model window and place the center of each animation figure in the axis origin. 

You can find the environment settings in the properties of  Main, section Space and network:

Run the model
  1. Build your project by clicking the Build Model toolbar button. If there are some errors in your model, the building fails and the Problems view appears listing all the errors found in your model. Double-click an error in the list to open the location of the error and fix it.
    After the model is successfully built, you can start it. Running the simulation, you automatically bring the current model up to date. 
  2. Choose the experiment you want to run from the drop-down list of the Run  toolbar button. Your simulation experiment is called  Maintenance/Simulation. Later on you can use the Run  toolbar button to start the previously run experiment.
  3. Having started the model, you will see the model window. It displays the presentation designed for your simulation experiment. 
  4. Click the Run  button in the control panel displayed at the window bottom to run the model. We have only started developing the model. At this moment we can see the maintenance center, turbines and our transport types distributed randomly in the continuous space.

Reference model: Maintenance - Phase 1

Next, we need to place the transport - trucks and helicopters - in the maintenance center.


          Wind turbine maintenance model

          Phase 2. Setting up the transport base