Search code examples
genetic-algorithmtraveling-salesmanevolutionary-algorithm

Travelling Sales Person - Evolutionary Algorithm


I have an understanding of how evolutionary algorithms work. I have written one to find the maximum of an equation in n-dimensional space.

I can see a problem using the same design to solve the TSM problem. When I use cross over, or even mutation, I might create an individual that goes to the same city twice, or doesn't visit every city.

What steps can I take to make sure each individual in my population visits every city only once? That is, every individual is a valid answer.


Solution

  • You cannot use the same design pattern which is used to find the maximum of an equation and apply it to TSP problem. The reason is that the chromosome encoding / decoding is different between two problems. For numeric equation problem, mostly the chromosome can be decoded as "real value" / "binary value" depending on the type of your problem. However, for TSP problem, we have to use the "permutation" encoding. This permutation encoding is mainly used for "Combinatorial optimization" (https://en.wikipedia.org/wiki/Combinatorial_optimization)

    Below is quite a good reference site for techniques in encoding in GA: http://www.obitko.com/tutorials/genetic-algorithms/encoding.php

    The idea behind this "permutation encoding/decoding" is that: Given a list of n city denoted as c1, c2, ..., cn; the chromosome will be encoded as the order of these cities where the travel salesman has traveled to one by one (e.g. chromosome = c1, c2, ..., cn). By apply permutation on this chromosome, you can generate different chromosomes for the population and GA operators will start from here. Having the chromosome encoded like this can help you to avoid the problem where one city is visited more than once!

    Since you do not mention any data structure or preferred programming language, so I cannot post the source code here. If you still want to have some example of working version, you can contact me via email.