简体   繁体   中英

Anylogic - Block and unblock based on condition

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.

The hold block likely does not check dynamically for your condition but only once at the start. It is your responsibility to tell it about the condition having changed. (Else it would need to check constantly, which is bad design and computationally expensive).

So instead, redesign your model so it updates the Hold block explicitly (change to "manual" mode) when the situation arises. In your case, whenever a resource turns idle, it should check if all are idle and then change the Hold block manually.

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

在此处输入图像描述

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 ie when a resource is seized or released. No need to check the condition any other time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM