netlogo - 如何将乌龟的局部变量与其邻居进行比较
问题描述
我正在尝试将乌龟的局部变量与其邻居进行比较,并尝试找出符合此标准的邻居 总数总计附近= 邻居总数。我正在根据海龟的颜色进行检查,如果颜色不同,那么我将检查属性/变量 Error: A patch can't access a turtle or link variable without指定哪个代理
代码:
turtle-own[
total-similar-nearby ; sum of previous two variables
total-other-nearby
total-nearby
native
language
income
maritalstatus
]
;;then assigning multiple number of turtles with different values to the local variables.
ask turtles[
repeat total-nearby
[
if color = [color] of one-of neighbors
[set d1 d1 + 1]
if color != [color] of one-of neighbors
[
if native = [ native ] of one-of neighbors
[set a 1]
if language = [ language ] of one-of neighbors
[set b 1]
if income = [ income ] of one-of neighbors
[set c 1]
if maritalstatus = [ maritalstatus ] of one-of neighbors
[set d 1]
] set p a + b + c + d
if p >= 50 [set d1 d1 + 1]
]
]
解决方案
neighbors
是patch
变量,不是turtle
变量。因此,模型中的海龟使用原语,当他们想要查询海龟neighbors
的代理集时,它们正在查询补丁的代理集。海龟有几种方法可以评估附近的海龟,例如or ,但在这种情况下,如果您想要专门位于直接相邻的补丁上的海龟,您可以使用、和原语来获得您正在寻找的东西. 举个简单的例子,看看这个玩具模型:in-radius
in-cone
other
turtles-on
neighbors
to setup
ca
ask n-of 300 patches [
sprout 1 [
set color one-of [ red blue ]
]
]
reset-ticks
end
to go
ask turtles [
; Make an agent-set of turtles on neighboring patches
let nearby-turtles other turtles-on neighbors
; If there are any turtles on neighboring patches,
; assume the color from one of them.
if any? nearby-turtles [
set color [color] of one-of nearby-turtles
]
]
tick
end
查看其他、turtles-on和邻居的字典定义以获取更多信息。
推荐阅读
- imagemagick - 在不使用“使用画板”的情况下将 AI 转换为 EPS / JPEG
- php - 如何通过错误“infiniteScroll 不是函数”?
- typescript - TypeScript:如何在带有剩余参数的函数中返回条件类型?
- python - 如何从@app.task 中获取 celery.Task 对象
- javascript - 刷新页面而不不断刷新
- angular - 使用 NzPicker (nz-year-picker) 的 NzNoAnimation 错误
- python - 如何生成所有可能的二进制 nxm 矩阵,其中每行之和为 1
- python - Keras人脸识别模型准确率差
- minishift - 创建新主机时出错:json: cannot unmarshal bool into Go struct field Driver.Virtio9p
- python-3.7 - python 函数 os.path.exists() 当我给出一个布尔值时返回 True