Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 764791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:47:08+00:00 2026-05-14T16:47:08+00:00

I’m working on a program for class that involves solving the Chinese Postman problem

  • 0

I’m working on a program for class that involves solving the Chinese Postman problem. Our assignment only requires us to write a program to solve it for a hard-coded graph but I’m attempting to solve it for the general case on my own.

The part that is giving me trouble is generating the partitions of pairings for the odd vertices.

For example, if I had the following labeled odd verticies in a graph:

1 2 3 4 5 6

I need to find all the possible pairings / partitions I can make with these vertices.

I’ve figured out I’ll have i paritions given:

  n = num of odd verticies  
  k = n / 2  
  i = ((2k)(2k-1)(2k-2)...(k+1))/2^n

So, given the 6 odd verticies above, we will know that we need to generate i = 15 partitions.

The 15 partions would look like:

1 2   3 4   5 6
1 2   3 5   4 6
1 2   3 6   4 5
...
1 6   ...

Then, for each partition, I take each pair and find the shortest distance between them and sum them for that partition. The partition with the total smallest distance between its pairs is selected, and I then double all the edges between the shortest path between the odd vertices (found in the selected partition).

These represent the edges the postman will have to walk twice.

At first I thought I had worked out an appropriate algorithm for generating these partitions:

  1. Start with all the odd verticies sorted in increasing order

    12 34 56

  2. Select the pair behind the pair that currently has the max vertice

    12 [34] 56

  3. Increase the second digit in this pair by 1. Leave everything to the
    left of the selected pair the same,
    and make everything to the right of
    the selected pair the remaining
    numbers in the set, sorted in
    increasing order.

    12 35 46

  4. Repeat

However, this is flawed. For example, I realized that when I reach to the end and the select pair is at the left most position (ie):

[16] .. ..

The algorithm I worked out will stop in this case, and not generate the rest of the pairs that begin [16], because there is no pair to the left of it to alter.

So, it is back to the drawing board.

Does anyone who has studied this problem before have any tips that can help point me in the right direction for generating these partitions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:47:08+00:00Added an answer on May 14, 2026 at 4:47 pm

    You can construct the partitions using a recursive algorithm.

    Take the lowest node, in this case node 1. This must be paired with one of the other unpaired nodes (2 to 6). For each of these nodes, create with match 1, then find all of the pairs of the remaining 4 elements using the same algorithm on the remaining four elements.

    In Python:

    def get_pairs(s):
        if not s: yield []
        else:
            i = min(s)
            for j in s - set([i]):
               for r in get_pairs(s - set([i, j])):
                   yield [(i, j)] + r
    
    for x in get_pairs(set([1,2,3,4,5,6])):
        print x
    

    This generates the following solutions:

    [(1, 2), (3, 4), (5, 6)]
    [(1, 2), (3, 5), (4, 6)]
    [(1, 2), (3, 6), (4, 5)]
    [(1, 3), (2, 4), (5, 6)]
    [(1, 3), (2, 5), (4, 6)]
    [(1, 3), (2, 6), (4, 5)]
    [(1, 4), (2, 3), (5, 6)]
    [(1, 4), (2, 5), (3, 6)]
    [(1, 4), (2, 6), (3, 5)]
    [(1, 5), (2, 3), (4, 6)]
    [(1, 5), (2, 4), (3, 6)]
    [(1, 5), (2, 6), (3, 4)]
    [(1, 6), (2, 3), (4, 5)]
    [(1, 6), (2, 4), (3, 5)]
    [(1, 6), (2, 5), (3, 4)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I finally solved the problem. Basically, I render the pdf… May 17, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer As ssokolow has noted you can never rely on anything… May 17, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer Have you tried: ie.DocumentComplete += (object o, ref object e)… May 17, 2026 at 1:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.