ABMEv_CFM.jl 1.28 KB
Newer Older
Victor's avatar
Victor committed
1
2
3
# CFM = Champagnat Ferriere Meleard
# This contains all methods for algorithm described in article
# DOI : 10.1016/j.tpb.2005.10.004
Victor's avatar
Victor committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# In this file lie the function for Gillepsie algorithm
"""
$(TYPEDEF)
"""
struct CFM <: AbstractAlg end
export CFM

function updateBirthEvent!(w::World,::CFM,mum_idx::Int)
    # updating competition only the two columns corresponding to agent idx
    offspring = give_birth(mum_idx,w)
    addAgent!(w,offspring)
end

18
19
function updateDeathEvent!(world::World,::CFM,i::Int)
    removeAgent!(world,i)
Victor's avatar
Victor committed
20
21
22
23
24
25
26
27
28
29
end

"""
$(SIGNATURES)
Updating rule for CFM setting.
algorithm described in article
DOI : 10.1016/j.tpb.2005.10.004
"""
function updateWorld!(w::World{A,S,T},c::CFM) where {A,S,T}
    # total update world
30
    @unpack Cbar,d,b = parameters(w)
Victor's avatar
Victor committed
31
32
    alive = agents(w)
    # Total rate of events
33
34
35
    n = size(w)
     = (n + 1)
    dt = - log(rand(T))/(Cbar * )
Victor's avatar
Victor committed
36
    update_clock!(w,dt)
37
38
39
    i = rand(1:n)
    x = get_x(w[i])
    W = rand()
Victor's avatar
Victor committed
40
    if dt > 0.
41
42
43
44
45
46
        deathprob = (sum(d.(get_x.(alive),Ref(x))) - d(x,x)) / (Cbar*(n+1))
        birthprob = b(x) / (Cbar*(n+1))
        if W <= deathprob
            updateDeathEvent!(w,c,i)
        elseif W <= deathprob + birthprob
            updateBirthEvent!(w,c,i)
Victor's avatar
Victor committed
47
48
49
50
51
52
        end
        return dt
    else
        return -1
    end
end