I have an agent set named "open patches", which I found using the following, in which "number_open_patches" is a specific radius depending on "length":
`ask turtles ['
let my_patch self
set number_open_patches ((50 * (length ^ 2)) / 100) / resolution
let open_patches patches in-radius number_open_patches
I found the distance of these patches to a particular turtle "my_patch" using:
let distance_patch [distance my_patch] of open_patches
I then calculate "patch attractiveness", which is just the distance of each of the patches ("distance_patch") in "open_patches" plugged into the equation below:
let patch_attractiveness ( map [[x] -> exp ((x / open_patches) * (log e (.2 / 1)))] distance_patch)
I would finally like to select the patch within "open_patches" that has the greatest value of "patch_attractiveness". I am using the code below:
let destination max-one-of open_patches [patch_attractiveness]
I get an error as it returns 'nobody'. Why would this be? How do I know that I would actually be selecting the right patch as "distance_patch" is just a list in random order?
EDIT: I also tried the code below, but am getting a "division by zero" error when I try to calculate patch attractiveness.
ask turtles [
let my_patch self
set number_open_patches ((50 * (length ^ 2)) / 100) / resolution
let open_patches patches in-radius number_open_patches
ask open_patches [
set distance_patch [distance self] of my_patch
set patch_attractiveness exp ((distance_patch / number_open_patches) * (log e (.2 / 1)))
] ]