I would like to convert an undirected graph into a directed graph such that for each tuple, the first value is a head and the second is a tail in a directed edge.
Initially I thought using DirectedGraph[G, "Acyclic"]
would straightforwardly solve this, but considering an example with edges E={{1,2},{2,3},{5,3},{3,4},{4,6}}
, the {5,3}
edge connects from 3
to 5
.
I could convert the graph into something like E={{1,2},{2,4},{3,4},{4,5},{5,6}}
, and imagine an algorithm exists that detects edges with a larger head and relabels the vertices. For example I could locate a bad pair, swap labels to get {{1,2},{2,5},{3,5},{5,4},{4,6}}
while swapping the vertex coordinates in-step, iterating until a result like {{1,2},{2,4},{3,4},{4,5},{5,6}}
. But I wonder what simpler and/or alternative methods you might think of.