如何映射代理集?

How to MAP over agentset?

我需要遍历一个特定的补丁代理集并获取它们的所有邻居,然后加入那些...

我会做类似的事情

reduce patch-set (map [patch-set neighbors self] patches with [somecondition?]) 

但是 MAP 和 REDUCE 不适用于代理集!

map 的正常想法对于集合没有真正意义,但您可以用 of 生成列表,然后将其转换为补丁集。

let _nbrs patch-set [neighbors] of mypatches

您可以根据需要使用 with 过滤 mypatches_nbrs

这是我为处理此类问题所做的疯狂黑客攻击。请注意,我真正想做的是列出将函数应用于代理集中的每个代理所产生的数值列表,但不是。我必须让他们全部应用关于我的函数,然后我必须额外调用一次该函数以找出传递给我的结果是什么。我还必须重写该函数,以便我可以将我感兴趣的代理作为参数(如果我是 运行 它)或我作为参数(如果代理是 运行关于我)。 !

to-report min-edge-distance [agentset maxsize]
  report ifelse-value (any? agentset)
    [edge-distance min-one-of agentset [edge-distance myself true] false]  ; grr, what I want is min map edge-distance agentset, instead I have to do backflips
    [maxsize]
end


to-report edge-distance [alex me?]
  report ifelse-value (me?)  ;because of netlogo's perverse syntax, I've been forced to ask someone else to figure out my edge distance – alex may be me!
   [(distance alex) * (sqrt [energy] of alex / (sqrt [energy] of alex + sqrt energy) )] ;alex is me!
   [(distance alex) * (sqrt energy / (sqrt [energy] of alex + sqrt energy) )] ; alex is not me
end