如何在 table of table extension 中使用代理作为键?

How to use agents as keys in table of table extension?

我正在使用 table 扩展名作为代理人拥有的变量。 此 table 的内容包含引用另一个代理集 (events) 的代理的值。 作为 table 键,我使用 e-ids 列表,其中包含 events 品种中每个代理的 who 编号。 以下过程初始化 tables:

to setup-tables
  ask walkers [
      set we-tfound table:make
      set we-interest table:make
      foreach e-ids [ [?] -> table:put we-tfound ? 0
                             table:put we-interest ? 1  ] ]
  ask links [
    set popularity table:make
    foreach e-ids [ [?] -> table:put popularity ? 0 ] ]
end

其他帖子的答案建议不要使用 who 数字并通过使用例如构造 ask agents [...] 来迭代代理。 但是,我不知道如何使用代理或比 whos ids 更好的方式迭代 table:keys 的最佳方法。

非常感谢您的帮助

由于在tables 中代理不能用作键,因此使用who 数字是完全合理的。这里的危险是,如果海​​龟死亡,您最终得到的条目实际上并不对应于现有的海龟。 (这也是 tables 中不允许代理作为键的原因。)您可以执行 is-turtle? turtle key 查看 key 是否对应于现有的海龟。

要将 table:keys 转换回代理集,您可以执行以下操作:

turtle-set map turtle table:keys my-table

因此,对于 ask 作为 table 中键的所有海龟,您需要:

ask turtle-set map turtle table:keys my-table [ do-stuff ]

map turtle table:keyswho 数字列表转换为海龟列表。 turtle-set 然后将其转换为代理集。