Genetic algorithms solution

For our first attempt to solve the TSP using a genetic algorithm, we created the Python program 02-solve-tsp-first-attempt.py, located at the following URL:

https://github.com/PacktPublishing/Hands-On-Genetic-Algorithms-with-Python/blob/master/Chapter04/02-solve-tsp-first-attempt.py

The main parts of our solution are described by the following steps:

  1. The program starts by creating an instance of the "bayg29" problem as follows:
TSP_NAME = "bayg29"tsp = tsp.TravelingSalesmanProblem(TSP_NAME)
  1. Next, we need to define the fitness strategy. Here we want to minimize the distance, which translates to a single-objective minimizing Fitness class, defined using a single negative weight:
creator.create("FitnessMin",  ...

Get Hands-On Genetic Algorithms with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.