Hello! I have a networkX graph of skeleton of inner space in porous structure. I need to calculate lengths of paths between the inlet and outlet nodes. In order to do it I consider nodes with z coordinate more/less than certain number (lower and upper black lines) and if they has paths between each other I calculate them. But with that approach I calculate almost the same paths several times because I don't know how to define only inlet (or outlet).
Asked
Active
Viewed 154 times
0
-
Can you show us some code, too? – AKX Feb 27 '20 at 13:37
1 Answers
1
Would it not be enough to
- grab a list of possible inlet nodes (z>450)
- grab a list of possible outlet nodes (z<50)
- compute all the combinations of input/output nodes (
itertools.product
) and stash them into a dict mapping pairs to paths (dict.fromkeys(combinations, None)
) - for each combination:
- compute whether a path is found (https://networkx.github.io/documentation/stable/reference/algorithms/shortest_paths.html)
- if a path is not found, mark it so in the dict
- if a path is found:
- mark it in the dict for the input/output pair
- if the path contains an input/output node combination that you haven't yet computed (the value in the dict is None), the same path (or a subset thereof) will apply for that combination too

AKX
- 152,115
- 15
- 115
- 172
-
1I would just add to this that inlet and outlet node candidates furthermore have the property that they have a node degree of 1 (i.e. they are a leaf in the graph) -- accessible via `nx.Graph.degree`. – Paul Brodersen Feb 28 '20 at 10:50
-
I did the combinations feature and it worked for me! Also thank you for node degree information, I didn't know about it. – Andrey Mar 03 '20 at 13:23