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:
The main parts of our solution are described by the following steps:
- The program starts by creating an instance of the "bayg29" problem as follows:
TSP_NAME = "bayg29"tsp = tsp.TravelingSalesmanProblem(TSP_NAME)
- 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", ...