AnyLogic
Expand
Font size

Creating custom resource types

You can create custom resource types. They have individual diagrams where you can add parameters, statecharts, functions, and so on. Additionally, you can create animations for these resource types, and modify them easily.

To define a custom resource type

  1. Drag the Resource Type from the Process Modeling Library palette into the graphical editor.

  2. The New agent wizard will open up.
  3. On the first page of the wizard, specify the name of the new resource in the Agent type name field.

  4. Choose the animation for the resources of this type. If you want the resource units to be animated both in 2D and 3D, choose 3D and select a 3D model from the list below, otherwise select 2D and choose from another (shorter) list. If no shapes satisfy your needs, just choose None. You can draw an animation for the resource on its graphical diagram later.

  5. Upon choosing the animation, click Next to proceed to the next step.
  6. Specify the parameters for this resource type. Click <add new…> in the Parameters list to create a new parameter. Having selected a parameter in this list, you can set its name, type, and initial value using the controls in the right panel. To remove a parameter from the list, select it, then click the button below.

  7. Click Finish.

The graphical diagram of the created resource type will open. You will see there the chosen resource unit animation (located in the axis origin) and the parameter(s) you have defined in the wizard.

Now you can specify this resource type in the flowchart blocks parameters, for instance, in ResourcePool properties:

Resource type properties

General

Name — The name of the resource type.

Since AnyLogic generates a Java class for each resource type, you should follow Java naming guidelines and start the name with an uppercase letter.

Ignore — If selected, the resource type is excluded from the model.

Parameters preview

Parameters preview properties are available only when this resource type has any parameters. Here you can rearrange the parameters of this resource. Resources of this type will list parameters in their property view in this well-defined order.

Agent actions

On startup — Perform resource initialization not here, but in the On new unit action property of the ResourcePool block that defines a set of resources of this type in your model.

On destroy — Define the resource’s actions to be executed upon destroying the resource unit not here, but in the On destroy unit action property of the ResourcePool block that defines a set of resources of this type in your model.

On arrival to target destination — This parameter is derived from agent type and is not applied to the movement defined with a Process Modeling Library flowchart.

On before step — This parameter is derived from agent type and is rarely used for resources. For details refer to the Agent article.

On step — This parameter is derived from agent type and is rarely used for resources. For details refer to the Agent article.

Agent in flowcharts

Use in flowcharts as — Here you choose the role for agents of this type in the flowcharts. To enable using these agents as resources in the blocks of the Process Modeling Library, leave the Resource Unit option selected. This way the agent of this type obtains resource-specific functions: resourcePool(), isIdle(), getUtilization(), etc.

On enter flowchart block — Here you can write the code to be executed when this resource enters the flowchart.

On exit flowchart block — Here you can write the code to be executed when this resource exits the flowchart.

On seize resource — Here you can write the code to be executed when this resource seizes another resource while being in the flowchart (it is a rather rare case).

On release resource — Here you can write the code to be executed when this resource releases another resource while being in the flowchart (it is a rather rare case).

Dimensions and movement

Initial speed — [Visible if Space type: Continuous or GIS] The speed of the resource.

Rotate animation towards movement — [Visible if Space type: Continuous or GIS] The heading of the resource.

Rotate vertically (incline on ramps) — If selected, the resource shape will be headed toward the target during the resource movement.

Space and network

The parameters in this section are derived from agent type and are rarely used for resources. For details refer to the Agent article.

Advanced Java

The parameters in this section are derived from agent type and are rarely used for resources. For details refer to the Agent article.

Advanced

The parameters in this section are derived from agent type and are rarely used for resources. For details refer to the Agent article.

Accessing parameters of custom resources

Since custom resources are derived from agent type, it is possible to enrich them with custom variables, parameters, functions, and other elements.

When using a custom resource, you have to specify the resource type explicitly to access its underlying elements.

Let’s say we have a custom resource pool named Cashiers that consists of multiple resource instances: the Cashier agents. On the Cashier agent’s diagram, there is the isBusy Boolean parameter whose value is false by default. Let’s say we want to set it to true upon starting the resource’s utilization.

To do this, specify the following as the On seize unit action in the Actions section of the Seize block:

((Cashier)unit).isBusy = true;
We address the agent type — Cashier, rather than the resource pool Cashiers itself.

Use a similar approach to access parameters, functions, and other underlying elements of the custom resource type.

To learn more about the parameters of custom agents, see the following article: Accessing agent parameters from a flowchart.

How can we improve this article?