【问题标题】:Anylogic: Dropoff given quantity using parametersAnylogic:使用参数丢弃给定数量
【发布时间】:2018-10-14 04:44:56
【问题描述】:

我的模型中运行着一列火车,其中有不同的代理。在其中一个站点,我想为每个代理下车。

我在火车上的代理人是:儿童、青少年、成人和 Golden_oldies。 在给定的站点,我想下车:

20% 的儿童

40% 的青少年

在 Drop-off 代理中,我更改了以下输入:

投递:给定数量(如果有)

数量:children.size(0.2) + Teens.size(0.4)

点击HERE查看投递属性

【问题讨论】:

  • 您的问题是什么?你的代码有什么问题?您应该将代码显示为 text.
  • 在 Drop-off 代理中,我更改了以下内容: Dropoff:给定数量(如果有) 数量:children.size(0.2) + Teens.size(0.4)

标签: java anylogic


【解决方案1】:

要实现这一点,您应该在您的火车接载代理之前为代理中的变量创建一个值。创建一个名为 willBeDropped 的变量,作为默认值 false 的布尔值。此变量应存在于您的 4 种代理类型中的每一种中。

因此,当代理被火车接走时,您应该为 willBeDropped 分配一个 true 或 false 值......所以当火车到达给定站点时,20% 的孩子将拥有willBeDropped=true,而 80% 的孩子将拥有willBeDropped=false.

在dropoff中你应该使用“while condition is true”,条件是agent.willBeDropped==true

我不知道你是如何接载乘客的,所以我不知道如何帮助你...你的问题不完整,但你可以自己弄清楚我刚才所说的。

但是,如果您有以下配置,每个人都被添加到火车上一个唯一的时间:

您可以使用以下代码:

int num1=count(queue,q->q instanceof Children);
int num2=count(queue,q->q instanceof Teenager);

int numToDropOff1=(int)round(num1*0.2);
int numToDropOff2=(int)round(num2*0.4);

int counter1=0;
int counter2=0;

for(int i=0;i<queue.size();i++){
    if(counter1<= numToDropOff1 && queue.get(i) instanceof Children){
        queue.get(i).willBeDropped=true;
        counter1++;
    }else if(counter2<= numToDropOff2 && queue.get(i) instanceof Teenager){
        queue.get(i).willBeDropped=true;
        counter2++;
    }
}

【讨论】:

  • 嗨,费利佩。我正在使用取货代理,因此我将能够在“On enter”中分配 willBeDropped=false 的值。但是,我仍然不确定如何准确地放弃 20% 的孩子。在 dropoff 条件中使用 agent.willBeDropped==true 将释放具有变量的所有代理,而不是 20%。我在哪里/如何将其限制为 20%
  • 谢谢费利佩。抱歉回复晚了
  • @ThabangMarote,如果您认为答案可能对其他人有所帮助,请将问题标记为已接受:)
猜你喜欢
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 2011-06-28
  • 2014-02-20
  • 1970-01-01
  • 2010-10-02
  • 1970-01-01
  • 2011-11-02
相关资源
最近更新 更多