Solving Traveling Salesman Problem (TSP) with a genetic algorithm (GA)
https://osi-oswald.github.io/ga-tsp/
Number of cities to generate.
Generates cities by random coordinates.
Generates cities on a circle. The optimal TSP solution for humans is obvious (just walking along the circle). But the GA does not know that ;-)
Simply finds a path by picking a random city after another.
Finds a path by picking the closest city after another. It will always find the optimal path if the cities were generated on a circle.
GA implemented as found documented on several sources.
Selection is done by Roulette Wheel.
The chance that 2 selected candidates are being crossed over. It uses the Order 1 Crossover operator.
The chance that a candidate is getting mutated. The mutation will swap two arbitrary cities.
How much of the best candidates (elites) of the current generation are being taken over to the next generation (without crossover and mutation).
I tried out some ideas of my own. Apart from the population size, no additional parameters are needed.
Selection is done by Roulette Wheel.
It always applies crossover to candidates (using Order 1 Crossover).
It always mutates candidates by a random mutation rate (0 - 99%). The mutation deletes arbitrary paths (depending on mutation rate) and repairs them again randomly.
Instead of an elitism rate, the next generation is selected by the elites of the previous generation and newly computed generation.