@@ -67,52 +67,51 @@ Stores the weights used in the graph, so they can be easily resampled.
This is the matrix of distributions, from which the edge weights are sampled. Specifically, weights for edges in `contact_array[i,j]` come from the distribution in `sampler_matrix[i,j]`, and are placed into `sample_cache[i,j]`. We only use the upper triangle of this but Julia lacks a good Symmetric matrix type. See `sample_mixing_graph!`.
"""
struct MixingEdges{M,M2}
total_edges::Int
contact_array::Matrix{Vector{GraphEdge}}
sample_cache::Matrix{Vector{UInt8}}
weights_dict::Dictionary{GraphEdge,UInt8}
sampler_matrix::M
mixing_matrix::Union{Nothing,M2}
function MixingEdges(total_edges,contact_array,sampler_matrix::M,mixing_matrix::M2)where{M,M2}
function MixingEdges(total_edges,contact_array,sampler_matrix::M,mixing_matrix::M2)where{M,M2}
This function constructs the `MixingEdges` type for rest and WS graphs. Calls `generate_contact_vectors!(..)` to get the degree distributions for a bipartite graph for each pair of demographics, and then adds edges to MixingEdges.contact_array with the Chung-Lu approach.
"""
function create_mixing_edges(demographic_index_vectors,mixing_matrix,weights_distribution_matrix)
This function constructs the `MixingEdges` type for the home graphs. Simply adds edges to MixingEdges from the graph `g`, since we already create that in `generate_population`.
"""
function create_mixing_edges(g::SimpleGraph,demographics,demographic_index_vectors,weights_distribution_matrix)
Add the edges defined by MixingEdges to the actual graph G. Another big bottleneck since adjancency lists don't add edges super efficiently, and there are a ton of them.
"""
function graph_from_mixing_edges(g,mixing_edges)
foriin1:3,jin1:i#diagonal
forkineachindex(mixing_edges.contact_array[j,i])
e=mixing_edges.contact_array[j,i][k]
add_edge!(g,e.a,e.b)
end
foreinkeys(mixing_edges.weights_dict)
add_edge!(g,e.a,e.b)
end
end
...
...
@@ -258,8 +254,8 @@ My own weighted graph type. Stores the graph in `g`, and the weights and edges i
mutable struct WeightedGraph{G,M}
g::G
mixing_edges::M
function WeightedGraph(demographics,demographic_index_vectors,mixing_matrix,weights_distribution_matrix)