如何在条件下使用另一个代理设置 link 的颜色
How to set the color of a link with another agent under condition
我想将连接一个代理(reader 的品种)的链接的颜色更改为具有标志(TM? = true
)的其他 reader。代码是这样的:
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
returns 我在行 ask my-rris with [other-TM-readers] [ set color red ]
中出错,因为 with
期望 true 或 false 而不是代理集。
我如何 select 连接当前的 rri
链接?reader 与具有 TM? = true
的 reader 链接?
此致
当你写:
let other-TM-readers other readers with [ TM? = true ]
你告诉 NetLogo 将 agentset 分配给 TM
为真的所有读者的 other-TM-readers
变量。所以当你写:
ask my-rris with [other-TM-readers] [ set color red ]
您正在将 other-TM-readers
agentset 传递给 with
,就像 NetLogo 在其错误消息中所说的那样。
这很容易修复,但首先,评论:写 = true
几乎总是多余的。您的 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 ]
]
你也可以直接询问 links,并使用 other-end
原语来检查邻居的颜色:
ask my-rris with [ [ TM? ] of other-end ] [ set color red ]
最后一个版本也比以前的版本更安全,因为它不假设调用者和其他读者之间存在 link:它只会询问 links实际上存在。 (前两个版本可以检查 rri-with myself != nobody
,但那样不太优雅。)
我想将连接一个代理(reader 的品种)的链接的颜色更改为具有标志(TM? = true
)的其他 reader。代码是这样的:
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
returns 我在行 ask my-rris with [other-TM-readers] [ set color red ]
中出错,因为 with
期望 true 或 false 而不是代理集。
我如何 select 连接当前的 rri
链接?reader 与具有 TM? = true
的 reader 链接?
此致
当你写:
let other-TM-readers other readers with [ TM? = true ]
你告诉 NetLogo 将 agentset 分配给 TM
为真的所有读者的 other-TM-readers
变量。所以当你写:
ask my-rris with [other-TM-readers] [ set color red ]
您正在将 other-TM-readers
agentset 传递给 with
,就像 NetLogo 在其错误消息中所说的那样。
这很容易修复,但首先,评论:写 = true
几乎总是多余的。您的 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 ]
]
你也可以直接询问 links,并使用 other-end
原语来检查邻居的颜色:
ask my-rris with [ [ TM? ] of other-end ] [ set color red ]
最后一个版本也比以前的版本更安全,因为它不假设调用者和其他读者之间存在 link:它只会询问 links实际上存在。 (前两个版本可以检查 rri-with myself != nobody
,但那样不太优雅。)