JuliaGraphs / Graphs.jl

An optimized graphs package for the Julia programming language
http://juliagraphs.org/Graphs.jl/
Other
450 stars 87 forks source link

Hypergraphs feature development advice #117

Open Philogicatician opened 2 years ago

Philogicatician commented 2 years ago

Hello, I'd like to start developing an implementation of hypergraphs (both directed and undirected) for Graphs.jl and a way to visualize them. I'm aiming for something like the following:

Hypergraphs- Julia example1

This was from me playing around with SimpleHypergraphs.jl which used PyCall.jl to utilize Python's HyperNetX. The issue with the package is that the native Julia implementation doesn't work and it doesn't support directed hypergraphs.

Consequently, I wanted to throw out the idea before I started development to see if the package I make should be following certain implementation or style guidelines (besides the ones listed here). Also, let me know if there's a preferred graph visualization library that is normally used by Graphs.jl so I can make it as compatible as possible. 👍

jpfairbanks commented 2 years ago

I like that visualization. I think you will have the best luck with Compose.jl. Layout will be the hardest part.

pszufe commented 2 years ago

Please note that SimpleHypergraphs is already totally compatible with Graphs.jl. (more info on the thread cross referenced in the previous post).

julia> h = Hypergraph([1 nothing nothing;
       1 1 nothing;
       nothing nothing 1
       nothing 1 1]
       );

julia> b = BipartiteView(h)
{7, 6} undirected simple Int64 graph

julia> supertype(BipartiteView)
Graphs.SimpleGraphs.AbstractSimpleGraph{Int64}
Philogicatician commented 2 years ago

Please note that SimpleHypergraphs is already totally compatible with Graphs.jl.

Perfect! In that case, the main issue will be displaying the graph in a way that captures the previous image (but without reaching into Python with PyCall.jl to get HyperNetX) and creating a way to represent directed hypergraphs. I'm thinking something along these lines (but with colors): image

One issue that came to mind for long-term hypergraph functionality is also allowing for oriented hypergraphs (which are a generalization of signed graphs). I'm thinking mainly of the work done by Neff & Rusnak that Rusnak outlines here.

pszufe commented 2 years ago

There is already a similar visualization in SimpleHypergraphs.jl. It is based on D3, JavaScript and can show hypergraph in a web browser. Have a look at https://pszufe.github.io/SimpleHypergraphs.jl/stable/reference/#SimpleHypergraphs.draw

Try in Jupyter notebook:

draw(h, GraphBased)
Philogicatician commented 2 years ago

At first I thought that feature was still broken, but it turns out it just took several minutes for it to display the first time. Thanks a lot @pszufe!

pszufe commented 2 years ago

perhaps it was downloading the JavaScript libs when run for the first time? I see in the other post that you were running it inside VS Code - quite likely it might be quite not suited for VS Code - we have tested it on Firefox and Chrome - I do not know what browser VS Code is using,

gdalle commented 2 years ago

Hi there! Just following up, is your problem solved @Philogicatician ? Can we close the issue?