Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to hand over graph in calc_distance_to_bus #2186

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@

**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 @@
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
Loading