NetLogo Burnin / Warmup issue - netlogo

Using NetLogo 5.3.1, i'm trying to set up BehaviorSpace so that all its model runs start after exactly the same 500-tick warmup period. However, the results are not intuitive to me.
For illustrative purposes, I will use the 'Flocking.nlogo' model in the model library. Below is the model code, with 2 lines of code added to the end of the setup which saves the model's state after 500 ticks.
turtles-own [
flockmates ;; agentset of nearby turtles
nearest-neighbor ;; closest one of our flockmates
]
to setup
clear-all
create-turtles population
[ set color yellow - 2 + random 7 ;; random shades look nice
set size 1.5 ;; easier to see
setxy random-xcor random-ycor
set flockmates no-turtles ]
reset-ticks
; Now execute a 500-tick warm-up period and save the model's state
repeat 500 [ go ]
export-world "Flocking-after-500ticks.csv"
end
to go
ask turtles [ flock ]
;; the following line is used to make the turtles
;; animate more smoothly.
repeat 5 [ ask turtles [ fd 0.2 ] display ]
;; for greater efficiency, at the expense of smooth
;; animation, substitute the following line instead:
;; ask turtles [ fd 1 ]
tick
end
to flock ;; turtle procedure
find-flockmates
if any? flockmates
[ find-nearest-neighbor
ifelse distance nearest-neighbor < minimum-separation
[ separate ]
[ align
cohere ] ]
end
to find-flockmates ;; turtle procedure
set flockmates other turtles in-radius vision
end
to find-nearest-neighbor ;; turtle procedure
set nearest-neighbor min-one-of flockmates [distance myself]
end
;;; SEPARATE
to separate ;; turtle procedure
turn-away ([heading] of nearest-neighbor) max-separate-turn
end
;;; ALIGN
to align ;; turtle procedure
turn-towards average-flockmate-heading max-align-turn
end
to-report average-flockmate-heading ;; turtle procedure
;; We can't just average the heading variables here.
;; For example, the average of 1 and 359 should be 0,
;; not 180. So we have to use trigonometry.
let x-component sum [dx] of flockmates
let y-component sum [dy] of flockmates
ifelse x-component = 0 and y-component = 0
[ report heading ]
[ report atan x-component y-component ]
end
;;; COHERE
to cohere ;; turtle procedure
turn-towards average-heading-towards-flockmates max-cohere-turn
end
to-report average-heading-towards-flockmates ;; turtle procedure
;; "towards myself" gives us the heading from the other turtle
;; to me, but we want the heading from me to the other turtle,
;; so we add 180
let x-component mean [sin (towards myself + 180)] of flockmates
let y-component mean [cos (towards myself + 180)] of flockmates
ifelse x-component = 0 and y-component = 0
[ report heading ]
[ report atan x-component y-component ]
end
;;; HELPER PROCEDURES
to turn-towards [new-heading max-turn] ;; turtle procedure
turn-at-most (subtract-headings new-heading heading) max-turn
end
to turn-away [new-heading max-turn] ;; turtle procedure
turn-at-most (subtract-headings heading new-heading) max-turn
end
;; turn right by "turn" degrees (or left if "turn" is negative),
;; but never turn more than "max-turn" degrees
to turn-at-most [turn max-turn] ;; turtle procedure
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
; Copyright 1998 Uri Wilensky.
; See Info tab for full copyright and license.
The BehaviorSpace window looks like this:
The added 2 lines of code, which saves the model's state after 500 ticks, come from the answer to question 6 in Chapter 9 in Railsback & Grimm 2012: Agent-based and individual-based modeling (1st edition). The answer continues by stating the next step: "Then, in BehaviorSpace, change the "Setup commands" to just import the saved world and run 1000 more ticks".
I did this, and then imported the file into R to summarise the data by calculating the mean and SD of number of flockmates at tick 100, 200, 300, 400, and 500. Below the R code:
df <- read.csv("ibm_table_output-test.csv", skip = 6)
df1 <- df %>%
rename(run_number = X.run.number.,
time_step = X.step.,
mean_flockmates = mean..count.flockmates..of.turtles
) %>%
select(run_number,
time_step,
mean_flockmates,
vision) %>%
arrange(run_number,
time_step) %>%
filter(time_step == 100 |
time_step == 200 |
time_step == 300 |
time_step == 400 |
time_step == 500)
df1_long <- melt(df1, # Apply melt function
id.vars = c("run_number", "time_step","vision"))
# Calculate a summary table
df1.summ <- df1_long %>%
group_by(time_step, vision) %>%
summarise(avg = mean(value),
sd = sd(value))
The output is as follows:
# A tibble: 15 × 4
# Groups: time_step [5]
time_step vision avg sd
<int> <int> <dbl> <dbl>
1 100 1 8.34 0
2 100 2 8.34 0
3 100 3 8.34 0
4 200 1 7.83 0
5 200 2 7.83 0
6 200 3 7.83 0
7 300 1 7.95 0
8 300 2 7.95 0
9 300 3 7.95 0
10 400 1 7.45 0
11 400 2 7.45 0
12 400 3 7.45 0
13 500 1 7.92 0
14 500 2 7.92 0
15 500 3 7.92 0
To me this output doesn't make sense.
My question is why is the average number of flockmates the same across different vision levels within the same time_step group? And why are the SDs all 0? In other words, why do the model runs produce identical outputs? I thought that initiating a burnin period would initiate identical starting positions for all simulations, but create different mean and SD values for each run because of different random numbers used? Or am I misunderstanding?
EDIT: The reason why the SDs are 0 is because there is no variation in mean values, but I don't understand why there is no variation. Below is the df1_long data frame:
run_number time_step vision variable value
1 1 100 1 mean_flockmates 8.340000
2 1 200 1 mean_flockmates 7.833333
3 1 300 1 mean_flockmates 7.953333
4 1 400 1 mean_flockmates 7.446667
5 1 500 1 mean_flockmates 7.920000
6 2 100 1 mean_flockmates 8.340000
7 2 200 1 mean_flockmates 7.833333
8 2 300 1 mean_flockmates 7.953333
9 2 400 1 mean_flockmates 7.446667
10 2 500 1 mean_flockmates 7.920000
11 3 100 2 mean_flockmates 8.340000
12 3 200 2 mean_flockmates 7.833333
13 3 300 2 mean_flockmates 7.953333
14 3 400 2 mean_flockmates 7.446667
15 3 500 2 mean_flockmates 7.920000
16 4 100 2 mean_flockmates 8.340000
17 4 200 2 mean_flockmates 7.833333
18 4 300 2 mean_flockmates 7.953333
19 4 400 2 mean_flockmates 7.446667
20 4 500 2 mean_flockmates 7.920000
21 5 100 3 mean_flockmates 8.340000
22 5 200 3 mean_flockmates 7.833333
23 5 300 3 mean_flockmates 7.953333
24 5 400 3 mean_flockmates 7.446667
25 5 500 3 mean_flockmates 7.920000
26 6 100 3 mean_flockmates 8.340000
27 6 200 3 mean_flockmates 7.833333
28 6 300 3 mean_flockmates 7.953333
29 6 400 3 mean_flockmates 7.446667
30 6 500 3 mean_flockmates 7.920000

My understanding is that you're running setup once, manually, and then running your BehaviorSpace experiment. The problem you will have with that is that the random number generator seed is including in the export-world data that you generate once by running the setup procedure. Then when you call import-world in the Setup commands: of each experiment run you will get that RNG seed imported as well. The export actually includes the full state of the RNG, but thinking of it as being the same seed is close enough.
LeirsW is correct that Flocking (as most NetLogo models, and probably the original one you had the problem with) is totally deterministic. So the outcome will be the same with the same RNG seed each time.
The fix is easy, add a second line to your BehaviorSpace experiment Setup commands: after the import-world that runs random-seed new-seed. This will make sure each model run has a new, unique RNG seed to use for the rest of its run.

The simple answer to the lack of variation is that the flocking model (after setup) is as good as 100% deterministic. There are some elements in the code that at first sight you might think have some stochasticity to them but that sochasticity doesn't have any effect.
The order in which turtles flock and move is stochastic, but they all choose how they want to move before any of them do so, which results in this stochasticity having no effect on the outcome.
The other part that you would expect carries some stochasticity is set nearest-neighbor min-one-of flockmates [distance myself], when two birds are at the exact same distance away from the focal bird. But all their locations have floating point numbers in both x and y, so I assume that the chance that you will have a tie in distances is also extremely low.

Related

Action not happening every certain amount of ticks

this code is for the reproduction of an animal. It should happen every 10 ticks, but it is happening instantly and i dont know why. They also have energy. Reproduction is set to be random to show females.
thanks in advance for the help.
turtles-own[ energia edad]
breed[perros perro]
to setup
resize-world 0 80 0 60
clear-all
ask patches[
set pcolor green]
create-perros 50
[
set size 3 ;; easier to see
set color yellow
setxy (41 + random 39) random 60
set heading random 360
set energia 100
set edad 1
]
reset-ticks
end
to go
ask perros [ set edad edad + 1]
ask perros [
morir-perros
moverse-perros
reproducirse
]
tick
end
to morir-perros
if edad > 15 [die]
if energia < 1 [die]
end
to moverse-perros
set heading random 360 fd 5
set energia energia - 5
end
to reproducirse
if ticks mod 10 = 0 [ if random 100 > 50 [set energia energia - 60
hatch 1 [ rt random-float 360 fd 2
set energia (energia + 60) / 3]]]
end
Right now you have tick to increment your time step at the end of your go procedure. In any model, ticks start at 0 by default, so your model is evaluating ticks mod 10:
observer> show 0 mod 10
observer: 0
Since that would satisfy the condition in reproducirse, the code is evaluated. You can handle this in a variety of ways. The simplest may be to modify your if statement in reproducirse- for example:
to reproducirse
if ticks > 0 and ticks mod 10 = 0 [ if random 100 > 50 [set energia energia - 60
hatch 1 [ rt random-float 360 fd 2
set energia (energia + 60) / 3]]]
end

Extremely slow simulation caused by (?) sprout in NETLOGO

In my model the patches contain eggs, larvae (which hatch from eggs) and pupae (which arise from larvae that have increased their weight to 1 mg) (so these three are variables and not agentsets).
to set-up-patches
ask patches [
set ppupae n-values 20 [0.1]
]
Modeling these works fine: the model runs smoothly and the dynamics of the populations are biologically realistic. But I want the pupae to turn into adult hoverflies when they are 20 days old. So I modeled this like this:
to time
every 144 [ ask patches with [ sum ppupae > 0.1] [sprout-hoverflies] ]
end
to sprout-hoverflies
every 144 [
sprout item dta ppupae [
set shape "hoverfly"
set size 8
]]
end
As soon as I add these lines the model becomes extremely slow. To see if it would run at all I left my PC running when I left for an hour, and when I came back it was at 50 ticks. When I put semicolons (;) in front of these lines and run the model again it works perfectly.By the way, because I wanted to keep this post small and easy to overview I didn't include all code, so there's procedures missing and also within each procedure I excluded some things. But only things that I think are not important to solve this issue. But I'll post my entire code at the bottom if necessary.
globals [ gtimeeating gtimeeating_honey ginterval gvisits genergy deggs gaphids halive R0 lm m meaninterval sdinterval mean_flowers sd_flowers forag_flow_crop forag_flow_strip alpha lambda test mean_S sd resource b y_g F0 gamma_c c waarde voedsel food_density number_to_pup larvae_max K_aphids nectar_production dta sigma]
turtles-own[S energy days trip eggs load target memoryF memoryP timeeating timeeating_honey interval];;R0 net reproducing rate, m list the number of eggs laid /hoverfly per age class
patches-own[ppupae crop pdays flowers nectarflowers fresheggs peggs nl_per_age larvae g visits aphids honeydew l_hatched l_weight_age] ;;lm list with the values of net reproducing rate for every day
;;;;;;;;;
;;Setup;;
;;;;;;;;;
to setup
clear-all
set-up-globals
set-up-patches
set-up-hoverflies
reset-ticks
end
to set-up-globals
set gvisits n-values 133 [[0]] ;; this sets global variables as lists
set deggs n-values 133 [[0]]
set gaphids n-values 133 [[0]]
set ginterval []
set halive []
set m []
set lm []
end
to set-up-patches ;; set-up-patches draws a flower strip with red color and the crop with green color, sets crop variable, flowers,aphids and the appropiate amount of food.
ask patches[
;;larvae and pdays start with 0 because to add a day (last value on the list +1) a value is needed. And to calculate A index, the have to have the same lenght.
set pdays [0 ]
ifelse pxcor = 532 or pxcor = 531 or pxcor = 533 or pxcor = 534 and pycor > 0 and pycor < 132 [
set pcolor red set crop false] [set pcolor green set crop true] ;; in case the condition is true it takes first option if not the second, ifelse-value can be used in a reporter, ifelse not.
;set peggs n-values 4 [0]
set peggs n-values 4 [0.1]
set nl_per_age n-values 20 [0];; number of larvae per age.
set l_hatched n-values 20 [0.0001];; weight of hatched larvae
set l_weight_age n-values 20 [0];; weight of hatched larvae + their individual growth per age
set ppupae n-values 20 [0.1] ;toegevoegd nog kijken of deze ook bij set-up-patches kan
set larvae 0 ;; larvae biomass
set aphids 0
set mean_flowers 125
set sd_flowers 25
set nectar_production 0.1
set K_aphids 1200;carrying capacity of the aphid population (where growth rate = 0)
if crop = false
[set flowers round (0.57 * random-normal mean_flowers sd_flowers) set nectarflowers precision (flowers * nectar_production) 5];; (random-normal mean sd) takes a random number from a normal distribution and multiplies it with the surface of one cell (0.57)
] ;; precision number decimal rounds a number with a number of decimals.
ask patches with [(pxcor > 3 ) and (pxcor < 1062) and (crop = true) and (pycor > 3) and (pycor < 129)] ;; infection * 34320 calculates the number of patches infected, infection is not applied to borders o the flower strip.
[ set aphids round (random-exponential Aphidsmean) if aphids > K_aphids [set aphids K_aphids]]
;; exp = e^
ask patches with [pxcor < 4 or pxcor > 1061 or pycor < 4 or pycor > 128] ;;this shows a border with conditions that prevent hoverfies from leaving the field.
[
set pcolor 52
]
end
to set-up-hoverflies
create-turtles Hoverflies ;creates turtles and gives them a random starting position
ask turtles[
set shape "hoverfly"
set size 8
set color cyan
set xcor 130 + random 800
set ycor 10 + random 112
set energy 0.5 + random-float 0.44
set eggs 100
set load round (random-gamma 3000 1) if load >= 3000 [set load 3000]
set memoryF n-values 50 [1] ;;n-values reports a list of 50 items all with value [].
set memoryP n-values 50 [10]
set interval [0]
]
end
;;;;;;
;;Go;;
;;;;;;
to go
if count turtles < 5
[;export-plot "Oviposition rate (m)" word "S" word S% "Ovr.txt"
;export-plot "Hoverflies alive" word "S" word S% "Hoval.txt"
;export-plot "Net reproducing rate" word "S" word S% "R0.txt"
;export-plot "Mean Time eating" word "S" word S% "TE.txt"
;export-plot "Visits" word "S" word S% "Visits.txt"
;export-plot "Aphids" word "S" word S% "Aphid.txt"
;export-plot "Fresh eggs" word "S" word S% "Fd.txt"
;export-plot "Mean energy level" word "S" word S% "MEnergy.txt"
stop] ;; the model stops when most turtles died
if ticks mod 144 = 0 [
time ;; every 144 ticks it is a new day, days, pdays w, and energy are updated
]
ask turtles [
if energy <= 0 [set ginterval sentence ginterval interval die]
if load <= 0 [set ginterval sentence ginterval interval die]
set trip 0
choose
]
tick
end
to time
let DMR 0.004 ;;daily mortality risk
let E_basic 0.072 ;;basic daily energy need
set sigma 0.28 ;;prey conversion efficiency
let f 0.2 ;;maximum predation rate by predator larvae on aphids
let H 300 ;;Half saturation aphid density
let ma 0.02 ;;maintenance costs
let r 0.23 ;; growth rate aphids
let weight_hatch 0.063 ;hatching weight of eggs
let weight_max 28 ;;maximum weight of larvae
let dtl 3;; developmental time of egg to larvae
set dta 19;; toegevoegd
let honey_production 0.1
let decay_honey 0.5
ask turtles
[if random-float 1 <= DMR * days [set ginterval sentence ginterval interval die] ;;Daily natural mortality risk
set days days + 1 set energy energy - E_basic set eggs 100 set timeeating 0 set timeeating_honey 0 ;; Some energy is discounted ine the beggining of the day assuming that there is basal metabolism at night
]
ask patches with [ (pxcor > 3) and (pxcor < 1062) and (pycor > 3) and (pycor < 129)]
[set pdays lput (last pdays + 1) pdays
set g precision (sigma * f * (aphids / (aphids + H)) - ma) 3;; (g) predator larvae growth rate depending on consumption rate.
set peggs but-last peggs ;;haalt het laatste item van de lijst af omdat die in de volgende developemtal stage gebruikt gaat worden
set peggs fput fresheggs peggs ;;op de eerste plek in de lijst komt het aantal fresheggs
set fresheggs 0
set nl_per_age fput item dtl peggs nl_per_age ;dit is het aantal larven per leeftijdsclasse. dus p(w) in hoverfly IBM explained
;set nl_per_age but-last nl_per_age; als ze langer dan 20 dagen een larve blijven en nog niet gepopt zijn sterven ze
set l_hatched fput (weight_hatch) l_hatched;hier wordt eerste item van de lijst het gewicht van de 0 dagen oude larven.
set l_hatched but-last l_hatched; als ze langer dan 20 dagen een larve blijven en nog niet gepopt zijn sterven ze
set l_weight_age fput weight_hatch l_weight_age
;set l_weight_age but-last l_weight_age ;anders zei die bij larvae map dat de lijsten niet dezelfde lengte hadden
set l_weight_age map [i -> (i * e ^ (g * (aphids)*(1 - (i / weight_max))))] l_weight_age
;set l_weight_age map [ larvae-growth ->
;(larvae-growth * e ^ (g * (aphids)*(1 - (larvae-growth / weight_max))))
;] l_weight_age;;dit is het gewicht van de larven per age. dus in hoverfly IBM explained wt+1. door het gebruik van de anonymous procedure 'larvae-growth ->' in combinatie met 'map'
;wordt voor ieder item van l_hatched l_weight_age uitgerekend.
;gaat dit wel goed? want nu wordt iedere stap in de functie de gewichten van l_hatched gestopt, en dit is dus steeds 0.063 maal de formule, terwijl het moet doorwerken met de
;voorgaande groei.
;nu geeïndigd met l_weight_age ipv l_hatched
;set larvae sum((map * nl_per_age l_weight_age)); hiermee wordt de lijst 'aantal larven / leeftijd' vermenigvuldigt met 'gewicht larven / leeftijd' zodat je het totaal krijgt
; de functie map zorgt er hier voor dat je de items uit twee lijsten met elkaar kunt vermenigvuldigen
set aphids aphids * e ^( r * ( 1 - (aphids / K_aphids))) - larvae * f * (aphids / (aphids + H))
set honeydew honeydew + honey_production * aphids - decay_honey * honeydew;;honeydew productie is dus 0.1 maal aantal aphids per tijdstap ;nu accumuleert en decayhet
if aphids < 0 [set aphids 0];; aphids grow following a logistic curve
;set larvae_max filter [weight -> weight = 0.07] l_weight_age ;;filter functie die alleen de larven van gewicht 28 mg eruit haalt
;set l_weight_age remove 0.07 l_weight_age
;set number_to_pup length larvae_max ;telt hoeveel er zijn van 28 mg
;set ppupae fput number_to_pup ppupae ;voegt het aantal van 28 mg toe aan puppae
; while [
; let n_item 0
; if item n_item l_weight_age > 0.07 [
; set number_to_pup number_to_pup + 1
; set nl_per_age replace-item 0 l_weight_age 0
; set l_hatched replace-item 0 l_weight_age 0
; set l_weight_age replace-item 0 l_weight_age 0
;]
; ] I know that the code below can be code way more efficient, I tried it with the while loop aboven but it didn't work. I however don't think that the long code is very problematic because the code runs fine without the sprout function that I mentioned in the title
if item 0 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 0 l_weight_age 0
set l_hatched replace-item 0 l_weight_age 0
set l_weight_age replace-item 0 l_weight_age 0
]
if item 1 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 1 l_weight_age 0
set l_hatched replace-item 1 l_weight_age 0
set l_weight_age replace-item 1 l_weight_age 0
]
if item 2 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 2 l_weight_age 0
set l_hatched replace-item 2 l_weight_age 0
set l_weight_age replace-item 2 l_weight_age 0
]
if item 3 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 3 l_weight_age 0
set l_hatched replace-item 3 l_weight_age 0
set l_weight_age replace-item 3 l_weight_age 0
]
if item 4 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 4 l_weight_age 0
set l_hatched replace-item 4 l_weight_age 0
set l_weight_age replace-item 4 l_weight_age 0
]
if item 5 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 5 l_weight_age 0
set l_hatched replace-item 5 l_weight_age 0
set l_weight_age replace-item 5 l_weight_age 0
]
if item 6 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 6 l_weight_age 0
set l_hatched replace-item 6 l_weight_age 0
set l_weight_age replace-item 6 l_weight_age 0
]
if item 7 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 7 l_weight_age 0
set l_hatched replace-item 7 l_weight_age 0
set l_weight_age replace-item 7 l_weight_age 0
]
if item 8 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 8 l_weight_age 0
set l_hatched replace-item 8 l_weight_age 0
set l_weight_age replace-item 8 l_weight_age 0
]
if item 9 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 9 l_weight_age 0
set l_hatched replace-item 9 l_weight_age 0
set l_weight_age replace-item 9 l_weight_age 0
]
if item 10 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 10 l_weight_age 0
set l_hatched replace-item 10 l_weight_age 0
set l_weight_age replace-item 10 l_weight_age 0
]
if item 11 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 11 l_weight_age 0
set l_hatched replace-item 11 l_weight_age 0
set l_weight_age replace-item 11 l_weight_age 0
]
if item 12 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 12 l_weight_age 0
set l_hatched replace-item 12 l_weight_age 0
set l_weight_age replace-item 12 l_weight_age 0
]
if item 13 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 13 l_weight_age 0
set l_hatched replace-item 13 l_weight_age 0
set l_weight_age replace-item 13 l_weight_age 0
]
if item 14 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 14 l_weight_age 0
set l_hatched replace-item 14 l_weight_age 0
set l_weight_age replace-item 14 l_weight_age 0
]
if item 15 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 15 l_weight_age 0
set l_hatched replace-item 15 l_weight_age 0
set l_weight_age replace-item 15 l_weight_age 0
]
if item 16 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 16 l_weight_age 0
set l_hatched replace-item 16 l_weight_age 0
set l_weight_age replace-item 16 l_weight_age 0
]
if item 17 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 17 l_weight_age 0
set l_hatched replace-item 17 l_weight_age 0
set l_weight_age replace-item 17 l_weight_age 0
]
if item 18 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 18 l_weight_age 0
set l_hatched replace-item 18 l_weight_age 0
set l_weight_age replace-item 18 l_weight_age 0
]
if item 19 l_weight_age > 0.07 [
set number_to_pup number_to_pup + 1
set nl_per_age replace-item 19 l_weight_age 0
set l_hatched replace-item 19 l_weight_age 0
set l_weight_age replace-item 19 l_weight_age 0
]
set larvae sum((map * nl_per_age l_weight_age)); hiermee wordt de lijst 'aantal larven / leeftijd' vermenigvuldigt met 'gewicht larven / leeftijd' zodat je het totaal krijgt
; de functie map zorgt er hier voor dat je de items uit twee lijsten met elkaar kunt vermenigvuldigen
set ppupae fput number_to_pup ppupae
set nectarflowers flowers * nectar_production ;; all flowers are filled with nectar again
set visits 0
set number_to_pup 0
]
every 144 [
ask patches with [ sum ppupae > 0.1]
[sprout-hoverflies]
]
end
to sprout-hoverflies
every 144 [
sprout item dta ppupae [
set shape "hoverfly"
set size 8
set color cyan
set xcor 130 + random 800
set ycor 10 + random 112
set energy 0.5 + random-float 0.44
set eggs 100
set load round (random-gamma 3000 1) if load >= 3000 [set load 3000]
set memoryF n-values 50 [1] ;;n-values reports a list of 50 items all with value [].
set memoryP n-values 50 [10]
set interval [0]
]
]
end
to choose
set S 1.47 * S% / 100
; set c 2 ;;shape parameter gamma distribution
; set b 0.3 ;;scale parameter gamma distribution (to be optimized)
; set F0 0
; set food_density mean(memoryF)
; set y_g (food_density - F0) / b
; set gamma_c 1; if c=3, then (c-1)! = 2. if c=2, then (c-1)! = 1.
;set S ((1 / b * gamma_c) * y_g ^ (c - 1) * exp(-1 * y_g))
ifelse energy <= S [foraging][oviposition] ;;NL dit betekent <= is less than or equal. Als dit waar is (E<=S) dan wordt gekozen voor foraging, anders voor oviposition
end
to foraging
set forag_flow_crop 0.0005
set forag_flow_strip 0.001
if ([nectarflowers] of patch-here / (1 + (count turtles-here))) > mean ( memoryF)[eat] ;;Compare food
set target patch 532 ycor
face target ;; Search food, A Lévy-flight searching behavior is assumed, first a direction is chosen from a Normal distribution, unprecision (S.D.) increases with denstance form margin.
right random-normal 0 (5 * distance patch 532 ycor) ;; move probability y cannot be smaller than 0.03333 which is the probability of doing up to 60 cells , this avoids theprobability
let y random-float 1 if y < 0.003333 [ set y 0.003333];;to be 0 and inderterminacy while calculating the number of steps (l), it also avoids the hoverflt flies more than 15 cells.
let j round (2 / y) ;;l is calculated from the cummulative distribution of a power law.
while [ j > 0] [ ;;Once the number of steps is calculated the hoverfly moves forward and compares the cell for food.
forward 1
if xcor < 3 or xcor > 1062 [set ginterval sentence ginterval interval die] ;;while creates a loop, the agent repeats it until the condition is not fulfilled.
set j j - 1 ;; in case the hoverfly reaches the border doing the Lévy-flight it will leave the field.
set trip trip + 1
set visits visits + 1
ifelse [crop] of patch-here = true [set energy energy - forag_flow_crop][set energy energy - forag_flow_strip] ;; when the hoverfly is within the flower strip it spends more energy since it searches for flowers, otherwise the energy requirements are lower.
if trip >= 60 [ set interval replace-item 0 interval (first interval + 1) stop]
if (nectarflowers / (1 + (count turtles-here))) > mean ( memoryF)[eat];; Compare nectarflowers
;;in case the hoverfly finds a patch better than the internal index it will stop.
]
end
to oviposition
if eggs <= 0 [set energy energy - forag_flow_strip stop] ;;Rest
if energy <= 1.25 * S and [honeydew] of patch-here > 4 [eat_honey] ;;als dus energy lager dan de helft van de threshold is én honeydew hoger is dan een waarde (dit kan ook nog memoryH worden) wordt er honeydew gegeten
if [P] of patch-here > mean (memoryP) and [P] of patch-here > 10 [lay] ;;Compare oviposition
right random 360 ;; Search host, The direction is chosen randomly within 360 degrees.
let y random-float 1 if y < 0.003333 [ set y 0.003333] ;;The number of cells the hoverfly will travel from a Lévy-flight.
let j round (2 / y)
while [j > 0] [
forward 1
if xcor < 3 or xcor > 1062 [ set ginterval sentence ginterval interval die]
set j j - 1
set trip trip + 1
set visits visits + 1
set energy energy - forag_flow_strip ;; Searching for host places is the most energy requesting behavior.
if trip >= 60 [ set interval replace-item 0 interval (first interval + 1) stop]
set memoryP but-first memoryP ;Part for assessing P index Everytime the hoverfly moves it takes information about memoryP
set memoryP lput P memoryP ;;Everytime the hoverfly moves it takes information about memoryP
if P > mean (memoryP) and P > 10 [lay] ;;Compare oviposition, cells are compared step by step, in case the hoverfly finds a patch better than the internal index it will stop.
]
end
to eat_honey
let a_honey 0.8 ;;honeydew exploration rate: little higher than that of flowers because aphids are closer (same patch) and honeydew is olfactory stimulant
let Th_honey 0.2 ;;honeydew handling time. higher than that of flowers because hoverflies are not as adapted to consuming honeydew as nectar (higher viscosity, harder to reach, etc.)
let HV a_honey * honeydew / (1 + Th_honey * a_honey * honeydew) ;;honeydew visitation (numbers / timestep) ;;similar FR to flowers
if (HV * 0.1) > (1.47 - energy) [set HV (1.47 - energy) * 0.1 ]; if satiated no more honeydew will be consumed
set honeydew honeydew - HV
let EAH 0.05 * HV ;;energy reward. Lower than when flowers are consumed because honeydew is likely nutriotionally inferior ;;als test heel hoog gezet
set energy energy + EAH
set timeeating_honey timeeating_honey + 1 ;;dit zou ik ook nog kunnen veranderen naar timeeatinghoneydew
;; in dit stuk code heb ik de parameters nog niet allemaal aangemaakt in het model. Dit kan later als dit goed blijkt te werken.
end
to eat
let a 0.5 ;; flower exploration rate (surface / timestep)
let Th 0.1 ;; flower handling time (timesteps)
let FV a * nectarflowers / (1 + Th * a * nectarflowers) ;; flower visitation (numbers / timestep)
if (FV * 0.1) > (1.47 - energy) [set FV (1.47 - energy) * 0.1 ] ;; if satiated no more flowers will be visited
set nectarflowers nectarflowers - FV ;; less flowers remain with nectar
let EA 0.1 * FV ;; nectar consumption
set energy energy + EA
set timeeating timeeating + 1
set memoryF but-first memoryF
set memoryF lput (nectarflowers / (1 + count turtles-here)) memoryF
if (first interval) > 0 [set interval fput 0 interval]
end
to lay
let ovi_costs 0.002
set eggs eggs - 1
set load load - 1
set fresheggs fresheggs + 1 ;;Lay it lays one egg
set energy energy - ovi_costs
set interval replace-item 0 interval (first interval + 1)
end
to-report P
report aphids / ( 1 + sum (peggs) + (larvae / sigma)) ;;index P = prey to predator ratio
end
Look up every in the NetLogo dictionary and you will see that you are basically saying to create the turtles then wait 144 seconds in real time. Then the procedure that actually creates the turtles says to wait 144 seconds between each sprout.
In your go procedure you have:
if ticks mod 144 = 0 [ time ]
As you say in your comments, this calls the 'time' procedure every 144 ticks (which represents once per day).
Simply get rid of all the every statements:
to time
ask patches with [ sum ppupae > 0.1]
[ sprout-hoverflies
]
end
to sprout-hoverflies
sprout item dta ppupae
[ set shape "hoverfly"
set size 8
]
end
For that matter, it's not entirely clear why you have a procedure which simply calls one other procedure. You stated that your model is complete, so it's not that you are intending to have other procedures called. So, you could have:
to time
ask patches with [ sum ppupae > 0.1]
[ sprout item dta ppupae
[ set shape "hoverfly"
set size 8
]
]
end
While you're at it, you could change the procedure name to something informative like 'daily-births'

The in-radius works different in Netlogo 6.1.0 than in previous version

I have the following code which creates a grid of agents and place links between pairs if they are in a distance of interference.
breed [ readers reader ]
undirected-link-breed [ rris rri ]
globals [
interf-rri-radius
num-readers
distance-var-x
distance-var-y
readers-per-row
readers-per-column
num-checkouts
]
to setup
ca
setup-globals
ask patches [ set pcolor blue - 3 ]
spawn-by-row-col
reset-ticks
end
to setup-globals
set interf-rri-radius 1005
set num-readers 40
set distance-var-x 12
set distance-var-y 22
set readers-per-row 8
set readers-per-column 5
set num-checkouts 0
end
to spawn-by-row-col
let half-step 0.5 * distance-var-x
let d-vals ( range ( min-pxcor + half-step ) ( min-pxcor + (readers-per-row * distance-var-x)) distance-var-x )
let dc-vals ( range ( min-pxcor + half-step ) ( min-pycor + (readers-per-column * distance-var-y)) distance-var-y )
show dc-vals
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach dc-vals [
d ->
set possible-coords ( sentence possible-coords map [ i -> (list i d) ] d-vals )
]
show (word "possible-coords = " possible-coords)
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let max-positions length possible-coords
if max-positions > (num-readers + num-checkouts) [ set max-positions (num-readers + num-checkouts) ]
let use-coords sublist possible-coords num-checkouts max-positions
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "square 2"
set size 2
set color 15
]
]
ask readers [ create-rris-with other readers in-radius (interf-rri-radius / 10) ]
end
The neighbors of reader 0 are
show [sort [who] of rri-neighbors] of reader 0
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39]
However, the distance between reader 0 and reader 39 is
show [distance reader 0] of reader 39
121.6552506059644
and the connection radius is 1005/10= 100.5 so they should not be connected with an rri link.
Notice, I use a origin-centered world of -50 to 50 in X and Y dimensions.
I have tested the code in previous Netlogo version 6.0.4 and the reader 39 is not a neighbour of the reader 0.
I do not know what can be the problem. I believe is the new version but I would like to be sure.
In case anyone else runs into this, there is a confirmed bug with in-radius in the NetLogo 6.1.0 release, and the details are in the bug report on GitHub.
The issue only affects in-radius when used in a non-wrapped world, and only when used on turtles, and only when used with a radius that's a significant % of the world width. If you're using a world with wrapping, or using in-radius with patches, or using a small radius relative to the world size, your data will be correct and you don't need the below workaround.
As a workaround if your model is affected, you can use a simple user-defined NetLogo procedure in your model until the fix is published. It's not going to be super-fast if your having turtles calculate in-radius many times per tick, but if you have few turtles or are just using it during setup, it should be okay:
to-report temp-in-radius [agentset r]
report agentset with [ distance myself <= r ]
end
Then, instead of create-rris-with other readers in-radius (interf-rri-radius / 10) you would do create-rris-with (temp-in-radius other readers (interf-rri-radius / 10)).
Or more generally, instead of something like count other turtles in-radius 5 would become count temp-in-radius (other turtles) 5.

agents sharing with each other their lists

I am making a NetLogo model. Each agent has a list of 5 integers (agent-list). On each tick, turtles create link with one other turtle, and share with each other their list.
turtles-own [ agent-list ]
.
.
.
ask turtles [
create-link-with one-of other turtles
set agent-list lput agent-list of link-neighbors agent-list
]
I know the code above doesn't work, how should I fix it?
The simplest way to combine the lists as you've described would probably be sentence:
turtles-own [ agent-list ]
to setup
ca
crt 3 [
set agent-list map [random 10] range 5
]
reset-ticks
end
to link-and-share
ask turtles [
let target one-of other turtles
create-link-with target
set agent-list sentence agent-list [agent-list] of target
show agent-list
]
end
However, you'll have do do some tweaking depending on what you're actually looking to do since that means that turtles linking later in the procedure are likely to pull the agent-list of turtles that have already modified their own agent-list. So, if turtle 0 grabs the agent-list of turtle 1, then later turtle 4 grabs the agent-list of turtle 0, turtle 4 would have an agent-list of 15 integers, not 10, similar to the output below:
(turtle 1): [6 1 5 4 7 3 9 8 1 1]
(turtle 0): [9 0 3 3 5 3 9 8 1 1]
(turtle 2): [3 9 8 1 1 9 0 3 3 5 3 9 8 1 1]

To create fixed number turtles each with separate headings on fixed ycor and equidistant xcor

I want to create 4 turtles on fixed pycor (like pycor = 10) and even spacing xcor over that pycor; and also I want to make the headings of each turtles separate from other. The display is like
............. O ............. O .............. O ........... O ............
(heading 45) (heading 90) (heading 230) (heading 180)
O is the turtle here. My code is as below.
ask n-of 4 patches with [ pcolor = 18 and pycor = 10 ] [
sprout-turtles 1 [
set shape "default"
set color blue
set size 2
set heading one-of [90 270]
]
]
With this code turtles are created but many time with same heading, sometimes on same patch, sometimes neighboring patch as shown below
..........OOO...................O or .........OO..........O.........O...
but this i don't want. Should i have to use Create turtles four times separately specifying xcor, ycor and heading? Actually i don't want to use it four times. Please any suggestion and help? Thanks a lot.
Since the only thing you are taking from the patch to the turtle, you may as well just use create-turtles instead of sprout-turtles and then put them where you want. Typically, sprout is used when the particular patch meets relevant conditions - such as having lots of resources. Also, since you want specific values, using one-of or n-of will not work because they randomly select.
Instead you want something more like this (not tested):
let gap 15 ; spacing between turtles
let directions [45 90 230 180] ; heading values
let ii 0 ; counter / index
repeat 4
[ create-turtles 1
[ setxy (0 + ii * gap) 10
set shape "default"
set color blue
set size 2
set heading item ii directions
]
set ii ii + 1
]