# Effect of Formation Size on Flocking Formation Performance for the Goal Reach Problem
## 2 Materials and Methods
### Behavior of Agents  
Each agent behaves based on its surrounding environment and neighbors within the perception zones. Each agent, \(i\), has a number of vectors that help to determine its direction. These vectors are as follows:  
* A goal-zone-detection vector, \(Vg_{i}=[vg_{i,1},vg_{i,2},\ldots,vg_{i,8}]^{T}\), where each \(vg_{i,k}\) is equal to 1 if a goal is detected in view sector \(k\) of agent \(i\), within its perception area (\(zoa\)), and is equal to zero otherwise. The unit vector \(dg_{i}\), which denotes the desired direction of agent \(i\) based on the goal detected, is calculated as follows: \(dg_{i}=\frac{s_{i}vg_{i}}{\|s_{i}vg_{i}\|}\).
* An obstacle-detection vector, \(Vb_{i}=[vb_{i,1},vb_{i,2},\ldots,vb_{i,8}]^{T}\), where each \(vb_{i,k}\) is equal to 1 if an obstacle is detected in view sector \(k\) of agent \(i\) within its perception area, and is equal to zero otherwise. The unit vector \(db_{i}\), which denotes the desired direction of agent \(i\) based on the opposite net direction of obstacles detected, is calculated as follows: \(\hat{db}_{i}=-\frac{s_{i}v\hat{b}_{i}}{\|s_{i}v\hat{b}_{i}\|}\).
* An arena-exploration unit vector, \(\hat{d}\hat{e}_{i}=[\cos\left(\theta_{rand,i}\right)\sin\left(\theta_{rand,i} \right)]\), is required, in order to help the agent explore the unknown environment. This vector has a single value: a random angle in the range \(\theta_{rand,i}\in(0,2\pi)\). In the case where an obstacle has been detected, the angle is modified to \(\theta_{rand,i}\in(0,\pi)\), such that the agent heads towards a region in the opposite direction of the observed obstacle.  
On the other hand, agents also have to consider their neighbors, in order to avoid collisions with each other, as well as maintaining the coherence of the flock, to avoid fragmentation, and to keep the agents aligned. Therefore, agents have another three vectors defining how they behave, according to their nearby neighbors. These vectors are defined according to the three zones (\(zor\), \(zoo\), and \(zoa\)) for each agent \(i\), as follows:  
* A repulsion zone vector \(Vr_{i}=[vr_{i,1},vr_{i,2},\ldots,vr_{i,8}]^{T}\). This vector allows for the detection of neighbors in the repulsion zone of agent \(i\). The existence of one or more neighbors in view sector \(k\) of agent \(i\) is represented by a 1 in \(vr_{i,k}\), whereas their absence is represented by a 0. The corresponding unit vector is calculated as \(\hat{dr}_{i}=-\frac{s_{i}vr_{i}}{\|s_{i}vr_{i}\|}\).
* For each neighbor, \(j\), detected in \(zoo\) of agent \(i\), having a travel direction represented as \(\theta_{j}\), the unit vector \((\hat{\phi_{j}})=[\cos{(\theta_{j})}\sin{(\theta_{j})}]\) stores the direction of travel of this neighbor. The unit vector with a size equal to the number of neighbors \(n_{0}\) in \(zoo\), which is responsible for alignment with other agents in the flock, is given by \(\hat{d_{i}}=\frac{\sum_{j=1}^{n_{0}}\hat{\phi_{j}}}{\|\sum_{j=1}^{n_{0}}\hat{ \phi_{j}}\|}\).
* The attraction zone vector, \(Va_{i}=[va_{i,1},va_{i,2},\dots,va_{i,k}]^{T}\). \(va_{i,k}\), is assigned a value of 1, based on the existence of one or more neighbors in the view sector \(k\) of agent \(i\), and is assigned as 0 otherwise. The corresponding unit vector is calculated as \(\hat{da}_{i}=\frac{s_{i}v_{i}u_{i}}{\|s_{i}v_{i}\|}\), which determines the direction of far neighbors in the \(zoa\), in order to avoid fragmentation of the flock.