Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 27th, 2004, 04:14 AM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to schwa
Default 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












Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.