Coder Social home page Coder Social logo

rameziophobia / travelling_salesman_optimization Goto Github PK

View Code? Open in Web Editor NEW
67.0 2.0 18.0 1.79 MB

Python implementation for TSP using Genetic Algorithms, Simulated Annealing, PSO (Particle Swarm Optimization), Dynamic Programming, Brute Force, Greedy and Divide and Conquer

License: MIT License

Python 100.00%
particle-swarm-optimization genetic-algorithms pso tsp algorithms visualizations travelling-salesman-problem simulated-annealing

travelling_salesman_optimization's Introduction

Solving the Travelling Salesman Problem in Python

Implemented techniques

  • Genetic Algorithm
  • Simulated Annealing
  • PSO: Particle Swarm Optimization
  • Divide and conquer
  • Dynamic Programming
  • Greedy
  • Brute Force

When the solution is found it is plotted using Matplotlib and for some algorithms you can see the intermediate results

Example visualizations

The following visualizations are all applied on the EIL51 dataset available through the TSP online library

Genetic Algorithm

Genetic Algorithm

Divide and Conquer

Divide and Conquer

Greedy

Greedy

PSO: Particle Swarm Optimization

Particle Swarm Optimization

travelling_salesman_optimization's People

Contributors

rameziophobia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

travelling_salesman_optimization's Issues

Inquiry about PSO code

Hi, I have a question about how you implemented particle swarm optimization. In pso.py, the section of code that updates the new routes has a bit of code that I'm not sure of the function of.

`

            for i in range(len(self.cities)):
                if new_route[i] != particle.pbest[i]:
                    swap = (i, particle.pbest.index(new_route[i]), self.pbest_probability)
                    temp_velocity.append(swap)
                    new_route[swap[0]], new_route[swap[1]] = \
                        new_route[swap[1]], new_route[swap[0]]

            for i in range(len(self.cities)):
                if new_route[i] != gbest[i]:
                    swap = (i, gbest.index(new_route[i]), self.gbest_probability)
                    temp_velocity.append(swap)
                    gbest[swap[0]], gbest[swap[1]] = gbest[swap[1]], gbest[swap[0]]

            particle.velocity = temp_velocity

            for swap in temp_velocity:
                if random.random() <= swap[2]:
                    new_route[swap[0]], new_route[swap[1]] = \
                        new_route[swap[1]], new_route[swap[0]]

            particle.route = new_route
            particle.update_costs_and_pbest()`

In the second for loop, what does gbest[swap[0]], gbest[swap[1]] = gbest[swap[1]], gbest[swap[0]] do? gbest doesn't seem to get used as it just gets replaced. It seems like you implemented pso by first making the new route the same as the personal best, then made the global best the same as the new route, and then returned the new route back to what it was originally based on a given probability. The first and third for loops make sense, but the second one is a bit confusing. I ran the code after commenting out gbest[swap[0]], gbest[swap[1]] = gbest[swap[1]], gbest[swap[0]] and it seemed to run the same. Could you clarify what that line of code is for? Thank you for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.