In AnyLogic, a resource is a special type of agent that other agents use to model assets that are in limited supply, that is, their quantity is finite. It can be used to model equipment, personnel, and vehicles that are necessary to perform specific tasks within the model.
In each model, resources reside within the ResourcePool blocks. From there, they are recognized as resources by other blocks and can be assigned various tasks. Resources from these blocks can be used by multiple other blocks at once. ResourcePool blocks are a primary way to create resources: you cannot create resources as regular agents via the Source and similar blocks.
The most simple tasks taking advantage of resources can be implemented with the Service block. This block is basically a combination of three other blocks: it seizes a specified number of resource units (the Seize block), models an operation with it (the Delay block), then releases the units (the Release block).
To compose a more complex process involving resources, start by adding a Seize block on the flowchart. It captures a necessary number of resource units. Then, you can model the whole process with other blocks. After the tasks are done, free up the busy resource units by adding a Release block on the flowchart.
As a special type of agent, resources have their own API. To learn more about available functions, see the corresponding article.
The following Process Modeling Library blocks work with resources:
Seize | Seizes specified resources and, optionally, sends them to a location. |
Release | Releases specified resources after their tasks are completed. |
Service | Designed to model simple tasks requiring resources, this block combines Seize, Delay, and Release blocks, exposing most of their properties. |
Downtime | Models downtimes caused by breakages and maintenance, and custom resource tasks. |
ResourceSendTo | Commands the resource to move to the specified location. |
ResourceTaskStart | Models the start of the task that the resource performs by itself, on the flowchart. |
ResourceTaskEnd | Models the end of the task that the resource performs by itself, on the flowchart. |
ResourceAttach | Attaches the resource to the specified agent, causing the resource to move with this agent. |
ResourceDetach | Detaches (removes) the resource from the specified agent, causing the resource to move separately from the agent. |
Assembler | Allows optional use of resources to assemble multiple types of agents into a single agent. |
A block that requires multiple varying resources can use resources from one or multiple ResourcePool blocks, depending on the concept you use in your model:
-
When you need the block to use multiple resources of the same pool (for example, two workers, three nurses, and so on):
- Set the Seize resources property to units of the same pool.
- In Resource sets (or the corresponding Resource pool property of your block), select the ResourcePool you need using the drop-down list or by clicking and selecting the pool in the graphical editor.
- In the Number of units field, specify the number of resource units the task requires.
-
When you need the block to use multiple different resource units (for example, a robot and a controller, workers with different skill sets, and so on):
- Set the Seize resources property to (alternative) resource sets.
-
Click the button to select one of the existing ResourcePool blocks, or
Click and select the pool in the graphical editor. - Repeat the action while specifying another ResourcePool.
- Specify the number of required resource units in the right part of the list.
-
When you need the block to consider multiple resource sets, with varying numbers of different resource units (for example, the task can be done with 2 robots and 1 controller, but if there is not enough free robots, a human assistant can replace the robot):
- Set the Seize resources property to (alternative) resource sets.
-
Click the button to select one of the existing ResourcePool blocks, or
Click and select the pool in the graphical editor. - Repeat the action while specifying another ResourcePool.
- Specify the number of required resource units in the right part of the list.
- Create the second list of resources by clicking Add list.
- Repeat steps 2–4 to complete the second list.
-
Repeat these steps until you create the necessary resource lists.
Do not add empty ResourcePool lists: it may cause issues.
The model below demonstrates various use cases for resources, including multiple sets of them. It contains a huge number of resources, assigned to different tasks within the Main agent. Most of the time, resources are used by the Service blocks, though there are cases when the work with the resource starts with the Seize block to model a more complex scenario.
Demo model: Trauma Center Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).Tasks are Java entities that the model and its parts use to manipulate resources. With tasks, AnyLogic decides which job to assign to the resource unit, when to free the unit up, and so on. This means that in most cases, if at some certain point in time, the resource unit does not have a task associated with it, then this resource unit does nothing.
Resource tasks are visible in the inspect window of the ResourcePool block during the model run.
There is a number of different task types. Some of them are:
- A service task is a basic task type assigned to the resource seized by some agent
- A wrap-up task commands the resource unit to stop its current action and go to its home location. It is created automatically by the Release block.
- An end-of-shift task commands the resource unit to stay at its home location and do nothing. For example, when the ResourcePool has its When capacity decreases property set to units are preserved, the “end-of-shift” task is what the resource units actually do.
- A custom task is what is created by the Downtime block. It models downtimes and custom tasks implemented by this block.
Each resource unit can be assigned a task from two queues:
-
The first queue is the one generated by the ResourcePool the unit belongs to. It combines all the tasks associated with this particular ResourcePool and is managed by ResourcePool itself.
In simple models, the queue of ResourcePool is the primary queue that operates resources. ResourcePool will simply assign resources in accordance with rules set in its properties. For more information, see the corresponding article. -
The second queue is the individual queue of the specific resource unit. This queue consists of tasks that only this particular resource unit can complete: for example, if this particular resource has an “end-of-shift” task associated with it, or the block requesting the resource has the Wait for original resource policy enabled.
Additionally, some blocks may have additional rules for selecting resources (the Customize resource choice is enabled in properties and the Resource choice condition is set). For more information, refer to the documentation on a specific block.
A set of resources may have multiple tasks with different priorities and preemption policies.
- If all tasks have the same priority, they will be executed in the usual way following their occurrence schedule. If there are enough resource units available, tasks can be executed simultaneously. If two tasks have the same priority, but one of them was suspended for some reason, this suspended task will be picked1.
- If you have configured no preemption policy for the tasks, these tasks will be executed one after another following their occurrence schedule. If there are enough resource units available, tasks can be executed simultaneously.
- The occurrence of one task does not reset the priorities for other tasks.
-
The suspended tasks from the individual queue of the resource unit have the highest priority.
This queue is formed by agents waiting in blocks that have the Task preemption policy set to Wait for original resource. -
After that, the suspended tasks from the queue of the ResourcePool block are processed.
This queue is formed by agents waiting in the blocks that have the Task preemption policy set to Seize any resource.
Once the suspended tasks from these queues are completed, the resource unit begins to process new tasks from their individual queues, and after that, the queue of the ResourcePool block.
If this order does not suit your needs, manually decrease the task’s priority by code, using the On task suspended action of the block.
-
How can we improve this article?
-