I am currently trying to solve the travelling salemsan problem using VBA. I have created a distance matrix for 20 cities. I also have a two column table with cities 1-20 listed in the first column and the corresponding distances in the second column. For example, from the table below the salesman starts at city 1 then goes to 2, then 3 etc. The distance between city 1 and 2 being 8km etc.
City Distance
1 0
2 8
3 4
4 3
I have a code that swaps the cities around, but I don't know how to write a code that also changes the distances with it. If I swap city's 2 and 3 around, the distance between city 1 and 3 is obviously not 8km. Can someone please help?
The code I to swap two cells is,
I'm not sure how to use this code to change the distances as well.Please Login or Register to view this content.
Bookmarks