NetLogo的两个代理集操作 [英] NetLogo two agentsets operations
本文介绍了NetLogo的两个代理集操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个代理集.是否有查找功能:
I have two agentsets. Are there functions for finding:
- 两个(交叉点)中都存在的代理的代理集
- 在一个而不是另一个中存在的代理的代理集
我发现手动执行此操作非常困难,尤其是在三元组ask
I'm finding it very difficult to implement this by hand, especially when it's needed inside of a triple ask
理想用法类似于with
语法:
let cross set1 and-in set2
let uniq set1 with [color = red] not-in set2
简单的事情,例如"A代理是否在X代理集中?"有问题
Simple things like "Is agent A in the agentset X?" are problematic
推荐答案
对于第一个,您使用turtle-set
原语.对于第二个,您需要member?
原语,它也适用于代理集.因此:
For the first one you use the turtle-set
primitive. For the second one you need the member?
primitive, which also works on agentsets. As such:
to setup
ca
create-turtles 10 [set color red]
create-turtles 10 [set color blue]
let red-ones turtles with [color = red]
let blue-ones turtles with [color = blue]
;join 2 agent sets
let joinset (turtle-set red-ones blue-ones)
show joinset
let even-ones (turtles with [who mod 2 = 0])
;subtract even-ones from red-ones
let subtractset red-ones with [not member? self even-ones]
show subtractset
end
这篇关于NetLogo的两个代理集操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文