Anylogic – Block and unblock based on condition

Tags: , ,



Is it possible to use a simple true/false statement in a Hold block’s blocking condition to block an agent if condition is true and unblock if condition is false? If not, is there another way?

I need the Hold block to block if the condition resourcePool1.idle()==0 is true, otherwise I need it to unblock. I have tried a few different statements, but none of them are working.

Answer

Since your condition is related to resources, I would recommend the following:

enter image description here

In the on seize and on release fields, write the following:

if(resourcePool.idle() == 0)
    hold.setBlocked(true);
else
    hold.setBlocked(false);

Note that since you are in the resource pool itself, you can replace its name by self.

This way, you optimize your model given that the block condition is only evaluated when its outcome might change i.e. when a resource is seized or released. No need to check the condition any other time.



Source: stackoverflow