To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

ABMEv_WF.jl 1.07 KB
Newer Older
1
# In this file lie the function for WF algorithm
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
$(TYPEDEF)
"""
struct WF <: AbstractAlg end
export WF

"""
    function updateWorld_WF!(world,newworld,C,p,update_rates!,t)
        If p["reflected"]=true, we reflect only first trait corresponding to geographic position
"""
function updateWorld_WF!(world,newworld,p,update_rates!,t)
    @debug "updating rates"
    update_rates!(world,p,t);
    # normalise to make sure that we have a probability vector
    fitness = get_fitness.(world)
    # we need to substract the minimum, otherwise fitness can be negative
    prob = normalize(fitness .- minimum(fitness) .+ eps(1.),1)
    offsprings = rand(Multinomial(length(world),prob))
    # this guy can be done in parallel
    @debug "filling new offspring row"
    for (parentID,nboffspring) in collect(enumerate(offsprings))
        for j in 1:nboffspring
            newworld[sum(offsprings[1:(parentID-1)]) + j] = copy(world[parentID])
25
26
        end
    end
27
28
29
30
31
32
    # we introduce randomness here
    @debug "incrementing offsprings traits"
    for w in newworld
        increment_x!(w,p)
    end
end