Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Topological sort of cyclic graph with minimum number of violated edges

Tags:

I am looking for a way to perform a topological sorting on a given directed unweighted graph, that contains cycles. The result should not only contain the ordering of vertices, but also the set of edges, that are violated by the given ordering. This set of edges shall be minimal.

As my input graph is potentially large, I cannot use an exponential time algorithm. If it's impossible to compute an optimal solution in polynomial time, what heuristic would be reasonable for the given problem?

like image 792
orsg Avatar asked Jun 17 '13 13:06

orsg


People also ask

Is topological sorting possible for cyclic graph?

No. A topological sorting is possible if and only if the graph is a DAG. The problem doesn't ask you to topologically sort a cyclic graph. It asks you to try (hand simulating) running the algorithm on a particular cyclic graph.

Can topological sort find shortest path?

The topological ordering can also be used to quickly compute shortest paths through a weighted directed acyclic graph. Let V be the list of vertices in such a graph, in topological order.

How many topological sorts of this graph are possible?

There can be more than one topological sorting for a graph. For example, another topological sorting of the following graph is “4 5 2 3 1 0”. The first vertex in topological sorting is always a vertex with in-degree as 0 (a vertex with no incoming edges).

What are the requirements for a topological sorting algorithm to be applicable on a graph?

In order to have a topological sorting the graph must not contain any cycles. In order to prove it, let's assume there is a cycle made of the vertices. v n . That means there is a directed edge between and v i + 1 ( 1 ≤ i < n ) and between and .


1 Answers

Eades, Lin, and Smyth proposed A fast and effective heuristic for the feedback arc set problem. The original article is behind a paywall, but a free copy is available from here.

There’s an algorithm for topological sorting that builds the vertex order by selecting a vertex with no incoming arcs, recursing on the graph minus the vertex, and prepending that vertex to the order. (I’m describing the algorithm recursively, but you don’t have to implement it that way.) The Eades–Lin–Smyth algorithm looks also for vertices with no outgoing arcs and appends them. Of course, it can happen that all vertices have incoming and outgoing arcs. In this case, select the vertex with the highest differential between incoming and outgoing. There is undoubtedly room for experimentation here.

The algorithms with provable worst-case behavior are based on linear programming and graph cuts. These are neat, but the guarantees are less than ideal (log^2 n or log n log log n times as many arcs as needed), and I suspect that efficient implementations would be quite a project.

like image 135
David Eisenstat Avatar answered Oct 19 '22 23:10

David Eisenstat