【问题标题】:Error: Element 287 of list [0] could not be found, which is only 1 in NetLogo错误:无法找到列表 [0] 的元素 287,在 NetLogo 中只有 1
【发布时间】:2021-06-14 14:57:51
【问题描述】:

我想量化每只海龟经过世界上每个补丁的次数。你知道我如何从 NetLogo 获得这些信息吗?我能够找出乌龟访问补丁的次数,但不知道它访问每个特定补丁的次数。例如:turtle 0 访问了 patch (0, 0) 2 次和 patch (0, 1) 4 次。但是,Turtle 2 访问了 3 次补丁 (0 0) 和 3 次补丁 (0, 1) 等等。

但是,出现以下错误:无法找到列表[0]的元素287,它只有1。 补丁 7 22 运行 ITEM 时出错 由(匿名命令:[ id -> let item id turtle-visits set turtle-visits replace-item id turtle-visits current-num-visits + 1 ])调用 由过程 GO 调用 由“go”按钮调用

有人可以帮我吗?

globals [ edge-size ]
patches-own [ turtle-visits ]

to setup
  ca
  let num-turtles 1
  set edge-size 29
  resize-world 0 edge-size 0 edge-size
  let pcolors []
  set pcolors [ 85 95 ]
  ask patches [       
    set turtle-visits n-values num-turtles [0]
    set pcolor item (random 2) pcolors
  ]
  reset-ticks
end

to go
  ask turtles [
    rt random 360
    fd 1
  ]

结束

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    问题是,您使用每个补丁的海龟数量初始化turtle-visits 列表,即num-turtles

    set turtle-visits n-values num-turtles [0]

    如果您将num-turtles 替换为count turtles,由于您希望为世界上的每只海龟设置一个值,它应该可以工作:

    set turtle-visits n-values count turtles [0]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 2021-05-18
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多