Git Product home page Git Product logo

tsp's Introduction

Solving Travelling Salesman using Genetic Algorithms

Build status

Build Status

Running the code

 make
 make run

Or alternatively use:

 make
 ./omp <InputFileName> <NumThreads>

Algorithm

Given the conditions of the problem at hand I have chosen the initial population of the first generation to be 1000 with a P of 256( P is the number of the fittest parents selected to crossover with a probability of 0.8 ). The algorithm works as follows : it first initialises the population with a set of chromosomes all distinct as can be seen from the use of std::set. This is sorted and the initial guess is stored. After entering the while loop for iterations I first crossover with PMX and GX and use their offsprings and the parents of these offsprings as the new population. This is sorted and the fitness of the new children is evaluated.

For the crossover technique I have used 2 offsprings from PMX and 2 from GX. I have used a hashing from city ids to characters using a startingChar as offset. The initialisation algorithm is Fisher Yates for randomly shuffling a string which is able to produce a completely distinct set of strings till upto ~2800 iterations.

Parallelisation has been done in crossover and mutation steps as these were the two heavy ops per iteration for the convergence of the GA. Special care had to be taken in the case of different seeds for rand() for different threads which has been taken care of. [ calculateFitness() 's parllelisation didnt yield good results] The for loops have been parallelised using standard omp technqiues and use the static load balancing.

Performance

For a test case of 32 cities following are the running times: (4 core, i7-1.8Ghz) Each of these running times indicate the time taken to reach the known maximum value of fitness.

Threads Running Times(s)
4 15.6586
6 5.814
8 4.824
12 3.489
16 3.005
24 2.744
32 2.610

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.