首页 > 解决方案 > Error: Element 287 of list [0] could not be found, which is only 1 in NetLogo

问题描述

I would like to quantify how many times each turtle has passed each patch in the world. Do you know how I can get this information from NetLogo? I was able to find out how many times the turtle visited the patches, but not how many times it went to each specific patch. For example: turtle 0 visited patch (0, 0) 2 times and patch (0, 1) 4 times. But,Turtle 2 visited patch (0 0) 3 times and patch (0, 1) 3 times and so on.

But, the following error appears: Element 287 of list [0] could not be found, which is only 1. error while patch 7 22 running ITEM called by (anonymous command: [ id -> let item id turtle-visits set turtle-visits replace-item id turtle-visits current-num-visits + 1 ]) called by procedure GO called by 'go' button

Can someone help me?

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
  ]

end

标签: netlogo

解决方案


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

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

如果你替换num-turtlescount turtles,因为你想为世界上的每一个海龟都设置一个值,它应该可以工作:

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


推荐阅读