## Figures

## Abstract

From the microscopic to the macroscopic level, biological life exhibits directed migration in response to environmental conditions. Chemotaxis enables microbes to sense and move towards nutrient-rich regions or to avoid toxic ones. Socio-economic factors drive human populations from rural to urban areas. The effect of collective movement is especially significant when triggered in response to the generation of public goods. Microbial communities can, for instance, alter their environment through the secretion of extracellular substances. Some substances provide antibiotic-resistance, others provide access to nutrients or promote motility. However, in all cases the maintenance of public goods requires costly cooperation and is consequently susceptible to exploitation. The threat of exploitation becomes even more acute with motile individuals because defectors can avoid the consequences of their cheating. Here, we propose a model to investigate the effects of targeted migration and analyze the interplay between social conflicts and migration in ecological public goods. In particular, individuals can locate attractive regions by moving towards higher cooperator densities or avoid unattractive regions by moving away from defectors. Both migration patterns not only shape an individual’s immediate environment but also affects the entire population. For example, defectors hunting cooperators have a homogenizing effect on population densities. This limits the production of the public good and hence inhibits the growth of the population. In contrast, aggregating cooperators promote the spontaneous formation of patterns through heterogeneous density distributions. The positive feedback between cooperator aggregation and public goods production, however, poses analytical and numerical challenges due to its tendency to develop discontinuous distributions. Thus, different modes of directed migration bear the potential to enhance or inhibit the emergence of complex and sometimes dynamic spatial arrangements. Interestingly, whenever patterns emerge, cooperation is promoted, on average, population densities rise, and the risk of extinction is reduced.

## Author summary

The production and maintenance of shared environmental resources such as access to nutrients in microbial communities or potable water in human societies require the cooperation of groups of individuals. However, cooperation is costly and prone to exploitation. If too many individuals follow selfish interests and spoil their environment, the group and possibly the entire population suffers. Nevertheless, many forms of biological life—from humans to microbes—migrate in response to resource availability. Here, we analyze the interplay of the social conflict in public goods production and targeted migration. In particular, we find that aggregation of cooperators can enhance or trigger the spontaneous formation of heterogeneous spatial distributions, which promote cooperation and result in higher population densities. Conversely, attempts to avoid defectors increases the risk of extinction because it tends to homogenize population distributions and lower population densities.

**Citation: **Funk F, Hauert C (2019) Directed migration shapes cooperation in spatial ecological public goods games. PLoS Comput Biol 15(8):
e1006948.
https://doi.org/10.1371/journal.pcbi.1006948

**Editor: **Antonio Celani,
Abdus Salam International Centre for Theoretical Physics, ITALY

**Received: **March 8, 2019; **Accepted: **June 28, 2019; **Published: ** August 8, 2019

**Copyright: ** © 2019 Funk, Hauert. This is an open access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.

**Data Availability: **All data was generated using the Matlab code provided in https://github.com/FFunk/Directed_Migration_in_SEPGG.

**Funding: **C.H. received the “Natural Sciences and Engineering Research Council of Canada” grant RGPIN-2015-05795; www.nserc-crsng.gc.ca. The funders had no role in study design, data collection and analysis, decision to public, or preparation of the manuscript.

**Competing interests: ** The authors have declared that no competing interests exist.

## Introduction

Directed migration is a phenomenon commonly observed in nature. Microbial populations such as *Escherichia coli* actively seek areas with higher concentrations of substances, such as amino-acids, through chemotaxis [1] and avoid toxic regions [2]. Birds sense seasonal changes and migrate to more hospitable climes [3]. Socio-economic factors attract people from rural communities to cities [4]. In all cases, individuals migrate to improve their access to resources.

Environmental factors influence the abundance of resources, but some resources such as public goods are produced and maintained by the population itself and require cooperation. Prominent examples are drinking water, clean air or the climate on a global scale [5] as well as the production of extracellular substances to access food [6] or to grant resistance to antibiotics [7, 8] on a microscopic scale. However, cooperation is costly and threatened by non-cooperating defectors who exploit public goods without contributing themselves [9]. Hence, the public resources dwindle whenever defection becomes common.

Ecological public goods introduce ecological dynamics into evolutionary games through variable population densities based on the production of the public good [10]. This feedback between population densities and interaction group sizes enables cooperators and defectors to coexist. In particular, this includes the intriguing case in which public goods production is crucial for the survival of the population [11] and represents our baseline scenario here.

In a spatial context, undirected movement introduces rich dynamics including the spontaneous emergence of heterogeneous density distributions resulting in pattern formation and chaotic spatio-temporal dynamics [12]. Pattern formation is driven by Turing instabilities [13], which have also been reported for purely ecological models such as predator-prey or chemotaxis models [14, 15]. Whenever patterns form, populations thrive through increased cooperation, raised population density, and reduced risk of extinction. However, spatio-temporal chaos and pattern formation also causes spatial heterogeneity in the public good, which naturally leaves some locations more attractive than others.

Through directed migration, cooperators and defectors can access the public good by actively seeking cooperators or reduce exploitation by avoiding defectors. Here, we extend the spatial ecological public goods game [12] by incorporating targeted migration in the “selection-diffusion” system, and analyze how directed migration shapes cooperation, and pattern formation, in particular. Based on the stability analysis of the dynamical equations and supported by numerical integration, we derive detailed criteria for pattern formation for the different modes of migration.

Directed migration can trigger, enhance or inhibit the spontaneous emergence of steady, quasi-steady or dynamic heterogeneous density distributions. Somewhat surprisingly, cooperators fleeing from defectors homogenize the density distribution, and endanger the population whenever cooperators spread themselves too thin. In contrast, if defectors avoid each other, cooperators can accumulate and patterns emerge. This allows cooperation to thrive under conditions, in which neither a well-mixed nor a diffusing population would survive. As expected, aggregating cooperators also facilitate pattern formation through positive feedback between cooperator densities and cooperator migration: cooperator aggregation gives rise to steeper gradients of the public good and thus creates even stronger incentives to migrate in towards those locations. However, the positive feedback comes with analytical and numerical challenges due to the potential to give rise to discontinuous distributions. Through the promotion or inhibition of spatial heterogeneity, directed migration is a critical determinant for cooperation, the survival of the population, and conducive to promoting and maintaining diversity of ecosystems.

### Ecological public goods

In traditional public goods games *N* individuals gather in a group and each individual chooses to cooperate and invest into a common pool at a cost *c*, or to defect and shirk the investment. The common pool is multiplied by a factor *r* > 1 and equally divided among all individuals within the group. This results in a payoff of *P*_{D} = *n*_{C} ⋅ *rc*/*N* for defectors and *P*_{C} = *P*_{D} − (1 − *r*/*N*)*c* for cooperators when facing *n*_{C} cooperators among the *N* − 1 other group members. For *r* < *N* every participant is tempted to withhold their investment because *P*_{C} < *P*_{D} and hence to forego the benefits of the public good to the detriment of all. Had everyone cooperated the payoff would be (*r* − 1)*c* > 0. This conflict of interest between the group and the individual constitutes the social dilemma at the heart of public goods interactions [16–18]. Only for *r* > *N* these interests align.

In well-mixed populations with normalized densities (frequencies) of cooperators, *u*, and defectors, *v* = 1 − *u*, both strategies encounter, on average, *n*_{C} = *u*(*N* − 1) cooperators among their interaction partners in randomly assembled interaction groups. In evolutionary game theory payoffs represent fitness and hence determine the rate of change of the population composition as captured by the replicator dynamics ∂_{t}*u* = *u*(1 − *u*)(*P*_{C} − *P*_{D}), where ∂_{t} denotes the time derivative [19]. Consequently, cooperation dwindles, ∂_{t}*u* < 0, whenever cooperators obtain lower payoffs in the public goods game than defectors, i.e. if *P*_{C} − *P*_{D} = −*c*(1 − *r*/*N*) < 0. Indeed, for *r* < *N* defection dominates and ∂_{t}*u* < 0 always holds. Conversely, for *r* > *N* cooperation spreads in the population, ∂_{t}*u* > 0.

The replicator equation does not take ecological quantities such as variable population densities into account. The interplay between ecological and evolutionary dynamics is captured by
(1a)
(1b)
where *w* = 1 − *u* − *v* reflects reproductive opportunities that diminish for increasing population densities [11]. Selection is based on ecological public goods interactions affecting the birth rates of cooperators and defectors through their average payoffs *f*_{C} and *f*_{D}, respectively, while the death rate is constant, *d* (see S1 Appendix for further details on dynamics).

Even in the absence of spatial dimensions, rich dynamics are observed especially under environmental stress where the death rate exceeds the baseline birth rate, *d* > *b* [10]. We focus on this case because the survival of the population hinges on the availability of the public good. Varying population densities introduce an interior equilibrium *Q*, which undergoes a Hopf-bifurcation [20] when increasing the rate of return of the public good, *r*, giving rise to stable and unstable limit cycles [11]. For *r* < *r*_{Hopf}, *Q* is unstable, and well-mixed populations are doomed. However, for *r* > *r*_{Hopf}, the equilibrium *Q* allows cooperators and defectors to coexist but the basin of attraction of the equilibrium *Q* remains limited. More specifically, if cooperators are too rare for the public goods production to offset the death rate *d*, or if defectors abound, the population may still go extinct.

Our baseline scenario can be interpreted as a microbial population in a biocide where the multiplication factor *r* reflects the effectivity of the public good to oppose the detrimental effect of the toxic environment. The following extensions explore the effects of different modes of motility on the public goods production and survival of the population.

## Materials and methods

### Spatial ecological public goods

The spatial dynamics of ecological public good interactions with undirected (diffusive) migration can be formulated as a selection-diffusion process
(2a)
(2b)
where the diffusion constants *D*_{C} and *D*_{D} reflect the migration of cooperators and defectors, respectively [12]. In spatial settings, undirected migration promotes coexistence of cooperators and defectors even if the coexistence equilibrium *Q* is unstable. In particular, if defectors run faster than cooperators, *D*_{D} > *D*_{C}, the dynamics exhibit Turing instabilities, where cooperators serve as activators and defectors as inhibitors. This enables the population to survive through spontaneous pattern formation. Close to the Hopf-bifurcation with *r* < *r*_{Hopf} (*Q* unstable), the influence of temporal oscillations gives rise to chaotic spatio-temporal dynamics [21], which facilitate population survival even for equal diffusion rates, *D*_{D} = *D*_{C}. Conversely, for slower diffusion of defectors, *D*_{D} < *D*_{C}, activation through cooperation is no longer tenable, spatial effects disappear and either results in homogeneous coexistence for *r* > *r*_{Hopf} (*Q* stable) or extinction for *r* < *r*_{Hopf}. This implies that attempts of cooperators at outrunning defectors are futile.

Here, we extend the spatial ecological public goods model, Eq (2), by introducing *directed* migration, which enables cooperators and defectors to bias their movement towards more attractive regions.
(3a)
(3b)
with *A*_{C}, *A*_{D}, *R*_{C}, *R*_{D} ≥ 0 and where terms of the form −*K*∇⋅(*ϕw*∇*ψ*) reflect that individuals of type *ϕ* are attracted to the gradient of type *ψ* proportional to reproductive opportunities, *w*, at a non-negative rate *K* (for a detailed microscopic derivation see S2 Appendix). The density of cooperators directly translates into the rate of production of public goods and hence serves as a proxy for its availability and the quality of the environment. For example, the term −*A*_{D}∇ ⋅ (*vw*∇*u*) reflects *hunting defectors* in search of public goods that are attracted to higher densities of cooperators at a rate *A*_{D}. Note that the negative sign indicates movement toward higher densities. Similarly, −*A*_{C}∇ ⋅ (*uw*∇*u*) represents *aggregating cooperators* that are attracted to their kind. In contrast, the density of defectors serves as a proxy to avoid exploitation and reduce competition. Instead of directly sensing the density of defectors their excretions from public goods consumption could reflect the poor quality of the environment. Thus, *R*_{C}∇⋅(*uw*∇*v*) reflects *fleeing cooperators* that avoid higher densities of defectors at a rate *R*_{C}, whereas *R*_{D}∇ ⋅ (*vw*∇*v*) refers to *spreading defectors* that steer clear of their kind.

Rich dynamics unfold under directed migration as showcased in Fig 1, ranging from the spontaneous formation of quasi-stable or stable patterns (Fig 1A) and ever-changing, chaotic spatio-temporal dynamics (Fig 1B) to cooperators aggregating under a self-reinforcing migration response (positive feedback, Fig 1C).

Snapshots of the density distribution of cooperators (green) and defectors (red) across the periodic *L* × *L* domain at time *t* = 0, 50, 100, 200, 1000, 2000. The color brightness indicates the density with coexistence (yellow) and vacant space (black). (A) Spreading defectors spontaneously form and settle in quasi-steady patterns (*R _{D}* = 8). (B) Chaotic spatio-temporal dynamics unfold for hunting defectors (

*A*= 4). (C) Aggregating cooperators induce positive feedback: as more cooperator leave scarcely populated areas in favor of highly cooperative locations, the divide between neighbouring areas grows and discontinuities can develop at the interfaces. (

_{D}*A*= 1)

_{C}*Parameters*: public goods interaction:

*b*= 1,

*r*= 2.325,

*d*= 1.2,

*N*= 8,

*c*= 1; diffusion:

*D*=

_{C}*D*= 0.1; directed movement:

_{D}*A*=

_{C}*A*=

_{D}*R*=

_{C}*R*= 0, unless otherwise indicated; numerical discretization in space and time:

_{D}*L*= 75,

*dx*= 0.375,

*dt*= 0.01; noisy Gaussian initial condition:

*u*(

*x*,

*y*) =

*v*(

*x*,

*y*) = 1/5 ⋅ exp[−((

*x*−

*L*/2)

^{2}+ (

*y*−

*L*/2)

^{2})/16

^{2}].

## Results

An overview of the long-term effects of the four types of directed migration on spatial ecological public goods interactions is summarized in Fig 2. Each type has distinct effects on pattern formation and population survival. For *r* < *r*_{Hopf}, aggregating cooperators, *A*_{C}, (see Fig 2A) and spreading defectors, *R*_{D}, (see Fig 2D) increase the chances of survival by promoting spontaneous formation of heterogeneous density distributions. For aggregating cooperators, this process is facilitated by a slower rate of expansion. In particular, aggregating cooperators directly oppose the effects of cooperator diffusion *D*_{C} and can even bring population expansion to a halt (see panel A in S2 Fig). In fact, sufficiently high *A*_{C} triggers a positive feedback between cooperator densities (or public goods production) and aggregation, which pose analytical and numerical challenges discussed below. In contrast, hunting defectors, *A*_{D}, increase competition in areas where cooperators aggregate (see Fig 2C) and fleeing cooperators, *R*_{C}, explore space to avoid exploitation (see Fig 2B). In both cases cooperator densities and hence the concentration of the public good are evened out. This suppresses pattern formation and renders the population more prone to extinction through global temporal fluctuations. For *r* > *r*_{Hopf}, coexistence of cooperators and defectors in well-mixed populations is stable and the spatial patterns tend to fade away. The only exception is the aggregation of cooperators, which may prevent expansion and hence colonization of empty territory.

Each of the four panels (A)-(D) shows snapshots of the spatial distributions at time *t* = 2000 as a function of the multiplication factor *r* when varying one of the four modes of migration. The bottom row shows the dynamics of purely diffusive migration in the proximity of *r*_{Hopf} ≈ 2.365 as a reference. (A) Aggregating cooperators oppose the effects of diffusion and hence slow down the population expansion. The positive feedback between cooperator densities and aggregation can cause discontinuous distributions and discretization-dependent numerical results. (B) Hunting defectors increase competition in areas where cooperators concentrate. This allows cooperators to escape into unpopulated terrain but also increases the risk of extinction. (C) Fleeing cooperators avoid defectors and hence readily explore vacant space but with the defectors at their tails also tend to spread themselves too thin and risk extinction. (D) Spreading defectors reduce exploitation on cooperator aggregates and consequently promote pattern formation as well as population survival. *Parameters* as in Fig 1 unless otherwise indicated.

### Emerging patterns

Public goods production and population survival are both crucially linked to the spontaneous emergence of spatial patterns. Here we derive necessary conditions for the onset of pattern formation. An analytical understanding of the pattern formation process is obtained by considering homogeneous population densities reflecting the coexistence equilibrium *Q* of the well-mixed population dynamics, Eq (1). A small perturbation vector *ϵ*(exp(*ik*(*x* + *y*)), exp(*il*(*x* + *y*))) of mode *k* (for cooperators) and *l* (for defectors) may get exponentially amplified by the dynamics and give rise to the emergence of heterogeneous density distributions, also called Turing patterns [13]. The temporal mode is reflected by *k* = *l* = 0 whereas *k*, *l* > 0 refers to spatial modes. Because defector survival depends on the public goods production by cooperators, the stationary spatial density patterns of the two types are highly correlated resulting in similar periodicity of the two types (see Fig 2). For this reason, we restrict the perturbation analysis to *k* = *l* (for more information, see S3 Appendix). The linearized dynamics in the vicinity of *Q* = (*u*_{eq}, *v*_{eq}, *w*_{eq}) is given by
(4)
where and *J*_{I}, *J*_{S} represent the Jacobians from public goods interactions and spatial migration (directed and undirected), respectively:
(5a)
(5b)
The largest eigenvalue (real part) of *J*_{I} + *k*^{2}*J*_{S} is a function of *k* and is called the dispersion relation λ(*k*) (see S3 Appendix). Modes with λ(*k*) > 0 are unstable indicating the potential for spatial patterns to emerge. If the spatial Jacobian *J*_{S} admits eigenvalues with positive real parts then λ(*k*) > 0 holds for all sufficiently large *k*, i.e. all spatial perturbations of sufficiently high frequency are unstable. This is not meaningful in natural systems. In order to ensure λ(*k*) < 0 for *k* → ∞, the condition det(*J*_{S}) > 0 or, more precisely, *D*_{C} > *A*_{C}*u*_{eq}*w*_{eq} is required, which means that at the homogeneous equilibrium, the effects of diffusion (undirected migration) need to outweigh effects of cooperator aggregation.

In spite of the above restrictions, intermediate modes can nevertheless become unstable through a combination of selection and migration. A necessary condition for pattern formation is
(6)
see S3 Appendix for details. Consequently, faster aggregating cooperators or spreading defectors (increased *A*_{C}, *R*_{D}) or slower undirected cooperator migration (decreased *D*_{C}) promote the development of heterogeneous patterns by actively or passively promoting cooperator aggregation. In contrast, faster directed migration of defectors towards cooperation or of cooperators away from defection (increased *A*_{D}, *R*_{C}) as well as slower undirected defector migration (decreased *D*_{D}) all increase exploitation of the public good, reduce the efficacy of cooperator aggregation and hence suppress pattern formation. Fig 3 depicts the competing effects of activating and inhibiting forms of directed migration. The most unstable mode determines the characteristic length scale of the emerging spatial patterns (see S3 Appendix).

(A), (C) Cooperator aggregation results in smooth patterns for small *A*_{C}, which are suppressed by increasing *A*_{D}, *R*_{C}. However, for larger *A*_{C} the positive feedback between aggregation and densities of cooperators dominates. This eliminates defectors and gives rise to discontinuous distributions. Consequently, directed migration triggered by defector densities through *A*_{D} or *R*_{C} no longer matters. (B), (D) Spreading defectors, *R*_{D}, also promote pattern formation but maintain smooth patterns, while increases in *A*_{D}, *R*_{C} again suppress them. *Parameters*: Multiplication factor *r* = 2.4, *D*_{D} = 0.5 > *D*_{C} = 0.1 to observe smooth patterns for *A*_{C}; snapshots taken at *t* = 2000; Gaussian initial configuration without noise. Other parameters as in Fig 1.

Hunting defectors, *A*_{D}, and fleeing cooperators, *R*_{C}, exhibit similar homogenizing effects. In contrast, significant qualitative differences arise in the promotion of pattern formation due to aggregating cooperators, *A*_{C}, and spreading defectors, *R*_{D}, in the sense that aggregating cooperators have the potential to fully suppress defection. In this case neither increases in *A*_{D} nor in *R*_{C} are capable of counteracting the positive feedback induced by *A*_{C} to recover coexistence.

### Aggregating cooperators

The positive feedback between cooperator densities and cooperator migration is intrinsic to aggregating cooperators. Regions of higher cooperator densities attract cooperators, which further increases their densities and, more importantly, the gradient along the periphery. As a result the region exerts an even stronger attraction. In fact, for sufficiently large *A*_{C} the attraction prevents cooperators from exploring the available space thus the population remains localized. The potential of aggregating cooperators to give rise to discontinuous distributions through positive feedback lies at the core of the necessary condition that diffusion must outweigh aggregation at the homogeneous equilibrium: *D*_{C} > *A*_{C}*u*_{eq}*w*_{eq}. However, this condition is conservative and no longer sufficient for heterogeneous distributions. The gradient in cooperator densities, ∇*u*, promotes further aggregation of cooperators despite being limited by reproductive opportunities, *w*, see Eq (3). As a consequence the gradient further increases and discontinuities in the density distribution can develop. Interestingly, this effect turns out to be strong enough to completely suppress defection (c.f. Fig 3). However, increasing gradients require finer discretization to numerically integrate the selection-migration dynamics, Eq (3), and hence the emerging distributions depend on the discretization. The manifestation of discontinuous distributions becomes increasingly likely for larger values of *A*_{C} (see S3 Fig) but can also be triggered by pattern formation or large gradients in initial distributions. Increased and differing diffusion rates, *D*_{D} > *D*_{C}, or spreading defectors, *R*_{D}, lower the threshold for pattern formation and are additionally required to reliably observe smooth patterns through aggregating cooperators, *A*_{C}.

### Social dynamics

Directed migration not only promotes or inhibits spontaneous pattern formation but also affects the frequency of cooperators as well as the population density and hence the survival of the population. Whenever patterns develop, cooperation is promoted and population densities consequently rise, see Fig 4.

In the absence of directed migration (undirected migration only) homogeneous coexistence results with densities *Q* = (*u*_{eq}, *v*_{eq}). The two panels depict the ratio of the average spatial population density to the population density in unstructured populations, (black solid line), and the ratio of the average cooperator frequency to their frequency in unstructured populations, (green solid line) for (A) cooperator aggregation, *A*_{C}, and (B) spreading defectors, *R*_{D}. (A) increasing *A*_{C} gives rise to four dynamical regimes: (i) homogeneity maintained, (ii) formation of smooth patterns, (iii) discontinuities emerge, and (iv) population expansion prevented. (B) increasing *R*_{D} only results in two regimes: (i) homogeneity (ii) formation of smooth patterns. In order to facilitate comparisons of regions (i) and (ii) across panels the large effects of discontinuities in (iii) and (iv) refer to the scale on the right of panel (A). In either case, heterogeneous distributions increase (average) population densities and cooperator frequencies. In (A), once discontinuities develop, populations consist exclusively of cooperators. The decrease in *r*_{p} for large *A*_{C} relates to the fact that populations are unable to expand and hence the ratio depends on the initial configuration. In contrast, *r*_{c} remains unaffected because defectors are absent and cooperators are at the maximum frequency. *Parameters* as in Fig 3.

This effect extends to multiplication factors below *r*_{Hopf}, which cannot sustain unstructured populations. In this domain, undirected migration is capable of inducing spatial heterogeneity for *D*_{D} > *D*_{C} and thereby promotes the survival of the population. Aggregating cooperators, *A*_{C}, and spreading defectors, *R*_{D}, further promote pattern formation and population survival even under conditions such as *D*_{C} ≥ *D*_{D}, where undirected migration alone is unable to support the population, c.f. Eq (6) and Fig 2A and 2D. Moreover, the positive feedback of aggregating cooperators coupled with limited reproductive opportunities, offers the intriguing prospect that defectors can potentially get crowded out and driven to extinction, see Figs 2A and 4A.

## Discussion

Cooperation is doomed in traditional public goods games—as paraphrased by Hardin’s “Tragedy of the Commons” [9]. In contrast, in ecological public goods interactions cooperators and defectors can coexist through the feedback between variable population densities and interaction group sizes [10] even if the reproductive performance and survival of the population hinges on the availability of public goods.

The introduction of continuous spatial dimensions allows population densities and social composition to vary across the domain. For undirected migration the ratio between the rates of cooperator and defector migration is crucial [12, 22]. For *D*_{C} > *D*_{D}, the population either settles in a homogeneous state with densities corresponding to the well-mixed coexistence equilibrium *Q*, if it is stable (*r* > *r*_{Hopf}), or goes extinct if *Q* is unstable (*r* < *r*_{Hopf}). In either case, attempts of cooperators at avoiding exploitation by outrunning defectors are futile. For *D*_{C} = *D*_{D}, chaotic spatio-temporal dynamics enable the population to survive for *r* slightly below *r*_{Hopf} [21]. However, for *D*_{C} < *D*_{D} cooperation is promoted through Turing instabilities that result in quasi-stable or dynamical patterns that increase cooperator frequency, overall population density, and enhance population survival.

Through undirected migration heterogenous density distributions of cooperators and defectors spontaneously arise [12, 22]. Consequently the abundance of public goods varies across space and renders some regions more attractive than others. This provides a natural incentive for directed migration—either to avoid poor areas or to seek out better ones. For example, chemotactic bacteria aggregate in patches in response to excreted attractants [23] or try to escape oxidative stress [2]. Instead of explicitly modelling the concentration of public goods and its waste products to assess the quality of the environment, we use the density of cooperators and defectors as proxies for the availability of public goods and the degree of exploitation, respectively. Thus, seeking cooperation and avoiding defection allows individuals to increase their access to public goods and improve their reproductive potential. Interestingly, even though the two migration patterns appear very similar, they may actually trigger movements in opposite directions. For example, cooperators that seek their kind aggregate at the centre of cooperative areas. The resulting increase in public goods also benefits defectors in that same location and may attract more defectors, which increases competition and exploitation. In contrast, cooperators that avoid defectors tend to migrate towards the periphery of cooperative areas and thereby effectively counteract cooperator aggregation. Analogous arguments apply to defectors seeking cooperators or avoiding their kind, respectively, but with opposite effects. More specifically, spreading defectors indirectly support cooperator aggregation by creating (temporary) refuges with low exploitation.

As a consequence, directed migration can both enhance as well as inhibit pattern formation. In particular, aggregating cooperators or spreading defectors both promote or even trigger pattern formation. This extends into unfavourable parameter regions that otherwise result in extinction, such as when cooperators outpace defector, *D*_{C} ≥ *D*_{D}, or small multiplication factors *r*, see Fig 2A and 2D. Conversely, fleeing cooperators and hunting defectors suppress pattern formation by levelling out population densities. For *r* < *r*_{Hopf} this increases the risk of extinction. The complementary effects of the different modes of directed migration are captured in Eq (6), which provides an analytical threshold for the onset of pattern formation. Regardless of whether spatial heterogeneities arise through directed or undirected migration, they invariably increase both the average frequency of cooperators as well as the average density of populations as compared to unstructured populations, see Fig 4, and thus improves the odds of population survival.

Traditionally the effects of spatial structure in evolutionary games have been investigated based on lattices or more general network structures [24, 25]. Such discrete spatial arrangements are capable of supporting cooperation because they enable cooperators to form clusters and thereby reduce exploitation by defectors. This effect is further enhanced by success-driven migration [26]. In contrast, in our setup space is continuous and the state of the population represented by density distributions of cooperators and defectors. This difference is crucial and renders cooperation even more challenging because, in general, the density of defectors may become arbitrarily small but never and nowhere zero within finite times. As a consequence cooperators are always subject to exploitation by defectors. In fact, in the absence of ecological dynamics and constant population densities cooperators invariably disappear (if *r* < *N*) or, conversely, take over (if *r* > *N*), just as in well-mixed populations.

Notably, the only exception to this rule refers to the aggregation of cooperators because this mode of directed migration can trigger a positive feedback between densities and migration of cooperators: increases in density due to cooperator aggregation result in steeper gradients, which heightens the attraction and hence further increases their density. As a result, cooperator densities may not only remain localized but also eliminate defectors. However, this positive feedback results in analytical and numerical challenges because it gives rise to discontinuous distributions. Yet, those challenges are common among models incorporating aggregation. For example, the Keller-Segel chemotaxis model predicts infinite population densities after finite times [27–30]. Even though a mathematical artifact, those singularities are associated with the inherent feedback between chemotaxis and the secretion of chemical attractants [15].

Nevertheless, the most striking feature of directed migration is the potential of aggregating cooperators to crowd out and eliminate defectors altogether, see Figs 2A, 3A, 3C and 4A. Unfortunately this intriguing phenomenon is linked to the positive feedback that gives rise to discontinuous distributions and hence eludes further analysis based on the present framework, Eq (3). Somewhat surprisingly, the reduced aggregation rate due to a lack of reproductive opportunities, represented by the term *w*∇*u*, turns out to be insufficient to maintain smooth numerical solutions.

Motility plays an important role in biofilms. Microbes excrete extracellular substances to generate and maintain this protective film. Free-riders benefit from the protection without contributing, which gives rise to the public goods dilemma. Experiments indicate that not only the inherent social conflict plays a vital role in the effective secretion of biofilms [31] but also the microbes motility [32–34]. Biofilms are no longer generated when deactivating the movement apparatus through deliberate mutations [35]. When specifically targeting the ability to chemotact, biofilm production significantly varies across microbes and experimental setups [32]. This sensitivity of public goods production in response to different types of migration is reflected in our model.

The complex interplay between ecological public goods and motility shapes population densities and distributions as well as their social composition. Not only does migration affect the production of the public good but some public goods also alter the motility of their producers. For example biofilms increase viscosity and reduce the motility of microbes or even segregate populations [36]. Conversely, *Paenibacillus* collectively lubricate hard surfaces to enhance population expansion [37]. Either scenario creates intriguing opportunities for novel feedback mechanisms where migration not only shapes the production and availability of the public good but where the public good represents the very infrastructure needed to stay put or migrate more efficiently.

## Supporting information

### S1 Appendix. Specifics of ecological public goods dynamics.

https://doi.org/10.1371/journal.pcbi.1006948.s001

(PDF)

### S2 Appendix. Derivation of directed migration terms.

https://doi.org/10.1371/journal.pcbi.1006948.s002

(PDF)

### S3 Appendix. Pattern formation: Dispersion relation and derivation of necessary criteria.

https://doi.org/10.1371/journal.pcbi.1006948.s003

(PDF)

### S1 Fig. Dispersion relation for directed migration.

(A) aggregating cooperators, *A*_{C}, and (D) spreading defectors, *R*_{D}, have both the potential to cause spatial instabilities through increased migration. In the process, the dominant mode *k*_{*} increases with increased aggregating cooperators, *A*_{C}, and decreases with spreading defectors, *R*_{D}. In contrast, (C) hunting defectors *A*_{D} and (D) fleeing cooperators *R*_{C} stabilize the system. *Parameters*: 2.4 = *r* > *r*_{Hopf} (such that λ(0) < 0), as well as *D*_{C} > *A*_{C}*u*_{eq}*w*_{eq} (to ensure λ(*k*) < 0 for *k* → ∞). (A), (D) *D*_{D} = 0.5, (B), (C) *D*_{D} = 0.7. Other parameters as in Fig 1.

https://doi.org/10.1371/journal.pcbi.1006948.s004

(TIFF)

### S2 Fig. Spatial and temporal dynamics for different types of directed migration.

Each panel illustrates the dynamics for a single type of directed migration as a function of the multiplication factor *r* in the proximity of *r*_{Hopf}. The small rectangles depict the cross section of the density distribution through the middle of the square *L* × *L* domain as a function of time from top to bottom. The color brightness indicates the density of cooperation (green) and defection (red) with coexistence (yellow) and vacant space (black). (A) Aggregating cooperators oppose the effects of diffusion and hence slow down the population expansion. The positive feedback between cooperator densities and aggregation can cause discontinuous distributions and the breakdown of numerical methods. (B) Hunting defectors increase competition in areas where cooperators concentrate. This allows cooperators to escape into unpopulated terrain but also increases the risk of extinction. (C) Fleeing cooperators avoid defectors and hence readily explore vacant space but with the defectors at their tails also tend to spread themselves too thin and risk extinction. (D) Spreading defectors again promote pattern formation and thereby support the survival of the population. *Parameters*: same as in Fig 1 but with Gaussian initial condition without noise and *t* = 250.

https://doi.org/10.1371/journal.pcbi.1006948.s005

(TIFF)

### S3 Fig. Pattern formation and discontinuities for aggregating cooperators *A*_{C}.

Analytical findings distinguish three domains based on *A*_{C} and the multiplication factor *r*: (i) aggregation is sufficiently strong to destabilize the homogeneous equilibrium (grey shaded region, *A*_{C}*u*_{eq}*w*_{eq} > *D*_{C}); (ii) unstable modes give rise to pattern formation (red shaded region, see Eq. (S4) in S3 Appendix); (iii) stable homogeneous coexistence (unshaded region). However, initial conditions significantly impact the emerging dynamics. Heterogeneous initial distributions trigger migration and aggregation of cooperators. Discontinuities emerge by *t* = 250 from a Gaussian initial distribution when the selection-diffusion system is numerically integrated (above dashed horizontal line). Below the dashed horizontal-line, patterns emerge (in red shaded region) or homogeneous coexistence is regained (in unshaded region) as predicted. For small *r* heterogeneous distributions are unable to develop and the population goes extinct (left of dashed vertical line). *Parameters*: same as in S2 Fig, except *D*_{D} = 0.5 to promote smooth patterns.

https://doi.org/10.1371/journal.pcbi.1006948.s006

(TIFF)

## Acknowledgments

We would like to thank Prof Michael Doebeli and Prof Joe Yuichiro Wakano for their helpful feedback and comments.

## References

- 1. Sourjik V, Berg HC. Receptor sensitivity in bacterial chemotaxis. Proceedings of the National Academy of Sciences. 2002;99(1):123–127.
- 2. Tso WW, Adler J. Negative chemotaxis in Escherichia coli. Journal of bacteriology. 1974;118(2):560–576. pmid:4597449
- 3.
Alerstam T. Bird migration. Cambridge University Press; 1993.
- 4. Glaeser EL. A world of cities: The causes and consequences of urbanization in poorer countries. Journal of the European Economic Association. 2014;12(5):1154–1199.
- 5. Milinski M, Semmann D, Krambeck HJ, Marotzke J. Stabilizing the Earth’s climate is not a losing game: Supporting evidence from public goods experiments. Proceedings of the National Academy of Sciences. 2006;103(11):3994–3998.
- 6. Greig D, Travisano M. The Prisoner’s Dilemma and polymorphism in yeast SUC genes. Proceedings of the Royal Society of London B: Biological Sciences. 2004;271(Suppl 3):S25–S26.
- 7. Wright GD. The antibiotic resistome: the nexus of chemical and genetic diversity. Nature Reviews Microbiology. 2007;5(3):175. pmid:17277795
- 8. Neu HC. The crisis in antibiotic resistance. Science. 1992;257(5073):1064–1073. pmid:1509257
- 9. Hardin G. The tragedy of the commons. science. 1968;162(3859):1243–1248. pmid:5699198
- 10. Hauert C, Holmes M, Doebeli M. Evolutionary games and population dynamics: maintenance of cooperation in public goods games. Proceedings of the Royal Society B. 2006;273:2565–2570. pmid:16959650
- 11. Hauert C, Yuichiro Wakano J, Doebeli M. Ecological Public Goods Games: cooperation and bifurcation. Theoretical Population Biology. 2008;73:257–263. pmid:18221761
- 12. Wakano JY, Nowak MA, Hauert C. Spatial dynamics of ecological public goods. Proceedings of the National Academy of Sciences. 2009;106(19):7910–7914.
- 13. Turing AM. The Chemical Basis of Morphogenesis. Philosophical Transactions of the Royal Society B. 1952;237(641):37–72.
- 14. Lee J, Hillen T, Lewis M. Pattern formation in prey-taxis systems. Journal of biological dynamics. 2009;3(6):551–573. pmid:22880961
- 15. Brenner MP, Levitov LS, Budrene EO. Physical mechanisms for chemotactic pattern formation by bacteria. Biophysical journal. 1998;74(4):1677–1693. pmid:9545032
- 16. Dawes RM. Social dilemmas. Annual Review of Psychology. 1980;31:169–193.
- 17. Hauert C, Michor F, Nowak MA, Doebeli M. Synergy and discounting of cooperation in social dilemmas. Journal of Theoretical Biology. 2006;239:195–202. pmid:16242728
- 18.
Sigmund K. The Calculus of Selfishness. Princeton Univ. Press; 2010.
- 19.
Hofbauer J, Sigmund K. Evolutionary Games and Population Dynamics. Cambridge University Press; 1998.
- 20.
Kuznetsov YA. Elements of applied bifurcation theory. vol. 112. Springer Science & Business Media; 2013.
- 21. Wakano JY, Hauert C. Pattern formation and chaos in spatial ecological public goodsgames. Journal of theoretical biology. 2011;268(1):30–38. pmid:20888344
- 22. Park HJ, Gokhale CS. Ecological feedback on diffusion dynamics. Royal Society open science. 2019;6(2):181273. pmid:30891264
- 23. Budrene EO, Berg HC. Complex patterns formed by motile cells of Escherichia coli. Nature. 1991;349(6310):630. pmid:2000137
- 24. Nowak MA, May RM. Evolutionary games and spatial chaos. Nature. 1992;359:826–829.
- 25. Ohtsuki H, Hauert C, Lieberman E, Nowak MA. A simple rule for the evolution of cooperation on graphs. Nature. 2006;441:502–505. pmid:16724065
- 26. Helbing D, Yu W. The outbreak of cooperation among success-driven individuals under noisy conditions. Proceedings of the National Academy of Sciences. 2009;106(10):3680–3685.
- 27. Keller EF, Segel LA. Model for chemotaxis. Journal of theoretical biology. 1971;30(2):225–234. pmid:4926701
- 28. Winkler M. Finite-time blow-up in the higher-dimensional parabolic–parabolic Keller–Segel system. Journal de Mathématiques Pures et Appliquées. 2013;100(5):748–767.
- 29. Herrero MA, Velázquez JJ. Singularity patterns in a chemotaxis model. Mathematische Annalen. 1996;306(1):583–623.
- 30. Hillen T, Painter KJ. A user’s guide to PDE models for chemotaxis. Journal of mathematical biology. 2009;58(1-2):183. pmid:18626644
- 31. Yurtsev EA, Chao HX, Datta MS, Artemova T, Gore J. Bacterial cheating drives the population dynamics of cooperative antibiotic resistance plasmids. Molecular systems biology. 2013;9(1):683. pmid:23917989
- 32. Merritt PM, Danhorn T, Fuqua C. Motility and chemotaxis in Agrobacterium tumefaciens surface attachment and biofilm formation. Journal of bacteriology. 2007;189(22):8005–8014. pmid:17766409
- 33. Korber DR, Lawrence JR, Caldwell DE. Effect of motility on surface colonization and reproductive success of Pseudomonas fluorescens in dual-dilution continuous culture and batch culture systems. Applied and environmental microbiology. 1994;60(5):1421–1429. pmid:16349247
- 34. Graf J, Dunlap PV, Ruby EG. Effect of transposon-induced motility mutations on colonization of the host light organ by Vibrio fischeri. Journal of bacteriology. 1994;176(22):6986–6991. pmid:7961462
- 35. Pratt LA, Kolter R. Genetic analysis of Escherichia coli biofilm formation: roles of flagella, motility, chemotaxis and type I pili. Molecular microbiology. 1998;30(2):285–293. pmid:9791174
- 36. Sutherland IW. Biofilm exopolysaccharides: a strong and sticky framework. Microbiology. 2001;147(1):3–9. pmid:11160795
- 37. Ben-Jacob E, Levine H. Self-engineering capabilities of bacteria. Journal of The Royal Society Interface. 2005;3(6):197–214.