Advertisement
Guest User

Untitled

a guest
Feb 12th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. For this assignment, you are to read an input file that gives the
  2. distances between each possible pair of "cities" for a traveling
  3. sales problem and then compute the cost of a "legal" tour.A legal tour of N cities starts at any one of them
  4. and visits each of the other cities exactly once before returning to
  5. the original destination city. And the cost of a tour is the sum of
  6. the "distances" between adjacent cities in the tour.
  7.  
  8. Your program output should print out the cost of the legal tour (or path) and
  9. also list the "cities" (well the integers associated with those cities) in the
  10. order visited. So, given data for a 4-city (Dallas, New York, Boston) the legal
  11. tours are:
  12.  
  13. Dallas, New York, Los Angeles, Boston, Dallas
  14. Dallas, Boston, New York, Dallas
  15. New York, Dallas, Boston, New York
  16. New York, Boston, Dallas, New York
  17. Boston, New York, Dallas, Boston
  18. Boston, Dallas, New York, Boston
  19.  
  20. and if we assume that the "cost" (or distance) or is represented as
  21.  
  22. Dallas to New York is 1900 miles
  23. Boston to Dallas is 1950 miles
  24. New York to Boston 150 miles
  25. Los Angeles to Dallas is 1400 miles
  26. Los Angeles to Boston is 3150 miles
  27. Los Angeles to New York is 3100 miles
  28.  
  29. your answer might be something like
  30.  
  31. The tour New York, Dallas, Boston, Los Angeles New York costs 7150.
  32.  
  33. which would represent the sum of 1900 (New York to Dallas), 1950 (Dallas to Boston),
  34. 3150 (Boston to Los Angeles) and 3100 (Los Angeles to New York). However, we'll
  35. "generalize" both our input and output to use consecutive integers, starting at 1,
  36. to represent the cities of the tour.
  37.  
  38. NOTE: For the example data given, 7150 would not be the minimal cost tour. For
  39. example, the tour Los Angeles, Dallas, Boston, New York, Los Angeles would
  40. cost only 6600. However, for THIS program you're not required to come up
  41. with a minimal cost tour, just a legal tour. Any legal tour will do.
  42.  
  43. Requirements:
  44.  
  45. Your C program should consist of the single file, X.c (or whatever
  46. you decide to call your program.)
  47.  
  48. Your program will read an input file (from stdin) which includes
  49. an unspecified number of command lines which describe the problem.
  50. The input (file) will contain two types of commands,
  51. and each command will be included on a single line of the file. The
  52. commands are:
  53.  
  54. c W
  55. a X Y Z
  56.  
  57. for Create a city and Add an edge between two cities. The symbols
  58. W,X,Y,Z all stand for "arbitrary" integers. Each "city" will be
  59. "named" with a distinct integer, specifically the one included in
  60. the "c" command. In the "a" command (add an edge) the edge should
  61. be From X To Y, with Cost Z. To make the program a bit easier,
  62. all the "Create" commands will precede any "Add" commands in the input
  63. file. If you wish you can assume an upper limit of 20 cities, "named"
  64. 0-19, for this version of the program. You may also assume that the
  65. "names" of the nodes will be consecutive integers starting at 1.
  66.  
  67. So, here is what the input file might look like for our problem including
  68. Dallas, Los Angeles, Boston and New York above.
  69.  
  70. c 1
  71. c 2
  72. c 3
  73. c 4
  74. a 1 2 1400
  75. a 1 3 1950
  76. a 1 4 1900
  77. a 2 3 3150
  78. a 2 4 3100
  79. a 3 4 150
  80.  
  81. Since we assume that the distance between cities X and Y is the same whether
  82. we go from X to Y or Y to X, we don't need to list the distance for each
  83. direction of travel between any pair of cities.
  84.  
  85. Output:
  86. A single line which lists the nodes in a legal tour and the cost of that
  87. tour. So, for our the input file provided and the example tour listed above
  88. (New York, Dallas, Boston, Los Angeles New York) the actual output of your
  89. program might be:
  90.  
  91. The tour 4 1 2 3 4 costs 7150.
  92.  
  93. Also, remember that we will (attempt to) compile your program using the command
  94.  
  95. gcc *.c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement