{"id":21124845,"url":"https://github.com/bitartisan1/tsp-genetic-algorithm-solver","last_synced_at":"2025-07-08T22:31:03.730Z","repository":{"id":185108960,"uuid":"673018485","full_name":"bitArtisan1/TSP-Genetic-Algorithm-Solver","owner":"bitArtisan1","description":"Python Implementation of  Traveling Salesman Problem (TSP) Using Genetic Algorithms/Hybridized with more Heuristic Optimizations","archived":false,"fork":false,"pushed_at":"2024-08-06T17:42:49.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-06T21:16:33.557Z","etag":null,"topics":["aco","genetic-algorithm","genetic-algorithms","gui","opt2","plotting","python","simulated-annealing","tsp","tsp-problem","tsp-solver"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitArtisan1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-31T17:21:52.000Z","updated_at":"2024-08-06T17:42:52.000Z","dependencies_parsed_at":"2024-08-03T22:21:43.332Z","dependency_job_id":null,"html_url":"https://github.com/bitArtisan1/TSP-Genetic-Algorithm-Solver","commit_stats":null,"previous_names":["yanpuri/tsp-genetic-algorithm-solver","git-aamar/tsp-genetic-algorithm-solver","bitartisan1/tsp-genetic-algorithm-solver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitArtisan1%2FTSP-Genetic-Algorithm-Solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitArtisan1%2FTSP-Genetic-Algorithm-Solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitArtisan1%2FTSP-Genetic-Algorithm-Solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitArtisan1%2FTSP-Genetic-Algorithm-Solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitArtisan1","download_url":"https://codeload.github.com/bitArtisan1/TSP-Genetic-Algorithm-Solver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225465595,"owners_count":17478590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aco","genetic-algorithm","genetic-algorithms","gui","opt2","plotting","python","simulated-annealing","tsp","tsp-problem","tsp-solver"],"created_at":"2024-11-20T04:18:15.956Z","updated_at":"2025-07-08T22:31:03.724Z","avatar_url":"https://github.com/bitArtisan1.png","language":"Python","funding_links":["https://ko-fi.com/D1D11CZNM1"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://ko-fi.com/D1D11CZNM1\"\u003e\n    \u003cimg src=\"https://ko-fi.com/img/githubbutton_sm.svg\" alt=\"Support me on Ko-fi\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n# TSP-Genetic-Algorithm-Solver\nThis repository contains a Python implementation of a Traveling Salesman Problem (TSP) solver using Genetic Algorithms hybridized with 2-Opt heuristic optimization and Simulated Annealing. The solver also includes metaheuristic optimizations like Ant Colony Optimization (AOC), also, an Interactive GUI with path highlighting and a city diagram drawer.\n## What is TSP ?\nThe traveling salesman problem (TSP) poses the question: \"Given a set of cities and the distances between each pair of cities, what is the shortest route that visits each city exactly once and returns to the starting city?\" This problem is classified as NP-hard in combinatorial optimization and is of major importance in the realms of theoretical computer science and operations research (OR).\n## Features\n### TSP Solver using Genetic Algorithms (GA):\n- The Genetic Algorithm is employed to find an approximate solution to the Traveling Salesman Problem.\n- The algorithm evolves a population of tours over generations, favoring shorter tours.\n- Tournament selection is used to select parents for the crossover process.\n- Ordered crossover (OX) is used to create offspring from selected parents.\n- Mutation is applied to the offspring with a specified mutation rate to maintain genetic diversity.\n### 2-Opt Heuristic Optimization:\nAfter obtaining the best tour from the Genetic Algorithm, a 2-Opt heuristic is applied to further optimize the tour.\nThe 2-Opt algorithm iteratively swaps pairs of edges in the tour to improve its length.\nThe process continues until no further improvement is possible.\n### Simulated Annealing (SA) Optimization:\nAdditionally, the 2-Opt optimized tour is subjected to Simulated Annealing optimization to escape local minima and potentially improve the result.\nSimulated Annealing is a probabilistic optimization method that allows the algorithm to accept worse solutions with a certain probability based on the current \"temperature\".\nThe temperature reduces over time, leading the algorithm to converge toward the optimal solution.\n### Pheromone Ant Colony Meta-heuristic Optimization Search (AOC):\nThe program also implements a separate search using Pheromone-Based Ant Colony Optimization, Pheromone-based ACO algorithm guides the ants to build a solution collectively, based on the pheromone trails deposited on the edges.\n### Plotting\nOnce the search finishes for GA/AOC, the search history will be plotted for analysis and estimation (Generation/Iteration vs Distance).\n## To Add\n* Implement other metaheuristics like Particle Swarm Optimization.\n* Improve the GA structure, Elitism and Population Diversity, Adaptive Mutation Rate.\n* Experiment with the Lin Kernighan Algorithm.\n* Improve the GUI for better user communication and clarity, also add the ability to customize the diagram from the GUI.\n* Expand the program to Solve other operational search problems (A* Algorithm, Djikstra's Algorithmm,...).\n* Organize the code into seperate files, add comments.\n## Requirements\nIt requires `numpy`, `tkinterr`, `matplotlib`:\n```\n$ pip install numpy tkinter matplotlib\n```\nInstall \u0026 launch using:\n```\n$ git clone https://github.com/yanpuri/TSP-Genetic-Algorithm-Solver.git\n$ cd TSP-Genetic-Algorithm-Solver\n$ python tsp_solver.py\n```\n\nYou can also modify other parameters for better tunning (alpha, beta, ...)\n\n\n## Support Me\nIf you find RepoUp useful, consider supporting me by:\n\n- Starring the repository on GitHub\n- Sharing the tool with others\n- Providing feedback and suggestions\n- Follow me for more :)\n\n\u003ca href=\"https://ko-fi.com/D1D11CZNM1\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/ba118768-9054-416f-b7b2-adaa69a53434\" alt=\"Support me on Ko-fi\" width=\"200\" /\u003e\n\u003c/a\u003e\n    \n---\nFor any issues or feature requests, please open an issue on GitHub. Happy coding!\n\u003ccenter\u003e\n\u003cdiv style=\"text-align: center;\"\u003e\n  \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/user-attachments/assets/36a3e590-bad2-463d-a25e-f56d65c26761\" alt=\"octodance\" width=\"100\" height=\"100\" style=\"margin-right: 10px;\"/\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\u003c/center\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitartisan1%2Ftsp-genetic-algorithm-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitartisan1%2Ftsp-genetic-algorithm-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitartisan1%2Ftsp-genetic-algorithm-solver/lists"}