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.ConstEdgeMapType.

struct 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.

source

# Erdos.EdgeMapType.

mutable 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).

source

# Erdos.edgemap2adjlistMethod.

edgemap2adjlist(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).

source

Vertex Maps

Any AbstractVector{T} or Dict{Int,T} can be used as a vertex map.

# Erdos.ConstVertexMapType.

struct 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.

source

# Erdos.VertexMapType.

mutable struct VertexMap{G <: AGraphOrDiGraph, T, D} <: AVertexMap{T}
    g::G
    vtype::Type{T}
    data::D
end

Type implementing an edge 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 each u=1:nv(g).

source

PropertyStore

# Erdos.PropertyStoreType.

mutable struct PropertyStore
    gmaps::Dict{String, Any}
    emaps::Dict{String,AEdgeMap}
    vmaps::Dict{String,AVertexMap}
end

A type storing properties associated to networks.

source