Skip to content

Commit

Permalink
Merge c8d2143 into 721b707
Browse files Browse the repository at this point in the history
  • Loading branch information
evadelmas committed Mar 24, 2020
2 parents 721b707 + c8d2143 commit ed29430
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/make_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function model_parameters(A;
parameters[:extinctions] = []
parameters[:extinctionstime] = []
parameters[:tmpA] = []
adbm_trigger == :interval ? parameters[:rewiretime] = [] : Nothing
else
error("Invalid method for rewiring -- must be :DO (alternatively :stan), :ADBM, :DS (alternatively :Gilljam) or :none")
end
Expand Down
15 changes: 13 additions & 2 deletions src/rewiring/parameters/checkParameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,32 @@ function check_rewiring_parameters(rewireP,rewireMethod)
:Nmethod,
:Hmethod,
:rewire_method,
:costMat]
:adbm_trigger,
:costMat,
:extinctions,
:extinctionstime,
:tmpA]
if rewireP[:adbm_trigger] == :interval
append!(required_keys, [:adbm_interval, :rewiretime])
end
elseif rewireMethod [:Gilljam, :DS]
required_keys = [
:rewire_method,
:similarity,
:specialistPrefMag,
:extinctions,
:extinctionstime,
:tmpA,
:preferenceMethod,
:cost,
:costMat,
:specialistPref]
elseif rewireMethod [:stan, :DO]
required_keys = [
:rewire_method,
:extinctions]
:extinctions,
:extinctionstime,
:tmpA]
end

if rewireMethod [:Gilljam, :ADBM, :stan, :DO, :DS]
Expand Down
13 changes: 11 additions & 2 deletions src/rewiring/parameters/updateParameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@ function update_rewiring_parameters(parameters::Dict{Symbol,Any}, biomass, t)
S = size(parameters[:A], 1)

if parameters[:rewire_method] == :ADBM
# Is there any extinction and/or rewiring happening?
A = parameters[:A] #interaction matrix
Anew = ADBM(S,parameters,biomass) #potentially new interaction matrix
if A != Anew #different matrices => rewired
append!(parameters[:tmpA], [parameters[:A]]) #store the old matrix
if parameters[:adbm_trigger] == :interval
append!(parameters[:rewiretime], t) #store the time t whichrewiring happened
end
end
#Is there any extinction?
extinct = findall(biomass .< 100*eps())
for i in extinct
if i parameters[:extinctions]
append!(parameters[:extinctions], i) ;
append!(parameters[:extinctionstime], [(t, i)])
append!(parameters[:tmpA], [parameters[:A]])
end
end
sort!(parameters[:extinctions])

#assign new array
parameters[:A] = ADBM(S,parameters,biomass)
parameters[:A] = Anew

#update the parameters
get_herbivores(parameters) #
Expand Down
14 changes: 13 additions & 1 deletion test/rewiring/ADBM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,17 @@ module TestADBM_interval

@test p[:extinctions] == [1,2]
@test p[:extinctionstime] == [(0.0, 2), (100.0, 1)]
@test p[:tmpA] == [A, [0 0 0 ; 0 0 0 ; 0 0 0]]
@test p[:tmpA] == [convert(Array{Any, 2}, A)]
@test length(p[:rewiretime]) != 0

A = [0 1 0 0; 0 0 0 1 ; 0 0 0 1 ; 0 0 0 0]
p = model_parameters(A, rewire_method = :ADBM, adbm_trigger = :interval, adbm_interval = 1, Z = 10.0)
b = [0.8, 2e-6, 0.8, 0.5]
s = simulate(p, b, stop = 10)

@test p[:extinctions] == [2]
@test length(p[:extinctionstime]) != 0
@test p[:tmpA] == map(x -> convert(Array{Any, 2}, x),[A, [0 1 1 1; 0 0 0 1; 0 0 0 1; 0 0 0 0]])
@test length(p[:rewiretime]) != 0

end

0 comments on commit ed29430

Please sign in to comment.