GithubHelp home page GithubHelp logo

nimagarshasebi / tsp-genetic Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 3 KB

This project implements a Genetic Algorithm to solve the Traveling Salesman Problem (TSP) using Python. The Traveling Salesman Problem involves finding the shortest possible tour that visits a set of cities and returns to the starting city.

Python 100.00%
geneticalgorithm matplotlib numpy optimization python tournoment-selection tournomentselection travelingsalesmanproblem

tsp-genetic's Introduction

TSP-Genetic

This code defines a genetic algorithm for solving the traveling salesman problem. The City and Country classes are used to represent the cities and the country, respectively. The Genetic class contains methods for initializing the population, calculating fitness, selecting parents through tournament selection, performing crossover and mutation operations, evaluating generations, finding the best generation, and showing the route of the best solution.

The fitness_function method calculates the total distance of each individual in the population and assigns a fitness value based on the distance.

The tournament_selection method selects two parents from the population based on their fitness values using a tournament selection approach.

The crossover method performs a crossover operation between two parents to create offspring.

The mutation method introduces random changes to an offspring to maintain genetic diversity in the population.

The evaluating_generation method evaluates each offspring in a generation by calculating its total distance.

The best_generation method finds the best solution in a generation based on its fitness value.

Finally, the show_route method visualizes the route of an individual using matplotlib.

tsp-genetic's People

Contributors

nimagarshasebi avatar

Stargazers

 avatar Nick Imanzi avatar

Watchers

 avatar

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.