dominikbraun / graph

A library for creating generic graph data structures and modifying, analyzing, and visualizing them.
https://graph.dominikbraun.io
Apache License 2.0
1.81k stars 94 forks source link

multigraph support #168

Closed miparnisari closed 7 months ago

miparnisari commented 7 months ago

I couldn't find documentation for this. How do I build a directed graph that allows more than one edge between the same two nodes? https://en.wikipedia.org/wiki/Multigraph

dominikbraun commented 7 months ago

Hi, this library doesn't support multigraphs out of the box. We actually had a note about this in the README, I wonder where that went...

The main reasons for this is that 1) supporting multigraphs basically requires implementing many algorithms twice (one for simple graphs, one for multigraphs), or at least make a multitude of checks; and 2) for most use-cases, I believe that it simple graphs are more common and also more desirable from a performance perspective.

May I ask about your use-case? Could there be a workaround?

miparnisari commented 7 months ago

We actually had a note about this in the README, I wonder where that went...

it disappeared because it's now supported? 😄 🤣

May I ask about your use-case?

The graphs that i want to build are multigraphs. I only need a HasCycle algorithm on it.

Could there be a workaround?

Another library :( https://pkg.go.dev/gonum.org/v1/gonum/graph/multi

dominikbraun commented 7 months ago

it disappeared because it's now supported? 😄 🤣

I would love to be able to confirm this, but I'm afraid I can't 😅

Another library :( https://pkg.go.dev/gonum.org/v1/gonum/graph/multi

This is actually a good example for why multigraphs haven't been implemented in this library yet: gonum's multi package is basically a second library. So I would love to support multigraphs here as well, but it means that you have to implement most things twice.

miparnisari commented 7 months ago

I ended up using gonum