2

当大多数代理群体具有相同的变量值但我真的不知道该怎么做时,我试图停止我的模拟。这是我的模型创建和过程的代码:

 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

我尝试使用不同的操作值来调节“高”变量,但是当至少 70-80% 的鸟类具有相同的“高”值时,我需要停止模拟。我尝试像这样使用命令“modes”和“max”:

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

但这会停止模拟,即使 1 只鸟具有该值,如果大多数人口都具有该值,那么有什么建议可以正确执行此操作吗?

4

1 回答 1

2

我会这样做:

let mode  (modes [high] of turtles)

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

首先我定义了列表mode,它是海龟拥有的最常见元素的列表high,然后对于它们中的每一个,我检查海龟的数量high是否大于或等于海龟总数的 70% .

如果列表中的任何元素mode满足此条件,则停止模拟。

于 2015-10-17T20:59:34.363 回答