## Abstract

Swarming is a phenomenon where collective motion arises from simple local interactions between typically identical individuals. Here, we investigate the effects of variability in behavior among the agents in finite swarms with both alignment and cohesive interactions. We show that swarming is abolished above a critical fraction of non-aligners who do not participate in alignment. In certain regimes, however, swarms above the critical threshold can dynamically reorganize and sort out excess non-aligners to maintain the average fraction close to the critical value. This persists even in swarms with a distribution of alignment interactions, suggesting a simple, robust and efficient mechanism that allows heterogeneously mixed populations to naturally regulate their composition and remain in a collective swarming state or even differentiate among behavioral phenotypes. We show that, for evolving swarms, this self-organized sorting behavior can couple to the evolutionary dynamics leading to new evolutionarily stable equilibrium populations set by the physical swarm parameters.

## Introduction

Collective motion in natural systems is a well studied phenomena that spans many spatial and temporal time scales^{1,2}, ranging from protein filaments driven by molecular motors^{3,4}, to swarming bacteria^{5} and active colloidal crystals^{6}, to fish^{7}, birds^{8}, and even robot swarms^{9,10}. Such collective phenomena rely on the sharing or transmission of local information by constituents of the group leading to global consensus. Information flow and information fidelity are therefore critically important for collective systems to persist, especially in situations where disorder is an issue.

Disorder may exist in the environment and it has been recently shown that topological disorder in the form of obstacles can have significant detrimental effects on the ability for systems to move collectively^{11,12,13}. Disorder can also exist in the form of variability in behavior among members of the group, which has been modeled using agents with varying velocities^{14,15} or differing noise sensitivity^{16}, agents that stochastically switch off social interactions^{17} and migratory groups of agents with varying sensitivity to external directional cues^{18,19}. An interesting manifestation of such behavioral heterogeneity would be swarms with agents that have varying abilities to process social cues. A specific scenario could be swarms with sub-populations of non-aligners that either refuse or are unable to participate in utilizing shared information with their neighbors resulting in significant impacts on the collective. For example, it has been observed in colonies of the quorum sensing bacteria *P. aureginosa* that colony collapse can occur if mutant cheaters (those that do not secrete signaling compounds to sustain colony swarming) are introduced into the swarm even though there are sufficient nutrients in the environment^{20,21,22,23,24}. Differential behavior can also be a result of disease in organisms. For example, in locust swarms, the introduction of parasites (Paranosema locustae) inhibit the production of aggregation pheromones that promote gregarious behavior, thus resulting in a transition to a non-swarming state^{25}. In analogy to these biological systems, non-alignment behaviors could also arise in robotic drone swarms^{9,26}, where software viruses or hardware failures could cause agents to malfunction, leading to an inability to swarm effectively and requiring the development of novel algorithms to alleviate this problem^{27,28,29}.

Since differential behavior or non-alignment can be fairly ubiquitous in swarming systems and too many such non-aligners will have a deleterious effect on the ability to swarm, it poses a number of significant questions regarding how natural swarms deal with non-aligners or more generally variations in alignment ability. Is there a maximum fraction of non-aligners that a finite swarm can carry and is there a simple predictive relation between the maximum non-aligner carrying capacity and the characteristics of the swarm? Could there exist robust mechanisms that allow the whole group to increase its non-aligner carrying capacity? Are there mechanisms that allow swarms to limit the spread of non-aligning? Do these same mechanisms operate if the alignment abilities have a more natural continuous spread? If there are fitness advantages associated with non-aligning how does it affect the evolutionary dynamics? To address these issues, we study an agent based model of finite swarms with local aligning and cohesive interactions between neighbors and a sub-population of non-aligning agents within the group that do not align with their neighbors and do not have a defined internal preferred velocity.

## The Model

Agents exist in a continuous two dimensional space where each agent interacts with other agents in its immediate neighborhood defined by a vision radius *d*_{v}. At any given time, *t*, each agent has a position , and a direction of travel . The direction of travel of the agent at the next time step is computed by taking into account both alignment and cohesive interactions with its neighbors as well as noise. This is implemented by computing an alignment interaction vector, and a cohesive interaction vector, . Here, for an agent is the sum of the direction vectors of its nearby neighbors, which is proportional to the mean consensus direction (see methods for details). The form of the alignment interaction we use is common in studies of swarming systems and can be found in many variants of the standard Vicsek model^{30,31,32}, which was formulated originally to study a thermodynamic phase transition of aligning agents resulting from an increase in temperature or noise of the system. The form of the cohesive interaction is modeled as arising from a Lennard-Jones (LJ) interaction which is attractive at large distances and repulsive at close range (see methods for details). The effect of the LJ interaction in our model is to encourage agents to maintain a preferred distance (*R*) thus providing an overall cohesiveness as well as collision avoidance within the swarm, as seen in similar swarming systems^{29,33,34}. It is to be noted that our results do not depend critically on the exact form of the potential as long as it prescribes a preferred separation distance. In what follows, we set , so that each agent sees only its first nearest neighbors on average, consistent with prior flocking models. The updated travel direction vector is then

Noise here is implemented as an angular adjustment by rotating the calculated travel direction vector through a randomly selected angle from a uniform distribution in the interval [−*η*/2, +*η*/2]. This is described in detail in the methods section below. Here the dimensionless parameters *α* and measure the importance of alignment and cohesiveness respectively (equation (1)). Directional updates are only performed in time intervals of *δt* corresponding to the physical reaction time of agents within the system. In contrast, positions are updated every simulation time-step, Δ*t*, which can be made arbitrarily small. It is to be noted that velocity is encoded by a new length scale, *d*_{r}, the reaction distance, which determines how far an agent moves before reprocessing information, i.e. in time *δt*. Our model for the swarm produced expected stable collective dynamics^{30}, including order-disorder transitions as a function of noise (see Supplementary Information 1.1), which have been subsequently studied using both hydrodynamics^{35,36}, and agent based models^{37}. Although such agent based models are quite simple and leave out many microscopic details, they have been shown to produce a rich and complex phase space of collective motion that mimics the behavior of real physical and biological swarming systems^{37,38,39,40}.

To introduce behavioral heterogeneity in the form of non-aligners who refuse, or are unable, to participate in utilizing local alignment cues to guide their movements, we choose, at random, a fraction *f* of the swarming agents to be non-aligners after a transient time period where collective motion is established. Non-aligner agents follow the same update procedures as aligners, except that the alignment interaction is suppressed by setting *α* = 0, so they no longer have any intrinsic tendency to align with their neighbors. Thus the only forces the non-aligners feel arise from the LJ potential.

## Results

## Large inter-agent cohesiveness limit

We first consider the limit where the cohesive interactions are strong enough to produce a single swarm that cannot break apart and shows no rearrangements over time. This happens when , which is high enough to prevent the swarm from fracturing. Thus, once a random spatial distribution of non-aligners is established in the swarm, it remains fixed in a *locked-in* state thereafter. We begin by focusing on the effects of adding a fixed fraction of non-aligners, *f*, to our system and analyzing how the addition of these non-aligners affects the ability of the agents to swarm. To quantify the degree of order in the swarm we use the group polarization of all the agents, , defined by,

Figure 1(a) shows that as *f* increases, the swarm undergoes a sharp transition from an ordered swarming state where to a static disordered non-swarming state with . The transition occurs at a critical non-aligner fraction, *f**, that is very weakly dependent on the system size as seen in Fig. 1(a) where the transition occurs near *f** ∼ 0.5 for = 1, *d*_{v}/*d*_{r} = 100, and various different system sizes. On the left of the transition the system has a low non-aligner fraction and all agent directions are aligned with each other, shown by the black arrow heads in Fig. 1(b) with non-aligners in red and aligners in blue, while on the right of the transition the system is no longer able to form an ordered state, and agents instantaneously have random directions (Fig. 1(c)), resulting in a state with no net movement of the center of mass of the swarm. Note however that each individual still moves within the cluster even in the disordered state. It is to be noted that the time at which non-aligners are introduced does not affect the results shown and there appears to be very little hysteresis in the system (see Supplementary Information 1.2 and 1.3), suggesting a possible first order transition^{17}, which implies that the results for a fixed non-aligner fraction are fairly unique. Intuitively, increasing the fraction of non-aligners, *f*, while keeping the swarm together as a single unit, decreases net alignment with different parts of the swarm trying to go in different directions and results in a disordered stationary state. With cohesive strength being fixed at a high value, the non-aligner carrying capacity, *f**, then depends sensitively on the ratio, *d*_{v}/*d*_{r}, where *d*_{v} ∼ *R* is the vision radius or agent-spacing and *d*_{r} is the reaction distance. Figure 1(d) shows the value of *f** where the system transitions from an ordered to a disordered state (green) increasing with the ratio *d*_{v}/*d*_{r}.

To identify the cause for this behavior, we looked at the average magnitude of the alignment interaction, , over all agents in the swarm, and the average magnitude of the cohesive interaction, . As the non-aligner fraction *f* increases, we found that the average magnitude of the alignment interaction, decreases as the non-aligners do not contribute to alignment and that the transition occurs at a value of *f* ∼ *f** when , becomes less than . Figure 1(d) shows the value of *f* where the measured value of in the simulation becomes less than (red) and we see that it compares well with the measured value *f** for the order disorder transition. Comparing the alignment and cohesive interactions also allows us to derive a simple analytic approximation for the value of *f** with no adjustable parameters (Equation 3).here, *C* is a constant set by the form of the cohesive interaction as well as the average number of neighbors per agent (See Supplementary Information 2 for derivation). The agreement between our analytical estimate and the simulation values is shown by the blue curve in Fig. 1(d).

The fact that *f** changes from about 10% to about 90% in just over a decade in the parameter *d*_{v}/*d*_{r} is of significance. Higher values of *d*_{v}/*d*_{r} correspond to situations where agents are spaced much further than they move between updating directions, resulting in agents being able to quickly correct for deviations from their perfect swarming formation. Thus a potential way for swarms to accommodate more non-aligners or malfunctioning agents is to increase *d*_{v}/*d*_{r}, which can be accomplished either by increasing their separation (increases *d*_{v}) or by moving slower and/or processing information more quickly (decreases *d*_{r}). The other mechanism to potentially increase the non-aligner carrying capacity *f**, is by reducing the cohesiveness /*α*.

## Tuning cohesiveness between agents allows for enhanced swarming

Reducing the cohesiveness results in a situation where the disorder is no longer quenched and the agents are able to rearrange themselves within the swarm or even cause the swarm to fracture. To study these cases, the system is initialized with a high = 1 in the *locked-in* state and a high value of *f* > *f** so that the system is in a static disordered state by default. After a transient time period allowing the system to reach a steady state, is reduced, allowing for potential rearrangements and fracture. When is reduced, we found that the system fragments into smaller clusters which can individually be ordered swarming clusters or disordered static clusters. Figure 2(A) shows the weighted average of the steady state order parameter of the fragmented clusters of the system for a fixed non-aligner fraction *f* = 0.8 versus the relative strength of the LJ interaction, , for a system size of *N* = 100. A modest reduction in appears to have a dramatic effect. When = 10^{−1.0} it appears that the polarization in the swarm is greatly amplified where swarming was completely suppressed in the quenched configuration case . Thus, the previously immobile single cluster has now broken up into smaller clusters, many of which are mobile. As is decreased further, the polarization begins to decay slightly suggesting that the cohesiveness has become so weak that some of the clusters begin to fracture into individual agents and thus are no longer part of ordered clusters. This suggests that there is some optimal regime of for collective motion in the presence of non-aligners.

We next probed the dynamics associated with the cluster reorganization. Figure 2(A inset) shows the percent change in the fraction of aligners (blue) and non-aligners (green) which are part of moving clusters as the simulation time progresses. The mobility fraction of non-aligners steadily decreases while the mobility fraction of aligners steadily increases. This suggests a sorting mechanism whereby non-aligners are being left behind allowing for clusters with more aligners to become ordered and move collectively. This can be visualized in Fig. 2(B,C) which illustrates how the system starts out as a single disordered group and then breaks apart into smaller ordered clusters with mixtures of non-aligners and aligners, as well as disordered clusters consisting of mostly non-aligners.

To examine the relative contribution of rearrangements within single clusters to the overall sorting, we measured the probability distribution of the angle between the direction of travel of the non-aligners and the cluster average, as well as the same probability distribution for aligners. We then calculated the difference in these two probability distributions (Fig. 2(D)). We observe that aligners contribute predominantly to angles close to zero (purple bar) within the spread due to noise (red shaded region), while non-aligners are more likely to travel at angles around *π*/2 (blue bars) with respect to the cluster average. This implies that non-aligners will gradually move towards the sides and backs of the clusters before getting left behind. By sorting out non-aligners, the over all average alignment interaction strength in the cluster increases due to the higher fraction of aligners present, and the smaller cluster is able to swarm.

We now consider the full range of behaviors exhibited by our system as the parameters, including cohesion and non-aligner fraction, are varied. Figure 3 (A) shows a phase diagram of the system in the non-aligner fraction/cohesion (*f*,) plane where the colors indicate the value of the order parameter . We see that if the non-aligner fraction exceeds a critical value *f**() predicted by equation (3) (solid white line), the system is in a disordered, *static* state - denoted “St”. Here, the cohesive forces dominate over the alignment, leading to the static state with no net order, due to the frustration of agents attempting to travel in differing directions exceeding a value which can be resolved by aligning to reach a consensus direction. Below the line, we see that the system is able to achieve order. There are, however, two very different behaviors within this region. For low values of *f*, the system is stable and achieves a high degree of polarization () as a *single* cohesive swarm, relieving frustration by aligning to reach a consensus direction. This is clearly shown by the *swarming* region labelled “Sw” in Fig. 3(B) where the colors now indicate the probability that the system fractures into two or more clusters. Now, as the non-aligner fraction is increased, we enter the sorting regime (“So”) that we examined earlier in this section, where the system begins to fracture into smaller clusters, leaving behind non-aligner rich clusters, allowing aligner rich clusters to swarm and thereby increasing the net polarization. It is of interest to note here that the transition between the swarming and sorting phases roughly occurs at a constant value of the non-aligner fraction, *f*^{c} equal to the critical non-aligner fraction, *f**, when the alignment and cohesion constants become equal, = 1 (in units of *α*), which is shown by the dashed white line, suggesting that at non-aligner fractions above *f*^{c} frustration within the system is relieved by fracture as well as alignment. The existence of these three regimes and their locations relative to the predicted transition lines turn out to be completely general and work over the range values of *d*_{v}/*d*_{r} feasible in our simulations with no adjustable parameters (see Supplementary Information 3).

## Self-organized sorting

Starting with a cluster with a high non-aligner fraction, we showed that, for low enough cohesive energies, the swarm dynamics spontaneously cause the re-organization and break-up of the cluster. What, then, is the non-aligner fraction of the sub-clusters that are now mobile and able to swarm? To answer this question, we looked more closely at the fragmented clusters and measured the average non-aligner fraction of all swarming clusters which have . Figure 3(C) shows the final fraction of non-aligners averaged over all swarming sub-clusters as a function of the initial non-aligner fraction in the system, for three different values of *f*^{c} of ∼0.3, 0.52 and 0.75, which is set by changing the value of *d*_{v}/*d*_{r} according to Fig. 3(D). For low values of the initial non-aligner fraction, *f*, the final non-aligner fraction appears to follow linearly with a slope of unity, implying that little sorting or fracturing occurs for low non-aligner fractions. This is as expected, since for non-aligner fractions below the transition for a single crystallized swarm, at *f*^{c}, are within the “Sw” region of the phase diagram in Fig. 3(A,B), and no fracturing is necessary to relieve frustrations within the system.

Then, as the initial non-aligner fraction continues to increase and approach *f* ≈ *f*^{c}, we enter a region where the final non-aligner fraction seems to level off. In this regime, the value of *f* is high enough that, if the cohesiveness, , were very high (>1), the system would be in a frustrated state with no overall alignment and different agents trying to go in different directions but being held together. But since the cohesiveness is actually low, the frustration can be relieved by the cluster fragmenting into smaller pieces that can have a net alignment. The same logic holds for resulting smaller clusters that still have too high of a non-aligner fraction *f* - they will continue to fragment. If a resulting cluster has a non-aligner fraction less than ∼*f*^{c}, it is within the “Sw” region of the phase diagram in Fig. 3(A,B), so it can move collectively by reaching a consensus direction to relieve frustrations without fragmenting further. Thus the aligners have effectively self-organized into small clusters with an average non-aligner fraction close to the critical value *f*^{c}. This picture is confirmed by Fig. 3(C inset) which shows the fraction of the system which is contained in ordered moving clusters. For low initial non-aligner fractions, almost the entire cluster is mobile, while beyond the critical non-aligner fraction, the mobility fraction decays linearly as predicted by the simple picture where non-aligners in excess of the critical fraction *f*^{c} are simply left behind.

To examine how robust our results were, and, in particular, if they were sensitive to the initial system size, we fixed and non-aligner fraction at = 10^{−1.0}, and *f* = 0.8, and examined the final swarming clusters for a range of initial system sizes. We also measured the spread of non-aligner fractions within final clusters of different sizes, again for a few systems sizes. Figure 3(D) shows the average ± standard-deviation of the non-aligner fraction over the different final cluster sizes. We can see that both the average non-aligner fraction and its variance within the final clusters are fairly independent of initial system size.

One can now imagine a generic swarm where the fraction of non-aligners (or defective/diseased agents) increases over time. This could be due to the spreading of a disease among organisms or the breakdown/malfunctioning over time of individual robotic agents, or simply the tendency of entropy to increase. As time goes on, the system will reach a state where the fraction of non-aligners exceeds the critical fraction, *f*^{c}, thus entering the sorting regime, if the cohesive forces are in the right regime. Our results indicate that the system can then shed almost the entire excess non-aligner population (above the critical threshold) and revert to a fraction close to but just below *f*^{c}. Then as the system evolves again over time the non-aligner fraction increases past the threshold and the process begins again. Thus, dynamical sorting can compete against natural processes that drive increases in the non-aligner fraction and provide a mechanism for the system to reach a dynamic equilibrium, regulating its composition so that it sits at the edge of criticality in behavior; reminiscent of a self-organized critical system.

## Swarms with a distribution of alignment behaviors

So far, we have considered behavioral variability to be binary in character with agents being either aligning or non-aligning (*α* = 1, 0). It is, however, quite reasonable to expect that many naturally occurring swarms might display a spectrum of behaviors that corresponds to natural abilities differing from individual to individual. We showed before that the phase behavior of the swarm is controlled by the mean level of alignment as compared to cohesion. Here we consider what happens if, instead of changing the mean level of alignment accomplished by changing the fraction of non-aligners in a binary system, we keep the mean value fixed and change the spread in a system with continuous values of the alignment interaction strength *α*. To implement this, we selected *α* for each agent from a Gaussian distribution with mean, *μ*, and standard deviation, *σ*. We consider two types of systems, one with a high value of *μ* that would result in an ordered swarming system in the *σ* = 0 case and one with a low value of *μ* which would result in a static system with *σ* = 0. Keeping these two values of *μ* fixed, we vary the spread *σ*.

Figure 4(A) shows both the low *μ* (blue) and high *μ* (red) cases and we can see that as *σ* increases there exists a critical threshold, *σ*_{c}, beyond which the system will be likely to fracture (solid lines show probability of fracture), however the reason for fracture is different in both cases. The average order parameter (dashed line) for the high *μ* case starts out high and as *σ* increases and fracture begins to occur, the order decreases slightly because some individuals now have a low enough *α* that they behave like non-aligners and break off of the main body of swarmers to form static clusters. In the case where *μ* is low the system has very low order at low *σ* and as the spread of *α* values increases the system begins to fracture and the average order increases. In this case some agents are reaching high enough *α* values to form an ordered state and will create clusters of ordered moving agents which break off from or fragment the static main body of agents. Figure 4(B) shows a snapshot from the simulation that started off as one swarming cluster. Here *σ* is high enough to allow fracture resulting in the sorting out of a smaller, static cluster of agents with a predominantly low value of *α*. Thus the increase in the spread of *α* has similar consequences whether one starts with a high or low average *α*. There is a self-organized separation of the population leading to clusters of similar “phenotype” providing a mechanism for a natural limitation to the extent of variability in any swarming population.

## Evolving populations

We now examine the idea that dynamical sorting could be a mechanism for *evolving* swarms to robustly sustain a certain composition over longer timescales. For swarms, over sufficiently long timescales, one could imagine that the non-aligner population fraction increases due to some fitness advantage that the non-aligners derive by not participating in orientational information processing. For example, in ref. 18, an agent’s ability to decide on a preferred travel direction due to social interactions or migratory tendency is assumed to come at some cost due to energy expenditure or reduced predator awareness during directional information processing. In this case the non-aligners would be cheaters in the evolutionary sense which can lead to some interesting dynamics. To model the evolutionary dynamics we considered a model replicator system^{41} where agents replicate themselves at a rate that is determined by their fitness, with the fitter species (cheater or non-cheater) being able to reproduce more quickly and increasing its proportion in the population over time. The assigned fitness of an individual agent depends on whether an agent is a cheater and whether it is in a swarming cluster. We take the fitness of an agent *i* at any point in time to be given by,here, is the polarization of the cluster that agent *i* belongs to, represents the fitness advantage that agents gain by being in ordered clusters and *ϕ*_{c} is the fitness advantage gained by cheating agents (say by avoiding energy expenditures associated with orientational processing or signaling) and *σ*_{i} is equated to 0 for non-cheaters and 1 for cheaters. These fitness advantages are similar qualitatively to those postulated to study evolution in migratory populations where there were costs associated with obtaining directional cues from the environment and an overall fitness associated with migrating close to the desired direction^{18,42,43}. We start with a system of *N* = 500 agents with = 10^{−0.5} with periodic boundary conditions at different total cheater fractions. For each simulation, the system is allowed to evolve until a steady state is reached and the relative fitness of all cheaters, , given byis measured. Here is the time averaged fitness of all cheaters/non-cheaters given by Eq 4. As an example, Fig. 4(C) shows how the relative fitness of cheaters varies with cheater fraction for the ratio of fitness advantage constants . In our evolutionary dynamics, we take the relative fitness of all cheaters, , to be the expected fraction of cheaters in the subsequent generation. The red dashed line in Fig. 4(C) shows a typical evolutionary trajectory. Here, a population that starts with a cheater fraction *f* = 0.7 has which results in a cheater fraction *f* ∼ 0.39 in the subsequent generation which has and so on. A fixed point at which the initial cheater fraction is equal to that in the next generation is then given by the intersection between the curve and the diagonal (black dot in Fig. 4(C)). An evolutionarily stable fixed point is obtained when a fixed point is an attractor of all evolutionary trajectories, as is the case here. Figure 4(D) shows how the relative fitness of cheaters varies with cheater fraction for several different values of the ratio of fitness advantage constants Φ. We observe a unique stable fixed point for each value of Φ, that increases with Φ, suggesting that in any system where both cheating and swarming are advantageous, competing pressures can result in stable populations of cheaters that are dynamically regulated by self-organized sorting.

## Discussion

Within a group of swarming or flocking animals there may exist intrinsic behavioral heterogeneities that can effect the ability of the group to remain cohesive and move collectively. Behavioral differences can arise from natural individual variations, diseases or genetic mutations that occur randomly as the group of animals produces progeny. In artificial systems, such as robotic drones, differences can manifest as malfunctioning hardware or compromised software. In natural systems, therefore, it seems likely that there could exist collective mechanisms that allow the whole group to carry a subgroup of individuals that do not participate collective decision making (i.e non-aligners or cheaters).

We studied a system of swarming agents that display individual variations in their alignment strength. For the binary case of mixtures of aligners and non-aligners, we found that when the cohesion is strong, there is a critical fraction of cheaters *f** above which collective motion of the whole group can no longer be achieved. We call this critical non-aligner fraction, the maximum non-aligner carrying capacity. We showed that there is a simple predictive relation between the maximum non-aligner carrying capacity and the length and interaction strength scales that characterize the swarm. We showed that swarms can increase their non-aligner carrying capacity *f** either by increasing the separation between agents or by moving slower and/or processing information more quickly, These simple robust mechanisms could allow for a swarm or flock to adapt to increased non-aligner loads “on the fly” and our results also suggest optimal designs of parameters for “non-aligner tolerant” artificial swarms.

Alternatively, we found swarming could be enhanced in an unusual manner by lowering the cohesive attraction between agents. We showed that, as cohesion is lowered, there exists a regime where the clusters can actively sort out and leave behind the excess non-aligning population. We find that the newly sorted clusters that emerge after segregating are capable of swarming and carry a fraction of non-aligners that is near a fixed critical non-aligner carrying capacity that we are able to predict. Thus the dynamics of the swarm naturally weeds out non-aligners above the critical capacity and maintains the non-aligner fraction in the swarm close to this value, reminiscent of a self-organized critical behavior. This result highlights a simple, robust and efficient mechanism that allows heterogeneously mixed populations to naturally regulate their composition and remain in a collective swarming state despite the natural tendency for cheating/diseased/defective population fractions to increase.

Lowering the value of cohesiveness too much can also lead to deleterious effects with the swarming clusters unable to hold themselves together. This suggests that, if such a sorting and segregation mechanism is utilized in nature, the relative magnitudes of cohesiveness and orientational alignment need to be tuned to lie within an optimal range. It is also interesting to note that though we considered cheaters or defective agents as having a negative effect on swarming, one could also consider situations where a swarm needed to break up or segregate between two populations. Our results indicate that a simple mechanism to achieve this would be for one group to simply become “non-aligners” and allow the swarm dynamics to automatically segregate and expel them from the swarm.

It is to be noted that we were able to map out the entire phase space of behaviors in these heterogeneous systems including swarming, static and sorting phases and relate them to simple relations between the swarm parameters. Furthermore, these swarm parameters can be directly observed or inferred from measurements of real swarms (see Supplementary Information 4). Thus our results provide us with predictive power about real swarms including their maximum non-aligner carrying capacity, their ability to sort and the critical non-aligner fraction that sorting leads to. It is also intriguing in this context that if there is a natural tendency for non-aligners to increase, we would expect to measure, in a real swarm, a composition of non-aligners close to a critical fraction that we can predict based on the estimated swarm parameters.

We were also able to show that our notions of sorting extend to swarms with a continuous distribution of individual alignment preferences. In fact, the existence of outliers, whether they were non-aligners or “super-aligners” or both triggered the sorting process. This is suggestive of a natural means of separating different types of behavior which could have implications not only for limiting variability in populations but also more generally for the division of labor in collectively moving systems.

Finally, we pursued the idea of competing cheating and sorting by considering the evolutionary dynamics of a replicator system, where there was a fitness advantage associated with being in a collectively moving swarm and an advantage for being a cheater. We showed that the system has a globally stable evolutionary fixed point corresponding to a particular fraction of cheaters that is set by relative fitness advantage of cheating and the swarm parameters. It is interesting to note that evolutionary equilibria between successful strategies can thus be tuned by changing the physical parameters of the swarm. Our work therefore makes connections to studies of evolutionary dynamics in structured populations and networks^{44,45,46} and specifically to work that shows that both network structure^{47} and its dynamics^{48} can influence the success of cheating or defection. In the broadest sense, our results suggests the idea that the spread of a non-aligner/defector/cheater strategy within a population beyond a critical threshold can spontaneously trigger large-scale re-organization of the collective that expels outliers and effectively limits the spread of behavioral variability.

## Methods

The alignment interaction is implemented by the agent choosing an updated direction of travel that, in the absence of cohesive interactions or noise, is the sum of the direction vectors of all its nearby neighbors, which is proportional to the mean consensus direction. In our model, at each reaction time step (*δt*), agents compute the summed direction (equation (6)) of all their neighbors (nbr) within a specified “vision” distance, *d*_{v}. *δt* is the physical reaction time of agents within the system, rather than the timestep of the simulation (Δ*t*).

The cohesive interaction is modeled as arising from a Lennard-Jones (LJ) interaction (equation (7)) between nearest neighbor agents which is attractive at large distances and repulsive at close range. To calculate the LJ interaction, is a unit vector pointing between the *i*^{th} and *j*^{th} agents and *s* is the separation between them.

The LJ interaction is calculated as a unitless LJ direction vector, . For a standard LJ potential well with depth the corresponding LJ force would be . The agents calculate the alignment direction vector as well as the LJ direction vector dictated by the cohesive LJ interactions with all their neighbors (equation (7)) at each timestep. For our simulations the equilibrium separation between agents (*R* in equation (7)) is set to a distance, relative to the vision distance *d*_{v}, such that each agent will see, on average, only their first nearest neighbors. A new direction of travel for the agent in the next time step is determined by the vector formed by adding with , where the dimensionless parameters *α* and measure the importance of alignment and cohesiveness respectively (equation (1)).

New positions are then calculated for each agent according to equation (8), where *d*_{r} is the reaction distance, or how far an agent moves in each timestep.

To mimic the response of real swarming individuals, we need to account for errors, either in processing local orientation information or in the execution of movement. Errors are modeled as noise that is added to the calculation of the updated direction by adding a randomly selected angle into the calculated direction, , where is a randomly selected angle from a uniform distribution in the interval [−*η*/2, +*η*/2]. In our model we set *η* = 0.2, *d*_{v} = 1, *R* = 0.7887, Δ*t* = *δt* = 1, and *α* = 1.

Swarms are generated by randomly seeding *N* agents in a circle with radius equal to the vision radius of agents, *d*_{v} and then allowing the swarm to set its own size by following the dynamics dictated by equation (1) and equation (8). The system has infinite boundaries and varying the initial density, and simulation time step have little effect on the resulting transitions (see Supplementary Information 1.4).

## Additional Information

**How to cite this article**: Copenhagen, K. *et al*. Self-organized sorting limits behavioral variability in swarms. *Sci. Rep.* **6**, 31808; doi: 10.1038/srep31808 (2016).

## References

- 1.
Vicsek, T. & Zafeiris, A. Collective motion.

*Physics Reports***517**, 71–140 (2012). - 2.
Couzin, I. D. & Krause, J. Self-organization and collective behavior in vertebrates.

*Advances in the study of behavior***32**, 1–75 (2003). - 3.
Schaller, V., Weber, C., Semmrich, C., Frey, E. & Bausch, A. R. Polar patterns of driven filaments.

*Nature letters***467**, 73–77 (2010). - 4.
Sanchez, T., Chen, D. T. N., Decamp, S. J., Heymann, M. & Dogic, Z. Spontaneous motion in hierarchically assembled active matter.

*Nature***491**, 431–434 (2012). - 5.
Shapiro, J. A. Thinking about bacterial populations as multicellular organisms.

*Annual Review Mocrobiology***52**, 81–104 (1998). - 6.
Palacci, J., Sacanna, S., Steinberg, A. P., Pine, D. J. & Chaikin, P. M. Living crystals of light-activated colloidal surfers.

*Science***339**, 936–940 (2013). - 7.
Couzin, I. D.

*et al.*Uninformed individuals promote democratic consensus in animal groups.*Science***334**, 1578–1580 (2011). - 8.
Bialek, W.

*et al.*Social interactions dominate speed control in poising natural flocks near criticality.*Proceedings of the National Academy of Sciences of the United States of America***111**, 7212–7217 (2014). - 9.
Turgut, A. E., Çelikkanat, H. & Gökçe, F. Self-organized flocking in mobile robot swarms.

*Swarm Intell***2**, 97–120 (2008). - 10.
Rubenstein, M., Cornejo, A. & Nagpal, R. Programmable self-assembly in a thousand-robot swarm.

*Science***345**, 795–799 (2015). - 11.
Chepizhko, O., Altmann, E. G. & Peruani, F. Optimal noise maximizes collective motion in heterogeneous media.

*Physical Review Letters***110**, 1–5 (2013). - 12.
Quint, D. A. & Gopinathan, A. Topologically induced swarming phase transition on a 2D percolated lattice.

*Physical Biology***12**, 1–6 (2015). - 13.
Shklarsh, A., Ariel, G., Schneidman, E. & Ben-Jacob, E. Smart swarms of bacteria-inspired agents with performance adaptable interactions.

*PLoS computational biology***7**, 9 (2011). - 14.
McCandlish, S. R., Baskaran, A. & Hagan, M. F. Spontaneous segregation of self-propelled particles with different motilities.

*arXiv*110.2479v2 (2012). - 15.
Barré, J., Chétrite, R., Muratori, M. & Peruani, F. Motility-induced phase separation of active particles in the presence of velocity alignment.

*Journal of Statistical Physics***158**, 589–600 (2014). - 16.
Ariel, G., Rimer, O. & Ben-Jacob, E. Order-disorder phase transition in heterogeneous populations of self-propelled particles.

*Journal of Statistical Physics***158**, 579–588 (2014). - 17.
Baglietto, G., Albano, E. V. & Candia, J. Gregarious vs individualistic behavior in Vicsek swarms and the onset of first-order phase transitions.

*Physica A: Statistical Mechanics and its Applications***392**, 3240–3247 (2013). - 18.
Guttal, V. & Couzin, I. D. Social interactions, information use, and the evolution of collective migration.

*Proceedings of the National Academy of Sciences of the United States of America***107**, 16172–16177 (2010). - 19.
Gelblum, A., Pinkoviezky, I., Fonio, E., Ghosh, A., Gov, N. & Feinerman, O. Ant groups optimally amplify the effect of transiently informed individuals.

*Nature communications***6**, 1–9 (2015). - 20.
Sandoz, K. M., Mitzimberg, S. M. & Schuster, M. Social cheating in Pseudomonas aeruginosa quorum sensing.

*Proceedings of the National Academy of Sciences of the United States of America***104**, 15876–15881 (2007). - 21.
Rumbaugh, K. P., Diggle, S. P., Watters, C. M., Ross-Gillespie, A., Griffin, A. S. & West, S. A. Quorum sensing and the social evolution of bacterial virulence.

*Current Biology***19**, 341–345 (2009). - 22.
Czárán, T. & Hoekstra, R. F. Microbial communication, cooperation and cheating: quorum sensing drives the evolution of cooperation in bacteria.

*Plos one***4**, e6655 (2009). - 23.
Venturi, V., Bertani, I., Kerényi, A., Netotea, S. & Pongor, S. Co-swarming and local collapse: quorum sensing conveys resilience to bacterial communities by localizing cheater mutants in Pseudomonas aeruginosa.

*PloS one*,**5**, e9998 (2010). - 24.
Xavier, J., Kim, W. & Foster, K. A molecular mechanism that stabilizes cooperative secretions in Pseudomonas aeruginosa.

*Molecular Microbiology***79**, 166–179 (2011). - 25.
Shi, W.

*et al.*Unveiling the mechanism by which microsporidian parasites prevent locust swarm behavior.*Proceedings of the National Academy of Sciences***111**, 1343–1348 (2014). - 26.
Santos, V., Campos, M. & Chaimowicz, L. On segregative behaviors using flocking and velocity obstacles.

*Distributed Autonomous Robotic Systems***104**, 121–133 (2014). - 27.
Momen, S., Amavasai, B. P. & Siddique, N. H. Mixed species flocking for heterogeneous robotic swarms.

*EUROCON 2007 - The International Conference on Computer as a Tool***34**, 2329-2336 (2007). - 28.
Hayes, A. T. & Dormiani-Tabatabaei, P. Self-organized flocking with agent failure: Off-line optimization and demonstration with real robots.

*Proceedings 2002 IEEE International Conference on Robotics and Automation*(*Cat. No.02CH37292*)**4**, 1–7 (2002). - 29.
Stranieri, A.

*et al.*Self-organized flocking with a heterogeneous mobile robot swarm.*Adaptive Behavior***20**, 460–477 (2012). - 30.
Vicsek, T., Czirók, A., Ben-Jacob, E., Cohen, I. & Shochet, O. Novel type of phase transition in a system of self-driven particles.

*Physical Review Letters***75**, 4–7 (1995). - 31.
Huepe, C. & Aldana, M. New tools for characterizing swarming systems: A comparison of minimal models.

*Physica A: Statistical Mechanics and its Applications***387**, 2809–2822 (2008). - 32.
Lobaskin, V. & Romenskyy, M. Collective dynamics in systems of active Brownian particles with dissipative interactions.

*Physical Review E***87**, 052135 (2013). - 33.
Gazi, V. & Passino, K. M. A class of attractions/repulsion functions for stable swarm aggregations.

*International Journal of Control***77**, 1567–1579 (2004). - 34.
Chuang, Y. L., Huang, Y. R., D’Orsogna, M. R. & Bertozzi, A. L. Multi-vehicle flocking: Scalability of cooperative control algorithms using pairwise potentials.

*Proceedings - IEEE International Conference on Robotics and Automation*DOI: 10.1109/ROBOT.2007.363661, 2292-2299 (2007). - 35.
Toner, J., Tu, Y. & Ramaswamy, S. Hydrodynamics and phases of flocks.

*Annals of Physics***318**, 170–244 (2005). - 36.
Marchetti, M. C.

*et al.*Hydrodynamics of soft active matter.*Reviews of Modern Physics***85**, 1143–1189 (2013). - 37.
Guillaume, G. & Chaté, H. Onset of collective and cohesive motion.

*Physical Review Letters***92**, 025702 (2004). - 38.
Kelley, D. H. & Ouellette, N. T. Emergent dynamics of laboratory insect swarms.

*Scientific reports***3**, 073 (2013). - 39.
D’Orsogna, M., Chuang, Y., Bertozzi, A. & Chayes, L. Self-propelled particles with soft-core interactions: patterns, stability, and collapse.

*Physical Review Letters***96**, 104302 (2006). - 40.
Herbert-Read, J. E.

*et al.*Inferring the rules of interaction of shoaling fish.*Proceedings of the National Academy of Sciences***108**, 18726–18731 (2011). - 41.
Nowak, M. Evolutionary dynamics: exploring the equations of life.

*Belknap Press*(2006). - 42.
Torney, C. J., Levin, S. A. & Couzin, I. D. Specialization and evolutionary branching within migratory populations.

*Proceedings of the National Academy of Sciences of the United States of America***107**, 20394–20399 (2010). - 43.
Pais, D. & Leonard, N. E. Adaptive network dynamics and evolution of leadership in collective migration.

*Physica D: Nonlinear Phenomena***267**, 81–93 (2014). - 44.
Szabó, G. & Fáth, G. Evolutionary games on graphs.

*Physics Reports***446**, 97–216 (2007). - 45.
Lieberman, E., Hauert, C. & Nowak M. A. Evolutionary dynamics on graphs.

*Nature***433**, 312–316 (2005). - 46.
Skyrms, B. & Pemantle, R. A dynamic model of social network formation.

*Proceedings of the National Academy of Sciences***97**, 9340–9346 (2000). - 47.
Ohtsuki, H., Hauert, C., Lieberman, E. & Nowak, M. A. A simple rule for the evolution of cooperation on graphs and social networks.

*Nature***433**, 312–316 (2006). - 48.
Rand, D. G., Arbesman, S. & Christakis, N. A. Dynamic social networks promote cooperation in experiments with humans.

*Proceedings of the National Academy of Sciences***108**, 19193–19198 (2011).

## Acknowledgements

We would like to thank K.C. Huang, Paul Goldbart and Jennifer Schwarz, for enlightening discussions. This work was partially supported by National Science Foundation grant EF-1038697 and a James S McDonnell Foundation Award. AG also acknowledges support from NSF grant DMS-1616926 and the NSF-CREST: Center for Cellular and Biomolecular Machines at UC Merced (NSF-HRD-1547848).

## Author information

## Affiliations

### University of California Merced, Merced CA, USA

- Katherine Copenhagen
- & Ajay Gopinathan

### Stanford University, Stanford CA, USA

- David A. Quint

### Carnegie Institute of Washington, Stanford CA, USA

- David A. Quint

## Authors

### Search for Katherine Copenhagen in:

### Search for David A. Quint in:

### Search for Ajay Gopinathan in:

## Contributions

A.G., D.A.Q. and K.C. designed the research, K.C. performed simulations, A.G. and K.C. analyzed the results and wrote the manuscript, all authors edited and reviewed the manuscript.

## Competing interests

The authors declare no competing financial interests.

## Corresponding author

Correspondence to Ajay Gopinathan.

## Supplementary information

## PDF files

## Comments

By submitting a comment you agree to abide by our Terms and Community Guidelines. If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

This work is licensed under a Creative Commons Attribution 4.0 International License. The images or other third party material in this article are included in the article’s Creative Commons license, unless indicated otherwise in the credit line; if the material is not included under the Creative Commons license, users will need to obtain permission from the license holder to reproduce the material. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/