-1

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)))

] ]

P_Grace
  • 107
  • 1
  • 7

1 Answers1

1

You didn't give enough code to see what the problems are. Your line with the exponential dividing by an agent set doesn't seem syntactically correct. You don't show the code for calculating open_patches_in_radius and I suspect there are none and the rest of the line using that is just a distraction.

That said, I'd suggest going the opposite way.

  • let the patches own a distance and an attractiveness variable but "distance" is a reserved word so it needs a different name.

  • ask the open-patches to determine their distance to your "my_patch" turtle and store that in their distance slot. ( instead of asking your patch )

  • compute whatever global things you need for your formula

  • ask open-patches to set their attractiveness based on their distance ( already computed) and some exponential decay formula that apparently includes some global factor.

  • then finally let your destination be the open-patch with the max attractiveness, which now has a much simpler formula using "max-one-of agentset [reporter]" syntax, such as

    let dest max-one-of open-patch [ attractiveness ]

  • or possibly you want only open-patches within a given radius, but again depending on the scattering of open-patches and the size of the radius, there may be none. Check for none when setting open-patches-in-radius because that's a valid subcase.

Wade Schuette
  • 1,455
  • 1
  • 8
  • 9
  • I'll try this, thanks. I just edited the question to include how I calculated "open_patches" ("open_patches_in_radius" was a typo). – P_Grace Jun 25 '22 at 05:14