I currently have a matrix like this:
[[2, 6, 8, 9, 8, 6, 3], [4, 8, 10, 10, 7, 5], [5, 6, 8, 8, 9], [4, 6, 7, 8], [3, 5, 9], [3, 6], [4]]
such that the first array is distances from city 1 to 2,3,4,5,6,7,8 the second is distances from city 2 to 3,4,5,6,7,8 ... the 7th array is the distance from city 7 to city 8. I need to convert it into a proper distance matrix.
So far, I've inserted 0's to make it size 7 and it becomes:
[[2, 6, 8, 9, 8, 6, 3], [0, 4, 8, 10, 10, 7, 5], [0, 0, 5, 6, 8, 8, 9], [0, 0, 0, 4, 6, 7, 8], [0, 0, 0, 0, 3, 5, 9], [0, 0, 0, 0, 0, 3, 6], [0, 0, 0, 0, 0, 0, 4]]
I then did
for i,j if distance==0 then distances[i][j]=distances[j][i]
and it becomes:
[[2, 6, 8, 9, 8, 6, 3], [6, 4, 8, 10, 10, 7, 5], [8, 8, 5, 6, 8, 8, 9], [9, 10, 6, 4, 6, 7, 8], [8, 10, 8, 6, 3, 5, 9], [6, 7, 8, 7, 5, 3, 6], [3, 5, 9, 8, 9, 6, 4]]
I then inserted 0's to include the distance from city to same city:
[[0, 2, 6, 8, 9, 8, 6, 3], [6, 0, 4, 8, 10, 10, 7, 5], [8, 8, 0, 5, 6, 8, 8, 9], [9, 10, 6, 0, 4, 6, 7, 8], [8, 10, 8, 6, 0, 3, 5, 9], [6, 7, 8, 7, 5, 0, 3, 6], [3, 5, 9, 8, 9, 6, 0, 4]]
and finally added on the final city's distances:
[[0, 2, 6, 8, 9, 8, 6, 3], [6, 0, 4, 8, 10, 10, 7, 5], [8, 8, 0, 5, 6, 8, 8, 9], [9, 10, 6, 0, 4, 6, 7, 8], [8, 10, 8, 6, 0, 3, 5, 9], [6, 7, 8, 7, 5, 0, 3, 6], [3, 5, 9, 8, 9, 6, 0, 4], [3, 5, 9, 8, 9, 6, 4, 0]]
but I appear to have gone wrong somewhere, as I have not produced the correct distance matrix. I believe it may be the distances[i][j]=[j][i] bit, but I'm not entirely sure.