This repository is implementation of Genetic Algorithm to solve the "Evolution of a salesman" problem. Lets say there is a travelling salesman who has to visit different cities daily. He starts from one of the cities and has to travel to each city once and return to the origin city. We have to calculate the shortest route using Genetic algorithm.
Genetic Algorithm is an algorithm that is inspired from the process of "Natural Selection". The theory of Natural Selection or Darwin's theory of evolution refers to evolution of species and survival of the fittest.
Let’s start with a few definitions, rephrased in the context of the problem:
- Gene: a city (represented as (x, y) coordinates)
- Individual (aka “chromosome”): a single route satisfying the conditions above
- Population: a collection of possible routes (i.e., collection of individuals)
- Parents: two routes that are combined to create a new route
- Mating pool: a collection of parents that are used to create our next population (thus creating the next generation of routes)
- Fitness: a function that tells us how good each route is (in our case, how short the distance is)
- Mutation: a way to introduce variation in our population by randomly swapping two cities in a route
- Elitism: a way to carry the best individuals into the next generation
Our Algorithm will proceed in the following steps:
- Create the population
- Determine fitness
- Select the mating pool
- Breed
- Mutate
- Repeat
- METHOD: POST
- URL: http://localhost:8080/GA/salesManRoute
- Body: This is a Sample Request with 8 cities with symmetric cartesian co-ordinates.
{
"data":{
"popSize":100,
"genSize":100,
"mutationRate":0.05,
"city":[
{
"name":"A",
"x":10,
"y":5
},
{
"name":"B",
"x":10,
"y":-5
},
{
"name":"C",
"x":5,
"y":-10
},
{
"name":"D",
"x":-5,
"y":-10
},
{
"name":"E",
"x":-10,
"y":-5
},
{
"name":"F",
"x":-10,
"y":5
},
{
"name":"G",
"x":-5,
"y":10
},
{
"name":"H",
"x":5,
"y":10
}
]
}
}