Paul
Paul

Reputation: 189

Stop the procedure when the population of agents have the same variable in Netlogo

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?

Upvotes: 2

Views: 45

Answers (1)

drstein
drstein

Reputation: 1113

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.

Upvotes: 2

Related Questions