You do not need networkX
to solve the problem, numpy
can do this if you understand the math behind it. An undirected, unweighted graph can always be represented by an adjacency matrix [0,1]. nth
degrees of this matrix represent the number of steps from (i,j)
after steps n
. We can work with a Markov matrix, which is the row normalized form adj. matrix. The authority of this matrix is ββa random walk on the graph. If the graph is small, you can take the strength of the matrix and see the index you are interested in (start, end)
. Make the last state absorbing as soon as the walk gets to where it cannot escape. For each power n
you get the probability that you will dissipate from (i,j)
. Impact time can be calculated from this function (as you know the exact impact time for discrete steps).
Below is an example with a simple graph defined by a list of edges. In the end, I draw this hit time function. As a control point, this graph is used:
from numpy import * hit_idx = (0,4)
source share