Genetic algorithm optimizer designed to solve Travelling Salesman Problem (TSP).
- Input should be in the form of a list [ [x_1, y_1], [x_2, y_2], ... , [x_n, y_n] ]
from random import randint
towns = []
for town in range(60):
towns.append([randint(0, 100), randint(0, 100)])
- How to initialize
from GeneticAlgorithm import GeneticAlgorithm
GA_optimizer = GeneticAlgorithm(elitism=50, mutation=0.01, fitness_function_degree=1.0)
GA_optimizer.fit(towns, popsize=500, gens=500, mode='tournament')
- Plotting results
GA_optimizer.plot()
- Visualization
GA_optimizer.show_graph(fitted=True)