问题描述
我同时使用 Queue 和 Hold 块,在所有代理到达 Queue 块之前,hold 一直处于阻塞状态.
I am using a Queue and hold block together, where the hold remains blocked until all the agents arrive at the Queue block.
如何更改它并希望在固定的时间间隔(例如每 3 分钟)只允许固定数量的代理(例如 5 个代理)?我的队列和保持块的当前属性:
How to change it and want to allow only a fixed number of agents (say 5 agents) at fixed intervals of time(say every 3 minutes)? Current properties of my Queue and hold block:
queue_block_properties
queue_block_properties
hold_block_properties
hold_block_properties
推荐答案
创建重复时间为 3 分钟的循环事件.还要创建一个变量,您可以将其命名为 count
,类型为 int
.
Create a cyclic event with recurrence time 3 minutes.Also create a variable which you can name count
of type int
.
在事件操作字段中写入:
In the event action field write:
count = 0;
hold.unblock();
然后,在保持块的 On enter
字段中写入以下内容:
Then, in the On enter
field of the hold block write the following:
count++;
if( count == 5 ) {
self.block();
}
我唯一的问题是,您是否希望每 3 分钟就有 5 个特工离开,或者他们晚一点到达是否可以.换句话说,如果 3 分钟后,队列中只有 3 个代理,他们是否离开并保持畅通,以防在下一个周期之前又有 2 个代理到达?还是保持块立即再次阻塞?
The only question that I have is whether you want every 3 minutes to have exactly 5 agents leave or whether it's okay if they arrive a bit later. In other words if after 3 minutes, there are only 3 agents in the queue, do they leave and the hold remains unblocked in case another 2 arrive before the next cycle? Or does the hold block blocks again immediately?
在我提供的解决方案中,如果在循环时间发生时少于 5 个,然后新的代理在下一个循环之前到达,他们可以通过.
In the solution I provided, if there are less than 5 at the cycle time occurrence, and then new agents arrive before the next cycle, they can pass.
否则,例如创建一个名为 target
的新变量并在事件操作中写入以下内容:
Otherwise, create a new variable called target
for example and write the following in the event action:
count= 0;
if( queue.size() >= 5 ) {
target = 5;
hold.unblock();
}
else if ( queue.size() > 0 ) {
target = queue.size();
hold.unblock();
}
在保留的输入处,写:
count++;
if( count == target ) {
self.block();
target = 0;
}
这篇关于在 Anylogic 中只允许固定数量的代理定期通过队列块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!