Reputation: 41
Currently I am constructing a model on opinion dynamics and want the model to stop automatically when a certain global variable global-participation-rate
remains unchanged for X amount of ticks. I probably should include something like
if stop-ticking? [stop]
in my go procedure. With the report looking something like this:
to-report stop-ticking?
ifelse (??) = ?? [report true] [report false]
end
What code should I use to check whether the global remained unchanged for a certain amount of ticks?
Upvotes: 0
Views: 94
Reputation: 9620
The easiest way is to add a new global to keep count. E.g., (abbreviating global-participation-rate
to gpr
):
globals [gpr ct-gpr]
to update-gpr
let old-gpr gpr ;store old value
set gpr get-gpr ;compute new value
;increment or reset the counter:
set ct-gpr ifelse-value (gpr != old-gpr) [1] [1 + ct-gpr]
end
Upvotes: 2
Reputation: 17678
You need a global variable for either the participation-rate or total converted or whatever. Then after your diffusion process, you do something like let new-adopters <calculation>
and if-else new-adopters = total-adopters [stop] [set total-adopters new-adopters]
If you need more than one time point comparison, then you need to create a list rather than a simple value and add the new value to the end of the list and check the end of the list is all the same number.
Upvotes: 1