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 agent's behaviour using parameters, variables, collections, functions, events, option lists and also 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 Scale: 5 pixels per kilometer.

As you can see in the image above, if we will keep the animations of our agents resized corresponding to the model scale, these agents (such as maintenance center here) will become invisible in our model's animation scene. So we will use greater scales for the agents to make them visible during the 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 down and for the agent's scale set the option Scale is: Specified explicitly. Then specify the Scale: 10 pixels per kilometer.
  2. Set the 3D object's Additional scale to 75%.

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 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.
  8. We don't want the animation of the turbine to resize automatically according to the change of the agent's scale. This option is only applicable to individual 3D objects, but the Wind Turbine Rotating animation figure is a group comprised of several such objects, therefore we have to disable the Resize automatically to match agent scale option for each object individually.
    Go to the Projects view and expand the Turbine > Presentation > level section to access the wind_turbine group. In the properties of wind_turbine_tower and wind_turbine_blades 3D objects disable the Resize automatically to match agent scale option.
  9. For both these objects specify the Additional scale: 50%.

  10. Since we disabled the automatic resize option and changed the scale, we have to manually configure the alignment of elements that comprise the wind_blades group. In its properties change the code in the Z property field to the following: 22.25 * Scale.DEFAULT_SCALE.pixelsPerUnit(METER).

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. Next, specify the Additional scale: 50%.
  13. 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 a 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 presentation of your top-level agent type Main. Since 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