Last modified on 29 July 2009, at 12:00

Simulation with AnyLogic/Agent-Based Modeling/Step 2. Creating agents

Step 2. Creating Agents

The first thing you do when creating agent-based model is create agents. Agent is the basic building block of the agent-based model. Agent-based model consists of multiple agents and their environment. Every agent is given a set of rules according to which it interacts with other agents; this interaction then generates the overall system behavior. In this model agents are people.

To create agents in AnyLogic, you define the agent’s internal structure using the active object class, and then create the required number of class instances, each one representing the individual agent.

Step 1. Creating a new model1.gif Create new active object class for an agent

  1. In the Project view, right-click the model item, and choose New|Active Object Class… from the popup menu.
    Step 2. Creating Agents1.png
  2. The New Active Object Class dialog box is displayed.
  3. Specify the name of the new active object class. Type Person in the Name field.
    Step 2. Creating Agents2.png
  4. Click Finish. The Person class diagram is opened automatically.
  5. Once you have created some new element, it becomes selected and its properties are displayed in the Properties view. You can adjust element properties here as your model requires. Please note that Properties view is context-sensitive view and it displays the properties of the currently selected element of the model. To adjust properties at a later time, first select the element (by clicking on the element in the graphical editor or in the Project view) and then modify the properties you want.
  6. On the General page of the Properties view, select the Agent check box. This makes this active object class an agent.
    Step 2. Creating Agents3.png

You have successfully created the class that will define the agent’s internal structure. Now it’s a time to add agents into the model. To place agents into the model environment, you should encapsulate the object that models agent (Person) into the class that models environment (Main).

Step 1. Creating a new model1.gif Place agents into the environment

  1. Open the Main class diagram by double-clicking the Main item in the Project view.
  2. Drag the Person class from the Project view onto the diagram of the Main class.
    Step 2. Creating Agents4.png
  3. On the General page of the Properties view, type the object’s Name: people.
  4. Specify the number of agents you want to have in your model. In the Replication edit box, specify the number of objects: 1000. The specified number of class instances will be automatically created, each one representing the individual agent.
    Step 2. Creating Agents5.png

We have created the required number of agents. Now we will model the adoption of the product influenced by advertisement.