-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Common interface for graphs with metadata #35
Comments
Thanks for opening this! I'll definitely be chiming in with some thoughts, but I might not have time until this weekend. I actually have my own metadata graph package that I developed. But it is pretty minimal---I developed it for my own personal use. |
It would certainly be convenient to be able to pass vertex labels instead of vertex indices wherever possible. The issues that I can think of though are
Maybe we could wrap labels in a type, like
|
Another point of reference is this package: https://github.com/scheinerman/SimpleGraphs.jl SimpleGraphs.jl lets you use any type for the vertices, so you can create your own custom vertex type and use it in a Example: using SimpleGraphs
struct Vertex{T}
label::T
weight::Float64
end
g = SimpleGraph{Vertex{String}}()
v1 = Vertex("a", 2.0)
v2 = Vertex("b", 3.0)
add!(g, v1)
add!(g, v2)
add!(g, v1, v2) julia> g
SimpleGraph{Vertex{String}} (n=2, m=1)
julia> vlist(g)
2-element Vector{Vertex{String}}:
Vertex{String}("a", 2.0)
Vertex{String}("b", 3.0)
julia> elist(g)
1-element Vector{Tuple{Vertex{String}, Vertex{String}}}:
(Vertex{String}("a", 2.0), Vertex{String}("b", 3.0)) I'll be back with more to say later---I just wanted to post this SimpleGraphs.jl example as food for thought. |
MotivationSuppose a developer wants to create a package with a metadata graph type with the following two properties:
The alternative to Property 1 is to create a custom graph data structure for the metadata graph. But this creates needless code duplication and restricts the user to only one type of underlying data structure for their metagraph. Property 1 appears to be a popular choice among developers of metadata graph packages. It is adopted in MetaGraphsNext.jl, SimpleValueGraphs.jl, and PropertyGraphs.jl. However, it runs into difficulties when the wrapped graph is a mutable graph, because the In my opinion, Property 2 is a very desirable feature for abstract type AbstractGraph{T} end So, the type Proposals for an
|
I made a small comparison of the implementation choices of various packages, hopefully this fuels the discussion:
|
Better support for metadata should definitely be a long term goal.
@gdalle SVG supports the |
If
There are many libraries in other languages, including retworkx, that allow non-integer vertex labels, and somehow they still manage to be fast. I think Julia is a sufficiently flexible language that we can implement performant graph types with arbitrary vertex labels. |
Here's another argument for guaranteeing that I think it makes sense to have the API for With that in mind, I think this is a sensible definition for the interface for
So if the vertex set is EDIT: This might just be fanciful thinking on my part, but it would be kind of cool to have an interface like this: # Add a vertex:
push!(vertices(g), v)
# Add an edge:
push!(edges(g), e)
# Remove a vertex:
delete!(vertices(g), v)
# Remove an edge:
delete!(edges(g), e) As long as |
One of the main points of a graphs with MetaData is to be able to label vertices with something different than a range of consecutive integers. The problem with such labeling is that multiple algorithms require indexing on vertices. The major workaround is to have an efficient function that maps integers from
Personally, I'm tempted by the second option, even though this will require a lot a rewrite work. |
Hey!
There has been some talk recently about adding better support for graph metadata, so here's an issue to centralize our discussions. First of all, here are the packages that I'm aware of that deal with vertex- & edge-level attributes:
One idea would be to design a common interface extending
AbstractGraph
to work with metadata. I'm aware that the four packages above are very different, and that the case of edge weights probably deserves special treatment. On the other hand, agreeing on a common set of names for functions would bring clear benefits:As food for thought, here are a few past discussions on this topic:
What is your take on this?
The text was updated successfully, but these errors were encountered: