Returns the length of the shortest path from node SrcNId to all other nodes in the network.
Parameters:
A Snap.py graph or a network.
Node id for source node.
Maps node id to shortest path distance. Only contains nodes that are reachable from SrcNId.
Indicates whether the edges should be considered directed or undirected.
Maximum number of hops that BFS expands to. This is helpful for speeding-up the code if one in interested only in nodes less than MaxDist away from SrcNId.
Return value:
The length of the shortest path from SrcNId to all other nodes.
The following example shows how to calculate the length of the shortest path in TNGraph, TUNGraph, and TNEANet:
import snap
Graph = snap.GenRndGnm(snap.PNGraph, 100, 1000)
NIdToDistH = snap.TIntH()
shortestPath = snap.GetShortPath(Graph, 10, NIdToDistH)
for item in NIdToDistH:
print item, NIdToDistH[item]
print shortestPath
UGraph = snap.GenRndGnm(snap.PUNGraph, 100, 1000)
NIdToDistH = snap.TIntH()
shortestPath = snap.GetShortPath(UGraph, 10, NIdToDistH)
for item in NIdToDistH:
print item, NIdToDistH[item]
print shortestPath
Network = snap.GenRndGnm(snap.PNEANet, 100, 1000)
NIdToDistH = snap.TIntH()
shortestPath = snap.GetShortPath(Network, 10, NIdToDistH)
for item in NIdToDistH:
print item, NIdToDistH[item]
print shortestPath