time_varying.jl 839 Bytes
Newer Older
1
2
3
###############################
# this example implements a birth rate that is time dependent
##############################
Victor's avatar
Victor committed
4

5
6
using ABMEv,UnPack
using Plots
Victor's avatar
Victor committed
7
8
9
10
11
12
13
14
15

ω = 2* π / 150 # angular frequency
optimal_trait(t) = sin(ω * t)
tend = 300
Plots.plot(1:tend,optimal_trait,label = "Optimal trait",xlabel = "time")
# savefig(joinpath(@__DIR__, "optimal_trait.png"))

myspace = (RealSpace{1,Float64}(),)
sigma_K = 1.;
16
K0 = 300 # We will have in total 1000 individuals
Victor's avatar
Victor committed
17
18
19
20
21
b(X,t) = gaussian(X[1],optimal_trait(t),sigma_K)
d(X,Y,t) = 1/K0
D = (5e-2,)
mu = [1.]
NMax = 2000
Victor's avatar
Victor committed
22
p = Dict{String,Any}();@pack! p = D,mu,NMax
23
24
myagents = [Agent(myspace,(0,)) for i in 1:K0]
w0 = World(myagents,myspace,p)
Victor's avatar
Victor committed
25
@time sim = run!(w0,Gillepsie(),tend, b, d, dt_saving=3.)
Victor's avatar
Victor committed
26
27

Plots.plot(sim, ylabel = "Adaptive trait")
28
# savefig(joinpath(@__DIR__, "time_varying_pop.png"))