Search code examples
resourcessimulationanylogic

Anylogic - create Resources and add to ResourcePool


I'm having difficulty finding the documentation I need to work with Resources and resourcePools - there is no "resource API documentation" that I can find.

I would like to programatically create static resources (of a custom type) and then add these resources to a resourcePool. When creating the resources, I'd like to be able to specify their property values prior to adding them to the resourcePool. In my mind the code would look something like this:

Room myRoom;
myRoom = new Room("redRoom", 20);
addTo_myResourcePool(myRoom);

myRoom = new Room("greenRoom", 10);
addTo_myResourcePool(myRoom);

Does anyone know if there are ways to achieve this end?


Solution

  • This is a bit of a blind spot in AnyLogic. It can only be done indirectly:

    1. Create an empty agent population with your agent type
    2. Tell the resource pool to use that agent type
    3. set the resource pool capacity as you need. The pool will create agents for your in that population (if the capacity is larger than the current number of resources)

    If you want to manually create a resource, you must call myResourcePool.set_Capacity(myResourcePool.getCapacity()+1)

    Destroying 1 resource works vice-versa.

    Also, make sure to "destroy resources on capacity decrease" so the agents are destroyed from the population