Lorena
Lorena

Reputation: 29

How can I print the xcor and ycor of all remaining turtles in a file at the end?

I want to know the coordinates of the turtles that survive at the end of my model's run. Im running everything through BehaviorSpace in a remote cluster, so ideally I'd like to have a table or a similar file that tells me which turtles survived the run, and where they are located.

I've tried writting it this way:

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

however, no files seem to be created.

Upvotes: 1

Views: 80

Answers (1)

Steve Railsback
Steve Railsback

Reputation: 1736

I'm not sure why you are not getting any files, but can help with a couple of issues.

a) When you use BehaviorSpace, writing output files is tricky because if more than one of the model runs tries to use the same output file at the same time there is going to be an error. One solution is to include the behaviorspace run number in the file name, so each run writes its own output file.

b) Your turtle coordinates output file has a clumsy format that will be hard to use--I expect it will be easier to use if each turtle writes one line with all its information.

You can solve both of these problems by using the csv extension and replacing your "print-coordinates" procedure with something like this observer procedure (which I have not tested).

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

Upvotes: 2

Related Questions