Thread: Travelling salesman problem algorithm

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    Travelling salesman problem algorithm

    Code:
    #define OO 2000000;
    
    int tsp(int **adjMatrix, int numberPoints)
    {
    	for (int i = 0; i < numberPoints; i++) 
    		for (int j = 0; j < numberPoints; j++) 
    			for (int k = 0; k < numberPoints; k++)
    				if (adjMatrix[i][k] + adjMatrix[k][j] < adjMatrix[i][j])
    					adjMatrix[i][j] = adjMatrix[i][k] + adjMatrix[k][j];
    	
    	int min = OO;
    
    	for (int i = 0; i < numberPoints; i++) 
    		for (int j = 0; j < numberPoints; j++) 
    			if (adjMatrix[i][j] + adjMatrix[j][i] < min)
    				min = adjMatrix[i][j] + adjMatrix[j][i];
    
    	return min;
    }
    I found this algorithm that solves the TSP problem. We give this function an adjacent matrix (a graph) and the number of points and it returns the minimal travel distance to visit all points (but only once each point).

    I can't understand what this algorithm do. Someone knows the name of this algorithm or could explain me how it works?

    Thank you,
    Rafael Andreatta
    Last edited by Salem; 03-22-2010 at 12:09 PM. Reason: Use proper code tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is the algorithm in this problem..
    By cfan in forum C Programming
    Replies: 2
    Last Post: 08-04-2009, 11:52 AM
  2. data mamgment problem (algorithm)
    By cfan in forum C Programming
    Replies: 0
    Last Post: 08-02-2009, 12:07 PM
  3. Help with grid problem (dynamic programming)
    By scp89 in forum C Programming
    Replies: 15
    Last Post: 05-07-2009, 12:16 PM
  4. Simple algorithm problem
    By stodd04 in forum C Programming
    Replies: 11
    Last Post: 03-04-2005, 11:08 AM
  5. algorithm problem
    By cdonlan in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2005, 09:16 PM

Tags for this Thread