This is a suggestion to add multiple features to UndirectedGraph
and DirectedGraph
.
Multiple conversion methods for UndirectedGraph
DirectedGraph
supports multiple conversion methods through its second argument. UndirectedGraph
just creates a single undirected edge between two vertices connected by a directed edge in either direction.
UndirectedGraph
should have additional conversion methods:
- Connect only reciprocally connected vertices:
Graph[{1,2,3}, {1->2, 2->1, 2->3}]
becomes Graph[{1,2,3}, {1<->2}]
- Create an undirected edge for each directed one, this preserving parallel edges:
Graph[{1 -> 2, 1 -> 2, 2 -> 1}]
becomes Graph[{1<->2, 1<->2, 1<->2}]
.
Plus of course the current behaviour.
UndirectedGraph
should support at least edge weights, preferably all properties
UndirectedGraph
should be able to handle edge properties such as edge weights. It should take a combiner function to decide what to do when two directed edges (1->2
and 2->1
) merge into one undirected one (1<->2
). One weight can be dropped (First
), the two weights can be averaged (Mean
), added (Total
), or even subtracted according to edge directions.
This immediately suggests a similar feature for SimpleGraph
, plus extension to SimpleGraph
to remove only parallel edges or only self-loops (but not both).
I understand that there are lots of cases to be considered. All possible combinations of multigraphs, mixed graphs, and conversion methods is maybe too much, but there are a few things that are commonly needed.
Ideally, the combiner function should also be able to take into account which property is being combined (in case there are multiple edge properties).
DirectedGraph
, acylic conversion, weights
DirectedGraph
does support weighted graphs, but there is one application which is cumbersome.
DirecetedGraph
has the "Acylic"
conversion method which creates an acyclic directed graph by orienting edges according to the vertex ordering in VertexList[g]
. But in some cases, I would want to provide my own ordering instead of VertexList[g]
. The easiest way to deal with this is to manually reorder vertices using Graph[VertexList[g][[ordering]], EdgeList[g]
. However, this drops properties.
I would like to have an easier way to convert a weighted undirected graph to a directed graph using my own vertex ordering and preserving weights, as well as other graph properties.
Admittedly, this last one is not that hard to implement. The only difficulty is to preserve vertex properties while reordering vertices.