如何找到两个补丁之间的距离?

时间:2019-04-13 22:38:49

标签: netlogo

我正在尝试让代理走到其目的地的最有效的路由(从10个补丁集中随机选择)。问题是,distance似乎是仅代理的命令,而我发现的唯一执行类似操作的代码似乎可以通过运行带有补丁的distance命令来工作,这会产生错误。

这是麻烦的过程:

to-report best-route

  let visible-patches patches in-radius turtles-vision-dist

 let visible-routes visible-patches with [ pcolor = gray ]

  let routes-that-take-me-closer visible-routes with [

    ;;THIS IS THE PROBLEM LINE RIGHT BELOW HERE

    [ distance visible-routes] of destination < [ distance destination - 1 ] of myself
  ]

在我发现的示例Paths中,这是代码:

to-report best-way-to [ destination ]

  let visible-patches patches in-radius walker-vision-dist

  let visible-routes visible-patches with [ pcolor = gray ]

  let routes-that-take-me-closer visible-routes with [

    distance destination < [ distance destination - 1 ] of myself
  ]

  ifelse any? routes-that-take-me-closer [

    ; from those route patches, choose the one that is the closest to me

    report min-one-of routes-that-take-me-closer [ distance self ]
  ] [

    ; if there are no nearby routes to my destination
    report destination
  ]

end

我本来有一些类似的东西,但是它没有用,所以我一直在运气不好,就像同学和我的教授一样。

1 个答案:

答案 0 :(得分:0)

我无法弄清楚您的路径算法应该如何工作,因为它看起来并不像您将移动限制为灰色补丁。但是,假设目标存储为补丁,则可以直接使用distance destination计算到该补丁的距离,如下所示:

turtles-own [ destination ]

to testme
  clear-all
  create-turtles 1
  [ set destination one-of patches
    ask destination [ set pcolor blue ]
  ]
  ask one-of turtles
  [ print distance destination
  ]
end
相关问题