首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未将结果正确写入文件的Net徽标

未将结果正确写入文件的Net徽标
EN

Stack Overflow用户
提问于 2017-12-15 14:59:08
回答 1查看 318关注 0票数 0

我在Netlogo中运行模拟,通过编码自动将结果发送到电子表格。这发生在模拟结束时,以保存每个人的变量(例如,身份、归属范围大小等)。电子表格的结果通常看起来很好,但是当使用BehaviorSpace时,有时来自个人变量的数据没有被正确地打印出来(例如,错误列中的数据或丢失的数据,请参见下面的屏幕快照)。

我想知道,在BehaviorSpace并行运行期间,当模拟同时结束时,这会导致同步写入文件。这有可能发生了吗?除了这些值得注意的问题外,我是否应该合理地相信,剩下的结果被正确地打印到了桌面上?最重要的是,如何避免这些错误打印到文件中?示例代码如下。

额外的问题解决了:我认为打印日期和时间会识别独特的模拟运行,但事实并非如此,因为每个海龟的变量需要超过一分钟才能打印到文件中。是否有一种为每次模拟运行添加唯一标识符的快速方法?

谢谢!

代码语言:javascript
复制
to start-output-file ;; Observer procedure, called from setup. 
  set-current-directory "C:\\... 
  file-open "Table_results.csv"
  ;; Define the names of the variables:
     file-type "Run,"
     file-type "Landscape,"
     file-type "Individual,"
     file-type "Home range size,"
     ;; ... and so on, ~60 results saved for each individual            
     file-print ""
     file-close ]
end

to end-simulation ;; Observer procedure, called from go.
  write-outputs
  file-close 
end

to write-outputs ;; Observer procedure, called from end-simulation.
  set-current-directory "C:\\...
  file-open "Table_results.csv"
  ask turtles
    [ file-type (word date-and-time ", ") ;;<---Would like a unique run identifier here instead if possible.
      file-type (word Landscape ", ")
      file-type (word Who ", ")
      file-type (word Home-range-size ", ")
      ;; ...
      file-print "" ]]    
end

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-12 22:55:28

Update/Solution:我的解决方案是让每个模型运行,写到一个单独的CSV。这允许我保存每个代理变量的结果。每个文件都有一个唯一的标识符,所以以后不会被覆盖或添加到其中。然后,所有的CSV都可以使用程序R轻松地导入和组合。

示例代码:在安装过程中定义CSV文件名,并要求海龟将其结果写入文件:

代码语言:javascript
复制
extensions [ csv ]
globals [ filename ] ;; Will define as the date/time and BehaviorSpace run #.

to setup
  clear-all 
  let run-ID (remove-item 6 (remove-item 7 (remove-item 8 (remove "-"(remove " "(remove "." (remove ":" date-and-time)))))))
  set filename (word "Results, " run-ID ", " word behaviorspace-run-number".csv")
  file-open filename
  start-output-file
  ;; Etc.
end

to start-output-file ;; Called from setup.
   file-open filename
   file-type "Turtle identity,"
   file-type "Home range size,"
   ;; Etc., rest of column headers.
   file-print ""
end

to end-simulation ;; Observer procedure, called from go.
  ask turtles [ write-outputs ]
  file-close 
end

to write-outputs ;; Called from end-simulation.
  file-type (word Who ", ") 
  file-type (word home-range-size ", ") ;; (Turtle variable for home range size.)
  ;; Etc., i.e., each turtle variable you are writing to file.
  file-print ""
end

希望这能帮助其他人做一些类似的事情,或者注意到他们从BehaviorSpace输出的CSV中类似的奇怪之处。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47834870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档