A matrix of vector pairs, such that one node is in the first vector and the other is in the second. The position of the vector pairs in the matrix corresponds to the distribution in sampler_matrix used to sample them. There is probably a better way to represent these, I did this so they could be sampled fast. We only use the upper triangle of this but Julia lacks a good Symmetric matrix type.
# A matrix of vector pairs, such that one node is in the first vector and the other is in the second. The position of the vector pairs in the matrix corresponds to the distribution in sampler_matrix used to sample them. There is probably a better way to represent these, I did this so they could be sampled fast. We only use the upper triangle of this but Julia lacks a good Symmetric matrix type.
The structure that pre-allocates the space for the weights of the edges in contact array. This is filled with weights and then the weights are added to weights_dict. We only use the upper triangle of this but Julia lacks a good Symmetric matrix type.
# sample_cache::Matrix{Vector{Int}}
weights_dict::Dictionary{GraphEdge,UInt8}
# The structure that pre-allocates the space for the weights of the edges in contact array. This is filled with weights and then the weights are added to weights_dict. We only use the upper triangle of this but Julia lacks a good Symmetric matrix type.
Stores the weights used in the graph, so they can be easily resampled.
# weights_dict::Dictionary{GraphEdge,UInt8}
sampler_matrix::M
# 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}
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}
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(index_vectors,mixing_matrix,weights_distribution_matrix)
# 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!`.
# """
# """
# 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.
# """
"""
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,index_vectors,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`.
# """
"""
...
...
@@ -168,13 +109,13 @@ Creates the `TimeDepMixingGraph` for our specific model.
Assumes the simulation begins on Thursday arbitrarily.
"""
function time_dep_mixing_graphs(len,base_network,demographics,index_vectors,ws_matrix_tuple,rest_matrix_tuple)
home_static_edges=WeightedGraph(base_network,demographics,index_vectors,contact_time_distributions.hh)#network with households and LTC homes
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)
foreinkeys(mixing_edges.weights_dict)
function graph_from_mixing_edges(g,weights_dict)
foreinkeys(weights_dict)
add_edge!(g,e.a,e.b)
end
end
"""
My own weighted graph type. Stores the graph in `g`, and the weights and edges in `mixing_edges`.
Weighted graph type. Stores the graph in `g`, and the weights and edges in `mixing_edges`.
"""
mutable struct WeightedGraph{G,M}
mutable struct WeightedGraph{G,M1,M2}
g::G
mixing_edges::M
function WeightedGraph(demographics,index_vectors,mixing_matrix,weights_distribution_matrix)