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

multigraph support

Open lazarusA opened this issue 2 years ago • 9 comments

any efforts (issues/branches) to support multigraphs?

https://github.com/QuantumBFS/Multigraphs.jl

lazarusA avatar Oct 12 '23 13:10 lazarusA

Not here, but over on GraphsBase.jl we're trying to hammer out the best interface for that

gdalle avatar Oct 12 '23 13:10 gdalle

Ok... so the current strategy is to work this on GraphsBase from scratch instead of using the implementation from Multigraphs.jl ?

lazarusA avatar Oct 12 '23 14:10 lazarusA

The idea of GraphsBase.jl is to discuss whether we can make MetaGraphs(Next).jl obsolete, and also design a better, more flexible interface for the graphs ecosystem. At the moment it is unclear what GraphsBase.jl will support and when, so don't expect too much from it for your current problem.

I haven't looked at the Multigraphs.jl code, but one of the devs told me it's basically a hack changing very little from Graphs.jl, so maybe MetaGraphsNext.jl would... just work? What are you trying to achieve?

gdalle avatar Oct 12 '23 15:10 gdalle

I wanna to do a mix, something like:

using Graphs, Multigraphs
using MetaGraphsNext

model_connections = MetaGraph(
    Multigraph(); # Graph() # using the usual Graph doesn't account for the second link as expected, Multigraph fails
    label_type=Symbol,
    vertex_data_type=String,
    edge_data_type=Symbol,
    graph_data=nothing,
    weight_function=identity,
);

model_connections[:src_1] = "one";
model_connections[:src_2] = "two";
model_connections[:model] = "model";

model_connections[:src_1, :model] = :var_1;
model_connections[:src_1, :model] = :var_2;
model_connections[:src_2, :model] = :var_3;

lazarusA avatar Oct 12 '23 15:10 lazarusA

That looks like something which might work, I'll try it out to see where it breaks

gdalle avatar Oct 12 '23 21:10 gdalle

no luck?

lazarusA avatar Oct 17 '23 17:10 lazarusA

no time :rofl:

gdalle avatar Oct 17 '23 18:10 gdalle

So I took a little look:

  • you had an issue in your multigraph constructor
  • the Multigraph type does not correctly implement the Graphs interface, because it does not define is_directed

With a little type piracy, we can make the code not error:

using Graphs, Multigraphs
using MetaGraphsNext

Graphs.is_directed(::Type{<:Multigraph}) = false

model_connections = MetaGraph(
    Multigraph(0); # Graph() # using the usual Graph doesn't account for the second link as expected, Multigraph fails
    label_type=Symbol,
    vertex_data_type=String,
    edge_data_type=Symbol,
    graph_data=nothing,
    weight_function=identity,
);

model_connections[:src_1] = "one";
model_connections[:src_2] = "two";
model_connections[:model] = "model";

model_connections[:src_1, :model] = :var_1;
model_connections[:src_1, :model] = :var_2;
model_connections[:src_2, :model] = :var_3;

But the behavior is as expected: the edge data for (:src_1, :model) is overwritten. I'm not sure how you expected to differentiate between both edges?

julia> model_connections.vertex_labels
Dict{Int64, Symbol} with 3 entries:
  2 => :src_2
  3 => :model
  1 => :src_1

julia> model_connections.edge_data
Dict{Tuple{Symbol, Symbol}, Symbol} with 2 entries:
  (:model, :src_1) => :var_2
  (:model, :src_2) => :var_3

gdalle avatar Mar 27 '24 08:03 gdalle

thanks. I will look again for the use case that I had for this and test if it works. I was mainly a combination of this and plotting the Graph with Makie. Thanks for taking a look.

lazarusA avatar Mar 28 '24 09:03 lazarusA