delta_competition.jl 1.6 KB
 Victor committed Nov 11, 2020 1 2 3 `````` # Space as a discrete segement using UnPack,ABMEv `````` Victor committed Oct 12, 2020 4 5 6 ``````nodes = 10 mysegment = DiscreteSegment(1,nodes) `````` Victor committed Nov 11, 2020 7 ``````# other possibility: defining the space as a graph `````` Victor committed Oct 12, 2020 8 ``````nodes = 10 `````` Victor committed Nov 11, 2020 9 ``````g = LightGraphs.grid([nodes,1]) # cf LightGraphs.jl for options to generate a graph `````` Victor committed Oct 12, 2020 10 11 12 ``````mysegmentgraph = GraphSpace(g) wholespace = (mysegmentgraph,) using GraphPlot `````` Victor committed Nov 11, 2020 13 ``````# plotting the graph `````` Victor committed Oct 12, 2020 14 15 ``````gplot(g, collect(1:nodes), collect(1:nodes)) `````` Victor committed Nov 11, 2020 16 ``````# Definition of birth and death rate `````` Victor committed Oct 12, 2020 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 committed Nov 11, 2020 20 ``````# Mutation / dispersal parameters `````` Victor committed Oct 12, 2020 21 22 ``````mu = [1.] D = (1.5,) `````` Victor committed Nov 11, 2020 23 ``````# maximum size, tend `````` Victor committed Oct 12, 2020 24 25 ``````NMax = 2000 tend = 300. `````` Victor committed Nov 11, 2020 26 27 28 29 ``````# wrapping up all the parameters p = Dict{String,Any}();@pack! p = D,mu,NMax # definining world 0 and running `````` Victor committed Oct 12, 2020 30 ``````myagents = [Agent(wholespace,(5,),ancestors=true,rates=true) for i in 1:K0/nodes] `````` Victor committed May 11, 2021 31 ``````w0 = World(myagents,wholespace,p) `````` Victor committed Nov 11, 2020 32 ``````@time sim = run!(w0,Gillepsie(),tend,b,d) `````` Victor committed Oct 12, 2020 33 34 35 `````` ### Plotting size of the world myagents = [Agent(wholespace,(5,),ancestors=true,rates=true) for i in 1:K0/nodes] `````` Victor committed May 11, 2021 36 ``````w0 = World(myagents,wholespace,p) # we need to reinitialise the world `````` Victor committed Nov 11, 2020 37 ``````@time sim = run!(w0,Gillepsie(),tend,dt_saving=2.,b,d) `````` Victor committed Oct 12, 2020 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) `````` Victor committed May 11, 2021 45 ``````# savefig(joinpath(@__DIR__, "delta_comp_wsize.png")) `````` Victor committed Oct 12, 2020 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) `````` Victor committed May 11, 2021 54 ``# savefig(joinpath(@__DIR__, "delta_comp_pos.png"))``