All Projects → maoaiz → tsp-genetic-python

maoaiz / tsp-genetic-python

Licence: other
A genetic algorithm to solve the Travelling Salesman Problem, implemented in Python. Made by Jack Frigaard, modified by Mauricio Aizaga

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tsp-genetic-python

OptimisationAlgorithms
Searching global optima with firefly algorithm and solving traveling salesmen problem with genetic algorithm
Stars: ✭ 20 (-72.6%)
Mutual labels:  genetic-algorithm
Genetic-Algorithm-on-K-Means-Clustering
Implementing Genetic Algorithm on K-Means and compare with K-Means++
Stars: ✭ 37 (-49.32%)
Mutual labels:  genetic-algorithm
multi objective optimization matlab
MATLAB Tool for Multi-Objective Optimization
Stars: ✭ 23 (-68.49%)
Mutual labels:  genetic-algorithm
biteopt
Derivative-Free Optimization Method for Global Optimization (C++)
Stars: ✭ 91 (+24.66%)
Mutual labels:  genetic-algorithm
GARI
GARI (Genetic Algorithm for Reproducing Images) reproduces a single image using Genetic Algorithm (GA) by evolving pixel values.
Stars: ✭ 41 (-43.84%)
Mutual labels:  genetic-algorithm
Neatron
Yet another NEAT implementation
Stars: ✭ 14 (-80.82%)
Mutual labels:  genetic-algorithm
NeuralGenetic
Building and training artificial neural networks (regression or classification) using the genetic algorithm.
Stars: ✭ 187 (+156.16%)
Mutual labels:  genetic-algorithm
neuroevolution-robots
Neuroevolution demo through TensorFlow.js, Neataptic, and Box2D
Stars: ✭ 31 (-57.53%)
Mutual labels:  genetic-algorithm
VRPTW-ga
Vehicle Routing Problem with Time Windows - Genetic Algorithm solution with Python
Stars: ✭ 40 (-45.21%)
Mutual labels:  genetic-algorithm
carAI-Demo
使用浅层神经网络和遗传算法训练一个可以自动驾驶小车的Demo
Stars: ✭ 64 (-12.33%)
Mutual labels:  genetic-algorithm
PHP
PHP Related Projects: Like simple PHP Genetic algorithm, LDAP login , Websockets and more
Stars: ✭ 22 (-69.86%)
Mutual labels:  genetic-algorithm
geneticalgorithm2
Supported highly optimized and flexible genetic algorithm package for python
Stars: ✭ 36 (-50.68%)
Mutual labels:  genetic-algorithm
ga-openai-gym
Usage of genetic algorithms to train a neural network in multiple OpenAI gym environments.
Stars: ✭ 24 (-67.12%)
Mutual labels:  genetic-algorithm
Smart-Algorithm
智能算法-遗传算法、蚁群算法、粒子群算法实现。实现版本Java,Python,MatLab多版本实现
Stars: ✭ 277 (+279.45%)
Mutual labels:  genetic-algorithm
freqgen
🎯 Generate DNA sequences with specified amino acid, codon, and k-mer frequencies
Stars: ✭ 16 (-78.08%)
Mutual labels:  genetic-algorithm
naturalselection
A general-purpose pythonic genetic algorithm.
Stars: ✭ 17 (-76.71%)
Mutual labels:  genetic-algorithm
wargames
two soldiers shooting at each other, controlled by a neural network with a genetic algorithm.
Stars: ✭ 22 (-69.86%)
Mutual labels:  genetic-algorithm
ant sugar
Genetic Algorithms, Mutation, Crossover, Mating, Particle Animation, Gaming, Learning, P5JS, Fun Project
Stars: ✭ 33 (-54.79%)
Mutual labels:  genetic-algorithm
Ascension
A metaheuristic optimization framework
Stars: ✭ 24 (-67.12%)
Mutual labels:  genetic-algorithm
arja
Multi-Objective GP for Automated Repair of Java
Stars: ✭ 31 (-57.53%)
Mutual labels:  genetic-algorithm

tsp-genetic-python

A genetic algorithm to solve the Travelling Salesman Problem implemented in Python 3

Usage

Run with:

> python tsp-genetic-python.py

All parameters are configure at the top of the tsp-genetic-python.py file. Parameters are documented in the code.

Cities can read from a .csv file. This is specified by the csv_name variable, provided that csv_cities = True. The .csv file must contain one city per line in the following format:

name,x,y
name,x,y
name,x,y
...

Alternatively, cities can be specified directly as City objects. This is seen in the code around line 730. Provided are some sample cities in a 200 x 200 grid, as well as the Australian capitals (not hard to solve, just go round in a straight line). If I remember correctly, the provided cities.csv file contains the state capitals of the USA. With 48 cities this dataset is quite hard to solve and the algorithm struggles.

GUI

The program has a GUI:

Screenshot

The 'map' will automatically rescale to encompass all of the cities.

Breeding/crossover

Breeding is done by selecting a random range of cities from the first parent route, and placing it into an empty child route (in the same range). Gaps are then filled in, without duplicates, in the order they appear in the second parent route. For example:

parent1: 0123456789
parent1: 5487961320

start_pos = 0 (random)
end_pos = 4 (random)

unfilled child: 01234*****
filled child:   0123458796

Each number represents a city. Asterisks are unfilled.

This algorithm conserves some of the order of the routes, but is not ideal. In the code, a method called crossover_experimental() is implemented but not used. This takes a random city and branches out left from the first parent route and right from the second parent until it hits a limit, then fills the gaps in randomly. It conserves the order of both routes from a central point. I'm still testing it.

Mutation

Mutation is done by swapping two random cities:

123456789 --> 123546789

This is primitive but does a reasonable job. The algorithm is most effective with a reasonable high rate of mutation (0.3+).

Evolution

Population evolution is achieved by filling a new population with new children from pairs of two tournament-winning parents. If elitism is set to True, the fittest from the initial population will also be carried over.

Future

In the future I might implement the 2opt manœuvre, since the algorithm often seems to get stuck with routes crossing over.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].