Skip to content

Commit 3133514

Browse files
committed
safe lookup for flow and capacity in calc_graph_capacity function
1 parent 08a0a59 commit 3133514

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

ngraph/algorithms/capacity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,13 @@ def calc_graph_capacity(
395395
min_ratio = float("inf")
396396
for u, neighbors in succ.items():
397397
for v in neighbors:
398-
assigned_flow = flow_dict[u][v]
398+
# Use safe lookup: some edges may not receive any nominal flow (e.g. due to very high branching)
399+
assigned_flow = flow_dict.get(u, {}).get(v, 0.0)
399400
if assigned_flow >= MIN_FLOW:
400-
cap_uv = residual_cap[u].get(v, 0.0)
401+
cap_uv = residual_cap.get(u, {}).get(v, 0.0)
402+
# Only consider positive assignments for scaling
401403
if assigned_flow > 0.0:
402-
ratio = cap_uv / assigned_flow
404+
ratio = cap_uv / assigned_flow if assigned_flow != 0.0 else 0.0
403405
if ratio < min_ratio:
404406
min_ratio = ratio
405407

0 commit comments

Comments
 (0)