Linking List Data to NetLogo Turtles

I have a question. I recently started using NetLogo and need to complete an assignment for my research with NetLogo, however I have a problem. I want to use data from an Excel file in a model. The dataset contains two rows of numbers, each row represents a different variable, say a and b, and I want to assign each turtle a set of these two variables so that each turtle has a value for the variables a and b. However, I have no idea how to do this. Ive managed to load the dataset into the model by translating it into a txt file. The lines in the .txt file are divided into a tab. This is the code I used to load the dataset in the model:

 globals [ turtle-data ]
 turtles-own [ awareness income housingtype adopt ]
 to setup
  clear-all
  reset-ticks
  create-turtles 11557
  ask turtles [
   set color white
  ]
  ask turtles [
   setxy random-xcor random-ycor
  ]
 load-turtle-data
 assign-turtle-data
end
to load-turtle-data
  ifelse ( file-exists? "input-data.txt" ) [
    set turtle-data []
    file-open "input-data.txt"
    while [ not file-at-end? ][
       set turtle-data sentence turtle-data (list (list file-read file-read))
    ]
   user-message "File loading complete!"
   file-close
   ]
   [
      user-message "There is no input-data.txt file in current directory!" 
   ]
end
to assign-turtle-data
  assign-income  
  assign-housingtype
end
to assign-income
  foreach turtle-data [
  ask turtles [ set income item 0 ? ]
  ;link to turtle-data
 ]
end
to assign-housingtype
  foreach turtle-data [
  ask turtles [ set housingtype item 2 ? ]
  ;link to turtle-data
 ]
end

      

How to bind the values ​​in the dataset to the right turtle variables? Alternative solutions for my problem are also welcome.

+3


source to share


1 answer


Good job defining the data import part. I've actually worked on an extension to do exactly that, but it looks like you don't even need it! Now, for your question:

Instead of creating a bunch of turtles (I am assuming one for each row of data), I will create turtles one by one as you iterate over the data:



to setup-turtles
  foreach turtle-data [
    crt 1 [
      set income item 0 ?
      set housingtype item 1 ?
    ]
  ]
end

      

This simplifies the task of assigning data to individual turtles without having to deal with indices or numbers who

(which other solutions require). It also makes it so that the turtle count is automatically adjusted if you add or remove data.

+2


source







All Articles