Reputation: 372
So, I'm using NetLogo and I'm trying to get a procedure which assigns each turtle a list of the hours of the day when they have to perform a certain task, which they have to do 6 times a day.
I want some hours to be more likely to be those where most turtles perform the task than others, because of this I used rnd:weighted-n-of-list
in the following way below.
I can run the program, but then, if I inspect one of the turtles, insted of something like action-time: [ 2 7 9 13 17 21 ]
, which is what I'm intending to get, they show action-time: [[2 0.02] [7 0.04] [9 0.08] [13 0.04] [17 0.04] [21 0.04]]
.
I'm not sure of what I'm doing wrong, I checked a couple of times that the weights sum 1.00 and the anonymous-reporter, but I can't still manage to get it to work as I would like to.
to probability
let hours [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ]
let weights [ 0.04 0.04 0.02 0.02 0.02 0.02 0.04 0.04 0.08 0.08 0.08 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04]
let combination (map list hours weights)
ask tutles [
set action-time rnd:weighted-n-of-list 6 combination [ [p] -> last p ]
]
end
Upvotes: 0
Views: 146
Reputation: 1181
Since you want only the first value of that list, you can use first
:
set action-time map first rnd:weighted-n-of-list 6 combination [ [p] -> last p ]
Upvotes: 2