Skip to content

Commit 74663b2

Browse files
authored
Apply suggestions from code review
1 parent 2629bbd commit 74663b2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pydatastructs/graphs/algorithms.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -903,36 +903,36 @@ def _floyd_warshall_adjacency_list(graph: Graph):
903903
_floyd_warshall_adjacency_matrix = _floyd_warshall_adjacency_list
904904

905905
def _johnson_adjacency_list(graph: Graph):
906-
new_vertex=AdjacencyListGraphNode('__q__')
906+
new_vertex = AdjacencyListGraphNode('__q__')
907907
graph.add_vertex(new_vertex)
908908

909909
for vertex in graph.vertices:
910910
if vertex != '__q__':
911-
graph.add_edge('__q__',vertex,0)
911+
graph.add_edge('__q__', vertex, 0)
912912

913-
distances, predecessors = shortest_paths(graph,'bellman_ford','__q__')
913+
distances, predecessors = shortest_paths(graph, 'bellman_ford', '__q__')
914914

915915
edges_to_remove = []
916916
for edge in graph.edge_weights:
917917
edge_node = graph.edge_weights[edge]
918918
if edge_node.source.name == '__q__':
919-
edges_to_remove.append((edge_node.source.name,edge_node.target.name))
919+
edges_to_remove.append((edge_node.source.name, edge_node.target.name))
920920

921-
for u,v in edges_to_remove:
922-
graph.remove_edge(u,v)
921+
for u, v in edges_to_remove:
922+
graph.remove_edge(u, v)
923923
graph.remove_vertex('__q__')
924924

925925
for edge in graph.edge_weights:
926926
edge_node = graph.edge_weights[edge]
927-
u,v = edge_node.source.name,edge_node.target.name
928-
graph.edge_weights[edge].value += distances[u]-distances[v]
927+
u, v = edge_node.source.name, edge_node.target.name
928+
graph.edge_weights[edge].value += (distances[u] - distances[v])
929929

930930
all_distances = {}
931931
all_next_vertex = {}
932932

933933
for vertex in graph.vertices:
934934
u = vertex
935-
dijkstra_dist,dijkstra_pred = shortest_paths(graph, 'dijkstra', u)
935+
dijkstra_dist, dijkstra_pred = shortest_paths(graph, 'dijkstra', u)
936936
all_distances[u] = {}
937937
all_next_vertex[u] = {}
938938
for v in graph.vertices:
@@ -941,7 +941,7 @@ def _johnson_adjacency_list(graph: Graph):
941941
else:
942942
all_next_vertex[u][v] = None
943943
if v in dijkstra_dist:
944-
all_distances[u][v] = dijkstra_dist[v]-distances[u]+distances[v]
944+
all_distances[u][v] = dijkstra_dist[v] - distances[u] + distances[v]
945945
else:
946946
all_distances[u][v] = float('inf')
947947

pydatastructs/graphs/tests/test_algorithms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ def _test_shortest_paths_negative_edges(ds, algorithm):
346346
'3': {'4': '3', '3': '3', '1': None, '2': None},
347347
'4': {'2': '4', '4': '4', '1': None, '3': None}}
348348

349-
_test_shortest_paths_negative_edges("List",'floyd_warshall')
350-
_test_shortest_paths_negative_edges("Matrix",'floyd_warshall')
351-
_test_shortest_paths_negative_edges("List",'johnson')
349+
_test_shortest_paths_negative_edges("List", 'floyd_warshall')
350+
_test_shortest_paths_negative_edges("Matrix", 'floyd_warshall')
351+
_test_shortest_paths_negative_edges("List", 'johnson')
352352

353353
def test_topological_sort():
354354

0 commit comments

Comments
 (0)