Search code examples
anylogic

Specifying resource sets in seize block based on agent variable


Agents being pushed through the model have a variable isMorning which is set to false, but is made true if they are injected before a certain time. When the agents enter a seize block, I would like to add a condition that relies on if isMorning is true or not in order to pick a resource set. I would like to know the proper syntax in using conditionals within the Resource sets parameter to choose between different resource sets, or if this must be done in another parameter.


Solution

  • Best option is to create a new function e.g. getResoruceSet(boolean isMorning and then return ResourcePool[][]

    You can then use this function to replace the resource set parameter in the seize block

    enter image description here

    your code inside the function needs to create new arrays for ResorucePool where the first dimension is the number of resources that needs to be seized and the second is the different sets.

    For example:

    if (isMorning) {
        return new ResourcePool[][] { 
            { resourcePool, resourcePool }
            };
    } else {
        return new ResourcePool[][] { 
    { resourcePool1},       
    { resourcePool, resourcePool2, resourcePool2}
            };
    
    }
    
    

    If it is morning you need to seize 2 units of resourcePool. If it is not morning you either need to seize 1 unit from resorucePool1 or 2 unit from resourcePool and 2 from resorucePool2