Pergunta

Consider the following matrix/array that contains the distances between 4 cities:

0 1 2 3
1 0 4 5
2 4 0 6
3 5 6 0

Each row/column pair (i,j) represents the distance between city i and city j. 
For example the distance between city 1 and city 4 is 3.

I just wanted to check if my understanding here is correct. Like an array, the first city starts off at 0. So in the matrix, city 1 is 0 and city 2 is 1.

The path between city 3 and city 3 would be 0? First we look at row 2 and then column 2.

Let's imagine we had the following tour: T = {1,3,2,4}. To work this out we do...

City 1 to city 3 is 2. City 3 to city 2 is 4. City 2 to 4 is 5.

So the length of the tour should be 2 + 4 + 5 = 11? In the traveling salesman problem however, we always travel back to the starting position, so from city 4 we must go back to 1 which will cost a extra 3, so our final tour is 14 (11 + 3).

Foi útil?

Solução

Yes, correct. For more TSP info see the TSP webpage.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top