有没有一种方法可以优化/加速与在NetLogo中查找路径相关的代码
我已在模型中定向网络。我有不同类型的代理选择网络上的最佳路径。设置过程中的所有代理都会获得当前节点(创建它们的位置)和目标节点(它们需要移动的位置),并且它们需要找到它们之间的最短路径。我用这段代码做到了:有没有一种方法可以优化/加速与在NetLogo中查找路径相关的代码,netlogo,Netlogo,我已在模型中定向网络。我有不同类型的代理选择网络上的最佳路径。设置过程中的所有代理都会获得当前节点(创建它们的位置)和目标节点(它们需要移动的位置),并且它们需要找到它们之间的最短路径。我用这段代码做到了: breed [crossing crossings] directed-link-breed [channel channels] breed [ship ships] .... to add-ships let j 0 foreach list-of-ships [ num
breed [crossing crossings]
directed-link-breed [channel channels]
breed [ship ships]
....
to add-ships
let j 0
foreach list-of-ships [
num-of-ships ->
create-ships num-of-ships [
set type j
set origin-node one-of crossings
move-to origin-node
set target-node one-of crossings
;; set the path variables
let target-n target-node
ask origin-node [ set temporary-path nw:weighted-path-to target-n "travel_time" ] ;; set the path to go
set path-to-go temporary-path
set path-to-return reverse path-to-go ;; set path to return
]
j j + 1
]
end
当我在循环(另一个循环)中添加这行代码时,ask origin节点[将临时路径nw:weightedpath设置为target-n“travel\u time”]
我遇到了内存问题。是否有另一种更优化的方法来设定路径
PS:我知道这条线工作正常,我测试过了