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

How to handle self-loops?

Open gdalle opened this issue 2 years ago • 2 comments

It is unclear how well self-loops are supported in Graphs.jl, but that should not prevent us from supporting them here. For now, I stated in the documentation that they are not properly handled, because of a few issues that were raised over the years and never closed in the original package:

  • https://github.com/sbromberger/SimpleWeightedGraphs.jl/issues/38
  • https://github.com/sbromberger/SimpleWeightedGraphs.jl/issues/53

What do you think?

gdalle avatar Apr 06 '23 11:04 gdalle

Good question. Is there any particular reason why self-loops are allowed for SimpleGraphs at all in Graphs.jl? It seems to violate the common definition.

pgrepds avatar Apr 11 '23 21:04 pgrepds

Adding self-loops to graphs it not very difficult from a technical perspective (unlike multi-edges), so while it does not strictly correspond to the mathematical definition of a simple graph, we still allow them. There are many cases where self-loops can be useful, for example in finite state diagrams.

In some cases, self-loops have given us some headaches over the last few years though, as one has to consider some extra cases when writing algorithms. And people often forget to write test cases with self-loops.

simonschoelly avatar Apr 11 '23 22:04 simonschoelly