Skip to content

Commit 81fb07b

Browse files
committed
Merge branch 'joel_graph' of https://github.com/joelkurien/Python into joel_graph
2 parents 2584473 + 2fb5bec commit 81fb07b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

graphs/johnson_graph.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def add_vertices(self, vertex: str) -> None:
3232
# assign weights for each edges formed of the directed graph
3333
def add_edge(self, vertex_a: str, vertex_b: str, weight: int) -> None:
3434
"""
35-
Adds a directed edge from vertex `vertex_a`
35+
Adds a directed edge from vertex `vertex_a`
3636
to vertex `vertex_b` with weight `weight`.
3737
>>> g = JohnsonGraph()
3838
>>> g.add_vertices("A")
@@ -49,7 +49,7 @@ def add_edge(self, vertex_a: str, vertex_b: str, weight: int) -> None:
4949
# perform a dijkstra algorithm on a directed graph
5050
def dijkstra(self, start: str) -> dict:
5151
"""
52-
Computes the shortest path from vertex `start`
52+
Computes the shortest path from vertex `start`
5353
to all other vertices using Dijkstra's algorithm.
5454
>>> g = JohnsonGraph()
5555
>>> g.add_vertices("A")
@@ -80,7 +80,7 @@ def dijkstra(self, start: str) -> dict:
8080
# carry out the bellman ford algorithm for a node and estimate its distance vector
8181
def bellman_ford(self, start: str) -> dict:
8282
"""
83-
Computes the shortest path from vertex `start` to
83+
Computes the shortest path from vertex `start` to
8484
all other vertices using the Bellman-Ford algorithm.
8585
>>> g = JohnsonGraph()
8686
>>> g.add_vertices("A")
@@ -111,7 +111,7 @@ def bellman_ford(self, start: str) -> dict:
111111
# or the bellman ford algorithm efficiently
112112
def johnson_algo(self) -> list[dict]:
113113
"""
114-
Computes the shortest paths between
114+
Computes the shortest paths between
115115
all pairs of vertices using Johnson's algorithm
116116
for a directed graph.
117117
>>> g = JohnsonGraph()
@@ -159,10 +159,10 @@ def johnson_algo(self) -> list[dict]:
159159
for vertex1 in self.graph:
160160
new_dist = self.dijkstra(vertex1)
161161
for vertex2 in self.graph:
162-
if new_dist[vertex2] < sys.maxsize-1:
162+
if new_dist[vertex2] < sys.maxsize - 1:
163163
new_dist[vertex2] += hash_path[vertex2] - hash_path[vertex1]
164164
for key in new_dist:
165-
if new_dist[key] == sys.maxsize-1:
165+
if new_dist[key] == sys.maxsize - 1:
166166
new_dist[key] = None
167167
distances.append(new_dist)
168168
return distances

0 commit comments

Comments
 (0)