Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Solving TSP using Genetic Algorithm

Gadi Paz
March 19, 2017

Solving TSP using Genetic Algorithm

Solving TSP using Genetic Algorithm

Gadi Paz

March 19, 2017
Tweet

Other Decks in Science

Transcript

  1. Traveling Salesman Problem Gadi Paz © March 2017 • Defined

    by a set of cities and the distances between each city pair. • The problem is to find a circuit that goes through each city once and that ends where it starts. (This in itself isn't difficult) • What makes the problem interesting is to find the shortest circuit among all those that are possible.
  2. Traveling Salesman Problem Gadi Paz © March 2017 • We

    need to compute the length of all possible circuits. • Keep the shortest one. Issue is that the number of such circuits grows very quickly with the number of cities. If there are n cities then this number is factorial of n-1 = (n-1)(n-2)...3.2 Indeed, we can select arbitrarily one city to start from (the starting point doesn't matter much given one must end at the same place). Then we have n-1 different choices for the second city to be visited, n-2 choices for the third city, and so on. For example, the factorial of 10 is 3628800, but the factorial of 20 is a gigantic, 2432902008176640000. (~ Seconds since the big bang…)
  3. Paradigm of Evolution Gadi Paz © March 2017 Every organism

    contains an array of traits - called DNA, when 2 parents mate they produce a child containing a mixture of their DNA. Depending on how well those traits work together to help the child survive so that he may reproduce, will determine if those traits will pass into future generation. Rarely a random trait enters a child's DNA that was not inherited from the parents, we call this mutation. If the mutation is beneficial, the organism will survive long enough to carry the mutation over to future generations. So the cycle continues, after many generations we continue to optimize the population by "mixing and matching", "trial and error" of DNA.
  4. Genetic Algorithm Gadi Paz © March 2017 Genetic Algorithms are

    used to find optimal solution by method of evolution-inspired search and optimization. Generally used in problems where linear/brute-force searches are not viable in terms of time, such as – Travelling Salesman Problem, Timetable Scheduling, Finding Neural Network Weights, Sudoku, Trees(data-structure) etc. The first requirement is a encoding scheme suitable for representing individuals, second requirement being a evaluation function for representing the fitness of an individual.
  5. Initialize Population Gadi Paz © March 2017 The population is

    initialized by randomly generating a collection of DNA samples. The size of the population depends on the size of the problems search space, and the computational time it takes to evaluate each individual. Most of the time you will be dealing in population counts of about 50 up-to a 1000.
  6. Evaluation Gadi Paz © March 2017 The evaluation function determines

    the fitness of an individual. This is the most important part to the Genetic algorithm, if this function is flawed, the algorithm will not produce results. The evaluation function should not return a Boolean(true/false) value, it has to be a comparable result. If individuals are able to be sorted from fittest to weakest, it is a viable evaluation function. For evaluating distances between cities you may return the total distance traveled as a fitness score.
  7. Selection Gadi Paz © March 2017 Selection is where we

    will be choosing the parents for mating. Selection happens for each child in the new population. There are three type of parent selection methods, Fitness Proportionate Selection, Tournament Selection, and Truncation Selection. A viable option is to carry over selected individuals to the next generation.
  8. Crossover Gadi Paz © March 2017 Once you have your

    selected individual(s) also known as the parents, we need to mix and match their DNA to produce a new population of children. We call this process Crossover.
  9. Mutation Gadi Paz © March 2017 Mutation allows the algorithm

    to introduce diversity into the population, expanding the opportunity to search unexplored areas in the search space for fitter solutions. Mutation is implemented by giving each element in the DNA array a probability of 2-5% of being randomly altered. The mutation procedure is called for every child. After the generating a new generation, we go back to the evaluation step.
  10. When to Stop? Gadi Paz © March 2017 After the

    Evaluation step, we can either stop: • From finding the most optimal solution. • Generation is not progressing (evolving) in fitness. • Where time is a factor.
  11. Back to TSP Gadi Paz © March 2017 Finding a

    solution to the travelling salesman problem requires we set up a genetic algorithm in a specialized way. For instance, a valid solution would need to represent a route where every location is included at least once and only once. If a route contain a single location more than once, or missed a location out completely it wouldn't be valid and we would be valuable computation time calculating it's distance. To ensure the genetic algorithm does indeed meet this requirement special types of mutation and crossover methods are needed.
  12. TSP Mutation Gadi Paz © March 2017 the mutation method

    should only be capable of shuffling the route, it shouldn't ever add or remove a location from the route, otherwise it would risk creating an invalid solution. One type of mutation method we could use is swap mutation.
  13. TSP Crossover Gadi Paz © March 2017 One crossover method

    that's able to produce a valid route is ordered crossover. In this crossover method we select a subset from the first parent, and then add that subset to the offspring. Any missing values are then adding to the offspring from the second parent in order that they are found. Implementation
  14. Gadi Paz © March 2017 References • https://www.ibm.com/developerworks/community/blogs/jfp/entry/no_the_tsp_isn_t_np_compl ete?lang=en •

    http://www.theprojectspot.com/tutorial-post/applying-a-genetic-algorithm-to-the-travelling-sal esman-problem/5 • http://techeffigytutorials.blogspot.co.il/2015/02/the-genetic-algorithm-explained.html • http://toddwschneider.com/posts/traveling-salesman-with-simulated-annealing-r-and-shiny