根据靠近运输车的代理设置速度

Set speed based on agents close to transporter

在我的模型中,我希望我的运输车队的代理类型每秒计算该运输机 2 米范围内是否有任何其他代理(人),如果有,它应该减慢速度。我知道一点如何编码,但由于我习惯了 python 而不是 java 我发现很难真正知道如何编码,所以目前我在代理类型中创建了一个事件每秒运行的AGV(这是运输车的代理类型)。

在代码框中,我想要这样的东西,但不知道具体怎么做:

for person (if person.walking=true) in personpopulation:
    if double distanceTo(person)<2:
      unit.setspeed(0.05)
        break // Since knowing that one agent is close is enough.
    unit.setspeed(2) // if there is no agent close he did not break and reaches this part of the code.

但是你如何在 java/anylogic

中准确地编码呢?

当前情况截图: 在方法 1 中,我通过添加设置速度功能来使用简单的方法。

我也试过了,在模型中看到代理的最大速度参数发生了变化,但 AGV 的运动并没有减速。

以下代码应该有效:

for (Person currPerson : personPopulation) {
    if (currPerson.walking==true) {
        for (AGV currAgv: agvPopulation) {
               if (currPerson.distanceTo(currAgv)<2){
                   currAgv.setMaximumSpeed(0.05,MPS);
    }
}
}
}