@@ -32,7 +32,7 @@ def add_vertices(self, vertex: str) -> None:
32
32
# assign weights for each edges formed of the directed graph
33
33
def add_edge (self , vertex_a : str , vertex_b : str , weight : int ) -> None :
34
34
"""
35
- Adds a directed edge from vertex `vertex_a`
35
+ Adds a directed edge from vertex `vertex_a`
36
36
to vertex `vertex_b` with weight `weight`.
37
37
>>> g = JohnsonGraph()
38
38
>>> g.add_vertices("A")
@@ -49,7 +49,7 @@ def add_edge(self, vertex_a: str, vertex_b: str, weight: int) -> None:
49
49
# perform a dijkstra algorithm on a directed graph
50
50
def dijkstra (self , start : str ) -> dict :
51
51
"""
52
- Computes the shortest path from vertex `start`
52
+ Computes the shortest path from vertex `start`
53
53
to all other vertices using Dijkstra's algorithm.
54
54
>>> g = JohnsonGraph()
55
55
>>> g.add_vertices("A")
@@ -80,7 +80,7 @@ def dijkstra(self, start: str) -> dict:
80
80
# carry out the bellman ford algorithm for a node and estimate its distance vector
81
81
def bellman_ford (self , start : str ) -> dict :
82
82
"""
83
- Computes the shortest path from vertex `start` to
83
+ Computes the shortest path from vertex `start` to
84
84
all other vertices using the Bellman-Ford algorithm.
85
85
>>> g = JohnsonGraph()
86
86
>>> g.add_vertices("A")
@@ -111,7 +111,7 @@ def bellman_ford(self, start: str) -> dict:
111
111
# or the bellman ford algorithm efficiently
112
112
def johnson_algo (self ) -> list [dict ]:
113
113
"""
114
- Computes the shortest paths between
114
+ Computes the shortest paths between
115
115
all pairs of vertices using Johnson's algorithm
116
116
for a directed graph.
117
117
>>> g = JohnsonGraph()
@@ -159,10 +159,10 @@ def johnson_algo(self) -> list[dict]:
159
159
for vertex1 in self .graph :
160
160
new_dist = self .dijkstra (vertex1 )
161
161
for vertex2 in self .graph :
162
- if new_dist [vertex2 ] < sys .maxsize - 1 :
162
+ if new_dist [vertex2 ] < sys .maxsize - 1 :
163
163
new_dist [vertex2 ] += hash_path [vertex2 ] - hash_path [vertex1 ]
164
164
for key in new_dist :
165
- if new_dist [key ] == sys .maxsize - 1 :
165
+ if new_dist [key ] == sys .maxsize - 1 :
166
166
new_dist [key ] = None
167
167
distances .append (new_dist )
168
168
return distances
0 commit comments