Skip to content

OptiNobles/tsp-genetic-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

tsp-genetic-algorithm

Genetic algorithm optimizer designed to solve Travelling Salesman Problem (TSP).

DEMO

  • 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()

output_plot_GAO

  • Visualization
GA_optimizer.show_graph(fitted=True)

output_graph_GAO

Releases

No releases published

Packages

No packages published

Languages