{"id":17662405,"url":"https://github.com/onkolahmet/tsp","last_synced_at":"2025-09-02T04:05:43.121Z","repository":{"id":115719984,"uuid":"279082353","full_name":"onkolahmet/TSP","owner":"onkolahmet","description":"using 2-opt algorithm with fast and guided local search heuristics","archived":false,"fork":false,"pushed_at":"2020-10-23T21:34:58.000Z","size":419,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T11:30:27.625Z","etag":null,"topics":["heuristic-search-algorithms","local-search","tsp-problem"],"latest_commit_sha":null,"homepage":"","language":"Java","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/onkolahmet.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":"2020-07-12T14:33:32.000Z","updated_at":"2020-10-23T21:35:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"719006de-6f5f-470c-bb13-ec75b2486de1","html_url":"https://github.com/onkolahmet/TSP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/onkolahmet/TSP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onkolahmet%2FTSP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onkolahmet%2FTSP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onkolahmet%2FTSP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onkolahmet%2FTSP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onkolahmet","download_url":"https://codeload.github.com/onkolahmet/TSP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onkolahmet%2FTSP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273227970,"owners_count":25067691,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"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":["heuristic-search-algorithms","local-search","tsp-problem"],"created_at":"2024-10-23T18:22:25.005Z","updated_at":"2025-09-02T04:05:43.105Z","avatar_url":"https://github.com/onkolahmet.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSP\n- The travelling salesman problem (TSP) asks the following question: \n- \"Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?\"\n-  Main purpose of this problem is to find the shortest path which is as close to the optimal tour as possible. \n- Since TSP problem is [NP-hard problem](https://en.wikipedia.org/wiki/NP-hardness), best approach for effiency is to find the approximate result in shortest amount of time.\n\n\n![Opera Snapshot_2020-10-24_000552_upload wikimedia org](https://user-images.githubusercontent.com/62245004/97054132-e5cdb300-158c-11eb-999d-aae7977a35c1.png)\n\n## What is used and how it works ?\n- I decided to use [2-opt heuristic algorithm](https://en.wikipedia.org/wiki/2-opt).\n- In this approach algorithm works by looking for search area of possible solutions that will result in different set of permutations of a tour. \n\n\n![2-opt](https://user-images.githubusercontent.com/62245004/97054287-37763d80-158d-11eb-884a-6d03b263ab26.gif)\n\n## 2-opt Approach with Fast Local Search(FLS) Algorithm\n\n- For optimizing this approach , in first step, I used Fast Local Search(FLS) optimization. Having\ndeclared 2-opt algorithm will create a chance to explore all possible 2-opt moves. \n\n- One approach is to continuously select two pair of edges and check whether they would result a better tour.\n\n- Instead of selecting random edges, FLS will iterate through all potential pair of edges and checking them for\npotential moves. If we found a move that can be used, then the corresponding pair of edges will be\nused in 2-opt algorithm and searching will be continued from the previous edge in the tour until\nthere is no possible moves left. Then at that point we found 2-optimal.\n\n- The trouble that comes with this approach is wasting time to evaluating moves that will not give an\nimprovement. To overcome this situation if a move is found by the program, I simply declare the pair\nof edges as used with using setUsedBits() and isUsed() functions. [So that program will not check\nthese edges ever again](http://tsp-basics.blogspot.com/2017/03/using-dont-look-bits-dlb-2-opt.html).\n\n\n## 2-opt Approach with Guided Local Search(GLS) Algorithm\n\n- In addition to FLS i decided to use [Guided Local Search](https://en.wikipedia.org/wiki/Guided_Local_Search) since  it works synchronously with FLS.\n- Guided Local Search is a metaheuristic search method. This approach is a method that builds on top of a local\nsearch algorithm to explore the search space for finding near-optimal solutions. \n- The main purpose of this approach is guiding a local search algorithm, FLS in this case, by improving the corresponding\nobjects that are declared and assigning a cost value to possible edges so that we can compare efficiently. \n\n## References\n- https://en.wikipedia.org/wiki/Guided_Local_Search\n- https://en.wikipedia.org/wiki/NP-hardness\n- https://pdfs.semanticscholar.org/2210/d4c2694894da361baf9175ac358970b58033.pdf\n- http://tsp-basics.blogspot.com/2017/03/using-dont-look-bits-dlb-2-opt.html\n- https://en.wikipedia.org/wiki/2-opt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonkolahmet%2Ftsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonkolahmet%2Ftsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonkolahmet%2Ftsp/lists"}