Swarm movement simulation

by Benjamin Helmer

Simulation

Simulation paused.
Unit:
Unit:
Obstacle radius:


Underlying Physics

Each of the $N$ actors state is defined by its position $\vec{r}_n$ and its velocity $\vec{v}_n$ ($1\leq n\leq N$). In each timestep $\Delta t$ the position changes by $\vec{r}_n(t+\Delta t)=\vec{r}_n(t)+\vec{v}_n(t)\cdot\Delta t$ and the velocity is changed acording to: \[ \vec{v}_n(t+\Delta t) = \vec{v}_n(t)+\frac{1}{N_c}\sum_{m\in\{N_c\}}\left(a\frac{\vec{r}_m-\vec{r}_n}{|\vec{r}_m-\vec{r}_n|}-b\frac{\vec{r}_m-\vec{r}_m}{|\vec{r}_m-\vec{r}_n|^2}+c\frac{\vec{v}_m-\vec{v}_n}{|\vec{r}_m-\vec{r}_n|^2}\right), \] where $\{N_c\}$ is the set of the #$N_c$ closest neighbours to actor n. The parameter $a$ thus govers the attraction between the actors, while $b$ determines how strongly they are repulsed from one another (at low distances to avoid collision). These are sufficient to describe some swarms. In bird swarm and fish schools however one can also observe velocity maching between neighbouring actors which is described by the $c$ term.

Simulation controls explained

The sliders are hopefully self explanatory. Use them to change the parameters $a,b,c,N$ and $N_c$. The dropdown menu next to the silders for $b$ and $c$ allows you to change the unit of the slider value. E.g. If $a=1.5$ and the b-slider has the value $0.01$, setting the unit of $b$ to $a$ will change the value of $b$ to $b=0.01a=0.015$. Then changing $a$ to e.g. $a=0.8$ will also change the value of $b$ to $b=0.01a=0.008$.

When the tickbox "show center of mass (com)" is checked, the simulation will display the center of mass of all actors (all considered to be of equal mass) as a yellow circle.

Clicking any place on the animation canvas will create an obstacle at that place. An obstacle is a special unmovable actor. The size of the obstacle can be adjusted with the corresponding slider. Obstacles are not considered one of the $N_s$ closest neighbours but affect all actors that are no further than $\frac{b}{a}$ away from them. Beyond this radius of influence they are unaffacted by the parameter $a$ (swarm animals aren't attracted by obstacles). When an obstacle is created inside an (moving) actor (or the other way around) the actor is moved to a nearby unoccupied location.

Pressing the "push all actors" button will add a velocity of $\Delta \vec{v}=(0.25,0.125)\cdot v_{max}$ to every actor. Note that there is a maximum velocity (default $v_{max}=8$) and if the velocity of an actor exceeds that amount it will be normalised to $v_{max}$.

The button "push actor #1" will set the velocity of the actor number one (marked as red circle; exept for when this button is pressed it does not behave any differently from all other actors) to $v_{max}$ in a randomly chosen direction when pressed.

The "stop all actors" button sets the velocity of all actors to zero. Unless either $a=b=0$ or $N_c=0$ the actors will usually pick up velocity quickly after beeing stoped.

Upon pressing the "center view on com" button the position of the center of mass is substracted from each actors position. As a result the com will be in the center of the window while the positions of the actors relative to one another stay the same.

The average velocity slider will show the average velocity of the actors (averaged over some small time). It is supposed to be disabeld (not allow input).

The predefined parameter values dropdown menu allows you to select from a few predefined settings.

 The insect swarm setting generates a big swarm with high $N_c$ and no velocity maching $c=0$. The actors move seemingly chaotically around inside the warm.

 The small swarms setting (might be most interesting) is quite similar to the initial settings. It has a rather small $N_c$ and therefore one will usually get multiple small swarms. When different swarms meet they will sometimes merge together or individual actors might change from one swarm to the other. Big swarms might sometimes split into two (or more) smaller swarms.

 The bird formation setting has a strong velocity maching (high $c$). After some time (stopping all actors a few times might speed this up) there will be one or two swarms where the actors stay at the same position relative to one another. When the velocity maching is removed (set $c=0$ with the slider) the actors will start to move chaotically around the swarm.

 The solid state setting has very strong repulsion between the actors. They will allign in a square grid making small oscillations. Basically a simple crystal model.

If you want to set a parameter to a value that is not available on the slider you can enter 'Update<CAPITAL_PARAMETER_NAME>Val(<some_value>)' in the console. E.g. UpdateAVal(-2) will set $a=-2$ and UpdateNVal(20) sets the number of actors to 20.

Further rading on swarm movement

Special thanks to Daniel Nevermann for providing a web page template.

If you find a bug or have some suggestions on how to improve the simulation/controls please contact me: s8773236@stud.uni-frankfurt.de.
Last updated: 06.04.2023