模型概述
这是一个地铁站行人行为建模的模型,使用了行人库、扶梯、上下层等智能体建模。总共分为两层,B1层完成行人的进站和查验行李、上下梯行为,B2层完成行人上下梯的行为。
B1层
B2层
问题描述
其实问题真的很简单,,大概就是在模型运行的过程中发现跑不动了,然后显示下面的报错信息。
Index 0 out of bounds for length 0
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:372)
at java.base/java.util.ArrayList.get(ArrayList.java:458)
at com.anylogic.libraries.pedestrian.PedEscalators_xjal.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEscalators_xjal.c(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEscalators_xjal.c(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEscalators_xjal$4.choice(Unknown Source)
at com.anylogic.libraries.processmodeling.SelectOutputIn.b(Unknown Source)
at com.anylogic.libraries.processmodeling.SelectOutputIn$1.outputBlock(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.forwardReadyEntityNotification(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.forwardReadyEntityNotification(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.forwardReadyEntityNotification(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.forwardReadyEntityNotification(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.action(Unknown Source)
at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal$a.execute(Unknown Source)
at com.anylogic.engine.LibraryEventHandler$a.execute(Unknown Source)
at com.anylogic.engine.Engine.h(Unknown Source)
at com.anylogic.engine.Engine.nj(Unknown Source)
at com.anylogic.engine.Engine$a.run(Unknown Source)
问题原因排查
这样的报错信息,首先找不到是出现在什么智能体上面,二是给出的报错信息,要么来自java原生包的、要么来自于anylogic的实例化函数(用户不可调),再看问题:Index 0 out of bounds for length 0。怎么说咱java也写了这么长时间了,可太熟悉这个了。
第一步 检查所有的定义循环、collection、queue的位置的逻辑是否正确
检查完之后发现所有元件,内部的语句都是没问题的。到这里我觉得够奇怪的了,但是这里的报错还好有指向性,那就是 Pedestrian Escalator(行人扶梯)的模块出了问题。
第二步 检查所有行人扶梯的设置是否正确
根据错误提示,这个模块的某个方法在执行时发生了“IndexOutOfBoundsException”的异常,也就是说它试图访问一个数组、列表或集合中不存在的元素。错误信息中显示“Index 0 out of bounds for length 0”,也就是说该模块的某个方法尝试获取一个长度为0的数组或列表中的第一个元素,这听起来就是有问题的,那么重点在于为什么这个长度为0。
对于扶梯组,如果让长度为0还要获取智能体,在测试中我能想到的只有扶梯方向设置反了。
最后再排查的时候发现,扶梯组设置的方向错了(据说小伙伴排查了一晚上,可能是当局者迷了)。请注意:扶梯组一个方向只能做一件事!(这个就跟我们生活中的逻辑一模一样)