diff --git a/graphs/johnson_graph.py b/graphs/johnson_graph.py index af9ed6c76..6328cd3f4 100644 --- a/graphs/johnson_graph.py +++ b/graphs/johnson_graph.py @@ -8,19 +8,19 @@ import sys class JohnsonGraph: def __init__(self) -> None: self.edges: list[str] = [] - self.graph: dict[str, int] = {} + self.graph: dict[str, list] = {} # add vertices for a graph - def add_vertices(self, u) -> None: + def add_vertices(self, u:int) -> None: self.graph[u] = [] # assign weights for each edges formed of the directed graph - def add_edge(self, u, v, w) -> None: + def add_edge(self, u:str, v:str, w:int) -> None: self.edges.append((u, v, w)) self.graph[u].append((v, w)) # perform a dijkstra algorithm on a directed graph - def dijkstra(self, s) -> dict: + def dijkstra(self, s:str) -> dict: distances = {vertex: sys.maxsize - 1 for vertex in self.graph} pq = [(0, s)] distances[s] = 0 @@ -37,7 +37,7 @@ class JohnsonGraph: return distances # carry out the bellman ford algorithm for a node and estimate its distance vector - def bellman_ford(self, s) -> dict: + def bellman_ford(self, s:str) -> dict: distances = {vertex: sys.maxsize - 1 for vertex in self.graph} distances[s] = 0 @@ -51,7 +51,7 @@ class JohnsonGraph: # perform the johnson algorithm to handle the negative weights that # could not be handled by either the dijkstra # or the bellman ford algorithm efficiently - def johnson_algo(self) -> dict: + def johnson_algo(self) -> list[dict]: self.add_vertices("#") for v in self.graph: if v != "#":