pathfinding-tools-dijkstra 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: pathfinding-tools-dijkstra
3
+ Version: 1.0.0
4
+ Summary: Pathfinding tools including a dijkstra algorithm
5
+ Author: Your Name
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: numpy>=1.26.0
9
+
10
+ # dijkstra-pathfinding-tools
@@ -0,0 +1 @@
1
+ # dijkstra-pathfinding-tools
@@ -0,0 +1,5 @@
1
+ from numpy import *
2
+ from .methods import *
3
+
4
+
5
+
@@ -0,0 +1,68 @@
1
+ from typing import Dict, List
2
+
3
+
4
+ class Node:
5
+ def __init__(self, data=None):
6
+ self.data = data
7
+
8
+
9
+ class Edge:
10
+ def __init__(self, node1, node2, cost=1.0, data=None):
11
+ self.data = data
12
+ self.node1: Node = node1
13
+ self.node2: Node = node2
14
+ self.cost: float = cost
15
+
16
+
17
+ class Path:
18
+ def __init__(self, nodes, edges, cost):
19
+ self.nodes: List[Node] = nodes
20
+ self.edges: List[Edge] = edges
21
+ self.cost: float = cost
22
+
23
+
24
+ def extend_path(old_path, edge, node):
25
+ return Path(nodes=old_path.nodes + [node],
26
+ edges=old_path.edges+[edge],
27
+ cost=old_path.cost+edge.cost)
28
+
29
+
30
+ def dijkstra(nodes, edges, start_node, end_node=None, bidirectional=True):
31
+
32
+ edges_of_node = dict((n, []) for n in nodes)
33
+ for edge in edges:
34
+ edges_of_node[edge.node1].append((edge, edge.node2))
35
+ if (bidirectional):
36
+ edges_of_node[edge.node2].append((edge, edge.node1))
37
+
38
+ reached_nodes: Dict[Node, Path] = {}
39
+ unresolved_reached_nodes: List[Node] = []
40
+
41
+ reached_nodes[start_node] = Path(nodes=[start_node], edges=[], cost=0)
42
+ unresolved_reached_nodes.append(start_node)
43
+
44
+ def reach_node(node, new_path):
45
+ if node in reached_nodes:
46
+ old_path = reached_nodes[node]
47
+ if (new_path.cost < old_path.cost):
48
+ reached_nodes[node] = new_path
49
+ else:
50
+ reached_nodes[node] = new_path
51
+ unresolved_reached_nodes.append(node)
52
+
53
+ def resolve_node(node):
54
+ old_path = reached_nodes[node]
55
+ for edge, next_node in edges_of_node[node]:
56
+ new_path = extend_path(old_path, edge, next_node)
57
+ reach_node(next_node, new_path)
58
+
59
+ while len(unresolved_reached_nodes) > 0:
60
+ unresolved_reached_nodes.sort(
61
+ key=lambda node: reached_nodes[node].cost)
62
+ node = unresolved_reached_nodes[0]
63
+ if (node is end_node):
64
+ break
65
+ resolve_node(node)
66
+ unresolved_reached_nodes.remove(node)
67
+
68
+ return reached_nodes
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: pathfinding-tools-dijkstra
3
+ Version: 1.0.0
4
+ Summary: Pathfinding tools including a dijkstra algorithm
5
+ Author: Your Name
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: numpy>=1.26.0
9
+
10
+ # dijkstra-pathfinding-tools
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ dijkstra/__init__.py
4
+ dijkstra/methods.py
5
+ pathfinding_tools_dijkstra.egg-info/PKG-INFO
6
+ pathfinding_tools_dijkstra.egg-info/SOURCES.txt
7
+ pathfinding_tools_dijkstra.egg-info/dependency_links.txt
8
+ pathfinding_tools_dijkstra.egg-info/requires.txt
9
+ pathfinding_tools_dijkstra.egg-info/top_level.txt
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pathfinding-tools-dijkstra"
7
+ version = "1.0.0"
8
+ description = "Pathfinding tools including a dijkstra algorithm"
9
+ authors = [
10
+ { name="Your Name" }
11
+ ]
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+
15
+ dependencies = [
16
+ "numpy>=1.26.0"
17
+ ]
18
+
19
+ [tool.setuptools]
20
+ packages = ["dijkstra"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+