I am computing a shortest path with networkx. Works fine most of the time, but sometimes the nodes are connected, but over a really weird very remote connection in the network. In this case the algorithm produces a memory error. My question is, if there is a nice way to check upfront if the connection between the nodes will make sense for a shortest path in terms of length, by a threshold which I define.