Netlogo:是否有一个`all-of`命令,与`one-of`相似?

时间:2017-10-12 16:26:19

标签: netlogo

是否有相同的命令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]
    ]

2 个答案:

答案 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 ]