{"id":26063756,"url":"https://github.com/sdley/traveling-salesman-problem","last_synced_at":"2026-07-10T20:31:28.308Z","repository":{"id":281317635,"uuid":"944895848","full_name":"sdley/traveling-salesman-problem","owner":"sdley","description":"Traveling Salesman Problem Algorithms","archived":false,"fork":false,"pushed_at":"2025-03-08T09:12:45.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T14:42:01.231Z","etag":null,"topics":["brute-force","data-structures-and-algorithms","nearest-neighbor","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sdley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-03-08T07:19:01.000Z","updated_at":"2025-03-08T09:12:49.000Z","dependencies_parsed_at":"2025-03-08T09:39:28.339Z","dependency_job_id":null,"html_url":"https://github.com/sdley/traveling-salesman-problem","commit_stats":null,"previous_names":["sdley/traveling-salesman-problem"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sdley/traveling-salesman-problem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdley%2Ftraveling-salesman-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdley%2Ftraveling-salesman-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdley%2Ftraveling-salesman-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdley%2Ftraveling-salesman-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sdley","download_url":"https://codeload.github.com/sdley/traveling-salesman-problem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdley%2Ftraveling-salesman-problem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35343135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-10T02:00:06.465Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["brute-force","data-structures-and-algorithms","nearest-neighbor","tsp-solver"],"created_at":"2025-03-08T17:18:48.937Z","updated_at":"2026-07-10T20:31:28.283Z","avatar_url":"https://github.com/sdley.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Traveling Salesman Problem\nThe Traveling Salesman Problem states that you are a salesperson and you must visit a number of cities or towns.\n\n- **Rules**: Visit every city only once, then return back to the city you started in.\n\n- **Goal**: Find the shortest possible route.\n\nThere is almost no other way to find the shortest route than to check all possible routes.\n\nThis means that the time complexity for solving this problem is O(n!), which means 720 routes needs to be checked for 6 cities, 40,320 routes must be checked for 8 cities, and if you have 10 cities to visit, more than 3.6 million routes must be checked!\n\n## Traveling Salesman Problem Algorithms\nHere are some of the most popular solutions to the Travelling Salesman Problem:\n\n### The brute-force approach\nTThe brute-force approach, also known as the naive approach, calculates and compares all possible permutations of routes or paths to determine the shortest unique solution. To solve the TSP using the brute-force approach, you must calculate the total number of routes and then draw and list all the possible routes. Calculate the distance of each route and then choose the shortest one — this is the optimal solution. \n\nThis is only feasible for small problems, rarely useful beyond theoretical computer science tutorials.\n\nThe reason why the brute force approach of finding the shortest route (as shown above) is so time consuming is that we are checking all routes, and the number of possible routes increases really fast when the number of cities increases.\n\n### The nearest neighbor method\nTo implement the nearest neighbor algorithm, we begin at a randomly selected starting point. From there, we find the closest unvisited node and add it to the sequencing. Then, we move to the next node and repeat the process of finding the nearest unvisited node until all nodes are included in the tour. Finally, we return to the starting city to complete the cycle.\n\nWhile the nearest neighbor approach is relatively easy to understand and quick to execute, it rarely finds the optimal solution for the traveling salesperson problem. It can be significantly longer than the optimal route, especially for large and complex instances. Nonetheless, the nearest neighbor algorithm serves as a good starting point for tackling the traveling salesman problem and can be useful when a quick and reasonably good solution is needed.\n\nThis greedy algorithm can be used effectively as a way to generate an initial feasible solution quickly, to then feed into a more sophisticated local search algorithm, which then tweaks the solution until a given stopping condition.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdley%2Ftraveling-salesman-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdley%2Ftraveling-salesman-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdley%2Ftraveling-salesman-problem/lists"}