0

hello friends
i wanna know is this algorithm for Travelling salesman problem (TSP) correct ? if isn't help me for correct algorithm plz ?
tnx

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;
}
2
Contributors
1
Reply
23
Views
3 Years
Discussion Span
Last Post by rubberman
0

Sigh... I see that your first problem is that you don't understand C syntax, especially with regard to pointer arithmetic... Where did you get this code and if you wrote it yourself, where did you get the algorithm? Start with that.

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.