Skip to content

Commit

Permalink
Update double directed to be flexible around edge_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobson committed Feb 9, 2024
1 parent 819957a commit 7229ef1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions swmmanywhere/graph_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph:
These new edges share the same data as the 'forward' edges but have a new
'id'. An undirected graph is not suitable because it removes data of one of
the edges if there are edges in both directions between two nodes
(necessary to preserve, e.g., consistent 'width').
(necessary to preserve, e.g., consistent 'width'). If 'edge_type' is
present, then the function will only be performed on 'street' types.
Args:
G (nx.Graph): A graph
Expand All @@ -235,7 +236,10 @@ def __call__(self, G: nx.Graph, **kwargs) -> nx.Graph:
# which direction the line should be going in...
G_new = G.copy()
for u, v, data in G.edges(data=True):
if ((v, u) not in G.edges) & (data['edge_type'] == 'street'):
include = data.get('edge_type', True)
if isinstance(include, str):
include = include == 'street'
if ((v, u) not in G.edges) & include:
reverse_data = data.copy()
reverse_data['id'] = '{0}.reversed'.format(data['id'])
G_new.add_edge(v, u, **reverse_data)
Expand Down

0 comments on commit 7229ef1

Please sign in to comment.