3
$\begingroup$

It appears duplicate edges confuse ReverseGraph A simple example

graph = Graph[{DirectedEdge[1,1],DirectedEdge[1,1],DirectedEdge[1,2]}, EdgeWeight->{Rule[DirectedEdge[1,2],-1}, VertexLabels->"Name", EdgeLabels->"EdgeWeight"]

Yields the graph with weight -1 on the edge from 1 to 2.

graph

ReverseGraph[graph]

Yields the reversed graph but the edge weight -1 has been lost.

reversegraph

Without the duplicate edges:

graph = Graph[{DirectedEdge[1,1],DirectedEdge[1,2]}, EdgeWeight->{Rule[DirectedEdge[1,2],-1}, VertexLabels->"Name", EdgeLabels->"EdgeWeight"]

Yields

graph-w-no-duplicate-edges

and

ReverseGraph[graph]

Yields the reversed graph as expected:

reverse-graph-no-duplicates

Bug?

$\endgroup$
2
  • $\begingroup$ There are issues with graphs with duplicated edges regarding property inheritance. In this example the reversed graph doesn't inherit the edge weights because there are two identical edges. I'm not sure if this is a bug or a limitation of the way edges were implemented. This was solved when edge tags were introduced recently, if you add a tag to each edge it becomes distinct. Try ReverseGraph[EdgeTaggedGraph[graph]] and see if that works for you. $\endgroup$
    – Jason B.
    Sep 1, 2022 at 19:39
  • $\begingroup$ It is bug in labeling. If you look at full-form of reversed graph you will see that the weights are still set correctly {1, 1, -1} just labeling is wrong. So to me it is a bug. $\endgroup$ Sep 1, 2022 at 21:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.