Split dijkstra.py into three files: node, edge, graph
This commit is contained in:
		
							
								
								
									
										5
									
								
								src/graph/edge.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/graph/edge.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
class Edge:
 | 
			
		||||
    def __init__(self, start: int, end: int, length: float):
 | 
			
		||||
        self.length: float = length
 | 
			
		||||
        self.start: int = start
 | 
			
		||||
        self.end: int = end
 | 
			
		||||
@@ -1,19 +1,8 @@
 | 
			
		||||
from math import inf
 | 
			
		||||
from typing import Iterator, Optional
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Node:
 | 
			
		||||
    def __init__(self, x: int, y: int):
 | 
			
		||||
        self.x: int = x
 | 
			
		||||
        self.y: int = y
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Edge:
 | 
			
		||||
    def __init__(self, start: int, end: int, length: float):
 | 
			
		||||
        self.length: float = length
 | 
			
		||||
        self.start: int = start
 | 
			
		||||
        self.end: int = end
 | 
			
		||||
 | 
			
		||||
from src.graph.node import Node
 | 
			
		||||
from src.graph.edge import Edge
 | 
			
		||||
 | 
			
		||||
class Graph:
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
@@ -63,26 +52,4 @@ class Graph:
 | 
			
		||||
                    node_sequences[end] = node_sequences[start].copy()
 | 
			
		||||
                    node_sequences[end].append(end)
 | 
			
		||||
 | 
			
		||||
        return node_sequences[target_index]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> None:
 | 
			
		||||
    graph = Graph()
 | 
			
		||||
 | 
			
		||||
    graph.add_node(1, 2)
 | 
			
		||||
    graph.add_node(4, 7)
 | 
			
		||||
    graph.add_node(3, 1)
 | 
			
		||||
    graph.add_node(-2, 0)
 | 
			
		||||
    graph.add_node(0, 0)
 | 
			
		||||
 | 
			
		||||
    graph.add_edge(0, 1, 1)
 | 
			
		||||
    graph.add_edge(1, 2, 2)
 | 
			
		||||
    graph.add_edge(2, 3, 3)
 | 
			
		||||
    graph.add_edge(3, 0, 1)
 | 
			
		||||
    graph.add_edge(1, 3, 3)
 | 
			
		||||
 | 
			
		||||
    print(graph.dijkstra(0, 3))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
        return node_sequences[target_index]
 | 
			
		||||
							
								
								
									
										4
									
								
								src/graph/node.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/graph/node.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
class Node:
 | 
			
		||||
    def __init__(self, x: int, y: int):
 | 
			
		||||
        self.x: int = x
 | 
			
		||||
        self.y: int = y
 | 
			
		||||
		Reference in New Issue
	
	Block a user