我想更改将一个代理(读者品种)加入其他具有标记(TM? = true
)的读者的链接的颜色。代码是这样的:
breed [ readers reader ]
undirected-link-breed [ rris rri ]
readers-own [ TM? ]
to start-TM [ ?reader ]
ask ?reader [
if any? other readers with [ TM? = true ] [
let other-TM-readers other readers with [ TM? = true ]
ask my-rris with [other-TM-readers] [ set color red ]
]
]
end
在行ask my-rris with [other-TM-readers] [ set color red ]
中返回错误,因为with
期望是真或假,而不是代理集。
如何选择将当前?读者与rri
的读者连接的TM? = true
链接?
此致
答案 0 :(得分:2)
当你写:
let other-TM-readers other readers with [ TM? = true ]
您告诉NetLogo将TM
为other-TM-readers
的所有读者的 agentset 分配给ask my-rris with [other-TM-readers] [ set color red ]
变量。所以当你写下来的时候:
other-TM-readers
您正在将with
代理集传递给= true
,就像NetLogo在其错误消息中所述。
这很容易解决,但首先是评论:写TM?
几乎总是多余的。您的with [ TM? ]
变量已经是布尔值,因此您可以通过编写with [ TM? = true ]
而不是let other-TM-readers other readers with [ TM? ]
ask other-TM-readers [
ask rri-with myself [ set color red ]
]
来直接检查它。
现在,要修复错误,您可以写:
ask other readers with [ TM? ] [
ask rri-with myself [ set color red ]
]
或只是:
ask my-rris with [ [ TM? ] of other-end ] [ set color red ]
您也可以直接询问链接,并使用other-end
原语检查邻居的颜色:
rri-with myself != nobody
最后一个版本比以前的版本更安全,因为它不假设调用者和其他读者之间存在链接:它只会询问实际存在的链接。 (前两个版本可以检查client = boto3.client('efs')
,但这样不太优雅。)