在 RNetLogo 中,如何导出代理集详细信息列表而不每次都覆盖该列表?
In RNetLogo how do I export a list of agentset details without overwriting the list each time?
我在 NetLogo 中有一个模型,其中代理(海龟)在景观中移动并以设定的速度生产其他代理(鸡蛋)。后者不动。我的目标是收集鸡蛋的坐标并测量最近邻距离之类的东西。
在 RNetLogo 中我有一些代码可以做到这一点:
NLCommand("setup")
NLDoCommandWhile("day < 10", "go")
eggcoords <- list()
eggcoords <- NLGetAgentSet(c("who","xcor","ycor"), "eggs")
问题是随着鸡蛋数量的增加,模型变慢了。一个解决方案是在一天结束时杀死鸡蛋,但将它们的详细信息存储在一个列表中,我可以每天更新该列表而不会覆盖任何内容。这就是我被困的地方。
希望对您有所帮助。
如果你的 day 是恒定的刻度数(比如 24),你可以这样做:
在清除鸡蛋的 NetLogo 模型中创建 end-of-day
过程。
然后这样调用你的模型:
turtles <- list()
NLCommand("setup")
# run for 10 days:
for (day in 1:10) {
NLCommand("repeat 24 [go]")
agent_set <- NLGetAgentSet(c("who", "xcor", "ycor",
"min [ distance myself ] of other turtles"),
"turtles")
names(agent_set) <- c("who", "xcor", "ycor", "nnd")
agent_set$day = day
turtles[[day]] <- agent_set
NLCommand("end-of-day")
}
注:
- 在
for
循环中 go
执行了 24 次 NLCommand
调用
- 您可以在
NLGetAgentSet
的 agent.var
参数中使用任何 NetLogo 报告器,这样您就可以即时计算最近邻距离
min [ distance myself ] of other turtles
.
- 结果 (
turtles
) 是一个数据帧列表。
您可以使用 df_turtles <- do.call(rbind, turtles)
将它们绑定到一个数据框
我在 NetLogo 中有一个模型,其中代理(海龟)在景观中移动并以设定的速度生产其他代理(鸡蛋)。后者不动。我的目标是收集鸡蛋的坐标并测量最近邻距离之类的东西。
在 RNetLogo 中我有一些代码可以做到这一点:
NLCommand("setup")
NLDoCommandWhile("day < 10", "go")
eggcoords <- list()
eggcoords <- NLGetAgentSet(c("who","xcor","ycor"), "eggs")
问题是随着鸡蛋数量的增加,模型变慢了。一个解决方案是在一天结束时杀死鸡蛋,但将它们的详细信息存储在一个列表中,我可以每天更新该列表而不会覆盖任何内容。这就是我被困的地方。
希望对您有所帮助。
如果你的 day 是恒定的刻度数(比如 24),你可以这样做:
在清除鸡蛋的 NetLogo 模型中创建
end-of-day
过程。然后这样调用你的模型:
turtles <- list() NLCommand("setup") # run for 10 days: for (day in 1:10) { NLCommand("repeat 24 [go]") agent_set <- NLGetAgentSet(c("who", "xcor", "ycor", "min [ distance myself ] of other turtles"), "turtles") names(agent_set) <- c("who", "xcor", "ycor", "nnd") agent_set$day = day turtles[[day]] <- agent_set NLCommand("end-of-day") }
注:
- 在
for
循环中go
执行了 24 次NLCommand
调用 - 您可以在
NLGetAgentSet
的agent.var
参数中使用任何 NetLogo 报告器,这样您就可以即时计算最近邻距离min [ distance myself ] of other turtles
. - 结果 (
turtles
) 是一个数据帧列表。 您可以使用df_turtles <- do.call(rbind, turtles)
将它们绑定到一个数据框