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
Newsletter
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

  • Why Kotlin or Java Is the Wrong Question For Enterprises
  • Beyond the Endpoint: How Agent Cards Enable Discovery, Interoperability, and Trust
  • The Window Closes: Why I Switched to Kotlin Before the Codebase Got Too Big
  • Evaluating RAG in Production — What the Numbers Actually Revealed

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Updated Oct. 26, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
13.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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