List Info

Thread: iteration dependent patch values




iteration dependent patch values
country flaguser name
United States
2007-06-15 07:49:47

Hi All:

I need some advice on how best to make some patches change values
based on iteration in the runs.

I need to make some patches flash certain values with varying
frequencies. For example, I have four patches that need to possess a
specific set of values, but for only one iteration. One patch flashes
the value every iteration (no problem). But the second only on every
fifth iteration, the third on every 10th, and the fourth only on every
50th. On every other iteration their values are reset to zero. It's
a kind of periodic display to which the turtles can react if they
happen to be in the vacinity. I've never tried to do this procedure
through the iterations in the run.

Any help would be much appreciated.

Don

__._,_.___
.

__,_._,___
Re: iteration dependent patch values
country flaguser name
United States
2007-06-15 11:00:53

Hi, Don!

You can use the modulus operator to get this kind of periodic behavior.

For example, (tick mod 50) = 0 when tick is a multiple of 50.

In the below example, the special patches are in agentset. Each has its own period and colors.

;; assumes patches-own [ period special-color normal-color ]
;; assumes that the special patches are in an agentset called "special-patches"
ask special-patches
[ let frame tick mod period
  ifelse frame = 0 [ set pcolor special-color ][ ;; change color every period ticks
  ifelse frame = 1 [ set pcolor normal-colro ][ ;; change color back on next tick
 ; ]]
]

You could, as an alternative, give the patches counter variables:

;; assumes patches-own [ period counter special-color normal-color ]
;; assumes that the special patches are in an agentset called "special-patches"
ask special-patches
[ ifelse counter = 0 [ set pcolor special-color ][ ;; change color every period ticks
  ifelse counter = 1 [ set pcolor normal-colro ][ ;; change color back on next tick
  ]]
  set counter counter + 1
  if counter = period [ set counter 0 ]
]

Adding and using if could be faster than using mod--if speed becomes important, test both.

If you have patches with the same (or coincident) periods that should not flash together, you can use an offset added to the tick, or initialize the counters to the non-zero values you desire.

Hope that helps!

~~James
_________________________
http://www.turtlezero.com


On 6/15/07, dnbrxtn < braxtonjuniata.edu">braxtonjuniata.edu> wrote:
Hi All:

I need some advice on how best to make some patches change values
based on iteration in the runs.

I need to make some patches flash certain values with varying
frequencies.&nbsp; For example, I have four patches that need to possess a
specific set of values, but for only one iteration.  ;One patch flashes
the value every iteration (no problem). But the second only on every
fifth iteration, the third on every 10th, and the fourth only on every
50th. &nbsp;On every other iteration their values are reset to zero. ; It&#39;s
a kind of periodic display to which the turtles can react if they
happen to be in the vacinity.&nbsp; I've never tried to do this procedure
through the iterations in the run.

Any help would be much appreciated.

Don


__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )