Netlogo 海龟从当前位置移动到选定的目的地,而不直接从一个节点移动到另一个节点

Netlogo 海龟从当前位置移动到选定的目的地,而不直接从一个节点移动到另一个节点,netlogo,Netlogo,我试图让海龟从当前节点位置移动到节点目的地,而不必从一个节点跳到另一个节点,而是从一个节点逐步移动到另一个节点。我查看了Move Toward Target示例和Link Walking Turtles示例模型,并尝试在下面的代码中结合这些模型,这似乎使turtle逐步地从一个节点移动到另一个节点,但只是以随机方式 to walk let distance-from-current-location distance current-location ifelse 0.5 < di

我试图让海龟从当前节点位置移动到节点目的地,而不必从一个节点跳到另一个节点,而是从一个节点逐步移动到另一个节点。我查看了Move Toward Target示例和Link Walking Turtles示例模型,并尝试在下面的代码中结合这些模型,这似乎使turtle逐步地从一个节点移动到另一个节点,但只是以随机方式

to walk
  let distance-from-current-location distance current-location
  ifelse 0.5 < distance from-current-location [
    fd 0.5 ]
  [
    let new-location one-of [ link-neighbors ] of current-location
    face new-location
    set current-location new-location
  ]
end
走路
让距离当前位置距离当前位置
ifelse 0.5<距当前位置的距离[
fd 0.5]
[
让新位置成为当前位置的[链接邻居]之一
面对新的位置
设置当前位置新位置
]
结束
我想要的是海龟在节点之间循序渐进地行走,直到到达目的地。例如,我尝试了下面的代码,但是海龟最终离开了链接

to walk
  if current-location != destination [
    let next-node item 1 [ nw:turtles-on-path-to [ destination ] of myself ] of current-location
    set current-location next-node
    ifelse distance current-location < 0.5 [
      move-to current-location ]
    [
      face current-location
      fd 0.5
    ]
end
走路
如果是当前位置!=目的地[
让下一个节点项目1[nw:乌龟在当前位置的[destination]路径上
设置下一个节点的当前位置
ifelse距离当前位置<0.5[
移动到当前位置]
[
面向当前位置
fd 0.5
]
结束
如何使海龟在其选定路径的节点之间从当前位置移动到目的地,而不直接从一个节点移动到另一个节点?例如,我希望海龟不从节点1跳到节点2跳到节点3…跳到节点n,而是从节点1向前移动0.5…直到到达目的地节点


谢谢。

我认为问题在于,
当前位置
在海龟实际到达下一个节点之前正在更新到下一个节点。请尝试以下操作:

to walk
  if current-location != destination [
    ifelse distance current-location < 0.5 [
      move-to current-location
      let next-node item 1 [ nw:turtles-on-path-to [ destination ] of myself ] of current-location
      set current-location next-node
    ] [
      face current-location
      fd 0.5
    ]
end

这看起来并不明显是错误的。当你说它离开了链接时,你的意思是方向不太正确,或者它一直在正确的方向上移动太远,或者其他什么吗?乌龟不是在到达下一个节点之前向前移动0.5,而是只向下一个节点的方向移动0.5次,然后继续移动ng 0.5在另一个方向。一些节点彼此非常接近,因此可能是海龟在经过下一个节点时走得太远而没有到达它。例如,当海龟与下一个节点的距离为0.5时,它应该直接向它移动。可能是海龟前进太多,所以它永远不会为0。5远离它的下一个节点,因此没有移动到它?我如何解决这个问题?有了更好的解释,我可以看到一个逻辑错误。您将当前位置设置到下一个节点,然后下次它循环时,我认为它将设置到路径中的下一个节点,然后下一个循环到下一个节点,因为
让下一个节点…
行正在运行由于当前位置正在更新,所以日期已定。所有内容现在已排序。感谢您抽出时间查看我的问题。
to walk
  if current-location != destination [
    ifelse distance next-node < 0.5 [
      ;; Close enough to the next node; make it my current location
      ;; and target the next node on the list.
      set current-location next-node
      move-to current-location
      set next-node item 1 [ nw:turtles-on-path-to [ destination ] of myself ] of current-location
    ] [
      ;; Not there yet; keep walking towards the next node.
      face next-node
      fd 0.5
    ]
end