首页 > 解决方案 > 如何纠正错误:找不到没有数字的列表的平均值

问题描述

我试图让海龟(觅食者)根据平均巢香的报告者移动,该报告者应该报告世界各地巢香的平均值,从巢穴的 200 高到对角的 120世界的。但是,在嵌套处,触发了下面的错误,我不明白为什么。平均巢香不是一个数字列表吗?我该如何纠正这个错误?

Can't find the mean of a list with no numbers: [].
error while forager 7 running MEAN
  called by procedure MEAN-NEST-SCENT-IN-CONE

to-report mean-nest-scent-in-cone [cone-distance angle angle-width ] ; ant procedure - reports the mean amount of nest-scent in cone
  rt angle
  let p patches in-cone cone-distance angle-width
  ;ask p [ show chemical ]
  if p = nobody [report 0]
  lt angle
  report (mean [nest-scent] of p)
end
`````````````````````````````````

标签: netlogo

解决方案


您将“p”设置为补丁集,但您正在测试它是否为“nobody”。代理集的原语是any?。尝试更换:

if p = nobody [report 0]
lt angle
report (mean [nest-scent] of p)

ifelse any? p
[ lt angle
  report mean [nest-scent] of p
]
[ report 0 ]

推荐阅读