Reputation: 9796
I want a turtle to Probabilistically move to one of the patches in it's neighbors. The value of probability for patch variable. This is quite similar to genetic algorithm selection. I wish to implement any selection technique possible.
UPDATE:
Value of probability of a patch: means the chance of getting that patch selected. So a patch with zero probability have get no chance of getting selected. And a patch with 100 percent probability will always get selected.:
UPDATE2: The following I found I think does so but I think understand it quite:
report last first filter [first ? >= rand-num] probabilities
The tried this other code,please check if it makes sense:
ask neighbors4[calculate-proabalities]
let patchset neighbors4
let pick random-float sum [score] of patchset
let winner nobody
ask patchset[
if (is-patch? winner = false)
[
ifelse (score > pick)
[set winner self]
[set pick pick - score]
]
]
report winner
Upvotes: 0
Views: 278
Reputation: 14972
This is something that can also be achieved with the rnd:weighted-one-of
primitive of the Rnd extension:
let winner rnd:weighted-one-of neighbors4 [ [score] of ? ]
Upvotes: 1
Reputation: 9610
You are basically repeating code from the Lottery example in the Models Library. (Attribution would be a good idea.) It is unclear why you changed the test for the existence of a winner. I would actually discard it altogether, like this.
to-report local-winner [#candidates]
ask #candidates [calculate-score]
let %pick random-float sum [score] of #candidates
let %winner nobody
ask #candidates [
ifelse score > %pick [
set %winner self stop
] [
set %pick (%pick - score)
]
]
report %winner
end
ask myturtle [move-to local-winner neighbors4]
Note that this assumes (as in your example code) that a patch can compute its score in isolation. If not, you will need to make appropriate changes. Note also that you cannot simply report out from inside the ask
, which one might be tempted to try.
Upvotes: 1