简体   繁体   English

等待资源获得免费

[英]Wait for resource to get free

在此处输入图片说明

Let me describe the situation above: 让我描述一下上述情况:

  • 20 agents injected at each soruce block. 每个soruce块注入20种药剂。
  • Wait block has max capacity. 等待块具有最大容量。
  • Assembler uses 1 of each source and delay is 1s. 汇编器使用每个源中的1个,延迟为1s。
  • Queue has max capacity 队列具有最大容量
  • QueueSize1 is a queue of size 1 QueueSize1是大小为1的队列
  • Delay is 15s 延迟15秒
  • ResourcePool has capacity of 1 ResourcePool的容量为1

Function startAssembly(): 函数startAssembly():

if(queue.size()==0 && wait.size()>=1 && resourcePool.idle()>=1){
  wait.free(wait.get(0));
}
System.out.println("Queue: " + queue.size());
System.out.println("Wait: " + wait.size());
System.out.println("Idle: " + resourcePool.idle());

Function startAssembly(); 函数startAssembly(); is called: 叫做:

  • onEntry of wait onEntry等待
  • onExit of assembler 汇编程序的退出
  • onExit of queue 队列的onExit

What do I want to happen: Model an assembly line with two processes connected through a queue(FIFO). 我要发生的事情:对具有通过队列(FIFO)连接的两个流程的装配线进行建模。 Process 1(assembler) is faster than process 2(delay). 进程1(汇编程序)比进程2(延迟)快。 Therefore queueSize1 fills up and after process 1 finishes a second part it can't work any further. 因此,queueSize1已填满,并且在进程1完成第二部分之后,它将无法继续工作。 Usually the worker is then displayed as busy() since the agent can't leave the assembler. 由于代理无法离开汇编器,因此通常将工作器显示为busy()。 I want it to be displayed as idle() when this happens using the function, wait and queue. 我希望使用函数,等待和排队时将其显示为idle()。

What happens: One agent passes the assembler and after that no other agent is able to pass through the wait block. 发生的情况:一个代理程序通过了汇编程序,此后,其他任何代理程序都无法通过等待块。 By collecting resourcePool.idle() I noticed that even after the agent exited the assembly block there are no free resources. 通过收集resourcePool.idle(),我注意到,即使代理程序退出了组装块,也没有空闲资源。 I also tried a consturct like assembler.delaySize()==0 in the if part, but there's also some strange behaviour. 我还在if部分中尝试了类似assembler.delaySize()==0的构造,但也有一些奇怪的行为。 Replacing the idle-part with the delaySize-part kinda works, but it also passes 2 or 3 agents into the assembler block. 可以用delaySize-part代替空闲部分,但也可以将2或3个代理传递到汇编块中。 So the "production line" contains more workpieces than it should. 因此,“生产线”包含的工件数量超过了应有的数量。

Question: Is this a normal behaviour of the assembler block? 问题:这是汇编块的正常行为吗? Is it possible to avoid this and get the correct idle()-amount? 是否有可能避免这种情况并获得正确的idle()数量? Is there any other possible way to model my "production line"? 还有其他可能的方式来为我的“生产线”建模吗?

For this particular example, you can go into the simulation experiment properties and set "Selection mode for simultaneous events" to "FIFO (in the order of scheduling)". 对于此特定示例,您可以进入模拟实验属性,并将“同时发生的事件的选择模式”设置为“ FIFO(按调度顺序)”。 As Felipe points out, you will need a queue between your 2nd source and assembler. 正如Felipe指出的那样,您将需要在第二个源和汇编器之间排队。 Once you do those 2 things, your model will run as expected. 完成这两项操作后,您的模型将按预期运行。

The release of the resource was put on the event calendar, all at the same time as other events. 资源的发布已与其他事件同时发布在事件日历中。 When the default of LIFO is utilized, the last in (ie, entering the queues) gets executed first. 当使用默认的LIFO时,将首先执行后入(即,输入队列)。 If you select FIFO, the release of the resource was first on the calendar, so it occurs before the other items. 如果选择FIFO,则首先在日历上释放资源,因此它在其他项目之前发生。

I believe AnyLogic changed the default behavior from FIFO to LIFO in AnyLogic 7. FIFO seems to be the much more common approach in discrete event simulation packages. 我相信AnyLogic 7将AnyLogic的默认行为从FIFO更改为LIFO,在离散事件模拟程序包中,FIFO似乎是更常见的方法。

截图

This solution is valid in case you are using LIFO for the selection mode on simultaneous events, in which case the agent moves from the assembler to the queue and then to the queueSize1 and then to the delay (all in zero time) and AFTER that the resource is released.... which is a bit counterintuitive but it's how things work in LIFO selection mode. 如果您在同时发生的事件中使用LIFO作为选择模式,则此解决方案有效,在这种情况下,代理将从汇编器移至队列,然后移至queueSize1,然后移至延迟(均在零时间内),然后资源被释放...。这有点违反直觉,但是这就是在LIFO选择模式下事情的工作方式。

So what you have to do is to create a dynamic event called StartAssembly and inside the dynamic event you will call the function: startAssembly(); 因此,您要做的是创建一个称为StartAssembly的动态事件,并在该动态事件内调用函数: startAssembly(); Then in the on exit of your assembler, you will call the dynamic event to run almost immediately: 然后,在汇编器的出口处,您将调用动态事件以使其几乎立即运行:

create_StartAssembly(0.001);

This will assure that the resource is released ... and that all the conditions are fulfilled. 这将确保资源被释放...并且满足所有条件。

You don't need to do the same in the other places, only on the exit of the assembler 您无需在其他地方执行相同的操作,只需在汇编器的出口处执行相同的操作

Also, I think you should add a queue between source1 and the assembler or you may get errors 另外,我认为您应该在source1和汇编程序之间添加一个队列,否则可能会出错

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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