HELLP
I am working on this homework for 2 days and ý am really bored.can anybody make a solution?
Nearest Neighbour Heuristic for the Travelling Salesman Problem (TSP)Write a program that will read the description of a graph (where nodes represent cities and weighted edges represent the distances between cities) from a file and solve the corresponding TSP problem using the Nearest Neighbour heuristic. The starting city and the name of the file that contains the graph description should be taken as command-line parameters. The first line in the file contains the number of cities and the subsequent lines contain the adjacency matrix where each entry represent the distance between the corresponding cities. The output will be list of the cities in the order they are visited and the total distance traveled.
Assume that your the executable of your program has the name tsp_nn, you want to start the tour from the 4th city (cities are numbered starting from 1) and the contents of the file graph.txt is as follows:
5
0 5 3 4 1
5 0 1 2 4
3 1 0 6 5
4 2 6 0 7
1 4 5 7 0
A sample run for your program should be:
$ ./tsp_nn 4 graph.txt
Path: 4 2 3 1 5
Total distance: 7
|