## Abstract

Experimental and theoretical studies have highlighted the impact of gene flow on the probability of evolutionary rescue in structured habitats. Mathematical modelling and simulations of evolutionary rescue in spatially or otherwise structured populations showed that intermediate migration rates can often maximize the probability of rescue in gradually or abruptly deteriorating habitats. These theoretical results corroborate the positive effect of gene flow on evolutionary rescue that has been identified in experimental yeast populations. The observations that gene flow can facilitate adaptation are in seeming conflict with traditional population genetics results that show that gene flow usually hampers (local) adaptation. The conditions for when gene flow facilitates survival chances of populations rather than reducing them remains a key unresolved theoretical question. We here present a simple analytically tractable model for evolutionary rescue in a two-deme model with gene flow. Our main result is a simple condition for when migration facilitates evolutionary rescue, as opposed as no migration. We further investigate the roles of asymmetries in gene flow and / or carrying capacities, and the effects of density regulation and local growth rates on evolutionary rescue.

## Introduction

Evolutionary rescue refers to the process of rapid adaptation to prevent extinction in the face of severe environmental change [Gomulkiewicz and Holt, 1995]. It is of particular interest in light of recent environmental and climatic change, with the potential to lead to new conservation strategies [Ashley et al., 2003]. Evolutionary rescue also plays a major role in other fields of public importance, such as the evolution of antibiotic or other treatment resistance (e.g. Normark and Normark [2002]), or resistance to pesticides (e.g. Chevillon et al. [1999]). Better understanding of evolutionary rescue is therefore critical in the context of global climatic change as well as in the field of evolutionary medicine. Experimental evolution studies of evolutionary rescue and antibiotic resistance are burgeoning (reviewed in Bell [2017]), empirical evidence for rescue under anthropogenic stress is now abundant [Hughes and Andersson, 2017, Bell, 2017], whereas evidence for rescue under natural conditions is difficult to obtain and more scarce (but see Vander Wal et al. [2013]).

The theoretical foundations for evolutionary rescue in single panmictic populations are laid out [Orr and Unckless, 2014] and several demographic genetic and extrinsic features that affect the chance for rescue have been identified (see table 1 in Carlson et al. [2014] for an overview), including the effects of recombination [Uecker and Hermisson, 2016], mating system [Uecker, 2017], intra-specific competition [Osmond and de Mazancourt, 2013, Bono et al., 2015], inter-specific competition [De Mazancourt et al., 2008], and phenotypic plasticity [Chevin et al., 2013, Carja and Plotkin, 2019]. A major goal of evolutionary rescue theory is to predict a populations chance of survival in the face of severe stress. Key theoretical predictions of evolutionary rescue have been strikingly confirmed in laboratory conditions [Carlson et al., 2014], for instance using yeast populations exposed to high salt concentrations [Bell, 2013]. In particular, it was found that only sufficiently large populations could be expected to persist through adaptation [Lynch, 1993, Bell and Gonzalez, 2009, Samani and Bell, 2010, Bell and Gonzalez, 2011, Ramsayer et al., 2013, Bell, 2013]). A second feature that has been shown to facilitate the chance for evolutionary rescue theoretically as well as experimentally is standing genetic variation [Barrett and Schluter, 2008, Agashe et al., 2011, Lachapelle and Bell, 2012, Vander Wal et al., 2013, Ramsayer et al., 2013]. Despite these advances, however, predicting evolutionary outcomes outside of the lab remains extremely difficult [Gomulkiewicz and Shaw, 2013].

Evolutionary dynamics in spatially (or otherwise) structured populations can differ dramatically form those in well-mixed populations [Lion et al., 2011] and unexpected rescue mechanisms may arise in such settings [Peischl and Gilbert, 2018]. Empirical and experimental results have highlighted the importance of dispersal for evolutionary rescue in metapopulations subject to gradual environmental change. In particular, Bell and Gonzalez [2011] showed that gene flow between different habitats can have positive effects on survival in changing environments, depending on dispersal distances and the speed of the environmental change in an experimental metapopulation of yeast exposed to gradually increasing environmental stress. A detailed theoretical study of evolutionary rescue in structured populations using mathematical analysis and simulations showed that intermediate gene flow between populations can maximize the chance of rescue as compared to a population without gene-flow [Uecker et al., 2013]. Uecker et al. [2013] identified two direct consequences of dispersal: (i) the unperturbed environment acts as a source for wildtype individuals that might mutate, thus increasing the chances of rescue, and (ii) dispersal moves mutant individuals to regions of the environment where the presence of the mutation is costly, leading to a net reduction of the mutant growth rate, and consequent lower rates of survival. The interplay between these two effects can often lead to situations in which the probability of rescue is maximized for an intermediate migration rate [Uecker et al., 2013]. In a continuous space model where the environment changes gradually across space and/or time, increased dispersal generally decreases the probability of establishment of rescue mutations, but it increases the effective population size of individuals that can contribute to evolutionary rescue [Kirkpatrick and Peischl, 2013]. Individual based simulations of gradually changing conditions and divergent selection between two habitats identified interactions of evolutionary rescue and local adaptation in a two-deme model [Bourne et al., 2014]. These results suggest that gene flow is beneficial for population survival only when divergent selection is relatively weak. These results were largely confirmed in a simulation study of a 2D metapopulation [Schiffers et al., 2013].

Although both theoretical and experimental advances have been made to understand the role of dispersal in metapopulation models of evolutionary rescue, the interactions between the speed and the severity of environmental change, and the amount and mode of dispersal are not well understood. For instance, the observation that gene flow can facilitate rescue in a changing environment is in seeming conflict with more traditional results that show that dispersal does generally not have a positive effect on (local) adaptation [Bulmer, 1972, Holt and Gomulkiewicz, 1997, Lenormand, 2002]). In particular, spatial structures with divergent selection pressures between different regions can lead to gene swamping for high migration rates [Bulmer, 1972], thus nullifying chances of survival during environmental change across space. Under which conditions dispersal facilitates evolutionary rescue in spatially or otherwise structured populations remains a key unresolved questions, both theoretically and empirically.

In this article, we present an analytically tractable model with two demes that exchange migrants and temporal change in environmental conditions. We focus on the case where the two demes deteriorate at different points in time, such that gene flow between the populations influences both the demographic as well as the evolutionary dynamics of evolutionary rescue. In the new environmental conditions, growth rates are negative and the population faces eventual extinction. We consider rescue mutations at a single locus and assume that they are counter-selected in the original environmental conditions. We derive conditions for when gene flow facilitates evolutionary rescue as compared to two populations without gene flow. We study the role of asymmetric migration rates or asymmetric carrying capacities (both cases can lead to source-sink dynamics, see Holt [1985], Pulliam [1988]), study the contributions of de novo mutations vs. standing genetic variation, and investigate the role of local growth rates and density regulation within demes.

## Model

We consider a population subdivided into two demes, labeled 1 and 2, with gene flow between them. Individuals migrate from deme *i* to deme *j* with probability *m*_{ij}, *i, j* = 1, 2. Fitness is determined by a single locus with two alleles: a wild-type allele and a mutant allele. We distinguish two possible environmental states. At the beginning both demes are in what we call the non-deteriorated state (or “old” state) and are at demographic equilibrium, filled with *κ*_{i} individuals. The total population size is therefore *K*_{tot} = *κ*_{1} + *κ*_{2}. At time *t* = 0 deme 1 deteriorates (that is, it is now in the “new” state). In the deteriorated environment, wild-type individuals have absolute fitness , such that the population size in deme 1 declines at rate *r*. After *θ* generations, deme 2 deteriorates too and local population size starts to decline at the same rate as in deme 1. In the absence of adaptation to the novel environmental conditions both demes will eventually go extinct. We assume that rescue mutations that restore positive growth rates in the new environment occur at rate *u* per individual and generation, and we ignore back mutations. The absolute fitness of a mutant individual is in the new habitat. We assume that the mutation is detrimental in the old environment and denote its carriers fitness by (0 < *s* < 1). We call *r* the environmental stress due to deterioration, and *s* and *z* are the selection coefficients of the mutant allele in the old and new state, respectively. We will call “phase 1” the phase in which the two demes have different environments (0 < *t* < *θ*) and “phase 2” the phase in which both demes are deteriorated.

### Probability of rescue

Let *P*_{rescue} denote the probability that a rescue mutation occurs and escapes genetic drift, such that it will increase in frequency and eventually restore a positive growth rate and rescue the population from extinction. To calculate the probability of rescue, one needs to take into account two ingredients: (i) the number of mutations entering the population in each generation and (ii) the probability of establishment of each single mutant copy in the population. In a single population, one can write the probability of rescue as
where *uN* (*t*) is the expected number of mutations entering the population in each generation, and *p*(*t*) is the probability that the mutation establishes and rescues the population [e.g., Gomulkiewicz and Holt, 1995].

Evolutionary rescue can stem from standing genetic variation, with probability *P*_{sgv}, or from *de novo* mutations, with probability *P*_{dn}. We define *de novo* mutations as mutations that arose after the first deterioration event occurred (that is, after time *t* = 0). We can thus write:

Mutations that occur before phase 2 (that is, after all demes are deteriorated) have different probabilities of establishment *p*^{(1)}(*t*) and *p*^{(2)}(*t*) depending on the deme in which they occur and the time at which they occur. However, currently no analytic solution is known for the establishment probabilities in this case. To proceed further we ignore the temporal heterogeneity in fitness values and use the current environmental conditions to calculate establishment probabilities using the results from Tomasini and Peischl [2018] for a time-homogeneous two-deme model. This should be a good approximation if *θ* » 0, since the fate of mutations in temporally changing environments is determined in the first few generations after they occur [Peischl and Kirkpatrick, 2012] and the contribution of mutations occurring just before environments change will be negligible. In contrast, if *θ* ≈ 0, the change in environmental conditions is almost instantaneous across all demes, such that population structure and migration would have virtually no effect on evolutionary rescue [Uecker et al., 2013]. During phase 2, when the two demes are in the same environmental state, the probability of establishment is simply 2*z* [Haldane, 1927]. Thus, we get

We can then write
where *f*_{0} is the frequency of rescue mutations in each of the demes at time *t* = 0. Similarly, the total probability due to *de novo* mutations is given by
where we approximate the joint probability that a copy of the rescue mutation will occur in generation *t* and then establish permanently by

To simplify calculations, we use that if *π*_{dn} is small, and for furter simplicity, we do the calculation in continuous time, so that we can switch the sum for an integral. The probability of rescue from *de novo* mutations is then

### Population dynamics

In order to calculate (6) and (7), we need to explicitly calculate *N*_{1}(*t*) and *N*_{2}(*t*) for *t* ≥ 0. We model the population dynamics as continuous in time, as we did in (8), and further assume that the mutation rate is low and neglect the number of wildtype individuals lost due to mutation. We assume that population growth and density regulation keep population density in deme 2 at carrying capacity, that is *N*_{2}(*t*) = *κ*_{2}, during phase 1. Population size in deme 1 then follows the differential equation

During phase 2, when both demes are deteriorated, *N*_{1}(*t*) and *N*_{2}(*t*) follow
where *i, j* ∈ {1, 2} and *i* ≠ *j*. Solutions can be obtained straightforwardly – more details are given in the supplemental material (Appendix A, equation (S4)).

### Simulation model

We performed stochastic simulations to validate and extend our analytical findings. We filled a habitat with 20’000 individuals divided into two demes, labelled *i* = 1, 2, with carrying capacities *κ*_{i}. We fixed the mutation rate at *u* = 1*/K*_{tot} = 5 × 10^{−5}, so that in a non-deteriorated habitat at carrying capacity on average one new mutant enters the population per generation. The initial mutant frequency *f*_{0} was set at mutation-selection equilibrium, *f*_{0} = *u/s* [Gillespie, 2004]. At *t* = 0, deme 1 deteriorates, and at *t* = *θ* deme 2 deteriorates. Individuals in each deme reproduced, mutated and migrated, followed by density regulation. Each individual had Poisson distributed offspring with the mean proportional to its fitness *w* (see table 1 for the definitions of fitnesses *w*). Every generation new mutants entered the population via binomial sampling from the wildtype population with probability *u*. Migration was also modeled as a binomial sampling from the local populations, where migrants from each deme *i* are sampled with probability *m*_{ij} (*i, j ∈* [1, 2], *i* ≠ *j*). Density regulation was applied only to deme 2 when *t < θ* (non-deteriorated deme), and consisted in bringing the deme back to carrying capacity at the end of the generation. The genetic composition of the regulated deme was composed by binomial sampling, thus maintaining wild-types and mutants in the non-perturbed deme at the same frequency that they reached after reproduction, mutation and migration. We run the simulation for two epochs of *θ* generations and add a burn-off period of 500 generations. Rescue is attained if at any moment during the simulation the number of mutants reaches *K*_{tot}*/*2. We performed 2000 replicates for each parameter combination.

## Results

### Probability of rescue if mutations are lethal in the old environment

We start by evaluating (2) for the symmetric case where *κ*_{1} = *κ*_{2} = *κ* and *m*_{12} = *m*_{21} = *m/*2. Furthermore, we assume that the mutation is lethal in the old environment (*s* = 1), hence each rescue event will result from a *de novo* mutation. This allows us to outline our main results in a simple model and to provide some intuition about the involved mechanisms at play. We relax these assumptions later. Figure 1A shows the the total probability of rescue (equation (2)) as a function of the migration rate, as well as the decomposition into mutations occurring during and after the deterioration of the environment. We observe that the probability of rescue with respect to migration is maximized for an intermediate migration rate for the parameter values used in Figure 1. This is consistent with previous results [Uecker et al., 2013]. The existence of an optimal intermediate migration rate reflects two effects that are at play here. On one hand the non-deteriorated deme act as a source of wildtype individuals, preventing extinction in deme 1, thus increasing the chance for rescue to occur. On the other hand, too much migration between demes prevents rescue mutations from establishing despite being positively selected in one of the two demes, a process called gene swamping [Bulmer, 1972, Lenormand, 2002, Tomasini and Peischl, 2018] (Fig. 1). Hence, for large migration rates, rescue can only occur during phase 2. In addition to these two processes, increasing the migration rate also increases the total wildtype population size at the beginning of phase 2 (see supplemental material, Appendix A). Thus, increasing *m* has a mild positive effect on evolutionary rescue during phase 2 (Fig. 1, also supplementary material, fig. S1).

Figure 1B shows comparison with simulations and reveals an excellent fit of our analytical approximation for low to intermediate migration rates. For large migration rates, however, we underestimate the true probability of rescue. This is due to the fact that we ignore the temporal change of the fitness of rescue mutations. In particular, we underestimate the establishment probabilities of mutations that occur at the end of phase 1, just before the environment in deme 2 deteriorates. Our approximation ignores this change in environmental conditions in deme 2 and hence assumes that individuals carrying mutations that occurred during phase 1 will be counter-selected in deme 2, even during phase 2 when they are actually positively selected in that deme. This effect is negligible for small migration rates but can have considerable effect for large migration rates. Importantly, however, the probability of survival for *m* → 0, as well as the optimal intermediate migration rate that maximizes the chance of rescue are correctly estimated by equation (2).

#### When does intermediate migration favors rescue?

A key unresolved question for evolutionary rescue in structured populations is: when does gene flow facilitate evolutionary rescue as compared to two populations in isolation? Our model allows us to derive a condition for when intermediate migration helps chances of survival by calculating when the derivative of with respect to *m* at *m* = 0 is positive. This is the case if (see supplemental material, Appendix B)

Thus, our model predicts that gene flow has a positive effect on evolutionary rescue if rescue mutations are strongly beneficial in the deteriorated environment (*z* > 0), respectively, if environmental change occurs slowly across space (large *θ*), and/or if the new environment is very harsh (large *r*). In particular, both *θ* and *r* influence the imbalance in population density between the two demes, hence for a long deterioration time or high stress, there will be a prolonged period where population in deme 1 is low and population in deme 2 is at carrying capacity. This population unbalance causes high migration to be too efficient in removing mutations from deme 1, but also low migration will not refill deme 1 quick enough with wild-types that could mutate. As a result, intermediate migration will be more effective.

### Non-lethal rescue mutations

If we consider only *de novo* mutations, eq. (11) can be readily generalized to non-lethal mutations and becomes
as is shown in the supplemental material (Appendix B). Note that this includes the condition (11) for lethal mutations as a special case if *s* = 1. if rescue mutations are sub-lethal or only slightly deleterious (*s* < 1), the range of parameters for which gene flow facilities evolutionary rescue increases. This is sensible as gene swamping is less likely if mutations are less deleterious in the environment to which they are not adapted to [Bulmer, 1972, Lenormand, 2002, Tomasini and Peischl, 2018].

Unless the selective disadvantage *s* of rescue mutations is very large, rescue mutations will generally be present at low frequencies in the population before the deterioration of the environment. We thus need to account for the contribution of standing genetic variation to the probability of rescue (figure 2). We can see that the chances of survival from standing mutations are maximal in absence of migration (figure 3, also figure S2). The reason is the following: a mutation in deme 1 at *t* = 0 will have higher chances of surviving compared to a mutation in deme 2, where it is counter-selected, that is, *p*^{(1)} > *p*^{(2)} for any combination of parameters. Further, because *p*^{(1)} is monotonically decreasing [Tomasini and Peischl, 2018], *P*_{sgv} tends to decrease with increasing migration rates (except if *s* is small and m is large, see Figure S2). By adding the contribution of standing genetic variation (as calculated with (5)) the equivalent of condition (12) yields

For *f*_{0} = 0, we recover equation (S7) in the supplemental material (Appendix B), which is in turn approximated to (12). When *f*_{0} increases, the left-hand part of (13) decreases, and gene flow loses importance. In fact, since *P*_{sgv} is monotonically decreasing with increasing migration rate *m*, standing genetic variation only matters for small to intermediate migration rates. Standing mutations will establish during phase 1 and are hence subject to gene swamping. Thus, if standing genetic variation is the predominant source of rescue mutations, gene flow is unlikely to have positive effects on rescue.

In the supplemental material (figure S3) we show comparison between simulations and theoretical expectations for different values of *s* (with standing genetic variation). We notice disagreement between simulations and calculations in particular for small values *s*. This is due to new mutants that will spread so slowly that they will reach high frequencies only during phase 2, when both environments are deteriorated. The contribution of these mutants to the probability of rescue, however, is calculated through their probability of establishment in phase 1, which does not account for the temporal change in fitness of rescue mutations at time *θ*. The discontinuity between *p*^{(i)}(*t < θ*) and *p*^{(i)}(*t > θ*) causes our approximation to underestimate the probability of rescue, especially for large migration rates.

### Effects of the parameters of the model

Figure 3 illustrates the influence of various parameters on the probability of rescue. Increasing *z* has the main effect of increasing the probability of rescue, because a more beneficial mutation clearly has a larger chances of surviving (Figure 3A). At the same time, the optimal migration rate (when it exists) increases with increasing *z*. The reason is that the critical migration rate beyond which gene swamping occurs increases with increasing *z* [Bulmer, 1972], which thus allows establishment to occur for larger *m* [Tomasini and Peischl, 2018]. Decreasing the strength of environmental stress, *r*, leads to a higher overall probability of rescue because population sizes decline more slowly, leaving more time for rescue to occur (Figure 3B). The critical threshold at which swamping occurs remains unaffected, as it depends on the ratio between *z* and *m* only [Tomasini and Peischl, 2018]. Increasing *θ* extends the length of phase 1, which can increase the probability of rescue dramatically for intermediate migration rates but not for low or high migration rates (Figure 3C). For low migration rates, the length of phase 1 has very little impact since the two demes evolve almost independently. For strong migration, the length of phase 1 does not matter, because swamping prevents the establishment of rescue mutations during phase 1. Figure 3D shows that decreasing the deleterious effect of rescue mutations *s* has a similar effect on the probability of evolutionary rescue from *de novo* mutations as increasing *θ*. Decreasing *s* also affects the critical migration rate beyond which gene swamping occurs [Bulmer, 1972, Tomasini and Peischl, 2018], but this effect is rather weak.

Figure 3 also confirms our approximation eq. (12) for the condition under which gene flow should lead to an increase in the probability for evolutionary rescue. For instance, for the solid line in figure 3C we used the parameters *z* = 0.02, *s* = 1.0, *r* = 0.25 and *θ* = 50. Hence, *s/z* = 50 > *rθ* = 12.5, thus violating (12) and resulting in a case where migration hinders the chances of evolutionary rescue. On the other hand, the dotted line (*θ* = 500), yields *s/z* = 50 *< rθ* = 125, resulting in a situation where migration increases the chances of rescue with respect to no migration. The same can be seen *e.g.* when modifying the selective advantage of the mutant, *z* (figure 3A): the solid line has *s/z* = 100 > *rθ* = 50 is maximized for *m* = 0, while the dotted line (*s/z* = 20 < *rθ* = 50) attains its maximum for an intermediate migration rate.

### Asymmetric carrying capacities and migration rates

We next consider the effect of asymmetric migration rates or asymmetric carrying capacities. For better comparison, we introduce two new parameters *ζ* and *β* that measure the degree of asymmetry:

Hence, the model is symmetric with respect to migration rates and carrying capacities if *ζ* = *β* = 0.5. For *ζ* < 0.5, migration from deme 1 to deme 2 is smaller, while the opposite is true when *ζ* > 0.5. Figure 4A shows the probability of rescue as a function of *m* for different values of *ζ*. For *ζ* = 0.9, deme 2 receives many more migrants than it sends out, as compared to the symmetric model. The main effect of this asymmetry in migration is to decrease the total probability of rescue because rescue mutations are more likely to be removed from the deme to which they are adapted to as compare to the symmetric case. Further, gene swamping happens for lower values of *m* [Bulmer, 1972], thus reducing any beneficial effects of gene flow. The opposite is true for *ζ* = 0.1: wildtype individuals are removed at a smaller rate from the deme where they are adapted to, which increases the chances of survival. At the same time, gene swamping occurs for larger values of *m* with respect to the symmetric case. The reduced effect of gene swamping with decreasing *ζ* also becomes apparent from the increase of the migration rate that maximizes the chance for evolutionary rescue. Figure S4A and S5A show comparison with simulations for *de novo* mutations and standing genetic variation with asymmetric migration rates.

We next keep migration rates symmetric, such that *m*_{12} = *m*_{21} = *m/*2, and investigate the effect of asymmetries in carrying capacities. Figure 4B shows the probability of rescue as a function of *m* for different *β*. We are going to call deme 2 “the reservoir”, as during phase 1 it is left untouched and it never gets extinct. We observe that a larger reservoir yields higher probability of rescue, and *viceversa*. This is mainly due to *de novo* mutations during the second phase. Hence, chances of new mutants to establish increase because there are more wildtype individuals to start with at *t* = *θ*. When it exists, the optimal migration rate remains the same as in the symmetric model, even though it yields higher chances of survival for a larger reservoir. Figures S4B and S5B show comparison with simulations for *de novo* mutations and standing genetic variation with asymmetric carrying capacities. The condition for when gene flow facilitates evolutionary rescue from *de novo* mutations as compared to no migration becomes (see supplemental material, Appendix B)

Condition (16) generalizes conditions (11) and (12) (it is also easy to generalize condition (13), as shown in the supplementary information, Appendix B, (S6)). This reflects the dynamics of a source-sink scenario. When deme 2 is large – the source is large – it sends many wild-types to the sink, where new mutants could arise and prosper. The same happens if immigration in deme 1, *m*_{21}, is large. In extreme cases, when *κ*_{1} *< m*_{21}*κ*_{2}, immigration in deme 1 causes overflow. This corresponds to a situation in which population does not declines until the reservoir gets deteriorated. On the other hand, since what matters most for ultimate rescue is the number of mutants, this high rate of migration also causes purifying selection in deme 1, not allowing any mutant to survive for long.

Similarly to what was done for the symmetric scenario, in figure 4 we can see condition (16) at work. The dotted line in panel A has *z* = 0.02 *s* = 0.5, *r* = 0.5 and *θ* = 100, while we have *F* = *m*_{21}*/m*_{12} = (1 *− ζ*)*/ζ ≈* 0.1 and 25 = *s/z > Frθ ≈* 5. On the other hand, for *ζ* = 0.1 (dashed line of figure 4A) we have 25 = *s/z < Frθ* = 450.

### The role of density regulation

So far we have assumed that density regulation keeps the unperturbed deme at carrying capacity at all times. This requires sufficiently high local growth rates so that any reduction of the populations size due to emigration is immediately compensated by rapid growth within the unperturbed deme. This has the advantage that we do not need to model density regulation explicitly and is the same kind of density regulation as described in [Uecker et al., 2013]. We relax this assumption by assuming Beverton-Holt dynamics [Beverton and Holt, 1957] in the unperturbed deme, which means that the number of individuals of a type *i* in the non-deteriorated deme in the next generation will be
where *ρ* denotes the growth rate of the population. Differences between the two modes of density regulation are summarized in supplemental material (Appendix C). We performed simulations of this model and compare the outcomes to the model with instantaneous growth (Figure 5). In all considered cases, the two modes of density regulation do not show any difference for low to intermediate migration rate. This is not surprising, as emigration affects the total number of individuals in the unperturbed deme only mildly, and even small values of *ρ* ensure that carrying capacity is maintained. For intermediate to large migration rates, however, the behavior can change dramatically (Figure 5). In particular, our simulations show that for large migration rates, the probability of rescue can be much lower if the growth rate *ρ* is small. To understand this behavior, let us first consider the case where population growth is instantaneous. The source population (unperturbed deme) is constantly loosing individuals due to emigration into the sink population (perturbed deme). As a consequence, population growth will increase the absolute fitness of the remaining individuals in the source population [Tomasini and Peischl, 2018]. Thus selection in the unperturbed deme is less efficient as compared to the case without gene flow. The increase of the probability of rescue as *m* increases is due to what Uecker et al. [2013] call “relaxed competition” and has been demonstrated formally in a two-model with source-sink dynamics [Tomasini and Peischl, 2018]. But if density regulation is logistic and growth rates are small, the advantage of relaxed competition disappears as emigration removes individuals more quickly than they can be reproduced. In this case we would expect that the probability of rescue starts to decline once the migration rate exceeds the critical value beyond which population growth can no longer maintain the population at carrying capacity. To calculate this critical migration rate, we approximate the net loss of individuals due to migration in deme 2 by solving

Note that in this calculation we neglect the number of individuals coming from deme 1 and all the mutant individuals. The evolution of the individuals in deme 2 is calculated explicitely in the supplemental material (see Appendix C, equation (S10)). Now, extinction occurs when *N*_{2}(*t*) = 0 for some *t* > 0. This happens when
or when the product of the rate of growth and the rate of migration (loss) is smaller than 1. We should note that relation (20) is a conservative limit. As we do not take into account the presence of mutants, but only the net loss of wildtype individuals, this result does not account for the possibility of having a mutant establishing in the first generations after the deterioration event, as it is often the case [Peischl and Kirkpatrick, 2012]. The vertical lines in Figure 5 indicate this critical migration rates and confirm our intuitive explanation above.

Hence, density regulation can reduce the beneficial effects of gene flow if the growth rate *ρ* is not large enough such that the unperturbed deme does not remain at carrying capacity, and there is no relaxed competition. Even when there is the potential for relaxed competition in terms of *s*, *r* and *θ* (see [Uecker et al., 2013]), a slower growth rate lowers the chances of rescue for intermediate migration rates and higher (see figure 5). Ultimately, small growth rate *ρ* disrupts all effects due to migration and allows gene swamping to occur more readily. This is sensible, as low growth rate means that there will be fewer individuals in deme 2 and migration is mainly detrimental to the establishment of rescue mutations and also reduces the population size that can contribute to evolutionary rescue.

## Discussion

We studied a model for evolutionary rescue in a spatially structure habitat using recent analytical results for establishment probabilities in structured populations [Tomasini and Peischl, 2018]. Our main result is an analytical prediction for the conditions under which gene flow facilitates evolutionary rescue in structured populations as compared to a population without gene flow. The potentially positive effect of gene flow on evolutionary rescue has been described previously both experimentally and theoretically; experimentally during adaptation to a gradient of salinity in a yeast meta-population [Gonzalez and Bell, 2013], mathematically in a model for evolutionary rescue in structured populations [Uecker et al., 2013], and via simulations of the evolution of treatment resistance in solid tumours [Waclaw et al., 2015]. These findings are in contrast to the fact that dispersal does generally not have a positive effect on (local) adaptation ([Bulmer, 1972], [Holt and Gomulkiewicz, 1997] [Lenormand, 2002]) in populations with more stable demographic scenarios, and the conditions for when gene flow facilitates survival in the face of drastic environmental change were previously not known. Our study fills this gap and provides surprisingly simple and intuitive conditions for when we expect positive effects of gene flow on survival via adaptation. Furthermore, our model allowed us to describe the interactions between density regulation, demographic dynamics and gene flow during adaptation to severe environmental stress.

We showed that the probability of evolutionary rescue from de novo mutations will be maximized for an migration rate *m* > 0 if *s/z* < *rθ*, where *r* describes the harshness of the new environment, *θ* the speed of environmental change, *s* < 0 is the cost of carrying a rescue mutation in the original environment (e.g., the cost of having a antibiotic mutation in the absence of antibiotics), and *z* > 0 is the selective advantage of a rescue mutation in harsh environments (e.g., the advantage of carrying an antibiotic resistance mutation in the presence of antibiotics). Thus, our model predicts that gene flow has a positive effect on evolutionary rescue if (i) rescue mutations are strongly beneficial/weakly deleterious in the deteriorated/original environment, respectively, if (ii) environmental change occurs slowly across space (large *θ*), and/or if (iii) the new environment is very harsh (large *r*). We then extended this result to account for the effects of standing genetic variation, asymmetry in carrying capacities and the direction of gene flow between demes. Finally, we investigate the details of density regulation and find that they strongly affect whether gene flow will facilitate survival or not. In particular, if local growth rates in unperturbed demes are so low that carrying capacities cannot be maintained due to emigration of individuals, positive effects of gene flow diminish. The predictions that we derive from the model are corroborated by stochastic simulations.

Our results show that the main positive effect of gene flow is during during phase 1, *i.e.* during the epoch in which only one deme is deteriorated. Gene flow from the unperturbed deme into the perturbed deme provides the raw material which can increase the chance of evolutionary rescue as compared to two populations without gene flow. This phenomenon has recently been formally studied in a two-deme model with divergent selection, where gene flow can be beneficial to the rate of establishment of locally adapted mutations [Tomasini and Peischl, 2018]. This is reflected in the equation *s/z* < *rθ*; the stronger the source-sink dynamics of the unperturbed and perturbed habitat (large *r*) and the longer these source-sink dynamics last (large *θ*), the more likely it is that gene flow is beneficial for evolutionary rescue. This effect is further amplified if carrying capacities or gene flow is asymmetric such that more individual migrate from the unperturbed to the perturbed habitat (*F* > 1 in eq. (16)).

We found that interactions between gene flow and density regulation play an important role. Ultimately, when the growth rate *ρ* of the wild-type in deme 2 is large enough to compensate emigration to deme 1, the system remains in a source-sink scenario (see *e.g.* Gomulkiewicz et al. [1999]) and gene flow can be beneficial for evolutionary rescue. Furthermore, if the growth rate is very large, we observe relaxed competition (see also Uecker et al. [2013]) which can counter the negative effects of rescue mutations in the unperturbed habitat. If, however, gene flow depletes individuals too quickly in the unperturbed deme such that density regulation cannot replace these individuals, the positive effects of gene flow disappear (Figure 5).

It has been argued that standing genetic variation, along with initial population density, is the main factor determining the chances of evolutionary rescue [Gomulkiewicz and Holt, 1995, Barrett and Schluter, 2008, Agashe et al., 2011, Lachapelle and Bell, 2012, Ramsayer et al., 2013, Vander Wal et al., 2013]. While we find that this is the case in the absence of gene flow or if gene flow is very high, we also find that the contribution of de novo mutations can dwarf the contribution of standing variation for intermediate migration rates (see e.g., Figure 1). Also, we find that not only the initial size of the total population plays a major role, but also the variation in population densities across habitats (Figure 4).

The main short-coming of our approach is the inability to account correctly for the time-inhomogeneity of selective coefficients of wildtype and mutant individuals. This becomes critical for mutants arising just before the second deterioration event, as their probability of establishment will be closer to 2*z* than the approximation we used. This discrepancy increases with increasing migration rate (see eqs. (3) and (4)) and decreasing *s* (as slightly deleterious mutations are less likely to be purged before time *θ*). Hence, for slightly deleterious mutations our model underestimates the probability of rescue (see figure S3). It would be interesting to generalize our approach in such a way to account correctly for time-inhomogeneous selective coefficients, which could be achieved by fusing the approaches of Peischl and Kirkpatrick [2012] and Tomasini and Peischl [2018]. This is, however, a mathematically challenging endeavour and beyond the scope of this paper. Another interesting extension of our model would be to account for more then two demes. This would allow us to study different modes of dispersal, e.g., island models vs. stepping stone model, and could help to explain experimental findings that show that the mode of dispersal can strongly influence a populations chance of survival [Bell and Gonzalez, 2011].

In our analysis, we assumed mutations that establish in isolation from other genetic events that may interfere with the process (*e.g.* clonal interference, [Gerrish and Lenski, 1998]). Therefore, we expect our results to hold in species reproducing sexually with strong recombination. By excluding competition with concurrent mutations from our analysis, we expect this model to be less predictive for organisms reproducing with low recombination rates - or for mutations occurring in regions with low recombination rate. However, some of our results could still be valuable, as many of the effects that we described depend strongly on ecological aspects (such as carrying capacities, growth rate, migration rate) and evolutionary rescue focuses on relatively short periods such that co-segregation of multiple mutations seems unlikely.

Our approach could help improve understanding some of the results found in experimental setups (*e.g.* Bell and Gonzalez [2011]) and in theoretical investigations (*e.g.* Uecker et al. [2013]) about the effects of dispersal on the probability of evolutionary rescue. The simple and intuitive analytical predictions are imperative for our understanding of evolutionary rescue in structured populations and help us sharpen our intuition about the interactions of ecological and evolutionary process on short time-scales. A setup similar to the one proposed by Bell and Gonzalez [2011], with sub-populations of yeast exposed to a gradient of salt changing in time would be ideal to test our predictions.

## Acknowledgements

We thank Sally Otto and Mark Kirkpatrick for stimulating discussions on this subject.