Skip to content

Make the custom vertex index optional #3

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

Closed
CameronBieganek opened this issue May 8, 2020 · 4 comments
Closed

Make the custom vertex index optional #3

CameronBieganek opened this issue May 8, 2020 · 4 comments

Comments

@CameronBieganek
Copy link

Currently one has to define a custom vertex index in order to use MetaGraphsNext. But I don't always need a custom vertex index. For example, suppose I want to use MetaGraphsNext to make a simple weighted graph. Here's what I would have to do:

julia> g = MetaGraph(Graph(), Label=Int, EdgeMeta=Float64)
Meta graph based on a {0, 0} undirected simple Int64 graph with vertices indexed by Int64(s), Nothing(s) vertex metadata, Float64(s) edge metadata, nothing as graph metadata, and default weight 1.0

julia> add_vertex!(g, 1, nothing)
true

julia> add_vertex!(g, 2, nothing)
true

julia> add_vertex!(g, 3, nothing)
true

julia> add_edge!(g, 1, 2, 0.3)
true

julia> add_edge!(g, 2, 3, 2.1)
true

Side note: Currently the only add_vertex! constructor is the add_vertex!(g::MetaGraph, label, val) constructor, hence the need for the third argument with nothing in it in the above example.

So far it looks like I've been using a normal integer index, but it's actually a custom index that happens to be equal to the underlying integer index:

julia> g.vprops
Dict{Int64,Tuple{Int64,Nothing}} with 3 entries:
  2 => (2, nothing)
  3 => (3, nothing)
  1 => (1, nothing)

Maybe that's ok, but it seems a little wasteful to me. It could also lead to bugs if the programmer thinks they are using the normal integer index. For example, the following should throw an error if the normal integer index is being used:

julia> g = MetaGraph(Graph(), Label=Int, EdgeMeta=Float64)
Meta graph based on a {0, 0} undirected simple Int64 graph with vertices indexed by Int64(s), Nothing(s) vertex metadata, Float64(s) edge metadata, nothing as graph metadata, and default weight 1.0

julia> add_vertex!(g, 1, nothing)
true

julia> add_vertex!(g, 3, nothing)
true

But it doesn't throw an error because it is actually creating a custom index:

julia> g.vprops
Dict{Int64,Tuple{Int64,Nothing}} with 2 entries:
  3 => (2, nothing)
  1 => (1, nothing)
@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

I agree this is potentially confusing. The reason I decided to require labels is because vertex codes get reassigned after rem_vertex!. That makes relying on them a little dangerous.

@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

As a minimal step, I could add a warning to the docstring saying that using Ints as Labels could cause confusion. Another option could be disallowing Ints as Labels, which might dovetail nicely with your suggestion here: #4 (comment)

@bramtayl
Copy link
Collaborator

bramtayl commented May 8, 2020

MetaGraphs currently have a mish-mash of features: graph level meta data, vertex level metadata, edge metadata, edge weights, and vertex labels. I did think about a way for users to pick and choose the features they want, but decided it would make the code-base too complex. But I'd be open to ideas on this front.

bramtayl added a commit that referenced this issue May 9, 2020
bramtayl added a commit that referenced this issue May 9, 2020
@bramtayl
Copy link
Collaborator

bramtayl commented May 9, 2020

Hopefully the clarification in e65a1bf should help. Feel free to reopen if not.

@bramtayl bramtayl closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants