首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >距离期望输入是一个代理,但是得到了数字0。

距离期望输入是一个代理,但是得到了数字0。
EN

Stack Overflow用户
提问于 2022-04-25 07:33:23
回答 1查看 29关注 0票数 0

我正在尝试创建一个群集模型,但是当我的滑块位于特定的区域或我的人口在100以下时,我会得到任何帮助都会非常感激的错误。

我知道这和我的“羊群”程序有关

代码语言:javascript
复制
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]] 
end
代码语言:javascript
复制
to 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
EN

回答 1

Stack Overflow用户

发布于 2022-04-25 10:29:36

你没有提供一个可重复的例子来说明你的问题,但原因必须是……

那里的错误信息非常丰富:distance希望找到一个代理,但是得到了数字0。这很可能是指distance nearest-neighbor。我们知道0是自定义变量的默认值,这意味着当出现此错误时,这是因为有些海龟还无法找到基于nearest-neighborfind nearest-neighbor (这意味着它在基于ifelse any? flockmates部分的find flockmates中找不到任何人)。

我不知道在explore中会发生什么,但这并不重要:您需要调整代码,以便在尚未找到nearest-neighbor的情况下,它不会要求海龟使用nearest-neighbor进行操作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71995939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档