Skip to content

Commit 786885f

Browse files
committed
Remove Whitespaces
1 parent eda1fbd commit 786885f

File tree

1 file changed

+0
-13
lines changed

1 file changed

+0
-13
lines changed

pydatastructs/graphs/algorithms.py

-13
Original file line numberDiff line numberDiff line change
@@ -1146,31 +1146,24 @@ def _breadth_first_search_max_flow(graph: Graph, source_node, sink_node, flow_pa
11461146
def _copy_graph_with_residual_edges(graph: Graph) -> Graph:
11471147
vertices = [graph.__getattribute__(v) for v in graph.vertices]
11481148
new_graph = type(graph)(*vertices)
1149-
11501149
for key, edge in graph.edge_weights.items():
11511150
new_graph.add_edge(edge.source.name, edge.target.name, edge.value)
1152-
1153-
11541151
for key, edge in list(new_graph.edge_weights.items()):
11551152
src = edge.source.name
11561153
tgt = edge.target.name
11571154
if new_graph.get_edge(tgt, src) is None:
11581155
new_graph.add_edge(tgt, src, 0)
1159-
11601156
return new_graph
11611157

11621158

11631159
def _dfs_max_flow(graph: Graph, node, sink, flow_passed, visited, flow):
11641160
if node == sink:
11651161
return flow
1166-
11671162
visited[node] = True
1168-
11691163
for next_node in graph.neighbors(node):
11701164
capacity = graph.get_edge(node, next_node.name).value
11711165
fp = flow_passed.get((node, next_node.name), 0)
11721166
residual_capacity = capacity - fp
1173-
11741167
if residual_capacity > 0 and next_node.name not in visited:
11751168
bottleneck_flow = _dfs_max_flow(
11761169
graph, next_node.name, sink, flow_passed, visited, min(flow, residual_capacity)
@@ -1179,24 +1172,18 @@ def _dfs_max_flow(graph: Graph, node, sink, flow_passed, visited, flow):
11791172
flow_passed[(node, next_node.name)] = fp + bottleneck_flow
11801173
flow_passed[(next_node.name, node)] = flow_passed.get((next_node.name, node), 0) - bottleneck_flow
11811174
return bottleneck_flow
1182-
11831175
return 0
11841176

11851177
def _max_flow_ford_fulkerson_(graph: Graph, source, sink):
11861178
graph_copy = _copy_graph_with_residual_edges(graph)
1187-
11881179
m_flow = 0
11891180
flow_passed = {}
1190-
11911181
while True:
11921182
visited = {}
11931183
new_flow = _dfs_max_flow(graph_copy, source, sink, flow_passed, visited, float('inf'))
1194-
11951184
if new_flow == 0:
11961185
break
1197-
11981186
m_flow += new_flow
1199-
12001187
return m_flow
12011188

12021189

0 commit comments

Comments
 (0)