{"id":16722698,"url":"https://github.com/ahojukka5/dijkstra","last_synced_at":"2025-03-21T21:30:46.321Z","repository":{"id":62568272,"uuid":"263528339","full_name":"ahojukka5/Dijkstra","owner":"ahojukka5","description":"dijkstra is a native Python implementation of famous Dijkstra's shortest path algorithm. The implemented algorithm can be used to analyze reasonably large networks. The primary goal in design is the clarity of the program code. Thus, program code tends to be more educational than effective.","archived":false,"fork":false,"pushed_at":"2020-05-20T09:33:43.000Z","size":279,"stargazers_count":21,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T05:12:07.171Z","etag":null,"topics":["algorithm","dijkstra","path","python","shortest"],"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/ahojukka5.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-13T04:49:56.000Z","updated_at":"2025-01-13T06:43:36.000Z","dependencies_parsed_at":"2022-11-03T17:36:13.753Z","dependency_job_id":null,"html_url":"https://github.com/ahojukka5/Dijkstra","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2FDijkstra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2FDijkstra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2FDijkstra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahojukka5%2FDijkstra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahojukka5","download_url":"https://codeload.github.com/ahojukka5/Dijkstra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874118,"owners_count":20524574,"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":["algorithm","dijkstra","path","python","shortest"],"created_at":"2024-10-12T22:35:26.114Z","updated_at":"2025-03-21T21:30:45.870Z","avatar_url":"https://github.com/ahojukka5.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dijkstra\n\n[![Python CI][ci-img]][ci-url]\n[![Coverate Status][coveralls-img]][coveralls-url]\n\n![example1](docs/example1.gif)\n\nPackage author: Jukka Aho (@ahojukka5, ahojukka5@gmail.com)\n\ndijkstra is a native Python implementation of famous Dijkstra's shortest path\nalgorithm. The implemented algorithm can be used to analyze reasonably large\nnetworks. The primary goal in design is the clarity of the program code. Thus,\nprogram code tends to be more educational than effective.\n\nProject source code is licensed undet MIT license. The source code of the\nproject is hosted on on GitHub: \u003chttps://github.com/ahojukka5/dijkstra\u003e.\nReleases of this package are hosted in PyPi, where they can be easily accessed\nusing `pip`: \u003chttps://pypi.org/project/dijkstra/\u003e.\n\n## Installing package\n\nTo install the most recent package from Python Package Index (PyPi), use git:\n\n```bash\npip install dijkstra\n```\n\nTo install the development version, you can install the package directly from\nthe GitHub:\n\n```bash\npip install git+git://github.com/ahojukka5/dijkstra.git\n```\n\n[ci-img]: https://github.com/ahojukka5/dijkstra/workflows/Python%20CI/badge.svg\n[ci-url]: https://github.com/ahojukka5/dijkstra/actions\n[coveralls-img]: https://coveralls.io/repos/github/ahojukka5/dijkstra/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/ahojukka5/dijkstra?branch=master\n\n## Usage\n\nPackage implements two classes, `DijkstraSPF` and `Graph`. The above example can\nbe solved with the following code:\n\n```python\nS, T, A, B, C, D, E, F, G = nodes = list(\"STABCDEFG\")\n\ngraph = Graph()\ngraph.add_edge(S, A, 4)\ngraph.add_edge(S, B, 3)\ngraph.add_edge(S, D, 7)\ngraph.add_edge(A, C, 1)\ngraph.add_edge(B, S, 3)\ngraph.add_edge(B, D, 4)\ngraph.add_edge(C, E, 1)\ngraph.add_edge(C, D, 3)\ngraph.add_edge(D, E, 1)\ngraph.add_edge(D, T, 3)\ngraph.add_edge(D, F, 5)\ngraph.add_edge(E, G, 2)\ngraph.add_edge(G, E, 2)\ngraph.add_edge(G, T, 3)\ngraph.add_edge(T, F, 5)\n\ndijkstra = DijkstraSPF(graph, S)\n```\n\nAfter running an algorithm, the shortest distance to each node, starting from\n`S`, is available:\n\n```python\nprint(\"%-5s %-5s\" % (\"label\", \"distance\"))\nfor u in nodes:\n    print(\"%-5s %8d\" % (u, dijkstra.get_distance(u)))\n```\n\n```text\nlabel distance\nS            0\nT           10\nA            4\nB            3\nC            5\nD            7\nE            6\nF           12\nG            8\n```\n\nAlso, we can extract the path. From S to T, the path is:\n\n```python\nprint(\" -\u003e \".join(dijkstra.get_path(T)))\n```\n\n```text\nS -\u003e D -\u003e T\n```\n\nIt's not mandatory to use `Graph`. To use your own data structure for graph, you\nneed to subclass `AbstractDijkstraSPF` and implement two functions connecting\ngraph object to the shortest path finder algorithms: `get_adjacent_nodes` and\n`get_edge_weight`. For example, implementation of `DijkstraSPF` using `Graph`\nis the following:\n\n```python\nclass DijkstraSPF(AbstractDijkstraSPF):\n\n    @staticmethod\n    def get_adjacent_nodes(G, u):\n        return G.get_adjacent_nodes(u)\n\n    @staticmethod\n    def get_edge_weight(G, u, v):\n        return G.get_edge_weight(u, v)\n```\n\n## References\n\n- \u003chttps://en.wikipedia.org/wiki/Dijkstra%27s_algorithm\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahojukka5%2Fdijkstra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahojukka5%2Fdijkstra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahojukka5%2Fdijkstra/lists"}