Netlogo:要求海龟数其邻居 [英] Netlogo: asking a turtle to count its neighbors
问题描述
我要一只海龟用下面的代码计算它相邻的健康海龟
I´m asking a turtle to count its neighboring turtles that are healthy with the following code
let healthy-neighbors count turtles-on neighbors with [infected? = false]
我得到以下信息:您不能使用 INFECTED?在补丁上下文中,因为感染?仅限海龟
I get the following: You can´t use INFECTED? in a patch context, because INFECTED? is turtle-only
我的错误一定是基本错误,但找不到,有什么帮助吗?
My mistake must be basic, but can't find it, any help?
推荐答案
NetLogo 将其视为 turtles-on (neighbors with [infected? = false)
,并且由于 neighbors
给出了一组补丁,with
子句需要补丁,但补丁没有 infected?
,正如错误中所说的那样.
NetLogo is seeing that as turtles-on (neighbors with [infected? = false)
, and since neighbors
gives an agentset of patches, the with
clauses is expecting patches, but patches do not have infected?
, as it says in the error.
你可能想要的是让健康的邻居数(海龟的邻居)与[感染?= false]
.括号会告诉 NetLogo 先从相邻的瓦片中获取海龟,然后用 with
过滤它们.
What you probably want is let healthy-neighbors count (turtles-on neighbors) with [infected? = false]
. The parentheses will tell NetLogo to get the turtles from the neighboring patches first, then filter them with with
.
这篇关于Netlogo:要求海龟数其邻居的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!