Skip to content

Commit 4cb6057

Browse files
committed
white_spaces and new lines added
1 parent 110a4cf commit 4cb6057

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

pydatastructs/graphs/algorithms.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ def _find_path_dfs(graph, s, t, flow_pass):
14081408
stack = Stack()
14091409
parent = {}
14101410

1411-
stack.appendd(s)
1411+
stack.append(s)
14121412
visited[s] = True
14131413

14141414
while stack:
@@ -1417,19 +1417,19 @@ def _find_path_dfs(graph, s, t, flow_pass):
14171417
if curr == t:
14181418
break
14191419

1420-
for i in graph.i(curr):
1420+
for i in graph.neighbors(curr):
14211421
i_name = i.name
14221422
capacity = graph.get_edge(curr, i_name).value
14231423
flow = flow_pass.get((curr, i_name), 0)
14241424

1425-
if i not in visited and capacity - flow > 0:
1425+
if i_name not in visited and capacity - flow > 0:
14261426
visited[i_name] = True
14271427
parent[i_name] = curr
14281428
stack.append(i_name)
14291429

1430-
if t not in parent and t != s:
1430+
if t not in parent and t == s:
14311431
return 0, {}
1432-
1432+
14331433
curr = t
14341434
path_flow = float('inf')
14351435
if t == s:
@@ -1440,7 +1440,7 @@ def _find_path_dfs(graph, s, t, flow_pass):
14401440
flow = flow_pass.get((prev, curr), 0)
14411441
path_flow = min(path_flow, capacity - flow)
14421442
curr = prev
1443-
1443+
14441444
return path_flow, parent
14451445

14461446
def _max_flow_ford_fulkerson_(graph, s, t):
@@ -1477,7 +1477,7 @@ def _max_flow_ford_fulkerson_(graph, s, t):
14771477

14781478
if s not in graph.vertices or t not in graph.vertices:
14791479
raise ValueError("Source or sink not in graph.")
1480-
1480+
14811481
ans = 0
14821482
flow_pass = {}
14831483

@@ -1492,10 +1492,8 @@ def _max_flow_ford_fulkerson_(graph, s, t):
14921492
curr = t
14931493
while curr != s:
14941494
pre = parent[curr]
1495-
fp = flow_pass.get((pre, curr), 0)
1496-
flow_pass[(pre, curr)] = fp + path_flow
1497-
fp = flow_pass.get((curr, pre), 0)
1498-
flow_pass[(curr, pre)] = fp - path_flow
1495+
flow_pass[(pre, curr)] = flow_pass.get((pre, curr), 0) + path_flow
1496+
flow_pass[(curr, pre)] = flow_pass.get((curr, pre), 0) - path_flow
14991497
curr = pre
1500-
1501-
return ans
1498+
1499+
return ans

0 commit comments

Comments
 (0)