Netlogo:现在还没有人被当作代理人对待吗?
Netlogo: is nobody still being treated as an agent?
我有一份包裹代理名单。但我会定期杀死包裹。然而,列表仍然记录着这样的事情:[nobody nobody nobody nobody nobody nobody nobody nobody],随着时间的推移,模型的 运行 越来越慢,最终弹出消息 "your model is too large to run with available memory"
在这种情况下,死亡的代理(即没有人)是否仍然被视为消耗大量内存的代理?如果它是纯数字或字符串列表怎么办?它会导致同样的OOM问题吗? Netlogo 中的列表可以有多大以及任何上限?
来自 die
的 NetLogo 字典:如果你有一个代理列表并且代理死了,那么代理将从任何代理集中删除并且:
- 代理将从它所在的任何代理集中消失,将这些代理集的大小减少一个。
- 任何存储代理的变量现在将不再包含任何人
死掉的特工没有消耗资源,但列表在消耗资源(正如您通过打印列表发现的那样)。您可以使用以下模型看到这一点:
globals [mylist myagentset]
to setup
clear-all
create-turtles 1
set mylist sort-on [who] turtles
set myagentset turtles
reset-ticks
end
to go
create-turtles 1
[ set myagentset (turtle-set myagentset self)
]
set mylist lput one-of turtles mylist
ask one-of turtles [die]
type "turtles: " print count turtles
type "list: " print length mylist
type "agentset: " print count myagentset
tick
end
如果你想从列表中删除死龟,你需要使用 remove-item
明确地这样做。数字、字符串等列表也是如此
或者,如果列表不需要在 ticks 上维护,但可以重建(例如,如果它是 turtles agentset 的排序列表),您可以在每个 tick 时创建它,并且该列表将只包含活着的海龟。
我有一份包裹代理名单。但我会定期杀死包裹。然而,列表仍然记录着这样的事情:[nobody nobody nobody nobody nobody nobody nobody nobody],随着时间的推移,模型的 运行 越来越慢,最终弹出消息 "your model is too large to run with available memory"
在这种情况下,死亡的代理(即没有人)是否仍然被视为消耗大量内存的代理?如果它是纯数字或字符串列表怎么办?它会导致同样的OOM问题吗? Netlogo 中的列表可以有多大以及任何上限?
来自 die
的 NetLogo 字典:如果你有一个代理列表并且代理死了,那么代理将从任何代理集中删除并且:
- 代理将从它所在的任何代理集中消失,将这些代理集的大小减少一个。
- 任何存储代理的变量现在将不再包含任何人
死掉的特工没有消耗资源,但列表在消耗资源(正如您通过打印列表发现的那样)。您可以使用以下模型看到这一点:
globals [mylist myagentset]
to setup
clear-all
create-turtles 1
set mylist sort-on [who] turtles
set myagentset turtles
reset-ticks
end
to go
create-turtles 1
[ set myagentset (turtle-set myagentset self)
]
set mylist lput one-of turtles mylist
ask one-of turtles [die]
type "turtles: " print count turtles
type "list: " print length mylist
type "agentset: " print count myagentset
tick
end
如果你想从列表中删除死龟,你需要使用 remove-item
明确地这样做。数字、字符串等列表也是如此
或者,如果列表不需要在 ticks 上维护,但可以重建(例如,如果它是 turtles agentset 的排序列表),您可以在每个 tick 时创建它,并且该列表将只包含活着的海龟。