Evolution of a salesman: A complete genetic algorithm tutorial for Python
In this tutorial, we'll be using a GA to find a solution to the traveling salesman problem (TSP). Let's start with a few definitions, rephrased in the context of the TSP: Now, let's see this in action. While each part of our GA is built from scratch, we'll use a few standard packages to make things easier: We first create a City class that will allow us to create and handle our cities. These are simply our (x, y) coordinates. Within the City class, we add a distance calculation (making use of the Pythagorean theorem) in line 6 and a cleaner way to output the cities as coordinates with __repr__ in line 12. We'll also create a Fitness class.
Jul-22-2018, 15:19:40 GMT