{"id":25397376,"url":"https://github.com/hasnainroopawalla/ant-colony-optimization","last_synced_at":"2025-10-30T21:30:27.019Z","repository":{"id":44644329,"uuid":"448248326","full_name":"hasnainroopawalla/ant-colony-optimization","owner":"hasnainroopawalla","description":"A Python package to find the shortest path in a graph using Ant Colony Optimization","archived":false,"fork":false,"pushed_at":"2024-06-03T06:43:59.000Z","size":44,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T01:36:07.653Z","etag":null,"topics":["ant-colony-optimization","antnet","graph","optimization","python","routing","routing-algorithm","shortest-path-algorithm"],"latest_commit_sha":null,"homepage":"https://medium.com/@hasnain.roopawalla/ant-colony-optimization-1bbc346c2da5","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/hasnainroopawalla.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}},"created_at":"2022-01-15T10:39:43.000Z","updated_at":"2025-01-16T14:57:56.000Z","dependencies_parsed_at":"2023-12-16T11:41:21.185Z","dependency_job_id":null,"html_url":"https://github.com/hasnainroopawalla/ant-colony-optimization","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.125,"last_synced_commit":"17d324e03d3a5527383c5d82ca119332f3bfb216"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasnainroopawalla%2Fant-colony-optimization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasnainroopawalla%2Fant-colony-optimization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasnainroopawalla%2Fant-colony-optimization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasnainroopawalla%2Fant-colony-optimization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hasnainroopawalla","download_url":"https://codeload.github.com/hasnainroopawalla/ant-colony-optimization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239060458,"owners_count":19574970,"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","antnet","graph","optimization","python","routing","routing-algorithm","shortest-path-algorithm"],"created_at":"2025-02-15T21:47:44.656Z","updated_at":"2025-10-30T21:30:27.014Z","avatar_url":"https://github.com/hasnainroopawalla.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eAnt Colony Optimization\u003c/h1\u003e\n\n[![PyPi version](https://img.shields.io/pypi/v/aco_routing.svg)](https://pypi.python.org/pypi/aco_routing/)\n![Downloads](https://img.shields.io/pypi/dm/aco_routing.svg)\n\n\u003c!-- [![Python versions](https://img.shields.io/pypi/pyversions/aco_routing.svg?style=plastic)](https://img.shields.io/pypi/pyversions/aco_routing.svg?style=plastic) --\u003e\n\nA Python package to find the shortest path in a graph using Ant Colony Optimization (ACO).\n\n➡️ Check out my [Medium article](https://medium.com/@hasnain.roopawalla/ant-colony-optimization-1bbc346c2da5) for a detailed walkthrough 🚀\n\nThe Ant colony Optimization algorithm is a probabilistic technique for solving computational problems which can be reduced to finding good paths through graphs ([source](https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms)).\n\nThis implementation of the ACO algorithm uses the [NetworkX](https://networkx.org/) graph environment.\n\n## 🏁 Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\n\n### To install the package directly from PyPi:\n\n```\n$ pip install aco_routing\n```\n\n## 🎈 Usage \u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n\u003e Check out: [example.py](https://github.com/hasnainroopawalla/ant-colony-optimization/blob/master/example.py)\n\nImport all the dependencies:\n\n```python\nfrom aco_routing import ACO\nimport networkx as nx\n```\n\nCreate a `NetworkX.Graph` object with nodes and edges:\n\n```python\nG = nx.DiGraph()\n\nG.add_edge(\"A\", \"B\", cost=2)\nG.add_edge(\"B\", \"C\", cost=2)\nG.add_edge(\"A\", \"H\", cost=2)\nG.add_edge(\"H\", \"G\", cost=2)\nG.add_edge(\"C\", \"F\", cost=1)\nG.add_edge(\"F\", \"G\", cost=1)\nG.add_edge(\"G\", \"F\", cost=1)\nG.add_edge(\"F\", \"C\", cost=1)\nG.add_edge(\"C\", \"D\", cost=10)\nG.add_edge(\"E\", \"D\", cost=2)\nG.add_edge(\"G\", \"E\", cost=2)\n```\n\nUse ACO to find the shortest path and cost between the `source` and `destination`:\n\n```python\naco = ACO(G, ant_max_steps=100, num_iterations=100, ant_random_spawn=True)\n\naco_path, aco_cost = aco.find_shortest_path(\n    source=\"A\",\n    destination=\"D\",\n    num_ants=100,\n)\n```\n\nOutput:\n\n```\nACO path: A -\u003e H -\u003e G -\u003e E -\u003e D\nACO path cost: 8.0\n```\n\n## 📦 Contents \u003ca name = \"contents\"\u003e\u003c/a\u003e\n\n### Ant\n\n`aco_routing.Ant`\n\n- An `Ant` that traverses the graph.\n\n### ACO\n\n`aco_routing.ACO`\n\n- The traditional Ant Colony Optimization algorithm that spawns ants at various nodes in the graph and finds the shortest path between the specified source and destination ([pseudo code](https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms#Algorithm_and_formula)).\n\n## Contributing\n\n- Post any issues and suggestions on the GitHub [issues](https://github.com/hasnainroopawalla/Ant-Colony-Optimization/issues) page.\n- To contribute, fork the project and then create a pull request back to master.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasnainroopawalla%2Fant-colony-optimization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasnainroopawalla%2Fant-colony-optimization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasnainroopawalla%2Fant-colony-optimization/lists"}