I am working on a Netlogo code that represents hundreds of turtles. Each turtle is characterized by a set of parameters and state variables that are stocked in csv tables (created before running the Netlogo code). Tables are stage-specific, i.e., if a turtle reaches a certain age and changes life stage (e.g., juvenile --> adult), it has to read another table that is specific for the new life stage. Moreover, each table is named with a number (e.g.,"juvenile_file_1.csv","adult_file_1.csv",...,"adult_file_8.csv", etc.), and each turtle chooses randomly among these tables. Here is an example:
set ran.num 50 ; there are 50 tables for juveniles
ask turtles[
let num.file random (ran.num) + 1
set unique.num.file num.file ; I added this line so that turtles keep the same table number among stages.
; I tried this to gain on speed and memory, but it did not change so much
let file.name (word "juvenile_file_" num.file ".csv")
if( file-exists? file.name = FALSE )
[ user-message "Warning: input file with num does not exist in the current directory!" ]
set juvenile.input csv:from-file file.name
set index 1 ; to read the firs row of the table. index in increased at each time step.
[other code lines]
set sex item 16 item index juvenile.input ; read column 17, first numerical row of the table (very first row has headings)
set stage item 17 item index juvenile.input
set exposure.surv item 18 item index juvenile.input
set reproduction-period item 19 item index juvenile.input
]
[other code lines]
if Length >= 0.95 * L-max and stage = "juvenile"
[
set stage "adult"
set juvenile.input 0
let file.name (word "adult_" choice.GUTS "_file_" unique.num.file ".csv")
if( file-exists? file.name = FALSE )
[ user-message "Warning: input file with num does not exist in the current directory!" ]
set adult.input csv:from-file file.name
]
Because asking the turtles to read the tables when they change life stage is too demanding, I thought that it would have been better to read all the tables in the setup procedure, and then just chose one of them later when needed. However, how can I read all the tables in an automated way in the setup procedure? Just writing dozen of names (e.g., adult.input.1, adult.input.2, juvenile.input.1, juvenile.input.2, etc.) seems pretty time-consuming to me. I hope this is clear. Thanks for your help!