Class ChinesePostman<V,E>
- java.lang.Object
-
- org.jgrapht.alg.cycle.ChinesePostman<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
public class ChinesePostman<V,E> extends java.lang.Object
This class solves the Chinese Postman Problem (CPP), also known as the Route Inspection Problem. The CPP asks to find a closed walk of minimum length that visits every edge of the graph at least once. In weighted graphs, the length of the closed walk is defined as the sum of its edge weights; in unweighted graphs, a closed walk with the least number of edges is returned (the same result can be obtained for weighted graphs with uniform edge weights).The algorithm works with directed and undirected graphs which may contain loops and/or multiple edges. The runtime complexity is O(N^3) where N is the number of vertices in the graph. Mixed graphs are currently not supported, as solving the CPP for mixed graphs is NP-hard. The graph on which this algorithm is invoked must be strongly connected; invoking this algorithm on a graph which is not strongly connected may result in undefined behavior. In case of weighted graphs, all edge weights must be positive. If the input graph is Eulerian (see
GraphTests.isEulerian(Graph)
for details) useHierholzerEulerianCycle
instead.The implementation is based on the following paper:
Edmonds, J., Johnson, E.L. Matching, Euler tours and the Chinese postman, Mathematical Programming (1973) 5: 88. doi:10.1007/BF01580113
More concise descriptions of the algorithms can be found here:- Author:
- Joris Kinable
-
-
Constructor Summary
Constructors Constructor Description ChinesePostman()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GraphPath<V,E>
getCPPSolution(Graph<V,E> graph)
Solves the Chinese Postman Problem on the given graph.
-
-
-
Method Detail
-
getCPPSolution
public GraphPath<V,E> getCPPSolution(Graph<V,E> graph)
Solves the Chinese Postman Problem on the given graph. For Undirected graph, this implementation uses the @KolmogorovWeightedPerfectMatching
matching algorithm; for directed graphs, @KuhnMunkresMinimalWeightBipartitePerfectMatching
is used instead. The input graph must be strongly connected. Otherwise the behavior of this class is undefined.- Parameters:
graph
- the input graph (must be a strongly connected graph)- Returns:
- Eulerian circuit of minimum weight.
-
-