411 REFERENCE · Wikibooks
Simulation with AnyLogic/Agent-Based Modeling/Step 2. Creating agents
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
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.
Image:Step_1._Creating_a_new_model1.gif Create new active object class for an agent
In the Project view, right-click the model item, and choose New|Active Object Class… from the popup menu.Image:Step_2._Creating_Agents1.png
The New Active Object Class dialog box is displayed.
Specify the name of the new active object class. Type Person in the Name field.Image:Step_2._Creating_Agents2.png
Click Finish. The Person class diagram is opened automatically.
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.
On the General page of the Properties view, select the Agent check box. This makes this active object class an agent.Image: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).
File:Step_1._Creating_a_new_model1.gif Place agents into the environment
Open the Main class diagram by double-clicking the Main item in the Project view.
Drag the Person class from the Project view onto the diagram of the Main class.File:Step_2._Creating_Agents4.png
On the General page of the Properties view, type the object’s Name: people.
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.File: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.