Skip to content

Commit a67b9ce

Browse files
committed
feat: add report_bottlenecks function
1 parent 7402397 commit a67b9ce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

prereise/gather/griddata/hifld/data_process/topology.py

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from tqdm import tqdm
1111

1212
from prereise.gather.griddata.hifld.const import abv_state_neighbor
13+
from prereise.gather.griddata.hifld.data_process.helpers import (
14+
distribute_demand_from_zones_to_buses,
15+
)
1316

1417

1518
def min_dist_of_2_conn_comp(
@@ -426,3 +429,27 @@ def identify_bottlenecks(branch, demand, root=None):
426429
k: v for k, v in descendant_pairs.items() if v["demand"] > v["capacity"]
427430
}
428431
return {"all": descendant_pairs, "constrained": constrained_pairs, "root": root}
432+
433+
434+
def report_bottlenecks(branch, bus, zone_demand):
435+
"""Separate the full branch table by interconnect, and report bottlenecks for each.
436+
437+
:param pandas.DataFrame branch: full branch table.
438+
:param pandas.DataFrame branch: full bus table.
439+
:param dict/pandas.Series demand: mapping of demand for each bus.
440+
"""
441+
bus_demand = distribute_demand_from_zones_to_buses(zone_demand, bus).max()
442+
bottlenecks = {
443+
interconnect: identify_bottlenecks(filtered_branch, bus_demand)
444+
for interconnect, filtered_branch in branch.rename(
445+
{"rateA": "capacity"}, axis=1
446+
).groupby("interconnect")
447+
}
448+
for interconnect, result in bottlenecks.items():
449+
print("interconnect")
450+
root = result["root"]
451+
constrained = result["constrained"]
452+
for (k1, k2), info in constrained.items():
453+
k1 = "root" if k1 == root else k1 if isinstance(k1, int) else set(k1)
454+
k2 = "root" if k2 == root else k2 if isinstance(k2, int) else set(k2)
455+
print("from", k1, "to", f"{k2}:", info)

0 commit comments

Comments
 (0)