Skip to content
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

multigraph support #68

Open
lazarusA opened this issue Oct 12, 2023 · 9 comments
Open

multigraph support #68

lazarusA opened this issue Oct 12, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@lazarusA
Copy link

any efforts (issues/branches) to support multigraphs?

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

@gdalle
Copy link
Member

gdalle commented Oct 12, 2023

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

@lazarusA
Copy link
Author

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

@gdalle
Copy link
Member

gdalle commented Oct 12, 2023

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?

@lazarusA
Copy link
Author

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;

@gdalle
Copy link
Member

gdalle commented Oct 12, 2023

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

@lazarusA
Copy link
Author

no luck?

@gdalle
Copy link
Member

gdalle commented Oct 17, 2023

no time 🤣

@gdalle gdalle added the bug Something isn't working label Oct 22, 2023
@gdalle gdalle mentioned this issue Oct 24, 2023
@gdalle
Copy link
Member

gdalle commented Mar 27, 2024

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

@lazarusA
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants