Introduction

What is this web page for?

The goal of this web page is to introduce you to graph theory using the Chinese Postman Problem as a guideline, and in particular, a procedure to solve this problem in the general case. If you are not familiar with graphs at all read the Vocabulary section first.

Chinese Postman Problem

A postman must walk through a set of streets in order to deliver his letters. The problem is to give him an itinerary that minimizes the total length of his walk. We will modelize the problem by a graph, where edges will represent streets and vertices will represent crossroads between them. With this modelization the problem amounts to searching a walk on this graph which go through all edges at least once such that the total length is minimal.

A network of streets and crossroads

Preliminary remarks

Let us observe the graph. If all vertices have even degree then we know that there exists an eulerian cycle, and ﬁnding the solution of our postman problem amounts to giving such an eulerian cycle in the graph. Indeed we must go through all edges at least once, and an eulerian cycle goes through all edges exactly once, so it doesn’t repeat any edge, so we satisfy the condition without any superﬂuous cost. What if the graph has vertices with odd degree? This means that it doesn’t have an eulerian cycle, so ﬁnding a solution of our postman problem amounts to ﬁnding which edges will be followed multiple times. To modelize this we will build an extension of our graph by duplicating edges such that the extended graph does have all his vertices of even degree. Our goal will be to minimize the cost of the duplicated edges.

Existence criterion of an eulerian cycle in a graph

A non-oriented connected graph possess an eulerian cycle if and only if all his vertices have even degree.

Property on the number of vertices with odd degree

A graph can only have an even number of vertices with odd degree. Indeed the sum of degrees over all vertices of the graph is equal to twice the number of edges, which is then an even number, giving a contradiction if we suppose that the number of vertices of odd degree is odd.

An eulerian graph

Vocabulary List

Graphs

In mathematics, and more specifically in graph theory, a graph is a representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges. Typically, a graph is depicted in diagrammatic form as a set of dots for the vertices, joined by lines or curves for the edges. Graphs are one of the objects of study in discrete mathematics.

Handshaking lemma

In graph theory, a branch of mathematics, the handshaking lemma is the statement that every finite undirected graph has an even number of vertices with odd degree (the number of edges touching the vertex). In more colloquial terms, in a party of people some of whom shake hands, an even number of people must have shaken an odd number of other people's hands.

Each time we add an edge in an undirected graph we add 2 to the sum of all vertex degrees.

Eulerian paths and cycles

In graph theory, an Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail which starts and ends on the same vertex.

Eulerian graphs

The term Eulerian graph has two common meanings in graph theory. One meaning is a graph with an Eulerian circuit, and the other is a graph with every vertex of even degree. These definitions coincide for connected graphs.

Resolution Draft

Given a graph modeling our problem, the ﬁrst step will consist of checking if all the vertices have even degree. If this is the case, then we will only need to search for an eulerian cycle in the graph. Otherwise we will have to decide of a set of edges to duplicate such that the extended graph will be eulerian, and the total length of the duplicated edges will be minimal.

Remark about the edges duplication

We can easily see that the extension of the graph will consist of path joining pairs of vertices with odd degree. Indeed let’s suppose it is not the case, then it means that there exists a vertex of even degree in the original graph adjacent to an odd number of duplicated edges. Its degree will become odd, hence we did not satisfy the condition of transforming the graph in an eulerian graph.

Main part of the problem

Here we arrive at the most difficult part of the problem. We showed that there is an even number of vertices with odd degree. Let’s call \(G(V,E)\) our graph, and let \(V = V_1 \cup V_2\) with \(V_1\) the set of vertices of odd degree, and \(V_2\) the set of vertices of even degree. Let \(V_1\) have cardinality \(2i\). We need to ﬁnd \(i\) paths joining pairs of vertices of \(V_1\). To do that, we will create an intermediate graph, let’s call it \(K(V',E')\) with \(V_1\), and let \(K\) be the complete graph on those vertices. Now associate at each edge of \(K\) the length of the shortest path in \(G\) joining the corresponding vertices. We will need to keep this correspondence between the shortest path in \(G\) and the edges of \(K\) because we will chose the edges of \(K\) in order to determine which edges of \(G\) must be duplicated. Now choosing \(i\) edges of \(K\) with minimal total length amounts to ﬁnd a perfect matching in \(K\) of minimal weight. In order to solve that we will use a blossom algorithm.

Graph \(V\).

Graph \(K\).

Research of eulerian cycle

Once we extended the graph such that each vertices has now an even degree, we only need to find an eulerian cycle on the extended graph to solve the problem.

Construction of an eulerian tour (in orange).

Algorithm in practice

Given a graph modeling our problem, our algorithm will proceed in multiple steps. First the graph might be not simple, and we will need to search shortest path, with the Floyd algorithm working on simple graphs. So we construct an intermediate graph which is the initial keeping only the shortest edge when they are multiple. On this graph we compute the shortest path between each couple of vertices with odd degree, so that we are able to build our complete graph on which we will search for the matching.

An input graph

Min-weight edges induced graph

Matching with blossom algorithm

Let us remind the idea of the algorithm for ﬁnding a maximum cardinality matching in a bipartite graph. We use the concept of alternating path, which is a succession of edges belonging alternatingly to the matching and not to the matching. If we can ﬁnd such an alternating path starting from an unmatched vertex and ending on another unmatched vertex, then we found what we call an augmenting path. More generally in a non-bipartite graph, we encounter new graph components which are cycles of odd length, that we will call blossoms. The new idea is that we can contract each blossom into a single vertex with the search for the augmenting path continuing on the contracted graph. But let’s not forget that we are searching for a matching with maximal cardinality and minimal total length. For that second condition we need to introduce dual variables and look at the modiﬁed cost of the graph. We look at the subgraph consisting of the set of edges with modiﬁed length equal to zero, and we search for a maximal cardinality matching on this subgraph. Each time we find one, we update the dual variables (without breaking the incumbent solution) in order to introduce new edges in the subgraph. We repeat this procedure until we saturate all vertices. We know that there exist a perfect matching on \(K\) because \(K\) is a complete graph. (For a detailed explanation of the matching procedure on general graphs see [1]
, [2]
, [3]
and [4]
).

Duplicating edges

We saved previously the bijection between the edges of the graph K and the paths in G, so now that we have the matching, we just need to duplicate the corresponding edges to extend G into an eulerian graph.

Min-weight matching on the odd degree vertices complete graph.

Extended graph is eulerian (duplicated edges in green).

Searching for eulerian walk

Starting from any vertex, we can ﬁnd an eulerian walk by proceeding like following. We follow a path consisting of edges we didn’t go through yet until we come back at our ﬁrst vertex. Then we check if we covered all the graph. If not it means that there exist at least one vertex on our walk adjacent to at least one edge not used yet. Then we can restart from this vertex, following edges that are not in our walk yet until we come back at this vertex, and we iterate.

Remark about the connected graph hypothesis

We supposed here for our algorithm that the input graph is in one component. If we don’t, then the problem changes a little bit. Remember that this come from a real problem, and in this original (not modeled) problem, this amounts to saying that not all streets must be run through. But those streets exist, we can still suppose that our streets are connected, otherwise it would make non sense, so we can associate a length between two vertices even if we don’t have any edge between them in the input graph. The difference is in our simple graph step, where we create the graph on which we will search for the shortest path between every couple of vertices with odd degree. Instead of only duplicating existing edges, we will allow to add edges even if there wasn’t any in the input graph. The rest of the problem is the same, we need to extend our graph such that it becomes an eulerian graph. We just have one hypothesis (not restrictive at all) instead of the connected input graph hypothesis, we will assume that the graph on which we will search for shortest path is connected.

Applying the matching algorithm on a disconnected graph.

Finding a tour an a single connex component.

Conclusion

Our algorithm starts with a connected non-oriented graph corresponding to a postman’s situation. As output it gives us an eulerian walk over an extension of our input graph, on which we can easily see which edges will be followed multiple times. It works in complexity \(O(|V|^3 + |E|)\). Indeed the main steps are the following. From the input graph, finding the simple graph on which we compute shortest paths, works in \(O(|V|^2 + |E|)\). Running Floyd algorithm on the simple graph works in \(O(|V|^3)\). From the input graph \(G\), finding \(K\) works in \(O(|V|+|E|+|V'|^2)\). Blossom algorithm works \(O(|V'|^3)\). Searching an eulerian walk on the extended graph works in \(O(|E|)\).

Variants

A few variants of the chinese postman problem have have been shown to be NP-complete. A first variant is the problem for mixed graphs, where some of the edges can be oriented and therefore can be run through only one direction. When the problem is minimal traversal of a digraph it is known as the New York Street Sweeper problem. A second variant is the \(k\)-chinese postman problem, consisting of ﬁnding \(k\) cycles all starting from a same point, covering all edges at least once, where we minimize the longest path over the \(k\) we found. The rural postman problem is a third variant that asks for the shortest hamiltonian cycle covering a set of edges.