Commit 96294c22 authored by Peter Jentsch's avatar Peter Jentsch
Browse files

optimization in solve

parent 99904e52
"""
A type that stores a pair of nodes representing an edge in the graph.
A type that stores a destination node and a weight representing an directed edge in the graph.
We need to define a custom type for these so we can define a hash function on graph edges, in order to more efficiently use them in hashmaps (dictionaries)
We need to define a custom type for these so we can define custom equality on edges.
"""
struct HalfWeightedEdge
a::Int
......@@ -10,7 +10,7 @@ end
"""
Define symmetric edge equality, matches the hash function.
Define edge equality to exclude the weight.
"""
function Base.:(==)(e1::HalfWeightedEdge,e2::HalfWeightedEdge)
return isequal(e1.a,e2.a)
......
......@@ -44,7 +44,9 @@ end
Base.@propagate_inbounds @views function update_infection_state!(t,modelsol; record_degrees = false)
@unpack β_y,β_m,β_o,α_y,α_m,α_o,recovery_rate,immunizing,immunization_begin_day = modelsol.params
@unpack u_inf,u_vac,u_next_inf,demographics,inf_network,status_totals, immunization_countdown, output_data = modelsol
β_vec = @SVector [β_y,β_m,β_o]
α_vec = @SVector [α_y,α_m,α_o]
function agent_transition!(node, from::AgentStatus,to::AgentStatus)
immunization_countdown[node] = -1
status_totals[Int(from)] -= 1
......@@ -64,8 +66,6 @@ Base.@propagate_inbounds @views function update_infection_state!(t,modelsol; rec
for he in neighbors_and_weights(mixing_graph,i)
j = he.a
if u_inf[j] == Infected && u_next_inf[i] != Infected
β_vec = (β_y,β_m,β_o)
α_vec = (α_y,α_m,α_o)
if rand(Random.default_rng(Threads.threadid())) < contact_weight(β_vec[Int(agent_demo)],he.weight[])
if agent_status == Immunized && rand(Random.default_rng(Threads.threadid())) < 1- α_vec[Int(agent_demo)]
agent_transition!(i, Immunized,Infected)
......@@ -105,11 +105,13 @@ end
Base.@propagate_inbounds @views function update_vaccination_opinion_state!(t,modelsol,total_infections)
@unpack infection_introduction_day, π_base_y,π_base_m,π_base_o, η,Γ,ζ, ω, ω_en,ξ = modelsol.params
@unpack demographics,time_of_last_alert, nodes, soc_network,u_vac,u_next_vac,app_user,app_user_list,output_data = modelsol
if t<infection_introduction_day
π_base_vector = @SVector [π_base_y,π_base_m,π_base_o]
else
π_base_vector = @SVector [π_base_y*ζ,π_base_m*ζ,π_base_o*ζ]
end
for i in 1:nodes
π_base = t<infection_introduction_day ?
(π_base_y,π_base_m,π_base_o) :
(π_base_y*ζ,π_base_m*ζ,π_base_o*ζ)
random_soc_network = sample(Random.default_rng(Threads.threadid()), soc_network.graph_list[t])
if !isempty(neighbors_and_weights(random_soc_network,i))
random_neighbour = sample(Random.default_rng(Threads.threadid()), neighbors_and_weights(random_soc_network,i)).a
......@@ -120,7 +122,7 @@ Base.@propagate_inbounds @views function update_vaccination_opinion_state!(t,mod
# display(t - time_of_last_alert[app_user_list[i]])
end
if u_vac[random_neighbour] == u_vac[i]
vac_payoff = π_base[Int(demographics[i])] + total_infections*ω + app_vac_payoff
vac_payoff = π_base_vector[Int(demographics[i])] + total_infections*ω + app_vac_payoff
if u_vac[i]
# display(1 - Φ(vac_payoff,ξ))
if rand(Random.default_rng(Threads.threadid())) < 1 - Φ(vac_payoff,ξ)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment