AnyLogic
Expand
Font size

Agent inheritance

You can inherit agent types from some other agent type.

Let's give the example when this feature can be useful. Assume you have different vehicle types in your transportation model. All of them have common behavior and attributes and some different ones. Say, a lorry and a truck. Both have the same statecharts consisting of the same states. But while the common is the same, some aspects differ.

You can create one agent type Vehicle that will act as a base type for two other agent types: Lorry and Truck. There, on Lorry and Truck diagrams you can define the attributes specific for these vehicles using parameters. Also there you can set specific animation shapes. But all the things you define in Vehicle agent type (statechart, parameters, etc.) will be common for both classes that extend Vehicle: Lorry and Truck.

To make the agent inherit from other agent type

  1. Select the agent type in the Projects view.
  2. In the Properties view, open the Advanced section and choose the base agent type from the Extends other agent combo box.

On the graphical diagram of the inherited agent type you will see all the elements of the base agent type. These elements cannot be edited (neither moved or deleted) and therefore they are shown grayed out. If some element of the base class (e.g. its animation shape) does not comply the inherited agent type, you can delete this element on the diagram of the base class and create analogous but a bit different elements on the diagram(s) of the inherited agent type(s).

Demo model: Population Model with Connections and Disease Spread Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).
How can we improve this article?