18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Eulerian Cycle / Chinese Postman<br />

are of even degree. <strong>The</strong>se two vertices will be the start and end points of the path.<br />

● A directed graph contains an Eulerian cycle iff (1) it is connected and (2) each vertex has the<br />

same in-degree as out-degree.<br />

● Finally, a directed graph contains an Eulerian path iff (1) it is connected and (2) all but two<br />

vertices have the same in-degree as out-degree, and these two vertices have their in-degree and<br />

out-degree differ by one.<br />

Given this characterization of Eulerian graphs, it is easy to test in linear time whether such a cycle exists:<br />

test whether the graph is connected using DFS or BFS, and then count the number of odd-degree<br />

vertices. Actually constructing such a cycle also takes linear time. Use DFS to find a cycle in the graph.<br />

Delete this cycle and repeat until the entire set of edges has been partitioned into a set of edge-disjoint<br />

cycles. Since deleting a cycle reduces each vertex degree by an even number, the remaining graph will<br />

continue to satisfy the same Eulerian degree-bound conditions. For any connected graph, these cycles<br />

will have common vertices, and so by splicing these cycles in a ``figure eight'' at a shared vertex, we can<br />

construct a single circuit containing all of the edges.<br />

An Eulerian cycle, if one exists, solves the motivating snowplow problem, since any tour that visits each<br />

edge only once must have minimum length. However, it is unlikely that any real road network would<br />

happen to satisfy the degree conditions that make it Eulerian. We need to solve the more general<br />

Chinese postman problem, which minimizes the length of a cycle that traverses every edge at least once.<br />

In fact, it can be shown that this minimum cycle never visits any edge more than twice, so good tours<br />

exist for any road network.<br />

<strong>The</strong> optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to<br />

make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G.<br />

Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us<br />

closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a<br />

minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is<br />

the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching,<br />

where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once<br />

the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described<br />

above.<br />

Implementations: Unfortunately, we have not able to identify a suitable Chinese postman<br />

implementation. However, it should not be difficult for you to roll your own by using a matching code<br />

from Section and all-pairs shortest path from Section . Matching is by far the hardest part of the<br />

algorithm.<br />

Combinatorica [Ski90] provides Mathematica implementations of Eulerian cycles and de Bruijn<br />

sequences. See Section .<br />

file:///E|/BOOK/BOOK4/NODE165.HTM (2 of 4) [19/1/2003 1:31:06]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!