Answer to Question #27691 in C for gene

Question #27691
Write a c program that will generate output (to stdout) for an input "file" for a traveling salesperson problem of up to 150 cities. The output (file) you build will contain two types of commands, and each command will be included on a single line of output. The commands are:

c W
a X Y Z

for Create a city and Add an edge between two cities. The symbols W,X,Y,Z all stand for "arbitrary" integers. Each "city" will be "named" with a distinct integer, specifically the one included in the "c" command. In the "a" command (add an edge) the edge should be From X To Y, with Cost Z. To make the program a bit easier, all the "Create" commands will precede any "Add" commands in the input file, AND, that the create command will be listed in increasing numerical order of the city name. You should assume an upper limit of 150 cities, "named" 1-150 "names" of the nodes will be consecutive integers starting at 1.

So, here is what the input file might look like for a four-city problem.

c 1
c 2
c 3
c 4
a 1 2 1900
a 1 3 1950
a 1 4 1400
a 2 3 150
a 2 4 3100
a 3 4 3150
Program Requirements:
As input to your Minor 7 program, you should read (from stdin) 4 integers, in the order specified below:
number of cities
minimum distance value between two cities
maximum distance value between two cities
an integer to provide input to the function srand, which will "seed" (start) the random number generator "random"
The program should generate a 'c' command for each city, in increasing numerical order, followed by as many 'a' commands as are necessary to list the distances between each distinct pair of cities. Use random() to generate random integers values for the distance between each city.
Expert's answer

Not answered

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

New on Blog