一定数量代理商的延误

时间:2018-09-12 02:01:42

标签: java anylogic

过去的几周我一直在研究AnyLogic,但似乎找不到某种方法来触发一定数量的代理的stopDelay()。例如,我只希望结束目前在“延迟”块中的15个座席的延迟。有什么办法吗?

2 个答案:

答案 0 :(得分:1)

在一个事件(或任何函数)中,您可以遍历延迟块以停止找到的前15个代理。该代码可能看起来像这样:

// assume delayBlock is the name of your delay block
int iAgentsStopped = 0;
int iAgentsToStop = min( delayBlock.size(), 15 ); // can't stop more than you have
// if we have any to stop
if( iAgentsToStop > 0 ){
   for( Agent agent : delayBlock ){
      delayBlock.stopDelay( agent );
      iAgentsStopped++;
      // if we have stopped enough, just stop looping
      if( iAgentsStopped == iAgentsToStop )
         break;
   }
}

答案 1 :(得分:1)

这是一个代码,该代码可以使延迟块中的代理随机停止,而不是按到达顺序执行:

int iAgentsStopped = 0;
int iAgentsToStop = min( delay.size(), 15 ); 
List <Agent> agents=findAll(delay,d->true);
Collections.shuffle(agents);
while(iAgentsStopped < iAgentsToStop){
     delay.stopDelay( agents.get(iAgentsStopped) );
     iAgentsStopped++;
}