我正在尝试创建一个群集模型,但是当我的滑块位于特定的区域或我的人口在100以下时,我会得到任何帮助都会非常感激的错误。
我知道这和我的“羊群”程序有关
turtles-own [
flockmates
nearest-neighbor
]
to setup
clear-all
create-turtles population
[set color white
set size 5
setxy random-xcor random-ycor]
reset-ticks
end
to go
ask turtles [flock wiggle]
tick
end
to flock
find-flockmates
ifelse any? flockmates
[find-nearest-neighbor]
[explore]
ifelse distance nearest-neighbor < perspace
[separate]
[ifelse distance nearest-neighbor < nearview [set color orange]
[align]]
endto find-flockmates
set flockmates other turtles in-cone maxview vision-angle
end
to find-nearest-neighbor
set nearest-neighbor min-one-of flockmates [distance myself]
end
to separate
rt 180
set color 13
end
to wiggle
rt random 20
lt random 20
fd 1
end
to align
face nearest-neighbor
set color yellow
end
to turn-towards [new-heading max-turn]
turn-at-most (subtract-headings new-heading heading) max-turn
end
to turn-away [new-heading max-turn]
turn-at-most (subtract-headings heading new-heading) max-turn
end
to turn-at-most [turn max-turn]
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
to explore
let r random exploration-option
ifelse r = 0
[rt search-angle]
[lt search-angle]
set color white
end发布于 2022-04-25 10:29:36
你没有提供一个可重复的例子来说明你的问题,但原因必须是……
那里的错误信息非常丰富:distance希望找到一个代理,但是得到了数字0。这很可能是指distance nearest-neighbor。我们知道0是自定义变量的默认值,这意味着当出现此错误时,这是因为有些海龟还无法找到基于nearest-neighbor的find nearest-neighbor (这意味着它在基于ifelse any? flockmates部分的find flockmates中找不到任何人)。
我不知道在explore中会发生什么,但这并不重要:您需要调整代码,以便在尚未找到nearest-neighbor的情况下,它不会要求海龟使用nearest-neighbor进行操作。
https://stackoverflow.com/questions/71995939
复制相似问题