Genetic algortihm implementation for travelling sales problem
Details of Genetic Algorithm
To initialize the population, cities are shuffled and added to the population list.
For cross over “Order One” cross over method is used.
Order One Cross Over
-
Choose random index to start swath.
-
Choose random swath width. Make sure the width does not exceed the length of the city list.
-
Create swath from parent 1 by taking the city list then copying from random index until random swath width.
-
Create a new child with empty city list.
-
Start copying from parent 2. If the city is in swath list then do not copy that city. Only copy the cities which are not present in swath.
-
Add swath to the child’s city list at random index chosen from step 1.
For mutation, “Inversion” mutation is used.
Inversion Mutation
-
Choose a random index to start from.
-
Choose another random index to stop.
-
Inverse the list from the starting index to stopping index.
For parent selection, “K-Way Tournament” selection method is used.
K-Way Tournament Selection
-
Choose random k individuals from population.
-
Compare the fitness’ of the chosen individuals.
-
Choose and return the individual with best fitness.