DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • ROTI: Return on Time Invested
  • How To Create a Network Graph Using JavaScript
  • Data Life With Algorithms
  • Universal Implementation of BFS, DFS, Dijkstra, and A-Star Algorithms

Trending

  • Pragmatica Aether: Let Java Be Java
  • Jakarta EE 12: Entering the Data Age of Enterprise Java
  • Liquid Glass, Material 3, and a Lot of Plumbing
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Solving the Chinese Postman Problem

Solving the Chinese Postman Problem

Learn the fundamental algorithm to solve the Chinese Postman problem using R. Also explore example images.

By 
Arthur Charpentier user avatar
Arthur Charpentier
·
Updated Oct. 26, 18 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
13.0K Views

Join the DZone community and get the full member experience.

Join For Free

Some pre-Halloween post today. It started actually while I was in Barcelona: kids wanted to go back to some store we've seen the first day, in the gothic part, and I could not remember where it was. And I said to myself that would be quite long to do all the street of the neighborhood. And I discovered that it was actually an old problem. In 1962, Meigu Guan was interested in a postman delivering mail to a number of streets such that the total distance walked by the postman was as short as possible. How could the postman ensure that the distance walked was a minimum?

A very close notion is the concept of traversable graph, which is one that can be drawn without taking a pen from the paper and without retracing the same edge. In such a case the graph is said to have an Eulerian trail (yes, from Euler's bridges problem). An Eulerian trail uses all the edges of a graph. For a graph to be Eulerian all the vertices must be of even order.

An algorithm for finding an optimal Chinese Postman route is:

  1. List all odd vertices.
  2. List all possible pairings of odd vertices.
  3. For each pairing find the edges that connect the vertices with the minimum weight.
  4. Find the pairings such that the sum of the weights is minimized.
  5. On the original graph add the edges that have been found in Step 4.
  6. The length of an optimal Chinese postman route is the sum of all the edges added to the total found in Step 4.
  7. A route corresponding to this minimum weight can then be easily found.

For the first steps, we can use the codes from Hurley and Oldford's Eulerian tour algorithms for data visualization and the PairViz package. First, we have to load some R packages.

Then use the following function from StackOverflow, then consider some networks with 12 nodes.

To plot that network, use:

Then we convert it to some traversable graph by adding 5 vertices as shown below:

We cut those 5 vertices in two parts, and therefore, we add 5 artificial nodes.

We get the following graph where all nodes have an even number of vertices!

Our network is now the following (new nodes are small because actually, they don't really matter, it's just for computational reasons).

Now we can get the optimal path or:

Let us try now on a real network of streets. Like Missoula, Montana.

I will not try to get the shapefile of the city, I will just try to replicate the photography above.

If you look carefully, you will see some problem: 10 and 93 have an odd number of vertices (3 here), so one strategy is to connect them (which explains the grey line).

But actually, to be more realistic, we start in 93, and we end in 10. Here is the optimal (shortest) path, which goes through all vertices.

Now we are ready for Halloween and to go through all the streets in the neighborhood!

Graph (Unix) Data visualization Network Pairing (computing) Algorithm Concept (generic programming) Mail (Apple) Convert (command)

Published at DZone with permission of Arthur Charpentier. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • ROTI: Return on Time Invested
  • How To Create a Network Graph Using JavaScript
  • Data Life With Algorithms
  • Universal Implementation of BFS, DFS, Dijkstra, and A-Star Algorithms

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook