Question: Trying to convert a Digraph to undirected Graph while keeping weights both ways

Here is what I'm trying to do. Say I have a Digraph G1 defined by:


I would like to produce the undirected graph G2, with the same weights:


After looking in the GraphTheory package, I found UnderlyingGraph, which seems to do what I want.



I had a first problem: there is a bug in the documentation, as the option is 'weights' in the documentation, whereas the source code shows it must be 'weighted'.


But then I had another problem, but maybe I didn't understand the purpose of UnderlyingGraph: apparently, I don't get G2. For instance:


            [[[a], 0], [[a, b], 2], [[a, b, c], 5]]

              [[[a], 0], [[a, b], 2], [[a, c], 4]]

            [[[a], 0], [[a, c, b], 0], [[a, c], 0]]

The problem seems to come from the weight matrix, which is not symmetric (it is for G2):

                           [0  2  0]
                           [       ]
                           [0  0  3]
                           [       ]
                           [4  0  0]


{[{a, b}, 0], [{a, b}, 2], [{a, c}, 0], [{a, c}, 4], [{b, c}, 0], [{b, c}, 3]}


However, G3 is undirected:



So, the graph is undirected, but it has different weights for a-b and b-a. Weird.

Now, I am wondering what UnderlyingGraph is supposed to return. After looking at the source code, it seems the statement EW := EW0 + LinearAlgebra:-Transpose(EW0) builds a symmetric weight matrix, but for some reason it's not what is returned.

Is this a bug in the function? Or did I do something wrong? Is there a better way to achieve what I wanted?


Please Wait...