0

I would like to remove a doubt and have some help.

I have a closed world of 600X600 patches. Each patch spawns a turtle (using the sprout command). Each turtle makes a series of moves and returns a value for its home patch. I would like to have the following result: know which turtle was in each patch in the world and export this result in table form in .csv

I created a list for this. But, NetLogo is running for a while and then it closes and doesn't finish the model. And so I think if I create a table it should work. The question is: will creating a table solve the problem of the model not running? And if so, how can I create a table by generating an output from that table in .csv? But, I haven't found a NetLogo command that I can create a table to adjust my code to.

Any tip is very welcome. I thank the attention

globals [ edge-size output-turtle-visits ]
patches-own [ turtle-visits ]

to setup
  ca
  random-seed 1
  set edge-size 599
  set-patch-size 1.2
  resize-world 0 edge-size 0 edge-size
  let pcolors []
  set pcolors [ 85 95 ]
  ask patches [ sprout 1 ]
  ask patches [
    set turtle-visits n-values count turtles [0]
    set pcolor item (random 2) pcolors
  ]
  reset-ticks
end

to go
  ask turtles [
    rt random 360
    fd 1    
  ]
ask patches [
    foreach [who] of turtles-here [ id ->
      let current-num-visits item id turtle-visits
      set turtle-visits replace-item id turtle-visits (current-num-visits + 1)
    ]      
  ]     
end

to output
  file-open ( output-turtle-visits )
  file-print ( word "id_turtle;my_xcor;my_ycor;turtle_visits" )
  foreach sort patches
  [
    t ->
    ask t
    [

     file-print ( word self " ; " xcor " ; " ycor " ; " turtle-visits )
    ]
  ]
  file-print ""  ;; blank line
  file-close
end
Rafaela
  • 419
  • 2
  • 8
  • I have reduced the size of the model (using `set edge-size 30` instead of `set edge-size 599`) because my pc was not even able to finish `setup` with the full size - it seems to me that this should not affect the rest of the code. That said, I have not been able to reproduce your problem: `go` runs forever without issues; also, I see that no agent is ever executing `to output` in this example and that there are no stop conditions, so I am not able to think what might be going wrong on your side. – Matteo Aug 24 '21 at 18:43
  • From my code is it possible to create a table instead of a list? Thanks – Rafaela Aug 24 '21 at 19:08
  • [This could help](https://stackoverflow.com/questions/63421572/netlogo-exporting-table-results-into-csv) with the table thing. Anyway, this wouldn't address the fact that you said that "NetLogo [runs] for a while and then it closes and doesn't finish the model"; might that be because of the model size? You have 600,000 turtles, 600,000 patches and each patch holds a list of 600,000 values - I think that really is a considerable size, so you have to make sure you have the right infrastructure. It might be best to test it with a reduced size and see if you still get the same unwanted behaviour. – Matteo Aug 25 '21 at 10:07
  • Which brings to the last point I touched: when you say that the list is not exported, I assume you refer to a different code than the one you provided in this question? Because in this code here the `to output` procedure is never called - so, even if the model didn't crash, you would get no output anyway (regardless of what format you decide to export). – Matteo Aug 25 '21 at 10:07

0 Answers0