delta_competition.jl 1.6 KB
Newer Older
Victor's avatar
Victor committed
1
2
3

# Space as a discrete segement
using UnPack,ABMEv
Victor's avatar
Victor committed
4
5
6
nodes = 10
mysegment = DiscreteSegment(1,nodes)

Victor's avatar
Victor committed
7
# other possibility: defining the space as a graph
Victor's avatar
Victor committed
8
nodes = 10
Victor's avatar
Victor committed
9
g = LightGraphs.grid([nodes,1]) # cf LightGraphs.jl for options to generate a graph
Victor's avatar
Victor committed
10
11
12
mysegmentgraph = GraphSpace(g)
wholespace = (mysegmentgraph,)
using GraphPlot
Victor's avatar
Victor committed
13
# plotting the graph
Victor's avatar
Victor committed
14
15
gplot(g, collect(1:nodes), collect(1:nodes))

Victor's avatar
Victor committed
16
# Definition of birth and death rate
Victor's avatar
Victor committed
17
18
19
K0 = 1000 # We will have in total 1000 individuals
b(X,t) = 1 / nodes
d(X,Y,t) = (X[1]  Y[1]) / K0
Victor's avatar
Victor committed
20
# Mutation / dispersal parameters
Victor's avatar
Victor committed
21
22
mu = [1.]
D = (1.5,)
Victor's avatar
Victor committed
23
# maximum size, tend
Victor's avatar
Victor committed
24
25
NMax = 2000
tend = 300.
Victor's avatar
Victor committed
26
27
28
29
# wrapping up all the parameters
p = Dict{String,Any}();@pack! p = D,mu,NMax

# definining world 0 and running
Victor's avatar
Victor committed
30
myagents = [Agent(wholespace,(5,),ancestors=true,rates=true) for i in 1:K0/nodes]
31
w0 = World(myagents,wholespace,p)
Victor's avatar
Victor committed
32
@time sim = run!(w0,Gillepsie(),tend,b,d)
Victor's avatar
Victor committed
33
34
35

### Plotting size of the world
myagents = [Agent(wholespace,(5,),ancestors=true,rates=true) for i in 1:K0/nodes]
36
w0 = World(myagents,wholespace,p) # we need to reinitialise the world
Victor's avatar
Victor committed
37
@time sim = run!(w0,Gillepsie(),tend,dt_saving=2.,b,d)
Victor's avatar
Victor committed
38
39
40
41
42
43
44
wsize = [length(w) for w in sim[:]]
using Plots
Plots.plot(get_tspan(sim),wsize,
                label = "",
                ylabel = "Metapopulation size",
                xlabel ="time",
                grid = false)
45
# savefig(joinpath(@__DIR__, "delta_comp_wsize.png"))
Victor's avatar
Victor committed
46
47
48
49
50
51
52
53

## plotting position through time
using Plots
Plots.plot(sim,
        label = "",
        ylabel = "Geographical position",
        grid = false,
        markersize = 10)
54
# savefig(joinpath(@__DIR__, "delta_comp_pos.png"))