# Exploration of Swarm Dynamics Emerging from Asymmetry
## 2 Basic Algorithm of Swarm Chemistry
The parameters newly introduced in SC are:  
* \(R\): the perception range to define the size of the neighborhood
* \(V_{n}\): the ideal speed
* \(V_{m}\): the maximum speed  
It should be noted that the perception range \(R\) is a particularly important parameter deciding whether an interaction occurs between an agent and another. Figure 3 illustrates the perception ranges of the agents. Each one of them has its perception range \(R_{i}\). An agent \(i\) (\(i=1,\ \cdots,\ N\)) perceives and communicates locally with its neighbors when they come within the perception range of agent \(i\). Figure 3 represents the \"cohesion\" effect, i.e., every agent makes its orientation towards the center position among its neighboring agents. Figure 3 represents the \"aligning\" effect, i.e., every agent adjusts its velocity (orientation) to the velocity averaged over those of its neighboring agents. Figure 3 represents the \"separation\" effect to avoid collisions between the agents. The smaller the distance between the agents \(i\) and \(j\) becomes, the greater the separating (repulsion) force becomes. These effects are involved together and used to determine the acceleration of the agent \(i\) as indicated in Line 8 of Algorithm 1. Figure 3: Kinetic interaction between agents (drawn based on [9]). (**a**) Agent \(i\) perceives the positions and the velocities of neighboring agents within its perception range, \(R_{i}\); (**b**) Cohesion; (**c**) Alignment and (**d**) Separation. ```
1:for all\(i\in\) agents do
2:\(\mathcal{N}\leftarrow\{j\
eq i\}\) that satisfies \(\left|\vec{x}_{j}-\vec{x}_{i}\right|<R^{i}\)
3:if\(\left|\mathcal{N}\right|=0\)then
4:\(\vec{a}\leftarrow\left(r_{\pm 0.5},\ r_{\pm 0.5}\right)\) // Random steering
5:else
6:\(\left\langle\vec{x}\right\rangle\leftarrow\sum_{j\in\mathcal{N}}\vec{x}_{j}/ \left|\mathcal{N}\right|\)
7:\(\left\langle\vec{v}\right\rangle\leftarrow\sum_{j\in\mathcal{N}}\vec{v}_{j}/ \left|\mathcal{N}\right|\)
8:\(\vec{a}\leftarrow c_{1}^{i}\left(\left\langle\vec{x}\right\rangle-\vec{x}_{i} \right)+c_{2}^{i}\left(\left\langle\vec{v}\right\rangle-\vec{v}_{i}\right)+c_ {3}^{i}\sum_{j\in\mathcal{N}}\left(\vec{x}_{i}-\vec{x}_{j}\right)/\left|\vec{x }_{i}-\vec{x}_{j}\right|^{2}\) // Cohesion, alignment and separation
9:if\(r<c_{4}^{i}\)then
10:\(\vec{a}\leftarrow\vec{a}+\left(r_{\pm 5},\ r_{\pm 5}\right)\) // Random perturbation
11:endif
12:endif
13:\(\vec{v}_{i}^{\prime}\leftarrow\vec{v}_{i}+\vec{a}\)
14:\(\vec{v}_{i}^{\prime}\leftarrow\min(V_{n}^{i}/\left|\vec{v}_{i}\right|,\ 1)\cdot\vec{v}_{i}^{\prime}\) // Limiting overspeed
15:\(\vec{v}_{i}^{\prime}\gets c_{5}^{i}(V_{n}^{i}/\left|\vec{v}_{i}\right| \cdot\vec{v}_{i})+(1-c_{5}^{i})\vec{v}_{i}^{\prime}\) // Self-propulsion
16:endfor
17:for all\(i\in\) agents do
18:\(\vec{v}_{i}\leftarrow\vec{v}_{i}^{\prime}\) // Update velocity
19:\(\vec{x}_{i}\leftarrow\vec{x}_{i}+\vec{v}_{i}\) // Update position
20:endfor
```  
**Algorithm 1** Kinetic Rules in Swarm Chemistry [9]. Line 2: The set of neighboring agents (i.e., other agents within the local perception range), \(\mathcal{N}\) of agent \(i\) is found. Lines 3-4: The number of neighboring agents, \(\left|\mathcal{N}\right|\), is then calculated. If the set \(\mathcal{N}\) is empty, i.e., if there is no agent within its perception range, a random acceleration is set, which means a random straying by the agent. Lines 6-7: Otherwise, the average positions and velocities of nearby particles are calculated, respectively. Line 8: A tentative acceleration is calculated according to the three Boids rules (cohesion, alignment and separation). Lines 9-11: At a given probability \(c_{4}\), a random perturbation is applied to the tentative acceleration. Line 13: A tentative velocity is calculated by time-integrating the acceleration. Line 14: The tentative velocity is limited to prevent overspeed. Line 15: The speed is approximated to its own normal speed (self-propulsion).