I'm using the FindShortestPath
function and am curious to know how Mathematica determines the shortest path when multiple such paths exist.
Here's what I have:
A = {{0, 1, 1, 0}, {1, 0, 1, 1}, {1, 1, 0, 1}, {0, 1, 1, 0}}
G = AdjacencyGraph[A, VertexLabels -> "Name"]
FindShortestPath[G, 1, 4]
The output is {1,2,4}
. However, {1,3,4}
is also valid. How does Mathematica choose? According to the order of the entries, 1,2,3,4?
Also, how is BetweennessCentrality
handled in such cases? For example,
BetweennessCentrality[G]
yields {0,.5,.5,0}
. The zeros are obvious. However, (2) falls one of the two shortest paths from (1) to (4). Do we count it as contributing 1/2 to the BetweennessCentrality
of (2), or is there a normalization constant I'm missing?
BetweennessCentrality
andFindShortestPath
. Also, it is not safe to make any assumptions about which path is returned—what if the implementation changes in the next version? $\endgroup$