ABMEv_WF.jl 1.11 KB
Newer Older
1
2
# In this file lie the function for WF algorithm
    """
Victor's avatar
Victor committed
3
4
        function updateWorld_WF!(world,newworld,C,p,update_rates!,t)
            If p["reflected"]=true, we reflect only first trait corresponding to geographic position
5
    """
Victor's avatar
Victor committed
6
    function updateWorld_WF!(world,newworld,p,update_rates!,t)
7
        @debug "updating rates"
8
        update_rates!(world,p,t);
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        # 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])
            end
        end
        # we introduce randomness here
        @debug "incrementing offsprings traits"
        for w in newworld
Victor's avatar
Victor committed
24
            increment_x!(w,p)
25
26
        end
    end