#### PARAMETERS, value, description, units ####

MinVal = 1e-10 #minimum value of densities, why not zero?

#DAYS and timestep
num_days <- 210
dt <- 0.1 #timestep

#Switches (1 = present, 0 = absent) 
I2 <- 0          #Mortality event habitat 2
I3 <- 0          #Mortality event habitat 3
I5 <- 0

#Temperature parameters
Ta <- 7.7        #Amplitude of the temperature cosine function, degrees Celsius
td <- 202-90     #Day at which the temperature is at its highest, day
Tc <- 10.7       #Average temperature over season, degrees Celsius

# Floral resources
B4l <- 0.02       #Background level floral resources in habitat 2 and 3 (flower strip), proportion
B1l <- 0.05        #Background level floral resources in habitat 1 (woody habitat), proportion
ks <- 2            #Shape Weibull distribution of flowering and aphid growth, -
k1 <- 2.8          #Shape Weibull distribution of flowering of woody habitat, -
B1m <- 0.25        #Maximum level floral resources habitat 1 in spring, proportion
T1s <- -7          #Start day flowering habitat 1 in spring, day
T1d <- 53          #Duration flowering habitat 1 in spring, days
B4m <- 0.49        #Maximum level floral resources habitat 2, proportion
T4s <- 59          #Start day flowering habitat 2, day
T4d <- 73          #Duration flowering habitat 2, days
B4m <- 0.49        #Maximum level floral resources habitat 3, proportion
T4s <- 59          #Start day flowering habitat 3, day
T4d <- 73          #Duration flowering habitat 3, days  

# Aphid resources
n1s <- 1.19        #Maximum level aphid resource supply in spring in habitat 1 
n1a <- 0.8625      #Maximum level aphid resource supply in autumn in habitat 1
A1s <- -19         #Start day aphid growth habitat 1 in spring, day
A1d <- 56          #Duration aphid growth in habitat 1 in spring, days
A1as <- 150        #Start day aphid growth in habitat 1 in autumn, day
A1ad <- 36         #Duration aphid growth in habitat 1 in autumn, days
A2f <- 120         #Final day aphid growth habitat 2, days
A2d <- 65          #Duration aphid growth habitat 2, days
A3f <- 180         #Final day aphid growth habitat 3, days
A3d <- 53          #Duration aphid growth habitat 3, days


#Aphid parameters
phi <- 1e-5        #Small corrective value for numerical stability (to prevent K2 and K3 to reach 0 and thus preventing division by 0 in logistic growth of aphids)
K1 <- 10000        #Maximum aphid density (carrying capacity) in habitat 1, aphids/m2
Km <- 20000        #Maximum aphid density (carrying capacity) in habitat 2 & 3, aphids/m2
rN1 <- 0.38        #Aphid maximum intrinsic rate of increase in habitat 1 at 22C, day^-1
rN2 <- 0.35        #Aphid maximum intrinsic rate of increase in habitat 2 at 22C, day^-1
rN3 <- 0.32        #Aphid maximum intrinsic rate of increase in habitat 3 at 22C, day^-1
mu1 <- 0.08        #Aphid death rate due to biotic and abiotic factors in habitat 1, day^-1
mu2 <- 0.08        #Aphid death rate due to biotic and abiotic factors in habitat 2, day^-1
mu3 <- 0.08        #Aphid death rate due to biotic and abiotic factors in habitat 3, day^-1
ks <- 2            #Shape Weibull distribution of flowering and aphid growth, -
Nr <- 0.5          #REFUGE in habitat 1: part of aphids not effected by predation, aphids/m2 #*

#Hoverfly parameters
em <- 1/13         #Maximum development rate hoverfly, 1/developmental period in days
G1m <- 25          #Maximum reproduction rate hoverfly in habitat 1, eggs female^-1 day^-1 #*
G2m <- 30          #Maximum reproduction rate hoverfly in habitat 2 & 3, eggs female^-1 day^-1 #*
fm <- 40           #Maximum per capita predation rate, aphids*hoverfly^-1*day^-1   
Nf <- 200          #Half saturation density functional response, aphids/m2
Ne <- Nf/2         #Half saturation density hoverfly juvenile development, aphids/m2
Ng <- Nf/2         #Half saturation density ovipositional/numerical response, aphids/m2
mu0 <- 0.03        #Mortality rate adult hoverflies in winter habitat, day^-1
muB <- 0.03        #Base mortality (predation, other factors), day^-1
muS <- 0.2         #Mortality rate for ill-fed adult hoverflies in all habitats (starvation), day^-1  #*
mum <- 0.01        #Mortality rate juvenile hoverflies at abundant aphids, day^-1
tauh <- 11         #Time delay due to hoverfly pupation and maturation, days
epsilon <- 0.25    #Shape parameter of muj

#Seasonal mortality
WN <- 0.5          #Winter survival aphids in habitat 1, proportion
WP <- 0.5          #Winter survival adult hoverflies in hibernation, proportion
W <- 1e-10         #Survival seasonal events, proportion
Wt1 <- 210         #Time of winter mortality event, day
Wt2 <- A2f-1       #Time of harvest winter wheat habitat 2, day
Wt3 <- A3f-1       #Time of haulm killing potato habitat 3, day
#Transition rates between subhabitats due to:
b <- 2.66             #Feeding when in flower habitat, depends on flower density, day^-1
a <- 0.2           #Energy use when in aphid habitat, day^-1

#Hibernation parameters
H0 <- 30           #Mean time of hoverfly emergence from hibernation, day
H1 <- 183          #Mean time of hoverfly going into hibernation, day
sigma0 <- 8        #Standard deviation of hoverfly emergence from hibernation, days
sigma1 <- 9        #Standard deviation of hoverfly going into hibernation, days

# dispersal
Nd  <-  20      # Aphid density at which the proportion that stays is half the maximum
Bd  <-  0.15    # Flower density at which the proportion that stays is half the maximum
max_distance  <- 40 * (1/sqrt(1/dt))      # Maximum dispersal distance (random walk)
distance_local  <- 1  * (1/sqrt(1/dt))    # Mean dispersal distance when searching within habitat (random walk) #*
distance_global  <- 10  * (1/sqrt(1/dt))  # Mean dispersal distance when searching for other habitat (random walk)#*
N_localsearch  <-  3      # minimum aphid density for applying local search for well-fed adults #* 
B_localsearch  <-  0.025  # minimum flower density for applying local search for ill-fed adults #* 

#Initial population densities
Pi <- 0.01        #Hoverflies (into hibernating population, P0)
N1i <- 0.5         #single infestation Aphids habitat 1, aphids/m2
N2i <- 0.15        #Yearly infestation aphids habitat 2, aphids/m2  
N3i <- 0.15        #Yearly infestation aphids habitat 3, aphids/m2 #*
T2i <- 45          #Time of infestation aphids habitat 2, day #*
T3i <- 84          #Time of infestation aphids habitat 3, day #*




