我有一个经常在 ask[] 中调用的过程“读取文件”。来自 read file lines with spaces into NetLogo as lists , 此过程将文件 .txt 读取为列表。是否可以直接在 Netlogo 中保存文件 .txt 的数据以节省时间,因为为每只海龟读取文件 .txt 会降低模型速度?
to read-file
let parameters split-into-n-lists 1 read-file-into-list "Parameters.txt"
end
在此先感谢您的帮助。
最佳答案
您可能不应该在ask
中调用read-file
文件。假设文件中的数据在模拟过程中没有改变,你应该调用它一次(可能在 setup
期间)并在你的 ask中访问结果列表(保存为全局变量)
.
而且我不完全确定这就是“直接在 Netlogo 中保存文件 .txt 的数据”的意思,但您也可以直接在代码中初始化列表:
globals [
a b c
]
to setup
set a [2321 2321 2321 213]
set b [23233 3223 313 321]
set c [2 2 1 1]
end
https://stackoverflow.com/questions/24071210/