MetaGraphsNext.jl icon indicating copy to clipboard operation
MetaGraphsNext.jl copied to clipboard

Empty constructor to initialize Metagraphsnext

Open harinandana02 opened this issue 1 year ago • 4 comments

At the moment MetaGraphs.jl/src/metagraphs.jl has an empty constructor which can be used to implement empty graphs. Also, the package Graphs.jl has empty constructors.

Similarly, can we have an empty constructor at MetaGraphsNext.jl/src/metagraphs.jl for constructing empty graphs of type MetagraphsNext?

Sample code:

  1. With MetaGraphs (working)
using MetaGraphs
     mg1 = MetaGraph() 
  1. With MetaGraphsNext (requesting review)
using MetaGraphsNext
         #adding an empty constructor
          MetaGraph() = MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing, e->1.0, Float64}()

With the help of this constructor we can initialize

using MetaGraphsNext
     mg2 = MetaGraph() 

harinandana02 avatar Sep 04 '23 08:09 harinandana02

I think the problem is that MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing, e->1.0, Float64}() will not work. So the empty constructor should be defined in these terms. In that regard I am in favor.

However, having MetaGraph() defaulting into SimpleGraph I don't find it completely necessary. Although you could easily argue in favor of that. After all in Graphs.jl, Graph() will similarly default in SimpleGraph().

filchristou avatar Sep 05 '23 05:09 filchristou

Thank you for the suggestion! However I don't think such an empty constructor is a good idea, because default vertex and edge data types are very arbitrary, and the user may not be aware of those choices

gdalle avatar Sep 05 '23 07:09 gdalle

What about MetaGraph{Int, SimpleGraph{Int}, Symbol, Nothing, Nothing, Nothing}(), which currently fails ? I think this empty constructor of the parametrized struct shouldn't fail.

e.g. we could define the following constructor

function MetaGraph{C, G, L, VD, ED, GD}() where {C<:Integer, G<:AbstractGraph{C}, L, VD, ED, GD}
  return MetaGraph(G(), L, VD, ED, GD)
end

My personal use case is that I want to make an empty copy of a graph. But I would like that to be consistent with all AbstractGraphs. I thought about empty constructors, but that might not go very far. E.g. for now I have been doing typeof(mygraph)(), which feels hacky and it breaks for MetaGraphsNext. Maybe it's an issue for GraphBase to define such an interface if nothing similar exists ?

filchristou avatar Sep 05 '23 10:09 filchristou

That sounds reasonable, but then again depending on the underlying graph type the constructor G() may not even exist.

gdalle avatar Sep 06 '23 07:09 gdalle