# Travelling Salesman Problem: Distance between solutions

I'm designing a genetic algorithm to solve the travelling salesman problem. So far, I've gotten fairly good results. I'm now trying to improve on them by implementing some sort of diversification scheme (like fitness sharing and crowding), although I'm struggling with the conceptualisation of the inter-solution distance a bit.

Solutions represent a path that goes through all cities, i.e. a permutation of the order in which they are visited. This is represented in my code by np.arrays. If I want to know how similar two solutions are, I basically want to find the distance between two permutations of n_cities elements. I currently have two ideas for the distance function.

1. Levenshtein distance, which is simply 'how many atomic edits are two sequences removed from each other.
2. Hamming distance, which denotes the number of positions that are the same.

Note that, for each solution, I make sure to cycle it so it starts in the same position (city). Otherwise these metrics won't make sense.

Which of them is more appropriate? Is there a better solution? I've browsed a number of articles, but haven't really found an answer yet.

• As you state, there are multiple ways of comparing to solutions and thus their distance. Which is more appropriate depends on what your goal is. – Juho Nov 22 '20 at 20:34
• Well, my ultimate goal is finding the best solution (i.e., the one with the smallest route length). The reason for implementing this distance metric is so I can use it in either a crowding step (for each best solution I select, remove the most similar one from the selection pool so it cannot be selected), or a fitness sharing algorithm (penalise solutions based on their proximity to other solutions). – Inkidu616 Nov 22 '20 at 20:38
• I doubt that we will be able to predict which of these will make your genetic algorithm most effective. That requires experimentation and trial-and-error. – D.W. Nov 22 '20 at 21:54
• Cross-posted: stackoverflow.com/q/64959096/781723, cs.stackexchange.com/q/132544/755. Please do not post the same question on multiple sites. Thank you! – D.W. Nov 22 '20 at 21:55