Loading ...
Sorry, an error occurred while loading the content.

Re: question about Netlogo syntax

Expand Messages
  • LMS
    Thank you -- this really helped!!
    Message 1 of 4 , Nov 30, 2010
    • 0 Attachment
      Thank you -- this really helped!!

      --- In netlogo-users@yahoogroups.com, James Steiner <gregortroll@...> wrote:
      >
      > Well, for this we need a couple things:
      >
      > IN-RADIUS lets us make an agentset of the agents in a certain radius
      >
      > OF lets us make another agent (or set of agents) do a calculation for us,
      > and give us the answer.
      >
      > When OF is used with a set of agents, the result is a list of the results.
      >
      > MEAN lets us get the arithmetic mean (aka the Average) of the elements of a
      > list
      >
      > So, lets throw all that up in the air and see what happens:
      >
      > let circle-turtles other ( turtles in-radius 5)
      > let avg-xvalue mean [ xvalue ] of circle-turtles
      > set xvalue ( xvalue + mean-xvalue) / 2
      >
      > And there you go.
      >
      > Now. One problem.
      >
      > If all the turtles are doing this... and since turtles really do things one
      > at a time, not all at once, some turtles will have already changed their
      > xvalue before other turtles... so some turtles new xvalue will include other
      > turtles new xvalue, not the old xvalue!! AUGH!
      >
      > So, the trick here is to give the turtles another variable, where they can
      > stash the NEW xvalue, until all turtles have completed the calculation. Then
      > all the turtles can apply the new xvalue at once.
      >
      > ;; assumes turtles-own [ xvalue new-xvalue ]
      > ask turtles
      > [ set new-xvalue (x-value + mean [ xvalue ] of (other (turtles in-radius
      > 5)))
      > ]
      > ask turtles
      > [ set xvalue new-xvalue
      > ]
      >
      > Voila!
      >
      > ~~James
      > www.turtlezero.com
      >
      >
      > On Sat, Nov 27, 2010 at 3:26 PM, LMS <lmsc20012@...> wrote:
      >
      > > ... trying to use variables of neighbors to update my turtle's variable,
      > > and need help with syntax (including brackets and spaces) -
      > >
      > > what I want to do for variable named XVALUE:
      > >
      > > update each turtle's XVALUE to include [(starting XVALUE + <average of the
      > > XVALUES of neighbors in a radius of 5>) divided by 2]
      > >
      > > -- thanks in advance,
      > > LMS
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.