Edge and Vertex Maps
Arbitrary values can be associated to a graph's vertices and edges, and handed over to method's that necessitate them, thanks to the edge maps and vertex maps interfaces. Also, edge and vector maps can be internally stored in network types and accessed through the property interface.
Example usage:
# create a graph
g = erdos_renyi(10,0.1)
# assign random weights to each edge
weights = EdgeMap(g, e -> rand())
for e in edges(g)
# access map value
w = weights[e]
# or
i, j = e
w = weights[i,j]
.....
end
Edge Maps
Erdos.ConstEdgeMap
— Typestruct ConstEdgeMap{T} <: SimpleEdgeMap{T}
val::T
end
A type representing a constant vector map. Any attempt to change the internal value, e.g. emap[u,v] = 4
, will fail silently.
Erdos.EdgeMap
— Typemutable struct EdgeMap{G <: AGraphOrDiGraph, T, D} <: AEdgeMap{T}
g::G
vtype::Type{T}
data::D
end
Type implementing an edge map. The underlying container data
can be a dictionary, a matrix or a vector (for graphs with indexed edges).
EdgeMap{T}(g, ::Type{T})
Returns a map that associates values of type T
to the vertices of graph g
. The underlying storage structures is chosen accordingly.
EdgeMap(g, data)
Construct a EdgeMap with data
as underlying storage. The storage type can be a matrix or an associative edg => val
type or a vector for graph with indexed edges.
EdgeMap(g, f)
Construct an edge map with value f(e)
for each e
in edges(g)
.
Erdos.edgemap2adjlist
— Methodedgemap2adjlist(emap)
Returns a vector of vectors containing the values of the edge map emap
on graph g
following the same ordering of adjacency_list
(g)
.
Erdos.weights
— Methodweights(g)
Returns an edge map containing the "weights" associated to edges. For simple graphs, the return value is ConstEdgeMap(g, 1). For networks, returns the "weights" edge property if defined, otherwise the constant map.
Notice that the edge map returned by weights
is the default value for the edge weights used in many flow and distance on graph algorithms.
Vertex Maps
Any AbstractVector{T}
or Dict{Int,T}
can be used as a vertex map.
Erdos.ConstVertexMap
— Typestruct ConstVertexMap{T} <: AVertexMap{T}
val::T
end
A type representing a constant vector map. Any attempt to change the internal value, e.g. vm[1] = 4
, will fail silently.
Erdos.VertexMap
— Typemutable struct VertexMap{G <: AGraphOrDiGraph, T, D} <: AVertexMap{T}
g::G
vtype::Type{T}
data::D
end
Type implementing a vertex map. The underlying container data
can be a dictionary or a vector.
VertexMap{T}(g, ::Type{T})
Returns a map that associates values of type T
to the vertices of graph g
. The underlying storage structures is chosen accordingly.
VertexMap(g, data)
Construct a VertexMap with data
as underlying storage.
VertexMap(g, f)
Construct a vertex map with value f(u)
for u in 1:nv(g)
.
PropertyStore
Erdos.PropertyStore
— Typemutable struct PropertyStore
gmaps::Dict{String, Any}
emaps::Dict{String,AEdgeMap}
vmaps::Dict{String,AVertexMap}
end
A type storing properties associated to networks.