Peter Czuppon

François Blanquart

Hildegard Uecker

Florence Débarre

The e ect of habitat choice on evolutionary rescue in subdivided populations

Keywords: evolutionary rescue, local adaptation, source-sink dynamics, dispersal, gene flow, habitat choice, density-dependent dispersal

Evolutionary rescue is the process by which a declining population successfully adapts genetically to avoid extinction. In a structured environment that deteriorates patch by patch, dispersal can substantially alter the chances of evolutionary rescue of a wild-type population not viable in deteriorated patches. Here, we investigate the effect of different dispersal schemes and intensities on the probability of successful establishment of a mutant population adapted to the deteriorated environment. We find that the probability of evolutionary rescue can undergo up to three phases when increasing the rate of dispersal: (i) at low dispersal rates, the probability of establishment of a mutant population increases; (ii) then at intermediate dispersal rates the establishment probability decreases; and (iii) at large dispersal rates, the population homogenizes, either promoting or suppressing the process of evolutionary rescue, depending on the fitness difference between the mutant and the wild type. Our results show that habitat choice, when compared to uniform dispersal, impedes successful adaptation when the mutant has the same habitat preference as the wild type, but promotes adaptation when the mutant mainly immigrates into patches where it has a growth advantage over the wild type.

Introduction

Facing current anthropogenic environmental changes such as deforestation, soil and water contamination or rising temperatures, the populations of many species are declining and might eventually go extinct [START_REF] Bellard | Impacts of climate change on the future of biodiversity[END_REF][START_REF] Alexandre | A macroecological approach to evolutionary rescue and adaptation to climate change[END_REF]. Pests and pathogens experience similarly strong selective pressures as a result of increased consumption of antibiotics and use of pesticides [START_REF] Ramsayer | Evolutionary rescue in populations of pseudomonas fluorescens across an antibiotic gradient[END_REF][START_REF] Kreiner | Population genomics of herbicide resistance: Adaptation via evolutionary rescue[END_REF]. The process of genetic adaptation that saves populations from extinction is termed evolutionary rescue. It is defined as an initial population decline followed by recovery due to the establishment of rescue types, resulting in a U-shaped demographic trajectory over time [START_REF] Gomulkiewicz | When does evolution by natural selection prevent extinction?[END_REF]. In recent years, empirical examples of evolutionary rescue have accumulated (as reviewed by [START_REF] Alexander | Priyanga Amarasekare. The role of density-dependent dispersal in source-sink dynamics[END_REF][START_REF] Carlson | Evolutionary rescue in a changing world[END_REF][START_REF] Bell | Evolutionary rescue[END_REF]. Evolutionary rescue has been observed both in wild populations (e.g. Vander [START_REF] Vander Wal | Evolutionary rescue in vertebrates: evidence, applications and uncertainty[END_REF][START_REF] Giallonardo | Viral biocontrol: grand experiments in disease emergence and evolution[END_REF][START_REF] Gignoux-Wolfsohn | Genomic signatures of evolutionary rescue in bats surviving white-nose syndrome[END_REF] as well as laboratory experiments (e.g. [START_REF] Bell | Evolutionary rescue can prevent extinction following environmental change[END_REF][START_REF] Agashe | Effects of founding genetic variation on adaptation to a novel resource[END_REF][START_REF] Lachapelle | Evolutionary rescue of sexual and asexual populations in a deteriorating environment[END_REF][START_REF] Lindsey | Evolutionary rescue from extinction is contingent on a lower rate of environmental change[END_REF][START_REF] Rike | Hybridization facilitates evolutionary rescue[END_REF].

In mathematical models, evolutionary rescue is often studied in a spatially homogeneous situation where the whole population experiences a sudden decrease in habitat quality. In this setting, a large number of theoretical results have been established, for example on the effects of recombination [START_REF] Uecker | The role of recombination in evolutionary rescue[END_REF] and horizontal gene transfer [START_REF] Samuel | Plasmids and evolutionary rescue by drug resistance[END_REF], reproduction mechanisms [START_REF] Glémin | Adaptation and maladaptation in selfing and outcrossing species: New mutations versus standing variation[END_REF][START_REF] Turgeon | Compensatory immigration depends on adjacent population size and habitat quality but not on landscape connectivity[END_REF], intra-and interspecific competition [START_REF] Miles | How competition affects evolutionary rescue[END_REF], predation pressure [START_REF] Osmond | When predators help prey adapt and persist in a changing environment[END_REF], bottlenecks [START_REF] Martin | The probability of evolutionary rescue: towards a quantitative comparison between theory and evolution experiments[END_REF], different genetic pathways [START_REF] Matthew M Osmond | Genetic paths to evolutionary rescue and the distribution of fitness effects along them[END_REF], and the context-dependent fitness effects of mutations [START_REF] Anciaux | Evolutionary rescue over a fitness landscape[END_REF]. In fragmented environments however, habitat deterioration is not necessarily synchronized across patches: there can be a transient spatially heterogeneous environment consisting of old-and new-habitat patches until eventually the whole environment has deteriorated. If individuals that populate different patches are able to move between those, the effect of dispersal on evolutionary rescue needs to be taken into account [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF][START_REF] Tomasini | When does gene flow facilitate evolutionary rescue? bioRxiv[END_REF]. Experiments that study the effect of dispersal on evolutionary rescue are rare but indicate that even low dispersal rates can significantly increase the likelihood of successful genetic adaptation [START_REF] Bell | Adaptation and evolutionary rescue in metapopulations experiencing environmental deterioration[END_REF].

Evolutionary rescue in a situation where one patch after the other deteriorates is tightly linked to the study of adaptation to a heterogeneous environment with source-sink dynamics. These describe a spatially heterogeneous environment that is constant in time where a population in unfavorable habitats can be maintained by constant immigration of the wild type. Experimental and theoretical studies have found that dispersal can have a positive or a negative effect on genetic adaptation in a heterogeneous environment (see e.g. [START_REF] Holt | How does immigration influence local adaptation? a reexamination of a familiar paradigm[END_REF]; [START_REF] Gomulkiewicz | The effects of density dependence and immigration on local adaptation and niche evolution in a black-hole sink environment[END_REF] for positive, [START_REF] Storfer | Gene flow and ineffective antipredator behavior in a streambreeding salamander[END_REF]; García-Ramos and Kirkpatrick (1997); [START_REF] Kirkpatrick | Evolution of a species' range[END_REF]; [START_REF] Fedorka | The role of gene flow asymmetry along an environmental gradient in constraining local adaptation and range expansion[END_REF] for negative, and [START_REF] Tadeusz | Adaptation to marginal habitats: contrasting influence of the dispersal rate on the fate of alleles with small and large effects[END_REF]; [START_REF] Gallet | Experimental demonstration of the impact of hard and soft selection regimes on polymorphism maintenance in spatially heterogeneous environments †[END_REF] for both effects).

In theoretical studies of local adaptation and evolutionary rescue, dispersal is typically assumed to be random, i.e. dispersing individuals are distributed uniformly among patches. Only few deterministic investigations in the context of local adaptation in source-sink sys-3 tems have taken into account non-random dispersal patterns (e.g. [START_REF] Tadeusz | Demography of source-sink populations and the evolution of ecological niches[END_REF][START_REF] Holt | Adaptive evolution in source-sink environments: Direct and indirect effects of density-dependence on niche evolution[END_REF][START_REF] Tadeusz | Evolutionary consequences of asymmetric dispersal rates[END_REF]Amarasekare, 2004). This analytical focus on random dispersal is in stark contrast to actually observed dispersal schemes in nature [START_REF] Edelaar | Matching habitat choice causes directed gene flow: A neglected dimension in evolution and ecology[END_REF][START_REF] Clobert | Informed dispersal, heterogeneity in animal dispersal syndromes and the dynamics of spatially structured populations[END_REF][START_REF] Edelaar | Non-random gene flow: an underappreciated force in evolution and ecology[END_REF]. Here, we explore and compare the effects of several biologically motivated dispersal schemes on adaptation and evolutionary rescue in a stochastic framework.

One of the best documented modes of non-random dispersal is density-dependent dispersal. Density dependence can be positive or negative: either individuals prefer to settle or stay in large groups (positive density-dependence), or they choose to remain in or move to less populated regions (negative density-dependence). Density-dependent dispersal, of either form, is ubiquitously found in nature and has been reported in many species across the tree of life, including insects [START_REF] Stacy | The importance of growing up: juvenile environment influences dispersal of individuals and their neighbours[END_REF], spiders [START_REF] De | Information use and density-dependent emigration in an agrobiont spider[END_REF], amphibians [START_REF] Gautier | Gregarious behaviour in a salamander: attraction to conspecific chemical cues in burrow choice[END_REF], birds [START_REF] Wilson | Density-dependent immigration promotes population stability in a long-distance migratory bird[END_REF], fishes [START_REF] Turgeon | Compensatory immigration depends on adjacent population size and habitat quality but not on landscape connectivity[END_REF], and mammals [START_REF] Støen | Inversely densitydependent natal dispersal in brown bears ursus arctos[END_REF].

Another well-established dispersal scheme is habitat choice, whereby individuals tend to immigrate into habitats they are best adapted to. This mechanism has for example been reported in lizards [START_REF] Bestion | Dispersal response to climate change: scaling down to intraspecific variation[END_REF], birds [START_REF] Dreiss | Local adaptation and matching habitat choice in female barn owls with respect to melanic coloration[END_REF][START_REF] Benkman | Matching habitat choice in nomadic crossbills appears most pronounced when food is most limiting[END_REF], fishes [START_REF] Daniel | Phenotype-dependent native habitat preference facilitates divergence between parapatric lake and stream stickleback[END_REF], worms [START_REF] Mathieu | Habitat quality, conspecific density, and habitat pre-use affect the dispersal behaviour of two earthworm species, Aporrectodea icterica and Dendrobaena veneta, in a mesocosm experiment[END_REF], and ciliates [START_REF] Jacob | Gene flow favours local adaptation under habitat choice in ciliate microcosms[END_REF][START_REF] Jacob | Habitat choice meets thermal specialization: Competition with specialists may drive suboptimal habitat preferences in generalists[END_REF].

Here, we concentrate on non-random dispersal effects of the immigration process. Yet, we keep in mind that density-dependence or habitat choice can also affect the emigration behavior, i.e. the likelihood for an individual to leave its current location, or even the vagrant stage when the individual is in the process of dispersal [START_REF] Bowler | Causes and consequences of animal dispersal strategies: relating individual behaviour to spatial dynamics[END_REF]Ronce, 2007).

In the following, we explicitly account for these non-random dispersal schemes in the context of genetic adaptation to a deteriorating and spatially structured environment. We model an environment that consists of various patches with one of two possible habitats: the 'old' habitat, in which both wild types and mutants are viable, and the 'new' habitat, where in the absence of immigration the wild-type population will eventually go extinct. In this framework, we study four biologically motivated dispersal patterns and compare them to the random dispersal scheme. We start by investigating their consequences for the establishment dynamics of an adapted mutant in a time-constant heterogeneous environment. From there, we derive an approximation for adaptation in a source-sink setting. Using these results, we study the probability of evolutionary rescue, i.e. of adaptation in the scenario where patches, one after the other, deteriorate over time until all locations contain the new habitat. We find that dispersal bias has a direct effect on the local growth rates which in turn affect the probability of establishment and evolutionary rescue.

Model

We consider a spatially structured environment consisting of M patches all connected to each other. The habitat of a patch is either in the old or in the new state, corresponding to habitat quality before and after environmental deterioration, respectively. The transition from the old to the new habitat is assumed to be irreversible. Patches are populated by two types 4 of asexually reproducing, haploid individuals, either wild type or mutant. Generations are discrete and non-overlapping generations (Wright-Fisher process). Wild type and mutant populations can each be maintained at carrying capacity in old-habitat patches; the mutant has a lower growth rate there. In new-habitat patches, the wild type population declines locally while the mutant has a positive growth rate -we will therefore call it a 'rescue mutant'.

We consider a time-varying environment, such that one after the other every τ generations, the habitat of a patch deteriorates (from old to new state). Initially (t < 0), all patches are of the old-habitat type. At time t = 0, the first patch deteriorates. After (M -1)τ generations, all patches are of the new-habitat type. We denote the time-dependent frequency of oldhabitat patches by f old . It equals 1 before the first environmental change takes place (t < 0), and decreases by 1/M after each environmental deterioration event until it eventually hits 0, when all patches have undergone the environmental change. This environmental setting corresponds to the one analyzed by [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF] and more recently in the special case of just two patches by [START_REF] Tomasini | When does gene flow facilitate evolutionary rescue? bioRxiv[END_REF].

The individuals are assumed to go through the following life-cycle: (i) Dispersal: individuals may move between patches; (ii) Reproduction: individuals reproduce within patches (the amount of offspring that is produced depends on the parent's type and its current location); (iii) Mutation: wild-type individuals mutate to the rescue mutant type with probability θback mutations from the mutant to the wild type are neglected; (iv) Regulation: the population size is (down)regulated to the carrying capacity K , if necessary. If the population size is below the carrying capacity, the regulation step is ignored.

. Old-habitat dynamics

We assume that in old-habitat patches, both types are able to maintain the population at carrying capacity K . Thus, independently of population composition in these patches, the carrying capacity is always reached after reproduction. We denote the fecundities of the wildtype and the mutant by ω w and ω m , respectively. We impose an adaptation trade-off for the rescue mutant, i.e. the mutant is less fit than the wild type in old-habitat patches (ω m < ω w ). In the following, we choose offspring numbers ω i large enough so that the reproduction, mutation and regulation events are well approximated by a Wright-Fisher process, a binomial sampling with size K and success probability p m ,

p m = ω m N old m + θω w N old w ω w N old w + ω m N old m , (1)
where the random variable N k i denotes the population sizes of type i (mutant or wild-type) in patches with habitat k (old or new) after the dispersal step, and θ is the mutation probability (wild-type individuals turning into mutants). Later on in the mathematical analysis, we approximate the binomial distribution by a Poisson distribution, which is reasonable for low mutant numbers, large wild-type numbers and a small mutation probability θ (of order 1/K ). The rate of this Poisson distribution is given by

K p m = K ω m N old m + θω w N old w ω w N old w + ω m N old m .
(2)

5

Setting N old m = 1 and neglecting mutations (θ = 0), we define the local growth rate of a single mutant by

1 + s old = K ω m ω w N old w .
(3) This is the average offspring number of one mutant individual after a completed life cycle. While still rare, mutant individuals will reproduce independently of each other and their dynamics will be described by the local growth rate given in eq. ( 3). The fecundity of mutant individuals in old-habitat patches is assumed to be lower than that of wild-type individuals, i.e. ω m < ω w . Still, the mutant's local growth rate, given by eq. ( 3), can be larger than one (s old > 0). This happens when the wild-type population in old habitats, N old w , becomes very small, which again depends strongly on the dispersal scheme and rate.

. New habitat dynamics

In the new habitat and in the absence of immigration, the wild-type population will go extinct. To account for this, we assume that the number of wild-type offspring in new-habitat patches is a Poisson distributed value with parameter (1 -r ), where r measures how strongly the wild type is affected by the environmental deterioration. For r = 1 the wild-type population becomes locally extinct in new-habitat patches after one generation.

The mutant type, in contrast, has a local growth rate larger than one and will (in expectation) grow in numbers. Again, the number of offspring is Poisson distributed with per-capita rate (1 + s new ), the local growth rate of the mutant in new-habitat patches.

Since we are interested in the dynamics when the mutant is rare, we do not explicitly consider density regulation in these patches in our calculations.

. Dispersal mechanisms

We assume that dispersal is cost-free, i.e. all emigrating individuals will settle in a patch, leaving the global population size before and after dispersal unchanged. We split the dispersal step into emigration and immigration. We focus on habitat choice during immigration, i.e. individuals have a bias to immigrate into patches of a certain habitat type. The bias of immigration into new-habitat patches is set equal to one, without loss of generality. The bias of immigration into an old-habitat patch is denoted by π i , with the index i indicating the wild-type (w) or mutant (m) bias. For π i < 1, individuals of type i are more likely to settle in new-habitat patches, while for π i > 1 the reverse is true. For π i = 1, individuals do not have a preference and dispersal is random.

We consider equal and constant emigration rates for both types and habitats throughout the manuscript. We denote the probability for an individual to leave its natal patch by m. Then, the probability for an individual of type i born in the old habitat to disperse to the new habitat is given by

m old→new i = m 1 -f old 1 -f old + π i f old = 1 -m old→old i , (4)
where m old→old i denotes the probability for a type i individual to remain in an old-habitat patch (or to emigrate and re-immigrate into an old-habitat patch), and f old is the frequency of 6 old-habitat patches. The rates for dispersal from new patches are given analogously.

From a biological perspective, there are a number of dispersal schemes that are of particular interest. Precisely, we distinguish between the following five scenarios (see also Figure 1 for an overview):

• Absolute habitat choice (ABS): Individuals prefer to immigrate into the habitat where they have the largest number of offspring before regulation. In our model this translates to both π w and π m being larger than 1, i.e. there is a bias towards old-habitat patches. In practice, individuals are thought to use biotic or abiotic cues to preferentially immigrate into habitats where their fecundity is highest when compared to other habitats. This type of dispersal, i.e. matching habitat choice, has for example been observed with common lizards Zootoca vivipara [START_REF] Bestion | Dispersal response to climate change: scaling down to intraspecific variation[END_REF], three-spine sticklebacks Gasterosteus aculeatus [START_REF] Daniel | Phenotype-dependent native habitat preference facilitates divergence between parapatric lake and stream stickleback[END_REF], and barn owls Tyto alba [START_REF] Dreiss | Local adaptation and matching habitat choice in female barn owls with respect to melanic coloration[END_REF].

The same range of parameters (π w > 1, π m > 1) is obtained when implementing positive density-dependent dispersal. In this dispersal scheme, individuals are more likely to immigrate into patches with higher population densities, so both the wild type and the mutant will prefer the old habitat where the carrying capacity is always reached. Highly populated locations can be an indication for a safe shelter, relevant for prey species, and potentially increase the mating success of individuals. This type of positive densitydependent dispersal (also called conspecific attraction) on immigration is for example found in several amphibians, e.g. the salamander species Mertensiella luschani [START_REF] Gautier | Gregarious behaviour in a salamander: attraction to conspecific chemical cues in burrow choice[END_REF] and Ambystoma maculatum [START_REF] Greene | The effects of conspecifics on burrow selection in juvenile spotted salamanders (ambystoma maculatum)[END_REF] or the frogs Oophaga pumilio [START_REF] Folt | Spatial patterns of the frog Oophaga pumilio in a plantation system are consistent with conspecific attraction[END_REF].

• Relative habitat choice (REL): Under this dispersal scheme, individuals tend to immigrate to habitats where they are fitter than the other type. This translates into the wild type preferring old patches, i.e. π w > 1, while mutants tend to immigrate more often to new habitats, i.e. π m < 1. Empirical evidence of this mechanism is scarce. It resembles the recently observed dispersal patterns of the ciliates Tetrahymena thermophila with a specialist and generalist type [START_REF] Jacob | Habitat choice meets thermal specialization: Competition with specialists may drive suboptimal habitat preferences in generalists[END_REF]. The specialist disperses to its preferred habitat while the generalist prefers to immigrate to a suboptimal habitat where it outcompetes the specialist.

• Negative density-dependent dispersal (DENS): Here, we focus on negative densitydependent dispersal, i.e. individuals are more likely to move to less populated patches. In these locations, resources might be more abundant, intra-specific competition alleviated and the chance of infection transmission decreased, which may compensate for the potentially reduced habitat quality. The corresponding parameter choice in our model is π w < 1, π m < 1, i.e. both types have a higher likelihood to immigrate to new-habitat patches, which are less populated during the relevant phase of rescue. The mutant being initially rare, it is unlikely that the carrying capacity is reached in these patchesas assumed throughout the analysis. Various empirical examples of negative densitydependent dispersal exist. Density-dependent immigration effects as described here, are for example found in the damselfish species Stegastes adustus

π m = π w = 1 for RAND (•), π m = π w = 2 for ABS (■), π m = 0.5, π w = 2 for REL ( ), π m = π w = 0.5
for DENS ( ), and π m = 2, π w = 0.5 for MAL ( ). All the results derived below depend continuously on these parameters, so that varying any of the parameters will not result in a sudden change or discontinuity of the corresponding curves.

2012) and the migratory birds Setophaga ruticilla [START_REF] Wilson | Density-dependent immigration promotes population stability in a long-distance migratory bird[END_REF]. In both species, immigrants fill the empty space left by dead or emigrated individuals. Notably, in the fish species, negative density-dependent immigration is further enhanced by residents defending their territory against potential immigrants.

• Maladaptive dispersal (MAL): For completeness, we also consider the scenario in which both types disperse preferentially into the habitat they are relatively less fit in (at least initially), i.e. we have π w < 1 and π m > 1. This dispersal scheme is similar to the concept of an 'ecological trap': Individuals tend to immigrate into patches that cannot sustain a population, in its most extreme form resulting in the extinction of the species [START_REF] Battin | When good animals love bad habitats: Ecological traps and the conservation of animal populations[END_REF]. This does not exactly apply to our framework since here the mutant is able to maintain a population in old-habitat patches, hence our choice of the term 'maladaptive dispersal'.

• Random dispersal (RAND): Individuals do not have a bias towards any of the two habitats, π w = 1, π m = 1. Most theoretical results examining the interplay of dispersal and establishment have been using this dispersal scheme. Therefore, we use it as a benchmark to which we compare the above defined dispersal patterns.

π m Mutant preference for the old habitat 0 < π m see Fig.1 M Number of patches 2 ≤ M 10 f old Frequency of old-habitat patches 0 ≤ f old ≤ 1 0.5 θ Mutation probability 0 < θ 1 25M K τ
Time interval between two consecutive deterioration events 0 < τ 100 All the model parameters are summarized in Table 1 along with the default parameter values and ranges. If not stated otherwise, the default parameter values are used for the stochastic simulations.

. Simulations

The algorithm implements the life cycle described above. First, a random number of dispersing individuals is drawn from a binomial distribution with success probability m and sample size equal to the local population size. The dispersing individuals are distributed according to one 9 of the studied dispersal patterns. Then reproduction happens locally. In old-habitat patches, the number of mutant offspring is drawn from a binomial distribution with sample size K and parameter p m as given in eq. ( 1). By doing so, reproduction, mutation and regulation are all merged in this single step. In new-habitat patches, reproduction is simulated by drawing a Poisson distributed number for both types according to the corresponding mean offspring numbers, 1 -r for the wild type and 1 + s new for the mutant. Then mutation of wild-type individuals takes place with rate θ, implemented using a binomial distribution. Lastly, if necessary, new-habitat patches are down-regulated back to carrying capacity using a hypergeometric distribution.

In Figures 234, we simulate a heterogeneous environment that is constant in time, i.e. no patches deteriorate. Initial population sizes are K wild-type individuals in old-habitat patches, and the stationary wild-type population size N new w in new-habitat patches (see Section S1 in the Supplementary Information (SI) for details). Figure 2 is started with initially one mutant either in an old-or new-habitat patch and the corresponding wild-type population size is reduced by one; in this figure, the mutation probability is set to zero. In all the other figures, mutants solely arise due to mutations. We stop the simulations when the total number of mutants in all new-habitat patches exceeds 0.8 × K × M (1 -f old ) (except in the case of absolute habitat choice and dispersal rates larger than 0.2, since then most individuals settle in oldhabitat patches; in this case the condition is adapted to the mutant number exceeding 80% of the total population in old-habitat patches), or, in Figure 2 where there is no mutation, if the mutant has gone extinct.

In the rescue scenario, where one patch after the other deteriorates (Figures 5 and6), we initialize all patches with K wild-type individuals. Simulations are run until either the population has gone extinct or the (global) mutant population size exceeds 0.8 × K × M after the last deterioration event has happened. Unless stated otherwise, the simulation results are averages of 10 5 independent runs. All simulations are written in the C++ programming language and use the Gnu Scientific Library. The codes and data to generate the figures are deposited on Gitlab (https://gitlab.com/pczuppon/evolutionary_rescue_and_dispersal).

Results

We investigate the effect of the different dispersal schemes on the probability of successful adaptation and evolutionary rescue. We first compute the establishment probability of a single mutant individual arising either in an old-or in a new-habitat patch. We then link this probability to the dynamics of a source-sink system, i.e. a fixed environment with a certain number of old habitats (sources) and new-habitat patches (sinks). We derive an expression for the probability of a mutation to emerge and establish in a given time interval. We call this second quantity the probability of adaptation. Lastly, we study the time-varying scenario where patches, one after the other, deteriorate. We consider a third quantity, the probability of evolutionary rescue, which corresponds to the probability that a mutant appears by mutation and establishes in the new environment where all patches have deteriorated. The theoretical results are complemented by stochastic simulations that support our predictions and help visualize the differences between the different dispersal schemes.

. Establishment probability in a heterogeneous environment

We derive the probability of establishment of a mutant population starting with a single individual initially located either in an old-or a new-habitat patch. In this analysis, we ignore further mutations and are only concerned with the fate of this single mutant lineage. The dynamics of the mutant population can be described by a two-type branching process, i.e. all mutant individuals, descendants of the initial mutant, evolve independently of each other. This is a reasonable assumption as long as the overall number of mutants is a lot smaller than the population size of the wild type. The two "types" of the two-type branching process correspond to the two habitat types (old and new). The process tracks the numbers of oldhabitat and new-habitat mutants, N k m with k denoting the habitat type (old or new). The number of offspring of a single mutant can be approximated by Poisson distributed numbers (see eqs. ( 2) and ( 3)). The mean number of offspring of a single mutant, either in an old-or a new-habitat patch, is then given by the following mean reproduction matrix:

old patch new patch old patch 1 -m old→new m (1 + s old ) m old→new m (1 + s new ) new patch m new→old m (1 + s old ) 1 -m new→old m (1 + s new ) , ( 5
)
where the rows denote the parent locations, and the columns the patch type of the offspring. For example, the top-left entry reads as the probability for the parent to stay in an old-habitat patch (1 -m old→new m ) times the average number of offspring in these patches, given by the mean of the corresponding Poisson distribution with rate (1+s old ), cf. eq. ( 3). The other entries are obtained analogously.

The survival probability of this multi-type branching process, ϕ k with k indicating the initial habitat type of the mutant, is then given by the unique positive solution of the following system of equations (see Haccou et al., 2005, Chapters 5.3 and 5.6)

1 -ϕ old = ∞ j =0 P( j offspring in old habitat)(1 -ϕ old ) j +P( j offspring in new habitat)(1 -ϕ new ) j = exp -1 -m old→new m (1 + s old )ϕ old -m old→new m (1 + s new )ϕ new , 1 -ϕ new = exp -m new→old m (1 + s old )ϕ old -1 -m new→old m (1 + s new )ϕ new . (6)
Intuitively the left hand side, the extinction probability, equals the sum over all possible scenarios of the trajectories towards extinction, e.g. the initial individual having j offspring in a patch of type k, old or new, and all of these j offspring becoming extinct ((1ϕ k ) j ). Unfortunately, a general analytical solution to these equations is not accessible, but the equations can be solved numerically. For weak selection and (potentially) weak dispersali.e. s old , s new , m 1 needs to hold for at least two of the three parameters -an approximation is available: see for example Haccou et al. (2005, Theorem 5.6) for the general theory and [START_REF] Tomasini | Establishment of locally adapted mutations under divergent selection[END_REF] for an application in a similar setting. The detailed derivation is presented in the SI, Section S2. We find

ϕ old ≈ s old + s old 1 -f old + π m f old C (s old -s new ) + m C s new (1 -f old ) + s old π m f old -(s old -s new )(1 -f old ) , ϕ new ≈ s new (1) local growth parameter + s new 1 -f old + π m f old C (s new -s old )
(2) effect of the heterogeneous environment

+ m C s new (1 -f old ) + s old π m f old -(s new -s old )π m f old ,
(3) effect of dispersal: new patches + old patchesloss to the other patch type (7) where C is a scaling constant given by

C = (1 -f old + π m f old ) (1 -f old )(s new -s old + m) 2 + π m f old (s new -s old -m) 2 . ( 8
)
The first term in the approximation of the establishment probabilities (ϕ old and ϕ new ) in eq. ( 7) describes the local growth depending on the habitat type under study. The second term captures the growth rate differences between the two habitat types.The factor (1-f old +π m f old ) accounts for the biased dispersal patterns (when π m = 1)). The third term in the equations corresponds to the direct effect of dispersal on the establishment probability. The first two summands in the bracket are the same for both establishment probabilities. They represent the general effect of dispersal due to the dynamics from new-habitat patches (first summand) and old-habitat patches (second summand). The dispersal bias induced by π m changes the relative impact of old-vs. new-habitat patches. Finally, the last summand in the bracket measures the growth rate loss (or gain) due to dispersal to the other patch type. It therefore differs between the two approximations.

Note that in these equations, the competition of the mutant with the wild-type in the oldhabitat patches appears in the local growth rate s old , defined in eq. ( 2). This quantity is not constant, but instead depends on the wild type population size in old-habitat patches, which itself depends on the wild type's dispersal and growth rate in both habitats.

If the emigration probability is zero (m = 0), the subpopulations in each habitat evolve in isolation from each other and we recover Haldane's classical result for the establishment probability of a slightly advantageous mutant: ϕ new = 2s new [START_REF] Haldane | A mathematical theory of natural and artificial selection, part v: Selection and mutation[END_REF]. Furthermore, in the case of random dispersal (π w = π m = 1) and for equal number of old-and new-habitat patches ( f old = 1/2), we obtain the approximation found in Tomasini and Peischl (2018) (compare system (7) to their eqs. ( 4) and ( 5)). Note that the approximation is independent of the actual number of patches, but only depends on the environmental configuration determined by the frequency of old-habitat patches f old .

Comparison to simulations and qualitative behavior

We compare in Figure 2 our predictions from eqs. ( 6) and ( 7) to simulation results for different values of the emigration rate m. We find good agreement with the numerical solution of eq. ( 6) Comparison with the results from stochastic simulations show very good agreement with our approximation found in eq. (7) (dashed lines). The solid lines are the numerical solution of eq. ( 6). The results in subfigure (a) show a clear separation of the three regions of the establishment probability as discussed in the main text.

(solid lines), which justifies our assumption of Poisson reproduction. The approximation given in eq. ( 7) (dashed lines) deviates slightly from the simulation results in regions where m, s new and s old are not small, i.e. when the assumptions made in the analytical derivation do not hold anymore.

The qualitative dependence of the establishment probabilities ϕ old and ϕ new on the dispersal probability m is similar for all dispersal schemes. The shape of the curve however strongly depends on the fecundity ω m of mutants in the old habitat. Before discussing the differences between the dispersal schemes, we first provide a qualitative understanding of this general behavior.

13

For the probability of establishment of a single mutant in an old-habitat patch (ϕ old ), we observe up to three different regions, cf. Figure 2(a). This is in line with previous observations in the context of local adaptation (e.g. [START_REF] Tadeusz | Demography of source-sink populations and the evolution of ecological niches[END_REF][START_REF] Tomasini | Establishment of locally adapted mutations under divergent selection[END_REF] and evolutionary rescue [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF]. We define the regions as follows: (i) an initial increase of the establishment probability at low dispersal rates m; (ii) a local maximum with a subsequent decrease of the establishment probability; (iii) an increase of the establishment probability for high dispersal rates.

A detailed assessment and explanation of the regions is provided in the SI, Section S2.1. Briefly, in region (i), the prevalent effect is the dispersal of mutants from old-to new-habitat patches where they are fitter than the wild type, thus increasing the establishment probability. This effect is mediated through the third term of the establishment probability in eq. ( 7). Region (ii), beginning with the local maximum, is a result of two counteracting processes: increased emigration of individuals from the old habitat and larger amounts of mutant individuals that, once emigrated to a new habitat, reimmigrate into an old-habitat patch. If we increase the emigration probabilities, more individuals will emigrate out of old-habitat patches, lowering competitive pressure in old-habitat patches. As a result, local growth rates of the mutant in oldhabitat patches, s old are higher. This effect was termed 'relaxed competition' by [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF]. Higher dispersal rates however also have a negative effect on mutant establishment, by lowering the number of mutants in new-habitat patches through back-migration. Depending on whether the effect of back-immigration is stronger than the effect of relaxed competition, the establishment probability either has a local maximum or not, compare 2(a) and (c). Finally, in region (iii), dispersal is so large that the population is close to being well-mixed. This results in less competitive pressure in old-habitat patches so that the local growth rate of the mutant in these patches, s old (first term in eq. ( 7)), becomes positive.

The width of region (ii) strongly depends on the fecundity of the mutant in the old habitat, ω m . If ω m is high, the local growth rate of the mutant s old starts to increase at a lower dispersal rate (see Figure S1). This can make region (ii) disappear, as visible in Figure 2(c). On the other hand, for low mutant fecundity values ω m , region (iii) might vanish (see Figure S2). There, the mutant is strongly disadvantageous in old-habitat patches when compared to the wild type, and the wild-type population will always outcompete the mutants due to the much higher offspring numbers.

We analyze the qualitative behavior of the establishment probability of a mutant emerging in the new habitat, ϕ new in a similar way (Figures 2(b,d)). The establishment probability ϕ new decreases at low dispersal rates: Since we let the mutant start in a new-habitat patch, where it fares better than the wild type, there is no initial benefit due to dispersal (the third term in eq. ( 7) is negative for ϕ new ). The interpretation of region (ii), describing the trajectory for intermediate emigration rates m, is the same as for ϕ old above. For large emigration rates m, region (iii), the resulting establishment probability is a combination of the local growth rate and the dispersal effect, the first and third terms in eq. ( 7). This is because the mutant can migrate to old-habitat patches, where it will enjoy relaxed competition.

Comparison of dispersal schemes

We now turn to the discussion of how the establishment probabilities compare for the various dispersal schemes. We consistently observe that negative density-dependent dispersal (green curves and downward triangles in Figure 2) enhances establishment when compared to the random dispersal scheme (black curves and circles). This can be attributed to two reasons:

(1) the mutant is more likely to disperse to the new habitat where it outcompetes the wild type (stronger weighting of new-habitat patches in the third term in eq. ( 7)); and (2) since the wild type prefers to settle in new-habitat patches (π w < 1), individuals in old-habitat patches experience relaxed competition for lower dispersal rates m, thus increasing the local growth rate s old , i.e. region (iii) is shifted to the left. An analogous (but reversed) argument explains why absolute habitat choice (blue curves and upward triangles in Figure 2) is always lower than the random dispersal scheme (black curves and circles).

The effect of relative habitat choice (orange curves and squares in Figure 2), where each type has a bias to move to the habitat where it is relatively fitter than the other type, is more involved. We disentangle the effects separately for each region. In region (i) at low emigration probabilities, the curve is almost identical to that of the negative density-dependent pattern. The mutant preference of these two dispersal modes is the same. The movement of the rare mutants is the prevailing force in this parameter regime, which explains the alignment of the green (negative density-dependent dispersal) and the orange curves. For intermediate dispersal rates, region (ii), the effect of the heterogeneous environment (second term in eq. ( 7)) becomes stronger, i.e. the local growth rate s old increases because of relaxed competition in old-habitat patches. For relative habitat choice, the wild type is more likely to re-immigrate into old-habitat patches and thereby increases the population size in these locations. This reduces the effect of relaxed competition. Therefore, the orange line now drops below the green curve and even starts to decrease (Figure 2(a)). For high emigration probabilities m, region (iii), the competitive pressure in old-habitat patches relaxes. Again, this region is dominated by the movement of wild-type individuals. In the random dispersal scheme (black), the wild type has a lower likelihood to be in old-habitat patches than with the relative habitat choice scheme (orange), thus the black curve is above the orange curve. For very large dispersal rates, also the absolute habitat choice scheme (blue curve) can lead to higher values of ϕ old than relative habitat choice (orange), cf. Figure 2(c). In this parameter regime, the mutant has a larger growth rate in old-than in the new-habitat patches (s old > s new ). Therefore, it is beneficial for the mutant to stay or to re-immigrate into old-habitat patches.

Finally, for the maladaptive dispersal scheme (purple curves and diamonds in Figure 2) we see that for low dispersal rates m the results match those obtained under the absolute dispersal scheme. The mutant preferences being the same, this again shows that this region is dominated by the mutant's dispersal behavior. For intermediate to large dispersal rates though, the maladaptive dispersal scheme results in large establishment probabilities. This is explained by the effect of strongly relaxed competition (wild-type individuals preferentially move into the new habitat) and the bias of mutants to disperse into old-habitat patches where their number of offspring individuals is now very large. Overall, this results in the highest establishment probabilities of all dispersal schemes. We note though that the term 'maladaptive dispersal' might be misleading for large dispersal values, since here the growth rate of the mutant in 15 old-habitat patches, s old , is actually larger than the growth rate in new-habitat patches, s new .

. Probability of adaptation in a heterogeneous environment

We now study the probability of adaptation when mutations occur recurrently. As in the previous section, we consider a heterogeneous environment with a fixed number of old-and new-habitat patches. This is effectively a source-sink system [START_REF] Holt | Population dynamics in two-patch environments: Some anomalous consequences of an optimal habitat distribution[END_REF][START_REF] Pulliam | Sources, sinks, and population regulation[END_REF], where old-and new-habitat patches correspond to sources and sinks for the wild type, respectively. In the previous section, we initialized the system with one mutant in either an old-or a new-habitat patch and computed the establishment probability. Now, we let mutants appear randomly within a certain time frame. The last time point at which a mutation can occur is denoted by t fin . Later, in the analysis of the probability for evolutionary rescue, this time will be replaced by the time between two consecutive patch deterioration events, τ. For now we will set this value arbitrarily to 100 and initialize the system with a fixed number of old-habitat patches.

The probability of adaptation in this setting, P adapt , is given by

P adapt = 1 -exp   -θt fin M    ϕ old f old K old habitat contribution + ϕ new (1 -f old ) N new w new habitat contribution       . ( 9
)
In words, the right-hand side is one minus the probability of no mutant establishing within the [0, t fin ] time interval. More precisely, the exponential is the probability of zero successes of a Poisson distribution. The rate of this Poisson distribution is given by the expected number of successfully emerging mutant lineages until time t fin . For t fin tending to infinity, there will almost surely be a successful mutant so that P adapt = 1. For finite values of t fin , the average number of mutations that appear until that time is given by the product of the mutation probability θ, the length of the time window of interest t fin , the number of patches M and the stationary number of wild-type individuals present in the different habitats, that is K and N new w for old-and new-habitat patches, respectively (cf. SI eq. ( S5)). Once such a mutant appears, it then has the previously computed establishment probability ϕ k to establish, depending on the patch type k (old or new) it arises in. This explains the factor ϕ k in the exponential.

We compare in Figure 3 our predictions to simulation results. The shape of the probability of adaptation as function of the emigration probability m depends on the fecundity of the mutant in old-habitat patches, ω m (Figures 3(a,c)). This is similar to the behavior of the establishment probability ϕ old in Figure 2. Likewise, the qualitative effects of the different dispersal schemes are comparable to the ones observed for the establishment probability.

In subfigures (b) and (d), we vary the frequency of old-habitat patches f old . We observe a maximum which is the result of two effects: (1) the likelihood for a mutation to appear increases with the number of wild-type individuals present in the system, which is highest for high frequencies of old-habitat patches f old , and (2) the probability of establishment of a mutant decreases with the number of old-habitat patches.

The different dispersal schemes alter both effects. Negative density-dependent dispersal (green), when compared to random dispersal (black), always shifts the maximum to higher 16 we vary the emigration rate m and observe a similar qualitative behavior as for the establishment probability ϕ k in Figure 2. In panels (b) and (d), we vary the frequency of old-habitat patches. The maximum is the result of two counteracting processes. The higher the number of old-habitat patches (i.e. the greater f old ), the larger the wild-type population. As a consequence, more mutants appear in the studied timeframe. In contrast, the less old-patch habitats there are in the environment (i.e. the lower f old ), the higher the probability of successful establishment of a mutant population. In all subfigures, the mutation probability is set to u = 1/(M K ) and the considered time-window for a mutant to appear is set to t fin = 100.

frequencies of old habitats while also increasing its quantitative value. Under negative densitydependent dispersal, mutant and wild-type individuals prefer settling in new-habitat patches (π w , π m < 1). As a result, the local population before reproduction in these patches is increased, so that the overall population size is higher compared to the other dispersal schemes.

There is therefore a higher number of mutants generated under this scheme. Additionally, the probability of establishment is also increased for negative density-dependent dispersal, further increasing the probability of adaptation (see also the discussion around Figure 2). Again, a reversed argument explains why absolute habitat choice (blue) always yields lower probabilities of adaptation than random dispersal.

. Habitat of origin of the adaptive mutation

We now identify the habitat type where the successful mutation arises. The established mutant population can arise from a mutant that is born in an old-or in a new-habitat patch, but can also be traced back to two (or more) mutant individuals, one from either patch type. For example, the approximation for the probability to observe a mutant population that can be traced back to a mutant from an old-habitat patch is the following P successful adaptation from old habitat 1 -P successful adaptation from new habitat

= 1 -exp -θt fin M ϕ old f old K exp -θt fin M ϕ new (1 -f old ) N new w .
(10) The corresponding probabilities for the other two scenarios can be computed analogously.

In Figure 4 we compare simulation results with our predictions for the origin of a successful mutant when varying the old habitat frequency f old . Surprisingly, even for a relatively strong fecundity disadvantage of the mutant in the old habitat, i.e. ω m is 10% smaller than ω w , we find that most successful mutations arise in old-habitat patches (subfigure 4(a)). Decreasing the fecundity disadvantage of the mutant by increasing its fecundity ω m further increases the number of successful mutant lineages from old-habitat patches (subfigure 4(b)). If we instead increase the fecundity difference in old habitats by decreasing ω m , we observe the opposite, i.e. eventually the probability for a successful mutation to arise in new-habitat patches becomes largest (see Figure S3 in SI).

. Evolutionary rescue

Finally, we consider a time-inhomogeneous environment where patches deteriorate one after the other at regular time intervals τ, until all patches have switched to the new habitat. If the wild-type population fails to generate a successful mutant, the population will unevitably go extinct. The probability of evolutionary rescue is therefore tightly linked to the probabilities of adaptation and establishment that we have computed in eqs. ( 7) and ( 9). Typically, in formulas expressing the probability of evolutionary rescue, one splits the contributions into mutations arising de-novo and evolutionary rescue due to standing genetic variation, i.e. mutations that are present in the population before the environmental change [START_REF] Alexander | Priyanga Amarasekare. The role of density-dependent dispersal in source-sink dynamics[END_REF]). We will discuss the effect of standing genetic variation in our system in the following section. For now, we focus on evolutionary rescue due to de-novo mutations. We approximate the probability 18 0.00 0.25 0.50 0.75 1.00 0.05 Figure 4: Origin of the adaptive mutant. The origin of the adaptive mutant is strongly affected by the fecundity differences in the old habitat. If the difference is large as illustrated in panel (a), mutants appear more often in old-habitat patches than in new-habitat patches. Still, mutants arising in new-habitat patches contribute to the overall probability of adaptation. If fecundity differences are small like in panel (b), the successful mutant largely arises in old-habitat patches. In this case, the contribution from new-habitat patches is negligible. Circles correspond to simulations where at least two successful lineages, one arising in an old-and one in a new-habitat patch, are still present after 1000 generations. Note the different scaling on the y-axis across the two panels.

for evolutionary rescue, denoted by P rescue , as

P rescue ≈ 1 -exp       -θ M -2 i =0       ϕ old f old (i ) (i +1)τ-1 j =i τ N old w ( j ) old habitat contribution + ϕ new ( f old (i )) (i +1)τ-1 j =i τ N new w ( j ) new habitat contribution       -θϕ new (0) ∞ j =τ(M -1) N new w ( j ) contribution after the last patch deteriorated        , (11)
where f old (i ) = (Mi )/M is the frequency of old-habitat patches after the i -th deterioration event and N k w ( j ) denotes the overall number of wild-type individuals living in habitat k (old or new) in generation j . The intuition for the form of this equation is the same as for eq. ( 9). The only difference is that we now need to account for a changing environment, which alters the population sizes, N k w , and the establishment probabilities ϕ k . In the formula, these changes are accounted for by the sums that iterate through the (discrete) time steps and by the time dependence of the corresponding quantities. We further note that we follow the wild-type population size deterministically over time, instead of assuming it to be already in its steady state as in eq. ( 9).

As visible in Figure 5, the approximation matches the qualitative pattern of the simulation results, i.e. the ranking and intersection of the dispersal schemes. Yet, it does not accurately predict the simulated data. This discrepancy can be explained as follows: in the formula we assume a constant establishment probability between two deterioration events. However, mutants that arise very shortly before a deterioration event just need to survive until this event happens and are thus carried over to the following environmental configuration with a higher probability than predicted by our formula. This explains why the real rescue probability is higher than our approximation, which ignores these "left-over" mutants present prior to the deterioration event. As a result, instead of assuming a constant establishment probability between two deterioration events, we should rather use a time-dependent establishment probability -which can however not be approximated in our general framework (but see [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF] where scenarios with an accessible time-dependent solution are studied).

Comparing the different dispersal schemes with each other, we see substantial differences. The dispersal schemes affect the dispersal pattern of both types and as such alter their respective population dynamics. Both small and large fecundity differences in the old habitat, ω m = 9.9 and ω m = 9, conserve the pattern of rankings of dispersal schemes obtained for the probabilities of establishment and adaptation: from highest to lowest we have negative densitydependent (green), random dispersal (black), absolute habitat choice (blue) and interversion of relative habitat choice (orange) and maladaptive dispersal (purple), cf. Figure 5(a,b). Based on our discussion of the same behavior in Figure 2(a,c), this indicates that the most influential factor in these parameter sets is the growth rate of the mutant in old-habitat patches, s old .

For very large fecundity differences in the old habitat (ω m = 3 and ω m = 0), the hierarchy of dispersal schemes is the same for all emigration probabilities without any changes in ranking; from highest to lowest, we find negative density-dependent dispersal, relative habitat choice, random dispersal, maladaptive dispersal, and absolute habitat choice (cf. Figure 5(c,d)). In this parameter setting, the probability of evolutionary rescue is dominated by the dispersal behavior of the mutant. Since the mutant is barely viable in old-habitat patches, it is always preferential for it to disperse towards new-habitat patches. Two schemes follow this rule, negative density-dependent dispersal (green) and relative habitat choice (orange), but differ in the preference of the wild type. Since wild-type individuals also preferentially disperse to new-habitat patches under density-dependent dispersal, more individuals are present in those patches. Therefore, there are more individuals overall, increasing the total amount of mutations over the deterioration time. This effect is even stronger for large dispersal rates that increase the wild-type population size in the whole environment. Together with the effect of relaxed competition, this explains the strong increase of the negative density-dependent, the maladaptive, and the random dispersal scheme in Figure 5(c).

Lastly, the probability of evolutionary rescue reaches a local (or global) maximum for intermediate emigration probabilities (Figures 5(c,d)). This extends previous results [START_REF] Uecker | Evolutionary rescue in structured populations[END_REF][START_REF] Tomasini | When does gene flow facilitate evolutionary rescue? bioRxiv[END_REF] to arbitrary dispersal schemes affecting the immigration process. The maximum can be attributed to the interaction of the three regions we identified when analyzing the establishment probability ϕ k (see also Figure 2). As such it is a result of 20 the largely positive effect of dispersal (initial increase of the probability of evolutionary rescue) and the negative effect of population mixing.

. Habitat of origin of the rescue mutant and standing genetic variation

Similar to what was found for the probability of adaptation, rescue mutants mainly originate from the old-habitat patches -acting as sources. Mutations are more likely to appear in the more populated patches (old-habitat). However, lower mutant fecundities ω m decrease the chance of establishment of these mutants that appears in old-habitat patches (compare black and yellow symbols in Figure 6 We compare the source of successful mutations under small (black) and large (yellow) fecundity differences in the old habitat. Decreasing the fecundity of the mutant results in more successful mutations emerging in new-habitat patches (+) while the contribution to the rescue probability from old-habitat patches (×) decreases. We have chosen π m = π w = 1. (b) For slower environmental degradation, i.e. τ = 200, the influence of standing genetic variation (sgv) on the probability of evolutionary rescue decreases. The simulations are done by letting the system evolve for 1, 000 generations before the first deterioration event happens. Parameters: π m = π w = 1 in all scenarios and ω m = 9.9. The relative contribution is then determined by (P rescue with sgv -P rescue only de novo )/P rescue with sgv . increase the probability for the rescue mutation to have appeared in the already deteriorated habitat, i.e. in new-habitat patches.

So far, we have considered settings where evolutionary rescue is exclusively due to de-novo mutations. To explore the role that could be played by standing genetic variation, we ran simulations were we let the system evolve for 1, 000 generations before the first degradation event happened. Figure 6(b) shows the relative contribution of de-novo mutations and of standing genetic variation, i.e. mutations that appeared before the first degradation event happened. With our parameters, where the environmental change lasts for 900 generations (= (M -1)τ) in total, contributions due to standing genetic variation, are small (circles in Figure 6(b)).

Additionally, the relative contribution of standing genetic variation declines as the emigration rate m increases. This holds because the mutant has no chance to establish for large frequencies of old-habitat patches f old and large emigration rates (see Figure S4 in SI). Thus, mutants that existed prior to the first deterioration event are very unlikely to survive even for a rapidly changing environment.

Discussion

We have studied the probabilities of establishment, adaptation and evolutionary rescue under four non-random dispersal schemes and compared them to random dispersal. Our analysis builds on the probability of establishment of a single mutant lineage in a heterogeneous environment with a fixed patch configuration. In line with previous results, we find that the probabilities of establishment, adaptation and evolutionary rescue can display up to three different phases when varying the dispersal rate m. The different dispersal schemes, by changing the population dynamics, broaden, tighten or shift these regions.

. Dispersal and adaptation

Theoretical studies that investigated the effects of spatial subdivision on the adaptation of a population in a heterogeneous environment can be classified into two types. One type of models, classically analyzed in a population genetic context, assumes constant population sizes in all patches, independent of their local habitat type and of dispersal strength. Results obtained in this framework show that larger dispersal rates tend to decrease the probability of successful establishment of a rare mutant favored in some part of the environment (e.g. García-Ramos and Kirkpatrick, 1997). This inhibiting effect of dispersal on adaptation, also termed "gene swamping", is a result of an increase in absolute numbers of non-adapted individuals in the habitat where the rare mutant is beneficial, resulting in a lower mutant frequency [START_REF] Lenormand | Gene flow and the limits to natural selection[END_REF][START_REF] Tomasini | Establishment of locally adapted mutations under divergent selection[END_REF]. Additionally, for very high dispersal rates, the population homogenizes and individuals encounter an averaged environment. Therefore, the type with the largest overall growth rate, averaged over the environment, is favored.

The second type of models explicitly takes into account demographic effects due to dispersal, often in the context of source-sink systems [START_REF] Holt | Population dynamics in two-patch environments: Some anomalous consequences of an optimal habitat distribution[END_REF][START_REF] Pulliam | Sources, sinks, and population regulation[END_REF]. Here, the effect of dispersal on adaptation depends on the growth rate differences of the mutant and the wild type in the two habitats [START_REF] Tadeusz | Adaptation to marginal habitats: contrasting influence of the dispersal rate on the fate of alleles with small and large effects[END_REF]. In accordance with this result, we find that dispersal increases the probability of adaptation if the mutant is just slightly less fit than the wild type in the old habitat, ω m /ω w = 0.99 (Figure 2(c,d)). When the mutant's fecundity in old habitats, ω m , is smaller, establishment probabilities are non-monotonic with a local maximum at intermediate dispersal rates (see Figure 2(a)). However, if the mutant's disadvantage in old-habitat patches is even greater, i.e. ω m even smaller, adaptation is also hindered for large dispersal rates. The establishment probability becomes hump-shaped (cf. Figure S2 in SI).

Hence, models with and without demographic changes differ most at higher emigration rates. This corresponds to region (iii) in our analysis; we illustrate these points by presenting in Figure S5 in SI the non-demographic equivalent of Figure 2.

. Dispersal and evolutionary rescue

Besides the general structure of the probability of evolutionary rescue when varying the emigration probability m, we also studied the effect of standing genetic variation on this quantity. We find that the contribution of standing genetic variation on the overall probability of evolutionary rescue increases with the speed of the environmental change, determined by τ (Figure 6(b)). This observation has also been made in a quantitative genetics setting where the adaptive trait is continuous (and not discrete as in our model) [START_REF] Matuszewski | Catch me if you can: Adaptation from standing genetic variation to a moving phenotypic optimum[END_REF]. Experimental results with Caenorhabditis elegans indicate that under slow environmental change the impact of standing genetic variation is small [START_REF] Thiago | Slower environmental change hinders adaptation from standing genetic variation[END_REF]. This is because the evolution of the trait is driven by de novo mutations with small effects. For a sudden or fast environmental change however (small τ), standing genetic variation becomes increasingly important for the probability of evolutionary rescue. These observations are in line with our findings in Figure 6(b) and other theoretical results obtained in this context [START_REF] Matuszewski | Catch me if you can: Adaptation from standing genetic variation to a moving phenotypic optimum[END_REF].

. The e ect of di erent dispersal patterns on adaptation and evolutionary rescue

The importance of considering dispersal schemes different from random dispersal has been highlighted in several papers [START_REF] Edelaar | Matching habitat choice causes directed gene flow: A neglected dimension in evolution and ecology[END_REF][START_REF] Clobert | Informed dispersal, heterogeneity in animal dispersal syndromes and the dynamics of spatially structured populations[END_REF][START_REF] Edelaar | Non-random gene flow: an underappreciated force in evolution and ecology[END_REF]. This has led to a number of simulation studies exploring the effects of various dispersal schemes onto adaptation and niche width (e.g. [START_REF] Vuilleumier | Evolution in heterogeneous populations: From migration models to fixation probabilities[END_REF][START_REF] Holt | The influence of imperfect matching habitat choice on evolution in source-sink environments[END_REF][START_REF] Mortier | Habitat choice stabilizes metapopulation dynamics by enabling ecological specialization[END_REF][START_REF] Pellerin | Matching habitat choice promotes species persistence under climate change[END_REF]. Two of these simulation studies examined the effects of matching habitat choice on adaptation to a heterogeneous environment [START_REF] Vuilleumier | Evolution in heterogeneous populations: From migration models to fixation probabilities[END_REF][START_REF] Holt | The influence of imperfect matching habitat choice on evolution in source-sink environments[END_REF]. Both investigations indicate that matching habitat choice increases the probability of adaptation when compared to random dispersal. This is in line with our findings: we predict that typedependent habitat choice (orange lines) generates higher probabilities of establishment and evolutionary rescue than random dispersal (black lines) (Figures 2,3,5).

The dispersal schemes also slightly affect the origin of the successful mutant lineage, cf. SI, Figure S6. Population densities, especially in new-habitat patches, are altered when compared to the random dispersal scheme.

To conclude, the effects of dispersal schemes are two-fold. By changing population densities in both habitat types, the dispersal schemes change the growth rate of the mutant in oldhabitat patches. This is the primary reason for the ranking of the dispersal schemes. In addition, they also affect the number of mutations arising in either habitat type. This has a minor effect on the probability of evolutionary rescue for the explored parameter range but is relevant when studying the origin of the successful mutant lineage.

. Evolutionary consequences of habitat choice

The interplay of local adaptation and habitat choice has interested evolutionary ecologists for several decades, see for example [START_REF] Michael | A theory of habitat selection[END_REF] for one of the first references. Our analysis shows that absolute habitat choice lowers the probability of establishment when compared to random dispersal; see blue lines in Figure 2. This indicates that habitat choice protects a population against locally deleterious mutations, that are potentially favorable elsewhere, if the mutant has the same dispersal pattern as the wild type, i.e. π m = π w > 1. A similar observation, protection of the already established type, was made in [START_REF] Ravigné | Live where you thrive: Joint evolution of habitat choice and local adaptation facilitates specialization and promotes diversity[END_REF] where a co-evolutionary model of a habitat choice trait and a local adaptation trait is implemented.

Moreover, [START_REF] Ravigné | Live where you thrive: Joint evolution of habitat choice and local adaptation facilitates specialization and promotes diversity[END_REF] find that habitat choice can actually evolve and lead to evolutionary branching, i.e. the coexistence of two specialist types with their own habitat preferences (our relative habitat choice dispersal scheme). In line with this, our results show that in parameter regions where relative habitat choice yields higher probabilities for establishment than random dispersal, if a mutant is able to quickly evolve its own habitat preference as it does in [START_REF] Ravigné | Live where you thrive: Joint evolution of habitat choice and local adaptation facilitates specialization and promotes diversity[END_REF], it has an increased chance of establishing in the meta-population. This is in agreement with recent experimental findings in the ciliate T. thermophila [START_REF] Jacob | Gene flow favours local adaptation under habitat choice in ciliate microcosms[END_REF]. Even though we do not explicitly consider speciation and the evolution of genetic polymorphisms, our results may suggest that type-dependent matching habitat choice enhances phenotypic divergence, if we use the probability of adaptation as a proxy for invasion probability. The probability of adaptation for relative habitat choice (orange) is higher than for absolute habitat choice (blue) or random dispersal (black), Figure 3. This idea has already been promoted in other theoretical and experimental studies (e.g. [START_REF] Michael | Habitat selection as a source of biological diversity[END_REF][START_REF] Rice | The evolution of reproductive isolation as a correlated character under sympatric conditions: Experimental evidence[END_REF][START_REF] Ravigné | Live where you thrive: Joint evolution of habitat choice and local adaptation facilitates specialization and promotes diversity[END_REF][START_REF] Berner | How mechanisms of habitat preference evolve and promote divergence with gene flow[END_REF][START_REF] Jacob | Habitat choice meets thermal specialization: Competition with specialists may drive suboptimal habitat preferences in generalists[END_REF].

. Generality of our theoretical analysis and future directions

Our mathematical results apply in the case where the mutant offspring numbers can be written in the form "migration times reproduction (and potential regulation)" with rates that are constant in time (see the mean reproduction matrix in eq. ( 5)). Biologically, this means that the resident population is stationary and the mutant is either at low numbers or unaffected by its own density. Furthermore, for our approximation in eq. ( 7) to generate accurate predictions, it is essential that growth rate differences between the wild type and the mutant are weak and dispersal is low. Formally, just two of these parameters need to be small -see also the corresponding discussion in [START_REF] Tomasini | Establishment of locally adapted mutations under divergent selection[END_REF].

Since we summarize the population dynamics in our parameters of the reproduction matrix, the approach taken here is quite general and can account for various dispersal schemes and local population dynamics. However, it cannot account for explicit spatial structure as for example the stepping stone model. It also cannot account for time-inhomogeneous environments. This is the reason for our approximation to perform worse in the context of evolutionary rescue (Figure 5). Additionally, in order to obtain analytical solutions, it is important that the stationary population sizes of the wild type have an accessible solution. This is not the case if for example we consider non-linear emigration rates that depend on habitat choice like those incorporated in some simulation studies (e.g [START_REF] Holt | The influence of imperfect matching habitat choice on evolution in source-sink environments[END_REF][START_REF] Mortier | Habitat choice stabilizes metapopulation dynamics by enabling ecological specialization[END_REF].

In contrast, it should be possible to include a cost of dispersal and a different life cycle. In particular, the variation of the life cycle could yield qualitatively different results regarding adaptation [START_REF] Holt | The influence of imperfect matching habitat choice on evolution in source-sink environments[END_REF] and more generally in the context of the evolution of dispersal [START_REF] Massol | Evolution of dispersal in spatially and temporally variable environments: The importance of life cycles[END_REF].

In conclusion, we studied the effect of dispersal and different dispersal schemes on the probability of establishment, adaptation and evolutionary rescue of a mutant under divergent 25 selection in a subdivided population. Our quantitative approach disentangles the interaction of dispersal and adaptation. We recover previous results on adaptation and provide a general framework for studying evolutionary dynamics of a subdivided population in heterogeneous environments. This unifying approach allows us to identify the forces that are responsible for the different predictions obtained in the population genetics literature and under source-sink dynamics, respectively. We find that including population demography significantly alters the results for high dispersal rates. For constant population sizes, high dispersal rates have a negative effect on establishment, while with explicit demography the effect is largely positive. The latter is a result of relaxed competition in old-habitat patches. Most importantly, we extend the existing literature by comparing different dispersal schemes and studying their effects on adaptation and evolutionary rescue. Our results indicate that habitat choice does not necessarily result in an increased adaptive potential and might even hinder successful establishment of a mutant population that would avoid population extinction. Negative density-dependent dispersal always increases the probability of adaptation and evolutionary rescue. These results show that non-random dispersal patterns can have a strong influence on population survival and adaptation in a heterogeneous environment.

Figure 1 :

 1 Figure 1: Parameter sets for the different dispersal schemes. The colors and markers are the same across all figures. The x and y axes show the dispersal bias of the wild type and mutant, respectively, to immigrate into old-habitat patches (π w and π m ). The markers are located at the parameter values used for the simulations:π m = π w = 1 for RAND (•), π m = π w = 2 for ABS (■), π m = 0.5, π w = 2 for REL ( ), π m = π w = 0.5for DENS ( ), and π m = 2, π w = 0.5 for MAL ( ). All the results derived below depend continuously on these parameters, so that varying any of the parameters will not result in a sudden change or discontinuity of the corresponding curves.

ii

  Number of type i (wild type or mutant) individuals in type k (old or new) habitat patches at stationarity N i Number of type i (wild type or mutant) individuals in type k (old or new) habitat patches after dispersal.

Figure 2 :

 2 Figure 2: Establishment probability when varying the emigration rate. We plot the theoretical results for ϕ old (panels (a) and (c)) and for ϕ new (panels (b) and (d)) for ω m = 9 in (a), (b) and ω m = 9.9 in (c), (d).Comparison with the results from stochastic simulations show very good agreement with our approximation found in eq. (7) (dashed lines). The solid lines are the numerical solution of eq. (6). The results in subfigure (a) show a clear separation of the three regions of the establishment probability as discussed in the main text.

Figure 3 :

 3 Figure 3: Probability of adaptation in a heterogeneous environment. In panels (a) and (c),we vary the emigration rate m and observe a similar qualitative behavior as for the establishment probability ϕ k in Figure2. In panels (b) and (d), we vary the frequency of old-habitat patches. The maximum is the result of two counteracting processes. The higher the number of old-habitat patches (i.e. the greater f old ), the larger the wild-type population. As a consequence, more mutants appear in the studied timeframe. In contrast, the less old-patch habitats there are in the environment (i.e. the lower f old ), the higher the probability of successful establishment of a mutant population. In all subfigures, the mutation probability is set to u = 1/(M K ) and the considered time-window for a mutant to appear is set to t fin = 100.

  patch frequency f old contribution to P adapt (b) w m = 9.9 (small fecundity difference)

Figure 5 :

 5 Figure5: The probability of evolutionary rescue compared to simulation results. Our predictions match the qualitative behavior of the simulated data for the probability of evolutionary rescue. All intersections and rankings of the dispersal schemes align well. Quantitatively though, we find that our predictions tend to underestimate the simulated data. In (a,b) the mutation probability is set to u = 1/(25M K ) while in (c,d) it is u = 1/(M K ).

Figure 6 :

 6 Figure6: Habitat of origin of the rescue mutation and the impact of standing genetic variation. (a) We compare the source of successful mutations under small (black) and large (yellow) fecundity differences in the old habitat. Decreasing the fecundity of the mutant results in more successful mutations emerging in new-habitat patches (+) while the contribution to the rescue probability from old-habitat patches (×) decreases. We have chosen π m = π w = 1. (b) For slower environmental degradation, i.e. τ = 200, the influence of standing genetic variation (sgv) on the probability of evolutionary rescue decreases. The simulations are done by letting the system evolve for 1, 000 generations before the first deterioration event happens. Parameters: π m = π w = 1 in all scenarios and ω m = 9.9. The relative contribution is then determined by (P rescue with sgv -P rescue only de novo )/P rescue with sgv .

Table 1 : Model parameters.

 1

Acknowledgements

PC and FD received funding from the Agence Nationale de la Recherche (ANR-14-ACHN-0003 to FD). HU appreciates funding from the Max Planck Society. We are grateful to the INRA MIGALE bioinformatics facility (MIGALE, INRA, 2018. Migale bioinformatics Facility, doi: 10.15454/1.5572390655343293E12) for providing computational resources. Additionally, we thank Jérôme Mathieu for highlighting the connection of the 'maladaptive dispersal scheme' to the ecological trap literature, and Staffan Jacob and Pim Edelaar for fruitful discussion concerning the biological motivation of the dispersal schemes.