To encapsulate the TSP, we created a Python class called TravelingSalesmanProblem. This class is contained in the tsp.py file, which can be found at the following link:
https://github.com/PacktPublishing/Hands-On-Genetic-Algorithms-with-Python/blob/master/Chapter04/tsp.py
The class provides the following private methods:
- __create_data(): Reads the desired TSPLIB file off the internet, extracts the city coordinates, calculates the distances between every two cities, and uses them to populate a distance matrix (two-dimensional array). It then serializes the city locations and serializes the calculated distances to disk using the pickle utility.
- __read_data(): Reads the serialized data, and if not available, calls ...