Anylogic-如何计算行人之间的距离

Anylogic-how to calculate distance between pedestrians

我使用行人库(使用ped source、ped Goto和ped sink),想模拟人行道环境。该模型的目标是获取行人之间距离小于1m的数据。所以,我试着计算行人之间的距离。在Anylogic中,可以通过getX()、getY、getId(可以每秒计算一次)来收集行人的信息。 但我不知道如何 select 行人代理并计算它们之间的距离。我的意思是,如果有10个行人(id:1、2、3 ...),如何获得1和2、1和3、2和3 ...之间的距离每秒?

创建一个事件,每秒循环遍历所有行人。确保所有行人都已实际添加到您的 PedSource 中的自定义代理群体(使其更容易遍历它们)。

在活动中,使用嵌套的 for 循环:

for (Pedestrian currPed : myPedPopulation) {
    for (Pedestrian currOtherPed : myPedPopulation) {
        if (currPed.equals(currOtherPed) break; // not needed
        double distance = currPed.distanceTo(currOtherPed);
        // do with this what you want :)
    }
}