Flocking

来自集智百科 - 复杂系统|人工智能|复杂科学|复杂网络|自组织
跳到导航 跳到搜索
Flocking.png

鸟群模型

This model is an attempt to mimic the Flocking of birds. (The resulting motion also resembles schools of fish.) The flocks that appear in this model are not created or led in any way by special leader birds. Rather, each bird is following exactly the same set of rules, from which flocks emerge.


这是一个模拟鸟群运动的模型(该模型的运动规律也也很像鱼群)。在这个模型中出现的鸟群运动规律并不是由特殊的或某一个领头鸟创造的,相反,每只鸟都遵循一套完全相同的规则,从而形成了鸟群的运动。


This model is inspired by the Boids simulation invented by Craig Reynolds. The algorithm we use here is roughly similar to the original Boids algorithm, but it is not the same. The exact details of the algorithm tend not to matter very much -- as long as you have alignment, separation, and cohesion, you will usually get flocking behavior resembling that produced by Reynolds' original model. Information on Boids is available at Boids.


这个模型的灵感来自克雷格·雷诺兹发明的 Boids模拟。我们在这里使用的算法与原始Boids算法大致相似,但并不相同。算法的具体细节并不重要——只要你拥有对齐、分离和靠近,你便能够获得类似于Reynolds最初模型所创造的群体行为。有关鸟群算法,请参见百科词条:鸟群算法 Boids


标签:NetLogo建模,鸟群算法,多主体,boids

运行规则

The birds follow three rules: "alignment", "separation", and "cohesion".

"Alignment" means that a bird tends to turn so that it is moving in the same direction that nearby birds are moving.

"Separation" means that a bird will turn to avoid another bird which gets too close.

"Cohesion" means that a bird will move towards other nearby birds (unless another bird is too close).

When two birds are too close, the "separation" rule overrides the other two, which are deactivated until the minimum separation is achieved.

The three rules affect only the bird's heading. Each bird always moves forward at the same constant speed.


每一只鸟遵循三条规则:“对齐alignment”“分离separation”和“靠近cohesion”

  • 对齐”指的是鸟会倾向于转向,这样它的移动方向与附近的鸟的移动方向相同。
  • “分离”指的是如果另外一只鸟靠的太近,鸟会转身避开。
  • “靠近”意味着一只鸟会向附近的其他鸟移动(除非另一只鸟离得太近)。

当两只鸟靠得太近时,“分离”规则会占据主导,直到达到一个最小的可接受的距离。

这三条规则只影响鸟的向前运动方向,每只鸟总是以同样恒定的速度向前移动。


算法的实现

NetLogo使用教程

First, determine the number of birds you want in the simulation and set the POPULATION slider to that value. Press SETUP to create the birds, and press GO to have them start flying around.

The default settings for the sliders will produce reasonably good flocking behavior. However, you can play with them to get variations:

Three TURN-ANGLE sliders control the maximum angle a bird can turn as a result of each rule.

VISION is the distance that each bird can see 360 degrees around it.

  • 首先,确定您想要在模拟中的鸟群数量,并将POPULATION滑块设置为该值。
  • 按SETUP键创建,然后按GO键让它们开始飞行。
  • 滑动块的默认设置可以产生效果不错的群集行为。
  • 不过你可以调整来改变其运动:
    • 三个转角滑块TURN-ANGLE控制鸟的最大转弯角度。
    • VISION 视力是每只鸟能360度看到的距离。


THINGS TO NOTICE(注意事项)

Central to the model is the observation that flocks form without a leader.

There are no random numbers used in this model, except to position the birds initially. The fluid, lifelike behavior of the birds is produced entirely by deterministic rules.

Also, notice that each flock is dynamic. A flock, once together, is not guaranteed to keep all of its members. Why do you think this is?

After running the model for a while, all of the birds have approximately the same heading. Why?

Sometimes a bird breaks away from its flock. How does this happen? You may need to slow down the model or run it step by step in order to observe this phenomenon.


该模型的要点是在于观察到鸟群在没有领导者的情况下的形成。

在这个模型中没有使用随机数,除了鸟类的初始位置。鸟群的流动、栩栩如生的行为完全是由确定性规则产生的。

另外,请注意每个鸟群都是动态的。一个鸟群,一旦聚集在一起,并不能保证能留住所有的成员。你认为这是为什么?

运行模型一段时间后,所有的鸟都有大致相同的方向。为什么?

有时鸟儿会从鸟群中飞走。这是怎么发生的?为了观察这种现象,您可能需要放慢模型的速度或一步一步地运行它。


代码实现

Netlogo Web - Flocking中有算法实现的接口,可调节参数观察程序运行结果。

  1 turtles-own [
  2   flockmates         ;; agentset of nearby turtles
  3   nearest-neighbor   ;; closest one of our flockmates
  4 ]
  5 
  6 to setup
  7   clear-all
  8   create-turtles population
  9     [ set color yellow - 2 + random 7  ;; random shades look nice
 10       set size 1.5  ;; easier to see
 11       setxy random-xcor random-ycor
 12       set flockmates no-turtles ]
 13   reset-ticks
 14 end
 15 
 16 to go
 17   ask turtles [ flock ]
 18   ;; the following line is used to make the turtles
 19   ;; animate more smoothly.
 20   repeat 5 [ ask turtles [ fd 0.2 ] display ]
 21   ;; for greater efficiency, at the expense of smooth
 22   ;; animation, substitute the following line instead:
 23   ;;   ask turtles [ fd 1 ]
 24   tick
 25 end
 26 
 27 to flock  ;; turtle procedure
 28   find-flockmates
 29   if any? flockmates
 30     [ find-nearest-neighbor
 31       ifelse distance nearest-neighbor < minimum-separation
 32         [ separate ]
 33         [ align
 34           cohere ] ]
 35 end
 36 
 37 to find-flockmates  ;; turtle procedure
 38   set flockmates other turtles in-radius vision
 39 end
 40 
 41 to find-nearest-neighbor ;; turtle procedure
 42   set nearest-neighbor min-one-of flockmates [distance myself]
 43 end
 44 
 45 ;;; SEPARATE
 46 
 47 to separate  ;; turtle procedure
 48   turn-away ([heading] of nearest-neighbor) max-separate-turn
 49 end
 50 
 51 ;;; ALIGN
 52 
 53 to align  ;; turtle procedure
 54   turn-towards average-flockmate-heading max-align-turn
 55 end
 56 
 57 to-report average-flockmate-heading  ;; turtle procedure
 58   ;; We can't just average the heading variables here.
 59   ;; For example, the average of 1 and 359 should be 0,
 60   ;; not 180.  So we have to use trigonometry.
 61   let x-component sum [dx] of flockmates
 62   let y-component sum [dy] of flockmates
 63   ifelse x-component = 0 and y-component = 0
 64     [ report heading ]
 65     [ report atan x-component y-component ]
 66 end
 67 
 68 ;;; COHERE
 69 
 70 to cohere  ;; turtle procedure
 71   turn-towards average-heading-towards-flockmates max-cohere-turn
 72 end
 73 
 74 to-report average-heading-towards-flockmates  ;; turtle procedure
 75   ;; "towards myself" gives us the heading from the other turtle
 76   ;; to me, but we want the heading from me to the other turtle,
 77   ;; so we add 180
 78   let x-component mean [sin (towards myself + 180)] of flockmates
 79   let y-component mean [cos (towards myself + 180)] of flockmates
 80   ifelse x-component = 0 and y-component = 0
 81     [ report heading ]
 82     [ report atan x-component y-component ]
 83 end
 84 
 85 ;;; HELPER PROCEDURES
 86 
 87 to turn-towards [new-heading max-turn]  ;; turtle procedure
 88   turn-at-most (subtract-headings new-heading heading) max-turn
 89 end
 90 
 91 to turn-away [new-heading max-turn]  ;; turtle procedure
 92   turn-at-most (subtract-headings heading new-heading) max-turn
 93 end
 94 
 95 ;; turn right by "turn" degrees (or left if "turn" is negative),
 96 ;; but never turn more than "max-turn" degrees
 97 to turn-at-most [turn max-turn]  ;; turtle procedure
 98   ifelse abs turn > max-turn
 99     [ ifelse turn > 0
100         [ rt max-turn ]
101         [ lt max-turn ] ]
102     [ rt turn ]
103 end
104 
105 
106 ; Copyright 1998 Uri Wilensky.
107 ; See Info tab for full copyright and license.

THINGS TO TRY(你可以试一试)

Play with the sliders to see if you can get tighter flocks, looser flocks, fewer flocks, more flocks, more or less splitting and joining of flocks, more or less rearranging of birds within flocks, etc.

You can turn off a rule entirely by setting that rule's angle slider to zero. Is one rule by itself enough to produce at least some flocking? What about two rules? What's missing from the resulting behavior when you leave out each rule?

Will running the model for a long time produce a static flock? Or will the birds never settle down to an unchanging formation? Remember, there are no random numbers used in this model.


调整滑块看看能不能得到更紧密的鸟群,更松散的鸟群,更少的鸟群,更多的鸟群,或多或少的鸟群分裂或合并,或多或少的鸟群内的鸟类重新排列,等等等等。

你可以通过将该规则的角度滑块设置为0来完全关闭该规则。一条规则本身是否足以产生至少一些群体?那两条规则呢?当您删除每个规则时,结果行为中缺少了什么?

长时间运行该模型是否会产生静态鸟群?或者这些鸟群永远不会安于一个不变的队形?记住,这个模型中没有随机数。


EXTENDING THE MODEL(模型的延伸)

Currently the birds can "see" all around them. What happens if birds can only see in front of them? The in-cone primitive can be used for this.

Is there some way to get V-shaped flocks, like migrating geese?

What happens if you put walls around the edges of the world that the birds can't fly into?

Can you get the birds to fly around obstacles in the middle of the world?

What would happen if you gave the birds different velocities? For example, you could make birds that are not near other birds fly faster to catch up to the flock. Or, you could simulate the diminished air resistance that birds experience when flying together by making them fly faster when in a group.

Are there other interesting ways you can make the birds different from each other? There could be random variation in the population, or you could have distinct "species" of bird.


目前,这些鸟可以“看到”周围的一切。如果鸟类只能看到前方会发生什么?可以用in-cone设置。

有没有什么方法能让鸟群变成V形,比如迁徙的大雁的形态?

如果你在世界的边缘设置围墙,鸟儿飞不进去会发生什么?

你能让鸟儿飞过世界中央的障碍物吗?

如果给鸟儿不同的速度会发生什么?例如,你可以让远离其他鸟儿的鸟飞得更快,从而赶上鸟群。或者,你可以模拟鸟群在一起飞行时经历的空气阻力减小,方法是让它们在群体中飞得更快。

你觉得还有其他有趣的方式可以让这些鸟彼此不同吗?种群中可能存在随机变异,也可能存在不同的“物种”。


NETLOGO FEATURES(NetLogo默认设定)

Notice the need for the subtract-headings primitive and special procedure for averaging groups of headings. Just subtracting the numbers, or averaging the numbers, doesn't give you the results you'd expect, because of the discontinuity where headings wrap back to 0 once they reach 360.


注意,取鸟群的平均飞行方向需要使用subtract-headings语句。单纯的减去数字或者取平均值并不能得到结果,在NetLogo默认设定中这些数字一旦达到360度,标朝向会自动转回0。

编者推荐

集智相关课程

讲师:张江(北师大系统科学学院教授、博士生导师,集智俱乐部、集智学园创始人。)

本课程通过数个案例教会大家如何去动手搭建一个多主体仿真模型,以及如何利用NetLogo去实现。从生命游戏到人工鸟群,从模拟经济系统到病毒沿网络的传播,通过循序渐进的案例,该课程带你逐步走入NetLogo多主体建模的神奇世界。


书籍推荐

《复杂》封面

蚂蚁在组成群体时为何会表现出如此的精密性和具有目的性?数以亿计的神经元是如何产生出像意识这样极度复杂的事物?是什么在引导免疫系统、互联网、全球经济和人类基因组等自组织结构?这些都是复杂系统科学尝试回答的迷人而令人费解的问题的一部分。理解复杂系统需要有全新的方法,需要超过传统的科学还原论,并重新划定学科的疆域。借助于圣塔菲研究所的工作经历和交叉学科方法,复杂系统的前沿科学家米歇尔在《复杂》一书中,以清晰的思路介绍了复杂系统的研究,横跨生物、技术和社会学等领域,并探寻复杂系统的普遍规律。与此同时,她还探讨了复杂性与进化、人工智能、计算、遗传、信息处理等领域的关系。


文章推荐

生命如何起源,智能如何涌现,因果如何反转,复杂谜题,引人深思。2019年7月13日,集智俱乐部创始人张江教授在混沌大学授课,详细解读了复杂系统中的混沌、涌现与进化,此文整理自课堂内容。

近期,由北京师范大学张江团队发表的文章《A general deep learning framework for network reconstruction and dynamics learning》在期刊Applied Network Science上刊登,这篇文章提出了一种基于深度学习的数据驱动模型,可以从节点的时间演化数据中重构出网络结构,并且学习到系统的动力学。本文是第一作者张章对该文章内容的解读。


课程推荐

本课程通过数个案例教会大家如何去动手搭建一个多主体仿真模型,以及如何利用NetLogo去实现。从生命游戏到人工鸟群,从模拟经济系统到病毒沿网络的传播,通过循序渐进的案例,该课程带你逐步走入NetLogo多主体建模的神奇世界。
本课程将视线转移到生物学领域,展现计算机模拟在生物学中的应用。认识自然现象,我们可以从物理、数学、生物、天文、化学等众多角度去解读,那么怎样将众多的知识综合起来转化为可以用计算机模拟的语言哪?本节课将通过一个模型案例来帮助我们打开思路,更好的去描述和模拟生物现象。

相关模型

相关方法

  • 多主体模拟

Reference

  • Wilensky, U. (1998). NetLogo Flocking model. http://ccl.northwestern.edu/netlogo/models/Flocking. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.



本中文词条由AvecSally整理,如有问题,欢迎在讨论页面留言。

本词条内容源自wikipedia及公开资料,遵守 CC3.0协议。