views:

240

answers:

4

Hello, I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.

I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.

Can anybody help me? Thanks

Edit>> All edges of that graph have the same cost - for instance 1

A: 

I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.

recursive
+3  A: 

Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).

If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.

Key quote (the second half for the directed version):

The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.

Larry
thanks, that is exactly what I need
joseph
A: 

what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here

Maxym
The distinction is that for Eulerian paths, you only want to visit each edge exactly once.
Larry
yup, I just noticed, thanks... hm... there are two kinds of cycles in graphs -> either wo visit each vertex once or each edge... then it should be "Hamiltonian path"
Maxym
"In July 2009, research published in the Journal of Biological Engineering showed that a bacterial computer can be used to solve a simple Hamiltonian path problem (using three locations)"from http://en.wikipedia.org/wiki/Hamiltonian_path_problem :))
Maxym
A: 

The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):

When all of the edges of a connected graph are directed and the graph is symmetric, there is a particularly simple and attractive algorithm for specifying an Euler tour...

The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at any node n, except the root r of the arborescence, specify any order for the edges directed away from n so long as the edge of the arborescence is last in the ordering. For the root r, specify any order at all for the edges directed away from r.

This algorithm was used by van Aardenne-Ehrenfest and de Bruin to enumerate all Euler tours in a certain directed graph [ 1 ].

ire_and_curses