Reputation: 71
In my model, patches have a variable called proximity. I would like my turtles to compare the proximity values of their own patch with another patch, which I called candidate-patch, and move to the candidate patch if the value is higher.
Here is what I have tried:
patches-own [proximity occupied?]
turtles-own [attachment-rate]
to move-patch
let my-proximity proximity
let candidate-patches patches with [occupied? = FALSE and proximity > my-proximity]
if (my-proximity - proximity) < attachment-rate
[ move-to max-one-of candidate-patches [proximity]
]
end
In my code this is not what is happening. Turtles are comparing the proximity values of their own patch to itself, and therefore are not moving.
Upvotes: 1
Views: 115
Reputation: 17678
my-proximity - proximity is subtracting one number from itself, so will always be 0. But this doesn't explain why turtles are not moving, it should make them always move. So the problem may be that you haven't set attachment-rate for the turtles (default is 0 unless you tell it to be something else).
If you reorganise your code a bit it should work and is easier to read the logic. I take it that you only want the turtle to move if the improvement in proximity is sufficiently large (though the code is written as if it moves if it's only a small decrease too):
to move-patch
let candidate max-one-of other patches with [not occupied?] [proximity]
if [proximity] of candidate > proximity + attachment-rate [move-to candidate]
end
Upvotes: 1