netlogo - Netlogo:询问其他代理的变量
问题描述
我试图让代理根据另一个代理的变量是否介于第一个代理的个人最小值和最大值之间做出决定。我遇到了 netlogo 预期的语法问题。
这一点,在下面的完整代码中:
to settle-decision
ask turtles [
ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
[ set settled? true ]
[ set color yellow ]
最终我想让特工做比改变颜色更有趣的事情,但我不能先通过这个!非常感谢任何帮助。
turtles-own [
myneighbor ;; closest other male frog to myself
mycall ;; the amplitude (loudness) of my own call
myminthresh ;; when my neighbor's call is below this threshold, I move toward him
mymaxthresh ;; when my neighbor's call is above this threshold, I move away from him
myNND ;; the distance to my nearest neighbor
settle? ;; true if male decides to create a territory and stop moving
]
to setup
clear-all
create-turtles population [ ;; use the population slider to choose number of males
set size 1.5 ;; easy to see but is it actual agent size or just agent image size?
setxy random-xcor random-ycor ;; distribute frogs randomly in the landscape
set mycall random 100 ;; choose the amplitude of my own call from a random distribution 0 to 100
set color scale-color red mycall 0 100 ;; allows easy visualization of variability in call amplitude
;; lighter color is a higher amplitude
set myminthresh inputminthresh ;; use the input on interface to set the min-threshold
set mymaxthresh inputmaxthresh ;; use the input on the interface to set the max-threshold
set myNND 0 ;; initialize nearest neighbor distance for all
]
reset-ticks
end
to go
choose-neighbors
settle-decision
move-turtles
tick
end
to choose-neighbors
ask turtles [
set myneighbor min-one-of other turtles [distance myself] ;; choose my nearest neighbor based on distance
set myNND distance myneighbor
]
end
to settle-decision
ask turtles [
ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
[ set settled? true ]
[ set color yellow ]
]
end
to move-turtles
ask turtles [
face myneighbor
ifelse mycall < myminthresh
[ set color blue ]
[ set color yellow ]
;; this works but everybody moves so needs more work
fd 5
pendown
]
end
解决方案
您需要的原语是of
使用类似[variablename] of agent
. 我无法对此进行测试,但可能不是:
to settle-decision
ask turtles [
ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
[ set settled? true ]
[ set color yellow ]
]
end
尝试
to settle-decision
ask turtles [
ifelse ([mycall] of myneighbor > myminthresh) AND ([mycall] of myneighbor < mymaxthresh)
[ set settled? true ]
[ set color yellow ]
]
end
推荐阅读
- spring - 不支持内容类型空白
- certificate - 我在哪里可以找到证书、标识符和配置文件中的配置文件页面?
- angular - 无法在 ng-2charts 折线图上添加注释
- ios - 在大部分屏幕模糊的 iOS 应用上显示相机
- angular - Angular 9 - 永远挂起的请求
- javascript - 如何在 JS 和 React 中填充数组?TypeError:无法设置未定义的属性“组织”
- node.js - POST 请求未通过 (MERN)
- javascript - 从 jsPDF 生成的 PDF 复制文本时粘贴乱码
- javascript - 错误-TypeError:无法读取 null 的属性“then”-Node js
- php - 如何解决问题:您的 PHP 安装似乎缺少 MySQL 扩展