Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I transform an undirected, very cyclic graph into a directed acyclic graph?

Tags:

graph

I'm working on a modified TopSort algorithm and am having trouble finding / creating large (more than 1000 nodes) directed acyclic graphs to use for testing. I have an undirected sample graph from another project that is of a good size, but has many cycles. Is there an algorithm I could use to direct the edges so that there are no longer cycles?

like image 219
Frank D. Avatar asked Dec 15 '10 02:12

Frank D.


People also ask

How do you convert an undirected graph to a directed graph?

The idea is to perform Breadth–first search (BFS) or Depth–first search (DFS) on the undirected graph starting from the given vertex and add edges to the directed graph in the direction of the scan.

How do you turn an undirected graph into a DAG?

Any undirected graph may be made into a DAG by choosing a total order for its vertices and directing every edge from the earlier endpoint in the order to the later endpoint. The resulting orientation of the edges is called an acyclic orientation.

Can an undirected graph be cyclic?

An undirected graph is acyclic (i.e., a forest) if a DFS yields no back edges. Since back edges are those edges ( u , v ) connecting a vertex u to an ancestor v in a depth-first tree, so no back edges means there are only tree edges, so there is no cycle.


1 Answers

this provides a way to get acyclic graphs. Basically, a graph traversal produces a tree, which defines a partial order on the original nodes. Then, just direct all the edges so that they either point in a consistent direction according to the partial order, or are between 2 elements that are not ordered (these can point in any direction).

like image 103
lijie Avatar answered Oct 17 '22 03:10

lijie