2

I am trying to stop my simulation when most of the population of agents have the same own variable value but I really don´t know ho to do it. Here is my code for the creation and the procedure of my model:

 breed [birds bird]   
 birds-own [high]

  to setup
 create-turtles birds
  [
  set color blue
   set shape "circle 2"
  set xcor (-40 + random 25 )
  set ycor  (-40 + random 12)] 
end

   to go 
   ask birds
    [
   let Si4  [high] of one-of birds in-radius 1
   let conc (( 4 * Si4) + ( 2 * Ai4 ) )
   set high conc
   ]  
   end

I try to modulate the "high" variable using different values for the operations but I need to stop the simulation when at least 70-80% of the population of birds have the same value of "high" . I tried to use the command "modes"and "max" like this:

   if max modes [high] of cells > 55 [stop]  

but this stops the simulation even if 1 bird have that value not if most of the population has it so, any suggestions to do this properly?

Joshua
  • 40,822
  • 8
  • 72
  • 132
Paul
  • 189
  • 6

1 Answers1

2

I would do like this:

let mode  (modes [high] of turtles)

foreach mode [
  if (count turtles with [high = ?] >= (count turtles * 0.7)) [stop]
]

where first i define the list mode wich is the list with the most common elements in the turtle-own high, then for each of them I check if the number of turtles with that high is greater or equal than the 70% of the total number of the turtles.

If any of the elements of the list mode satisfy this condition, stop the simulation.

drstein
  • 1,113
  • 1
  • 10
  • 24
  • 1
    Great answer! But since, by definition, each mode has the same count, you don't need `foreach`. You can just check the first of them: `if count turtles with [ high = first modes [ high ] of turtles ] > count turtles * 0.7 [ stop ]`. – Nicolas Payette Oct 17 '15 at 21:10
  • Thanks for the advice, you're absolutely right, I didn't think about that! – drstein Oct 19 '15 at 07:12