HAJZ
HAJZ

Reputation: 43

Inserting unspecified number of lists into a list [Netlogo]

General Issue: I have a reporter that is a list of a breed-owned variable. Every tick this list changes and what I want is to make a list that will store this breed-owned variable list for every tick.

Specifically: I record the "age" of breed of turtle (ants here). I get them to be reported into a list of "ant nest ages" via the following

to-report nest_age_dist

  let nest-ages-list [nest-age] of ants
  report (list [nest-age] of ants)

end

If I call this reporter I get something like the following at every tick (where numbers are the ages):

[[1 2 3 3 3 3 3 4 4 4 4 4 5 5 6 6 6 6 6 6 6 6 6]]

This is fine and good, but want a tick from each list to be added to a list that holds them. For example I want

[[1 1 1 1 2 2 2 3 3 3 ][2 2 2 2 3 3 3 4 4 4][3 3 3 3 4 4 4 5 5 5]]

Where

[[tick 1 nest_age_dist ] [tick 2 nest_age_dist ] [tick 3 nest_age_dist ] [tick n nest_age_dist]] 

I hope this is clear.

It seems like the solution to this should be simple but I am not sure how to do it and I have not been able to find a solution on stackoverflow. The fact that lists in NetLogo are immutable blows my mind.

As a side note, I have to do this because when I use BehaviorSpace I can't use the nest_age_dist reporter because when that large list is reported every tick the .csv that is created is too large to be opened in any text editor I have tried (TextWrangler, Texteditor, Excel). Once I have my list of lists (given this is resolved) I want to only report the last 100 lists (nest age lists) of my list of lists. I understand I could just run smaller simulations many times but whats the point if I can't leave it overnight to do the whole damn thing!

Hope my questions and my motives for asking are clear. Thanks in advance!

Upvotes: 0

Views: 177

Answers (2)

Charles
Charles

Reputation: 4168

If you want to keep only the most recent 100 nest-age-dist lists in say biglist, you could construct it with

let biglist ifelse-value (length biglist >= 100) [lput nest-age-dist but-first biglist] [lput next-age-dist biglist]

So, following up on Luke C's answer which also does the trick, it would look like:

globals [all_nest_age_list last_10]
turtles-own [age]

to setup
  ca
  crt 5 [
    set age random 6
  ]
  set all_nest_age_list []
  set last_10 []
  reset-ticks
end

to go

  repeat 150 [
    ask turtles [
      set age age + 1
    ]
    set last_10 ifelse-value (length last_10 >= 10) 
       [lput sort [age] of turtles but-first last_10] 
       [lput sort [age] of turtles last_10]
    set all_nest_age_list lput ( sort [age] of turtles ) all_nest_age_list
  ]

  let x 10   ;; however far back you want  
  let last_x_list sublist all_nest_age_list (length all_nest_age_list - x)  (length all_nest_age_list)  
  print last_x_list
  print last_10

end

where I've kept only the most recent 10 rather than 100.

Upvotes: 1

Luke C
Luke C

Reputation: 10301

Responding to your last answer there Hajz, you can use sublist. Something like:

globals [ 
  all_nest_age_list
  last_x_list
]

turtles-own [
  age
]

to setup
  ca
  crt 5 [
    set age random 6
  ]
  set all_nest_age_list []

end

to go

  repeat 10 [
    ask turtles [
      set age age + 1
    ]
    set all_nest_age_list lput ( sort [age] of turtles ) all_nest_age_list
  ]

  let x 3   ;; however far back you want  
  set last_x_list sublist all_nest_age_list (length all_nest_age_list - x)  (length all_nest_age_list)  
  print last_x_list

end

Upvotes: 2

Related Questions