【发布时间】:2022-08-14 13:23:16
【问题描述】:
我在 Fleets 属性的“On enter node”中使用以下代码创建了一个 transporterFleet。
当运输机进入特定节点时,速度由名为agvCycle 的变量设置。
我是这样编码的,因为传输器的速度必须在每个节点上改变。
我注意到我的模拟运行时间在“虚拟”上变得非常慢。我认为不必要的重复编码可能是原因。在这种情况下如何实现循环?这会加快模拟时间吗?
if (node == locationCycle1) {
unit.setMaximumSpeed(agvSpeedCycle1/60.0, MPS);
}
else if (node == locationCycle2){
unit.setMaximumSpeed(agvSpeedCycle2/60.0, MPS);
}
else if (node == locationCycle3){
unit.setMaximumSpeed(agvSpeedCycle3/60.0,MPS);
}
else if (node == locationCycle4){
unit.setMaximumSpeed(agvSpeedCycle4/60.0, MPS);
}
else if (node == locationCycle5){
unit.setMaximumSpeed(agvSpeedCycle5/60.0, MPS);
}
else if (node == locationCycle6){
unit.setMaximumSpeed(agvSpeedCycle6/60.0, MPS);
}
else if (node == locationCycle7){
unit.setMaximumSpeed(agvSpeedCycle7/60.0, MPS);
}
else if (node == locationCycle8){
unit.setMaximumSpeed(agvSpeedCycle8/60.0, MPS);
}
else if (node == locationCycle9){
unit.setMaximumSpeed(agvSpeedCycle9/60.0, MPS);
}
else if (node == locationCycle10){
unit.setMaximumSpeed(agvSpeedCycle10/60.0, MPS);
}
... // Goes on till locationCycle27 and variable agvSpeedCycle27```
-
我不是任何逻辑用户,但我的理解是它基于 Java。如果是这样,则整个 if/else 替代方案链可以替换为
HashMap,您可以使用node值作为键来生成相应的avgSpeedCycle。这将在设置映射后将上述所有内容简化为单个语句。任何时候你看到一个数字后缀来区分一堆类似命名的变量,你应该丢失后缀并使用数组或某种哈希集合。 -
您可能还想只存储那些速度循环 / 60计算所以你只做一次。如果您想保留原始值,可能值得为此创建一个特殊查找,在其中映射每个地点到其对应的速度/60.您还将相同的
MPS值传递给该函数,所以也许那里正在进行一些不必要的计算,您也可以避免(因为它总是相同的)
标签: simulation anylogic