在netlogo运行结束时,我想输出520个特定于运行的变量。我用文件写这样做。但是,当我这样做时,创建的输出文件是不完整的。例如,如果我执行1,008次运行,则仅将734.xxx运行的结果写入该文件。这是文件写入命令的代码:
file-open
"Part01Results.txt"
file-write actualcombo
file-write parmcombo
file-write xqa1
file-write xqa2
file-write xqa3
file-write yqa1
file-write yqa2
file-write yqa3
file-write zqa1
file-write zqa2
file-write zqa3
file-write aqa1
file-write aqa2
file-write aqa3
file-write bqa1
file-write bqa2
file-write bqa3
file-write cqa1
file-write cqa2
file-write cqa3
file-write ptotBP
file-write ptotNBP
file-write ptotNone
file-write ptotDout
file-write ototBP
file-write ototNBP
file-write ototNone
file-write ototDout
file-write utotBP
file-write utotNBP
file-write utotNone
file-write utotDout
file-write pmidit3
file-write pmidit2
file-write pmidit1
file-write pmidit0
file-write omidit3
file-write omidit2
file-write omidit1
file-write omidit0
file-write umidit3
file-write umidit2
file-write umidit1
file-write umidit0
file-write pcounterBP
file-write pcounterNBP
file-write pcounterNone
file-write pcounterDout
file-write ocounterBP
file-write ocounterNBP
file-write ocounterNone
file-write ocounterDout
file-write ucounterBP
file-write ucounterNBP
file-write ucounterNone
file-write ucounterDout
file-write pc440tot
file-write pc430tot
file-write pc420tot
file-write pc410tot
file-write ppm440MeanHgt
file-write ppm440LowHgt
file-write ppm440HiHgt
file-write ppm430MeanHgt
file-write ppm430LowHgt
file-write ppm430HiHgt
file-write ppm420MeanHgt
file-write ppm420LowHgt
file-write ppm420HiHgt
file-write ppm410MeanHgt
file-write ppm410LowHgt
file-write ppm410HiHgt
file-write ppm340MeanHgt
file-write ppm340LowHgt
file-write ppm340HiHgt
file-write ppm330MeanHgt
file-write ppm330LowHgt
file-write ppm330HiHgt
file-write ppm320MeanHgt
file-write ppm320LowHgt
file-write ppm320HiHgt
file-write ppm310MeanHgt
file-write ppm310LowHgt
file-write ppm310HiHgt
file-write ppm240MeanHgt
file-write ppm240LowHgt
file-write ppm240HiHgt
file-write ppm230MeanHgt
file-write ppm230LowHgt
file-write ppm230HiHgt
file-write ppm220MeanHgt
file-write ppm220LowHgt
file-write ppm220HiHgt
file-write ppm210MeanHgt
file-write ppm210LowHgt
file-write ppm210HiHgt
file-write ppm140MeanHgt
file-write ppm140LowHgt
file-write ppm140HiHgt
file-write ppm130MeanHgt
file-write ppm130LowHgt
file-write ppm130HiHgt
file-write ppm120MeanHgt
file-write ppm120LowHgt
file-write ppm120HiHgt
file-write ppm110MeanHgt
file-write ppm110LowHgt
file-write ppm110HiHgt
file-write opm440MeanHgt
file-write opm440LowHgt
file-write opm440HiHgt
file-write opm430MeanHgt
file-write opm430LowHgt
file-write opm430HiHgt
file-write opm420MeanHgt
file-write opm420LowHgt
file-write opm420HiHgt
file-write opm410MeanHgt
file-write opm410LowHgt
file-write opm410HiHgt
file-write opm340MeanHgt
file-write opm340LowHgt
file-write opm340HiHgt
file-write opm330MeanHgt
file-write opm330LowHgt
file-write opm330HiHgt
file-write opm320MeanHgt
file-write opm320LowHgt
file-write opm320HiHgt
file-write opm310MeanHgt
file-write opm310LowHgt
file-write opm310HiHgt
file-write opm240MeanHgt
file-write opm240LowHgt
file-write opm240HiHgt
file-write opm230MeanHgt
file-write opm230LowHgt
file-write opm230HiHgt
file-write opm220MeanHgt
file-write opm220LowHgt
file-write opm220HiHgt
file-write opm210MeanHgt
file-write opm210LowHgt
file-write opm210HiHgt
file-write opm140MeanHgt
file-write opm140LowHgt
file-write opm140HiHgt
file-write opm130MeanHgt
file-write opm130LowHgt
file-write opm130HiHgt
file-write opm120MeanHgt
file-write opm120LowHgt
file-write opm120HiHgt
file-write opm110MeanHgt
file-write opm110LowHgt
file-write opm110HiHgt
file-write upm440MeanHgt
file-write upm440LowHgt
file-write upm440HiHgt
file-write upm430MeanHgt
file-write upm430LowHgt
file-write upm430HiHgt
file-write upm420MeanHgt
file-write upm420LowHgt
file-write upm420HiHgt
file-write upm410MeanHgt
file-write upm410LowHgt
file-write upm410HiHgt
file-write upm340MeanHgt
file-write upm340LowHgt
file-write upm340HiHgt
file-close
以下是我所做的一些事情:
1)我在作业运行时监视机器上的内存使用情况。我没有观察到记忆似乎不足的情况。但是,我考虑过增加Netlogo对内存的访问权限,并且已经找到了这样做的方法。但是,在没有明确知道这就是问题的情况下,我宁愿不去处理这些深层命令。因此,我先做了几件事。
2)一半的变量是介于-1和1之间的浮点数。我将它们的精度降低到小数点右边的5位数。
3)我没有编写520个变量的文件,而是尝试将变量的子集写入不同的文件(用一个匹配的键)。较小的文件仍然存在问题。但即使是我的小文件也有超过80个字符的行。那是问题吗?要使所有文件每行少于80个字符,我需要至少18个文件。这可以实现,但在实现此响应之前,我宁愿知道这是问题。
4)我在文件的不同位置删除了“文件刷新”(如果我遇到了未观察到的内存问题)。
5)我在整个文件中删除了'file-write'\ n“'命令(如果行太长)。
6)如果我使用错误的“file- *”命令,我将所有内容都切换到文件打印。
7)我五元组检查文件是否实际上是正确的长度,并且我对统计软件包的读数存在缺陷。但是,由于我只是阻止文件写入命令列表并将其复制到包中并删除“文件写入”语言,因此这不是文件错误的基础。该文件实际上已被截断。
8)我在每个文件写命令之后删除了“file-print”“”命令来输入一个单独的行,以防变量互相写入(在我截断浮点数之前)。
我试图运行模型1,008次,每次都设置不同的全局参数。目的是能够在有效的全局参数空间中进行采样。但是,我不能使用行为空间,因为全局参数不是独立的,并且将它们视为独立参数会产生可能性,只有极小部分实际上是有效的组合。因此,使用行为空间至少会浪费大量的时间和计算周期;更有可能的是,使用行为空间会因为有效运行的发生率低而无法进行研究。因此,相反,我已经确定了全局参数的有效组合,并寻求运行它们的一些子集,获得产生的输出,然后分析结果。因此,我需要一些方法来输出总结结果的520个变量。
我感谢任何人都能提供的任何帮助。
答案 0 :(得分:3)
我经常在每次写入文件后调用file-close
。我不能为你提供一个很好的技术理由,为什么它会起作用,我知道它并不是一个特别令人满意的解决方案,但在我遇到I / O问题的几个时候,#&# 39; s通常解决它。为了省去复制/粘贴file-close
519次的麻烦,看看你是否可以生成所有这些的列表,并做一个
foreach list-with-var-names [
file-open "results.txt"
file-write ?
file-close
]
FWIW,当记录学生时#9;在NetLogo中工作我用file-write
编写了10MB +文件,因此每个变量写入520行绝对不是问题。