最后如何在文件中打印所有剩余海龟的 xcor 和 ycor?
How can I print the xcor and ycor of all remaining turtles in a file at the end?
我想知道在我的模型 运行 结束时幸存的海龟的坐标。
我 运行 通过远程集群中的 BehaviorSpace 处理所有内容,所以理想情况下,我希望有一个 table 或类似的文件,告诉我哪些海龟在 运行 中幸存下来,以及它们在哪里位于。
我试过这样写:
to setup
set-current-directory "/home/lorena/Documents/UNAM/Tesis/versiones_de_corrección"
end
to go
if ticks = 180 [
stop
ask turtles [print-coordinates]
export-plot "Populations" "/home/lorena/Documents/UNAM/Tesis/versiones_de_corrección/populations.csv"
]
end
to print-coordinates
file-open "coordinates.csv"
file-write who
file-write xcor
file-write ycor
file-print ""
file-close-all
end
但是,似乎没有创建任何文件。
我不确定您为什么收不到任何文件,但可以帮助您解决几个问题。
a) 当您使用 BehaviorSpace 时,编写输出文件很棘手,因为如果多个模型 运行s 试图同时使用相同的输出文件,就会出现错误。一种解决方案是在文件名中包含行为空间 运行 编号,这样每个 运行 都会写入自己的输出文件。
b) 你的海龟坐标输出文件的格式很笨拙,很难使用——我希望如果每只海龟都写一行包含它的所有信息,它会更容易使用。
您可以通过使用 csv 扩展并用类似 observer 程序(我尚未测试)替换您的“打印坐标”程序来解决这两个问题。
to write-turtle-coordinates
let file-name (word "coordinates-" behaviorspace-run-number ".csv")
csv:to-file file-name [(list who xcor ycor)] of turtles
end
我想知道在我的模型 运行 结束时幸存的海龟的坐标。 我 运行 通过远程集群中的 BehaviorSpace 处理所有内容,所以理想情况下,我希望有一个 table 或类似的文件,告诉我哪些海龟在 运行 中幸存下来,以及它们在哪里位于。
我试过这样写:
to setup
set-current-directory "/home/lorena/Documents/UNAM/Tesis/versiones_de_corrección"
end
to go
if ticks = 180 [
stop
ask turtles [print-coordinates]
export-plot "Populations" "/home/lorena/Documents/UNAM/Tesis/versiones_de_corrección/populations.csv"
]
end
to print-coordinates
file-open "coordinates.csv"
file-write who
file-write xcor
file-write ycor
file-print ""
file-close-all
end
但是,似乎没有创建任何文件。
我不确定您为什么收不到任何文件,但可以帮助您解决几个问题。
a) 当您使用 BehaviorSpace 时,编写输出文件很棘手,因为如果多个模型 运行s 试图同时使用相同的输出文件,就会出现错误。一种解决方案是在文件名中包含行为空间 运行 编号,这样每个 运行 都会写入自己的输出文件。
b) 你的海龟坐标输出文件的格式很笨拙,很难使用——我希望如果每只海龟都写一行包含它的所有信息,它会更容易使用。
您可以通过使用 csv 扩展并用类似 observer 程序(我尚未测试)替换您的“打印坐标”程序来解决这两个问题。
to write-turtle-coordinates
let file-name (word "coordinates-" behaviorspace-run-number ".csv")
csv:to-file file-name [(list who xcor ycor)] of turtles
end