Closed Krastanov closed 1 year ago
How about
using Graphs
using MetaGraphsNext
meta_graph = MetaGraph(Graph(), Label = Int, VertexData = Pair{Symbol, Symbol})
meta_graph[1] = :key => :value
This will work, you will just get a warning, because it's easy to confuse integer vertex labels with integer vertex codes.
This seems like a neat workaround! I am still curious though, does this not involve an extra lookup step that needs to map an integer vertex label to an integer vertex code? Is there something I can do in order to avoid this computational expense if all I need is vertex/edge metadata, without the need for custom labels?
Yes, there is an extra lookup step. Do you plan on deleting vertices? If so, I think it's probably worth it. Graphs.jl reassigns vertex codes when a vertex is deleted.
Thanks! This was very helpful and it answers all my questions. I would leave this issue opened and rename it to focus on adding this to the documentation. Please close it if it is a duplicate.
Ok, feel free to make a PR to update the docs!
Hi @Krastanov, would you like to contribute by documenting this workaround?
@bramtayl if we decide to forbid integer labels for good, what happens to this method?
Yeah this wouldn't work anymore...part of why I'm conflicted
One alternative could be to provide a custom integer type with the package, which would not subtype Integer
, so that people can use it as label. Something like
struct IntegerLabel{T<:Integer}
n::T
end
const IL = IntegerLabel
but it seems a bit overkill
With the old
MetaGraphs
it was easy to make a graph where indexing was still done with integers, not with symbolic labels. How do I do this withMetaGraphsNext
.E.g., how do I do
g = MetaGraph(Graph()); add_vertex!(g)
? (and maybe then followed byset_prop!(g,1,:key,:value)
)