Creating a graph with objects or structs as nodes

MetaGraphs.jl stores the vertex information in a Dict{Symbol, Any} so the name of the property is always a Symbol, but the data itself can be anything you want.
You can get back the property you want as follow:

julia> props(mg, 1)[:name]
"Susan"

julia> props(mg, 2)[:name]
"John"


julia> props(mg, 1)[:id]
123

MetaGraphs.jl is now quite old and suffer from poor design (Dict{Symbol, Any} is really bad for type stability). There is an experimental package that you might check if you want better performance. However, as it is experimental, the documentation is relatively sparse and the implementation might have some bugs.

Another option that is really easy to implement is just to manage yourself your metadatas. SimpleGraphs maintain vertices in a UnitRange starting from 1, so you could store your metadata in a Vector, where the data for vertex k is stored at index k. You just need to be careful if you mutate your graph, the index of vertices are modified in order to keep a UnitRange starting from 1. You just need to delete the k-th element of you Vector whenever you delete vertex k.

3 Likes