How to use a genetic algorithm for TSP in Matlab
Show older comments
Hello everyone,
For a programming course I'm working on a heuristic solution of the travelling salesman problem. I've written a Matlab code that uses a nearest neighbour search to build an initial route that is hopefuly a good approximation of a fast route. The next step in my assignment is to improve the route using a method of choice. For this i have chosen a genetic algorithm, which i have written in Matlab.
A route consists of N cities that all should be visited once and only once. They are represented by a n integer and their x,y coordinates are stored in a textfile. Every route should always start and end with 1 (you have to return to your first city). The goal is to find the shortest route possible. I've based my code heavily on these tutorials for a genetic algorithm:
http://www.theprojectspot.com/tutorial-post/applying-a-genetic-algorithm-to-the-travelling-salesman-problem/5 and http://www.theprojectspot.com/tutorial-post/creating-a-genetic-algorithm-for-beginners/3
In my case, the route's fitness is represented by its length.
The problem is that the code seems to work, but the routes it finds only seem to get worse every iteration of the program, and not better. I've looked at the code over and over and can't figure out what i'm doing wrong. Could anybody please take a look and see what's wrong? Many thanks in advance.
Kind regards,
Joris
Answers (1)
Matt J
on 26 Nov 2012
0 votes
Why not use the TSP genetic algorithms already available on the FEX
Alternatively, you could compare the code there with yours to get an idea of what's wrong.
Categories
Find more on Nearest Neighbors in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!