{"id":17103542,"url":"https://github.com/akshatkarani/randomized_tsp","last_synced_at":"2025-03-23T19:43:58.832Z","repository":{"id":57459860,"uuid":"264403353","full_name":"akshatkarani/randomized_tsp","owner":"akshatkarani","description":"Randomized Algorithms for Travelling Salesman Problem","archived":false,"fork":false,"pushed_at":"2020-06-14T06:04:00.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T23:03:38.965Z","etag":null,"topics":["ant-colony-optimization","genetic-algorithm","randomized-algorithms","simulated-annealing","travelling-salesman","travelling-salesman-problem","tsp"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/randomized-tsp","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/akshatkarani.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}},"created_at":"2020-05-16T09:33:33.000Z","updated_at":"2021-12-30T11:47:49.000Z","dependencies_parsed_at":"2022-09-09T22:52:05.990Z","dependency_job_id":null,"html_url":"https://github.com/akshatkarani/randomized_tsp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshatkarani%2Frandomized_tsp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshatkarani%2Frandomized_tsp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshatkarani%2Frandomized_tsp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshatkarani%2Frandomized_tsp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akshatkarani","download_url":"https://codeload.github.com/akshatkarani/randomized_tsp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245162094,"owners_count":20570691,"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":["ant-colony-optimization","genetic-algorithm","randomized-algorithms","simulated-annealing","travelling-salesman","travelling-salesman-problem","tsp"],"created_at":"2024-10-14T15:33:47.444Z","updated_at":"2025-03-23T19:43:58.804Z","avatar_url":"https://github.com/akshatkarani.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# randomized_tsp\n\nA python3 package implementing randomized algorithms for [Travelling Salesman Problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem).\nThe implementations are based off of [A first course in Artificial Intelligence: Deepak Khemani](https://www.mheducation.co.in/a-first-course-in-artificial-intelligence-9781259029981-india).\n\nThe algorithms implemented include:\n- [Genetic Algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm)\n- [Simulated Annealing](https://en.wikipedia.org/wiki/Simulated_annealing)\n- [Ant Colony Optimization](https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms)\n\n## Installation\n\nYou can install this using `pip`. Just run\n\n``pip install randomized_tsp``\n\n## Usage\n\nSee [example](example/) here.\n\nIf you have `n` cities in your problem then you need to define the distances between cities using a two dimensional `n X n` list.\n`distances[i][j]` should give the distance between city i and city j.\n\n```python\nfrom randomized_tsp.tsp import tsp\n\n# If you have 3 cities then you need to define this list \n# which gives the distances between two cities\ndistances = [[0, 4, 2], [4, 0, 3], [2, 3, 0]]\n\ntsp_obj = tsp(distances)\n\n# To run genetic algorithm\ntour, cost = tsp_obj.genetic_algorithm()\n\n# To run simulated annealing\ntour, cost = tsp_obj.simulated_annealing()\n\n# To run ant colony optimization\ntour, cost = tsp_obj.ant_colony()\n```\n\nAll the three algorithms return that best tour found and the cost of that tour. Tour is represented using path representation.\n\nSome optional parameters are also available for the above algorithms.\n```python\ndef genetic_algorithm(self,\n                      population_size=50,\n                      mutation_prob=0.1,\n                      crossover='order'):\n        \"\"\"\n        :param population_size: Defines the size of the population used in the algorithm\n        :param mutation_prob:   Probability that a offspring will mutate\n        :param crossover:       Defines the crossover operator, currently two options are available\n                                `order` and `cycle`.\n        :return:                Returns the best tour found and the cost of that tour\n                                A tour is represented using path representation\n        \"\"\"\n\ndef simulated_annealing(self):\n        \"\"\"\n        :return: Returns the best tour found and the cost of that tour\n                 A tour is represented using path representation\n        \"\"\"\n\ndef ant_colony(self,\n               num_of_ants=20,\n               pheromone_evapouration=0.2):\n        \"\"\"\n        :param num_of_ants:            Number of ants in the colony\n        :param pheromone_evapouration: Evapouration rate of the pheromone deposited by ants\n        :return:                       Returns the best tour found and the cost of that tour\n                                       A tour is represented using path representation\n        \"\"\"\n```\n\n\n## Contributing\n\nMany of these algorithms need improvements and optimizations. If you want to improve this project or fix a bug then all contributions are welcome. \n\n## Contact\n\nIf you find any bugs then open a issue on this repository. You can also contact me on [gitter](https://gitter.im/akshatkarani).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshatkarani%2Frandomized_tsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakshatkarani%2Frandomized_tsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshatkarani%2Frandomized_tsp/lists"}