Networkx Dijkstra Shortest Path exists but is way too long - algorithm that gives me an approximation upfront

Viewed 271

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.

2 Answers

If you are interested in general solution you can modify Dijkstras algorithm and limit it to a maximum number of nodes or a maximum length and just abort, once that threshold is broken.

I don't know networkx so I don't know if this is available out of the box.

Try this algo:

from networkx.algorithms import approximation as approx
approx.local_node_connectivity(G, source, target, cutoff=2)
Related