java - Anylogic:使用参数丢弃给定数量
问题描述
我的模型中有一列火车,里面有不同的代理。在其中一个站点,我想放下每个代理的一部分。
我在火车上的代理人是:儿童、青少年、成人和golden_oldies。在给定的站点,我想下车:
20% 的儿童
40% 的青少年
在 Drop-off 代理中,我更改了以下输入:
Dropoff : 给定数量(如果有)
数量:children.size(0.2) + Teens.size(0.4)
点击这里查看下车属性
解决方案
为了实现这一点,您应该在您的火车接载代理之前为代理中的变量创建一个值。创建一个名为 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++;
}
}
推荐阅读
- python - 使用 selenium 和 python 将具有相同类的所有元素添加到列表中
- entity-framework-core - 在 EF Core 3.1 中调用一个简单的存储过程
- python-3.x - Flask Pdfkit-无法添加自定义字体
- ios - 如何以编程方式向下滚动推送通知打开的视图?
- sql - 如何计算具有不同包含表字段的两个不同表的总和
- linux - 使 nautilus 在挂载磁盘时停止询问密码
- python - Firestore 身份验证要求为 kivy 应用选择“android/ios”或“web”
- django - Django 下拉菜单没有给我选择的全名
- javascript - 使用 Javascript 突出显示同一页面上多个文本区域上的特定单词
- r - 整数的下限函数:找到十位的最小值