是否有相同的命令one-of
可以执行所有代理?那么all-of
命令?我需要我的代理人要求特定的其他代理人汇总并报告一个值。 one-of
命令只会随机选择一个其他代理,但我需要选择列表中的所有代理。
详细信息:我需要我的household
代理商要求其他household
代理商汇总并报告其HHwaterUse
值。每个household
代理都会在其SocialNetwork
列表中询问所有其他代理。 SocialNetwork
列表由Public_ID
值组成,这是每个代理拥有的值。
Ex:因此,如果household-1
拥有SocialNetwork
列表[9126 3495 4197 8771]
,我需要Public_ID
值为9126的所有座席,3495等报告他们的HHwaterUse
值。
ask households [
set NetUseSum sum [HHwaterUse] of households with [[Public_ID] of myself = all-of [SocialNetwork] of self]
]
答案 0 :(得分:2)
member?
原语应该有效,请查看dictionary entry了解详情。这是一个例子,只有一个家庭检查其社交网络用水量的总和:
breed [ households household ]
households-own [ Public_ID Social_Network HH_Water_Use]
to setup
ca
create-households 10 [
setxy random-xcor random-ycor
set Public_ID 1000 + random 1000
set HH_Water_Use 100 + random 50
]
ask households [
set Social_Network sort [Public_ID] of n-of 4 other households
]
reset-ticks
end
to sum-social-network
ask one-of households [
show ( word "My social network comprises: " Social_Network )
ask households with [ member? Public_ID [Social_Network] of myself ] [
print ( word Public_ID " has a water use of " HH_Water_Use )
]
let social_sum sum [HH_Water_Use] of households with [ member? Public_ID [Social_Network] of myself ]
print ( word "My social network has a sum water use of " social_sum )
]
end
修改:
请注意,我同意Nicolas和Jen的说法 - 这绝对不是最好的方法。如果可能,请使用他们的链接或代理集建议。
答案 1 :(得分:0)
这很有用,Luke C建议使用member?
代码片段。我能够同时汇总代理商列表中的价值。
let social_sum sum [HH_Water_Use] of households with [ member? Public_ID [Social_Network] of myself ]