Skip to content

Commit

Permalink
added option to hand over graph in calc_distance_to_bus
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohmeier committed Dec 7, 2023
1 parent 2da47f3 commit 02b312c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pandapower/topology/graph_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def connected_components(mg, notravbuses=set()):


def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
notravbuses=None, weight='weight'):
notravbuses=None, weight='weight', g=None):
"""
Calculates the shortest distance between a source bus and all buses connected to it.
Expand All @@ -110,6 +110,8 @@ def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
**weight** (string, None) – Edge data key corresponding to the edge weight.
**g** (nx.MultiGraph, None) – MultiGraph of the network. If None, the graph will be created.
OUTPUT:
**dist** - Returns a pandas series with containing all distances to the source bus
in km. If weight=None dist is the topological distance (int).
Expand All @@ -120,8 +122,9 @@ def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
dist = top.calc_distance_to_bus(net, 5)
"""
g = create_nxgraph(net, respect_switches=respect_switches, nogobuses=nogobuses,
notravbuses=notravbuses)
if g is None:
g = create_nxgraph(net, respect_switches=respect_switches, nogobuses=nogobuses,

Check warning on line 126 in pandapower/topology/graph_searches.py

View check run for this annotation

Codecov / codecov/patch

pandapower/topology/graph_searches.py#L125-L126

Added lines #L125 - L126 were not covered by tests
notravbuses=notravbuses)
return pd.Series(nx.single_source_dijkstra_path_length(g, bus, weight=weight))


Expand Down

0 comments on commit 02b312c

Please sign in to comment.