Search code examples
anylogic

AnyLogic: Select specific resource set based on condition


I have created a simple model in AnyLogic (see screenshot). Now I want to add a condition that selects one of the two resource sets in the service block. As an example the following scenario shall apply: If there are more than 5 parts in the queue, worker 3 and worker 4 should perform the service. If there are <= 5 parts in the queue, the service shall be performed by worker 1 and worker 2. This is only meant to be a simplified example. I am primarily interested in solving this problem using a condition. I have already tried different approaches, but without success. Does anyone have an idea how the Java code for this condition could look like?

enter image description here


Solution

  • First, you don't need the queue since the service block already has a queue... So For this particular example in your resource choice conditions you will do the following:

    service.queueSize()>5 ? (worker3.containsUnit(unit) || worker4.containsUnit(unit))
    :
    (worker1.containsUnit(unit) || worker2.containsUnit(unit))
    

    You can change service.queueSize() with queue.size() if you insist in using a queue. After that you need to be sure to recalculate the conditions when needed, for this particular example i think you only need to recalculate them on exit action of the service block:

    self.recalculateResourceChoiceConditions();