Split dijkstra.py into three files: node, edge, graph
This commit is contained in:
parent
509c7fec8a
commit
9870a643dd
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 math import inf
|
||||||
from typing import Iterator, Optional
|
from typing import Iterator, Optional
|
||||||
|
|
||||||
|
from src.graph.node import Node
|
||||||
class Node:
|
from src.graph.edge import Edge
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class Graph:
|
class Graph:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -64,25 +53,3 @@ class Graph:
|
|||||||
node_sequences[end].append(end)
|
node_sequences[end].append(end)
|
||||||
|
|
||||||
return node_sequences[target_index]
|
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()
|
|
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
|
Loading…
Reference in New Issue
Block a user