{"id":17972408,"url":"https://github.com/nmarkert/python-dijkstra","last_synced_at":"2025-04-03T22:42:11.006Z","repository":{"id":63179513,"uuid":"503660467","full_name":"nmarkert/python-dijkstra","owner":"nmarkert","description":"Python Package for easy applicable Dijkstra Algorithm","archived":false,"fork":false,"pushed_at":"2022-12-17T14:23:54.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T10:30:43.701Z","etag":null,"topics":["dijkstra-algorithm","python3"],"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/nmarkert.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":"2022-06-15T07:27:06.000Z","updated_at":"2022-11-14T10:35:38.000Z","dependencies_parsed_at":"2023-01-29T17:30:53.361Z","dependency_job_id":null,"html_url":"https://github.com/nmarkert/python-dijkstra","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmarkert%2Fpython-dijkstra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmarkert%2Fpython-dijkstra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmarkert%2Fpython-dijkstra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmarkert%2Fpython-dijkstra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmarkert","download_url":"https://codeload.github.com/nmarkert/python-dijkstra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247092376,"owners_count":20882217,"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":["dijkstra-algorithm","python3"],"created_at":"2024-10-29T16:14:46.674Z","updated_at":"2025-04-03T22:42:10.983Z","avatar_url":"https://github.com/nmarkert.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyDijkstra\n\nThis python package provides an implementation of the  Dijkstra Search Algorithm for any kind of graphs.\nThe focus of this realization lies on the usability. \u003cbr\u003e\nIf you have your own class which represents some sort of graph, and you want to use the dijkstra algorithm for finding the shortest paths, this package is extremely easy to integrate. \nYou don't have to transform your graph into another special search graph or anything else.\nThe only things you have to do, is inheriting from the provided class and implementing the abstract methods.\n\n## How to Use\n**Install Package**\n```\npip install pydijkstra\n```\n\n**Import Package and Inherit from Dijkstra Class**\n```python\nimport pydijkstra\n\nclass MyGraph(pydijkstra.Dijkstra):\n    ...\n```\n\n**Implement the Abstract Methods**\n```python\ndef all_nodes(self) -\u003e List[Any]:\n    \"\"\" Return all nodes in the graph \"\"\"\n\ndef neighbors(self, node: Any) -\u003e List[Any]:\n    \"\"\" Return all neighbor nodes of the given node \"\"\"\n\ndef weight(self, node1: Any, node2: Any) -\u003e float | int:\n    \"\"\" Return the weight for going from node1 to node2 (i.e. the distance) \"\"\"\n```\n*The typing 'Any' here stands for the representation of one node. So you are free in the choice\nhow you want to represent a node, i.e. use your own defined class, coordinates, ...*\n\n**Use the dijkstra_search Method**\n\u003cbr\u003ewhich was inherited from the Dijkstra class\n```python\ndijkstra_search(start: Any, \n                target: Any = None, \n                output_format: str = 'dijkstra')\n```\n- (param) **start**: Node to start the dijkstra search from.\n- (param) **target**: Target node in order to perform early stopping.\n- (param) **output_format**: String which defines the format of the output. More on this at [Output Formats](#output-formats).\n- (return) Result of the dijkstra search based on the output_format.\n\n### Output Formats\nFor different uses you  may be need different outputs from the dijkstra search, so you can define the output of the\nfunction by the output_format parameter. \u003cbr\u003e\n**Important!** The algorithm to calculate the path finding stays the same, independent of the output format. So changing\nthe output format does not lead to a change in calculation cost.\n\u003cbr\u003e \u003cbr\u003e\nThe different options:\n- `dijkstra` For each found node, it gives the previous visited node and the distance from the start node.\nThe value pair for each node is represented as a dict with 'prev' and 'dist' as its keys.\n- `path` For each found node, it gives a list of nodes, which represents the shortest path from the start node.\n- `path+dist` For each found node, it gives the shortest path and the distance from the start node.\nThe value pair for each node is represented as a dict with 'path' and 'dist' as its keys.\n- `target_path` Gives a list of nodes, which represents the shortest path from the start node to the target node. (Only\n                possible if target is given).\n\nIf the output format defines outputs for multiple nodes (i.e. when using 'dijkstra' or 'path'), it tries to return it \nas a dictionary with the nodes as the keys. If the node is not hashable (and so not usable as a key in the dictionary),\nit instead returns a list with tuples where the node is the first object and the output the second\nobject of the tuple.\n\n### Examples\nSome examples on how the package can be used are found in the tests package. \u003cbr\u003e\nIn simple_graph.py, a new graph structure is defined, which inherits from pydijkstra.Dijkstra and implements the needed functions\nto be able to perform a dijkstra search on the graph it represents. \u003cbr\u003e\nIn nx_search.py, a search class is defined, which gets a NetworkX graph and implements the needed functions with the\nhelp of the functions provided by the graph, so it can serve as a path finding class for NetworkX graphs. \u003cbr\u003e\nIn test.py, some unittests for the dijkstra algorithm are defined, which use the two implemented classes in order to\ntest the correctness of the dijkstra algorithm.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmarkert%2Fpython-dijkstra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmarkert%2Fpython-dijkstra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmarkert%2Fpython-dijkstra/lists"}