|
10 | 10 | from tqdm import tqdm
|
11 | 11 |
|
12 | 12 | 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 | +) |
13 | 16 |
|
14 | 17 |
|
15 | 18 | def min_dist_of_2_conn_comp(
|
@@ -426,3 +429,27 @@ def identify_bottlenecks(branch, demand, root=None):
|
426 | 429 | k: v for k, v in descendant_pairs.items() if v["demand"] > v["capacity"]
|
427 | 430 | }
|
428 | 431 | 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