Hey guys, I was wondering how difficult of a Program this is and around how much time it would be expected to complete it.



  1. Traveling Salesperson Problem

  2. We have talked about the Traveling Salesperson Problem in class.
  3. For this assignment, you are to read an input file that gives the
  4. distances between each possible pair of "cities" for a traveling
  5. sales problem and then compute the cost of a "legal" tour. Again,
  6. as defined in class, a legal tour of N cities starts at any one of them
  7. and visits each of the other cities exactly once before returning to
  8. the original destination city. And the cost of a tour is the sum of
  9. the "distances" between adjacent cities in the tour.

  10. Your program output should print out the cost of the legal tour (or path) and
  11. also list the "cities" (well the integers associated with those cities) in the
  12. order visited. So, given data for a 4-city (Dallas, New York, Boston) the legal
  13. tours are:

  14. Dallas, New York, Los Angeles, Boston, Dallas
  15. Dallas, Boston, New York, Dallas
  16. New York, Dallas, Boston, New York
  17. New York, Boston, Dallas, New York
  18. Boston, New York, Dallas, Boston
  19. Boston, Dallas, New York, Boston

  20. and if we assume that the "cost" (or distance) or is represented as

  21. Dallas to New York is 1900 miles
  22. Boston to Dallas is 1950 miles
  23. New York to Boston 150 miles
  24. Los Angeles to Dallas is 1400 miles
  25. Los Angeles to Boston is 3150 miles
  26. Los Angeles to New York is 3100 miles

  27. your answer might be something like

  28. The tour New York, Dallas, Boston, Los Angeles New York costs 7150.

  29. which would represent the sum of 1900 (New York to Dallas), 1950 (Dallas to Boston),
  30. 3150 (Boston to Los Angeles) and 3100 (Los Angeles to New York). However, we'll
  31. "generalize" both our input and output to use consecutive integers, starting at 1,
  32. to represent the cities of the tour.

  33. NOTE: For the example data given, 7150 would not be the minimal cost tour. For
  34. example, the tour Los Angeles, Dallas, Boston, New York, Los Angeles would
  35. cost only 6600. However, for THIS program you're not required to come up
  36. with a minimal cost tour, just a legal tour. Any legal tour will do.

  37. Requirements:

  38. Your C program should consist of the single file, X.c (or whatever
  39. you decide to call your program.)

  40. Your program will read an input file (from stdin) which includes
  41. an unspecified number of command lines which describe the problem.
  42. The input (file) will contain two types of commands,
  43. and each command will be included on a single line of the file. The
  44. commands are:

  45. c W
  46. a X Y Z

  47. for Create a city and Add an edge between two cities. The symbols
  48. W,X,Y,Z all stand for "arbitrary" integers. Each "city" will be
  49. "named" with a distinct integer, specifically the one included in
  50. the "c" command. In the "a" command (add an edge) the edge should
  51. be From X To Y, with Cost Z. To make the program a bit easier,
  52. all the "Create" commands will precede any "Add" commands in the input
  53. file. If you wish you can assume an upper limit of 20 cities, "named"
  54. 0-19, for this version of the program. You may also assume that the
  55. "names" of the nodes will be consecutive integers starting at 1.

  56. So, here is what the input file might look like for our problem including
  57. Dallas, Los Angeles, Boston and New York above.

  58. c 1
  59. c 2
  60. c 3
  61. c 4
  62. a 1 2 1400
  63. a 1 3 1950
  64. a 1 4 1900
  65. a 2 3 3150
  66. a 2 4 3100
  67. a 3 4 150

  68. Since we assume that the distance between cities X and Y is the same whether
  69. we go from X to Y or Y to X, we don't need to list the distance for each
  70. direction of travel between any pair of cities.

  71. Output:
  72. A single line which lists the nodes in a legal tour and the cost of that
  73. tour. So, for our the input file provided and the example tour listed above
  74. (New York, Dallas, Boston, Los Angeles New York) the actual output of your
  75. program might be:

  76. The tour 4 1 2 3 4 costs 7150.

  77. Also, remember that we will (attempt to) compile your program using the command

  78. gcc *.c