Networking 如何在NetLogo中找到网络加权路径上的下一只海龟?

Networking 如何在NetLogo中找到网络加权路径上的下一只海龟?,networking,netlogo,Networking,Netlogo,我正在运行一个交通交互模拟器,其中包含一个导入的生成道路网络的形状文件。该网络上的节点和节点之间的链接是创建的,代理在这些节点之间进行旅行。这一切都通过网络扩展(nw:turtles on path to command)解决了,但为了结合速度限制,我正在尝试实现加权路径查找。因此节点之间的链接也有一个speedLimit权重变量 这是当前有效的代码-我正在尝试将“nw:turtles on path to[destination]”更改为“nw:turtles on weighted path

我正在运行一个交通交互模拟器,其中包含一个导入的生成道路网络的形状文件。该网络上的节点和节点之间的链接是创建的,代理在这些节点之间进行旅行。这一切都通过网络扩展(nw:turtles on path to command)解决了,但为了结合速度限制,我正在尝试实现加权路径查找。因此节点之间的链接也有一个speedLimit权重变量

这是当前有效的代码-我正在尝试将“nw:turtles on path to[destination]”更改为“nw:turtles on weighted path to[destination speedLimit]”。然而,当添加权重变量时,“of”嵌套被证明是有问题的,并且无论我如何尝试添加它,都会抛出错误

to set-location
  set current-location min-one-of nodes [distance myself]
end

to set-destination
  let test current-location
  nested-set-destination
  while [destination = test] [nested-set-destination]
  set next-node item 1 [nw:turtles-on-path-to [destination] of myself] of current-location
  face next-node
end

to nested-set-destination
  set destination one-of [ nodes with [is-number? [ nw:distance-to myself ] of myself] ] of current-location
end

to move
  let test-location min-one-of nodes [distance myself]
  if (any? nodes with [distance myself < 1]) and (test-location != current-location) [
    set current-location min-one-of nodes [distance myself]
    ifelse current-location = destination [
      set-destination
    ]
    [
      set next-node item 1 [nw:turtles-on-path-to [destination] of myself] of current-location
      face next-node
    ]
  ]
  fd speed
end

。。。这可以使它通过代码检查,但一旦调用该函数,该函数将返回预期输入为字符串或列表的项,但得到的却是TRUE/FALSE。有时处理笨拙语法的最简单方法是完全避免它,这也会使代码更具可读性。在本例中,我将为目标创建一个临时变量并使用它。因此,与其在一个命令中完成所有操作,不如:

let target [destination] of myself
set next-node item 1 nw:turtles-on-weighted-path-to target speedLimit
但如果您确实希望将其放在一行中,括号可能会有所帮助:

set next-node item 1 nw:turtles-on-weighted-path-to ([destination] of myself) speedLimit

这很好用!感谢这两个例子——我知道有一种方法可以使临时变量工作,但不知道如何使用该语法让我感到困扰。
set next-node item 1 nw:turtles-on-weighted-path-to ([destination] of myself) speedLimit