NetLogo:仅在 运行 末尾为每只海龟记录变量

NetLogo: record variable for every turtle only at end of run

我很想知道我的每只海龟在模拟过程中走了多远 (dist) 运行。在这个postHow to write values in files for each turtle?之后,我对file-print的使用很谨慎。

但是,此文件记录了模拟 运行 中每个时间步长的 dist 个值。我怎样才能只访问每只甲虫 最终行驶的距离 ?这也可以包含在 BehavioralSpace 中吗? “\r\n”是什么意思?

我的代码:

turtles-own [
  dist
]

to setup
  clear-all
  setup-turtles
  reset-ticks
end

to setup-turtles
  crt 5
  ask turtles [
    set color red
    setxy random-xcor random-ycor 
  ]
end

to go
  if ticks >= 10 [stop ]
  move-turtles
  write-locations-to-file
  tick
end

to move-turtles
  ask turtles [
    rt random 90 lt random 90
    let step.lenght random 5
    jump step.lenght
    set dist dist + step.lenght
    set label dist
  ]
end

to write-locations-to-file 
  ask turtles [ 
   file-open "/Users/.../Documents/outputs.txt"
   file-print (word who " ; " dist "\r\n" )
   file-close
  ]
end

我希望每只乌龟最终 dist: 22 24 12 13 22

谢谢!

你的问题是你在每个滴答声中调用写入位置到文件的过程,并且它正在这样做 - 将位置写入文件。试试这个:

to go
  if ticks >= 10
  [ write-locations-to-file
    stop
  ]
  move-turtles
  tick
end