【问题标题】:how to find the nearest agent based on distance?如何根据距离找到最近的代理?
【发布时间】:2021-10-22 08:57:39
【问题描述】:

我试图让代理与其他代理之间的距离小于指定距离时,它们会改变颜色。但是当我使用getNearestAgent(this.getPopulation()) 时,它会给我人口列表中位置 0 的代理。 我正在使用一个事件来让代理改变颜色。 this is the code of the event and the output of the console

颜色变化取决于事件的发生率,有时还取决于与点 (0,0,0) 的距离

【问题讨论】:

    标签: anylogic agent-based-modeling


    【解决方案1】:

    您可以使用distanceTo() 函数。

    每个代理都需要遍历所有其他代理,然后检查它们与其他代理的距离。

    【讨论】:

    • 我正在解决这个问题,结果发现我在设置速率时犯了一个错误,在我的模拟中,它每 100 秒查找一次最近的代理,所以它总是返回代理 [0] 为最近的一个
    猜你喜欢
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2017-06-21
    • 2018-02-06
    • 1970-01-01
    • 2018-01-15
    相关资源
    最近更新 更多