如何使用代理作为表扩展表中的键? [英] How to use agents as keys in table of table extension?
问题描述
我将表扩展名用作一系列代理所拥有的变量.
该表的内容包含引用了另一个代理集(events
)的代理的值.
作为表键,我使用e-ids
列表,其中包含events
品种中每个代理的who
号.
以下过程将初始化表:
I am using the table extension as variable owned by a breed of agents.
The content of this table contains values referred to agents of another agent-set (events
).
As table keys, I use e-ids
a list with the who
numbers of each agent in events
breed.
The following procedure initializes the 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 [...]
在代理上进行迭代.
但是,我不知道使用代理迭代table:keys
的最佳方法还是比whos id更好的方法.
The answer to others posts recommends not to use who
numbers and iterate over agents by using, for example, construct ask agents [...]
.
However, I do not know how could be the best way to iterate over table:keys
using agents or someway better than whos ids.
非常感谢您的帮助
推荐答案
由于不能将代理用作表中的键,因此使用who
数字是完全合理的.这里的危险是,如果乌龟死亡,您最终得到的条目实际上与现有的乌龟不对应. (这也是不允许将代理用作表中键的原因.)您可以执行is-turtle? turtle key
来查看key
是否对应于现有的乌龟.
Since agents can't be used as keys in tables, using who
numbers is perfectly reasonable. The danger here is that if a turtle dies, you end up with an entry that doesn't actually correspond to an existing turtle. (This is also the reason agents are not allowed as keys in tables.) You can do is-turtle? turtle key
to see if key
corresponds to an existing turtle.
要将table:keys
转换回代理集,您可以执行以下操作:
To convert table:keys
back to an agentset, you can do:
turtle-set map turtle table:keys my-table
因此,要ask
表中所有作为键的海龟,请执行以下操作:
Thus, to ask
all the turtles that are keys in a table, you do:
ask turtle-set map turtle table:keys my-table [ do-stuff ]
map turtle table:keys
将who
数字列表转换为海龟列表. turtle-set
然后将其转换为代理集.
map turtle table:keys
converts the list of who
numbers to a list of turtles. turtle-set
then converts that to an agentset.
这篇关于如何使用代理作为表扩展表中的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!