allShortestPaths            package:e1071            R Documentation

_F_i_n_d _S_h_o_r_t_e_s_t _P_a_t_h_s _B_e_t_w_e_e_n _A_l_l _N_o_d_e_s _i_n _a _D_i_r_e_c_t_e_d _G_r_a_p_h

_D_e_s_c_r_i_p_t_i_o_n:

     'allShortestPaths' finds all shortest paths in a directed (or
     undirected) graph using Floyd's algorithm. 'extractPath' can be
     used to actually extract the path between a given pair of nodes.

_U_s_a_g_e:

     allShortestPaths(x)
     extractPath(obj, start, end)

_A_r_g_u_m_e_n_t_s:

       x: matrix or distance object

     obj: return value of 'allShortestPaths'

   start: integer, starting point of path

     end: integer, end point of path

_D_e_t_a_i_l_s:

     If 'x' is a matrix, then 'x[i,j]' has to be the length of the
     direct path from point 'i' to point 'j'. If no direct connection
     from point 'i' to point 'j' exist, then 'x[i,j]' should be either
     'NA' or 'Inf'. Note that the graph can be directed, hence 'x[i,j]'
     need not be the same as 'x[j,i]'. The main diagonal of 'x' is
     ignored. Alternatively, 'x' can be a distance object as returned
     by 'dist' (corresponding to an undirected graph).

_V_a_l_u_e:

     'allShortestPaths' returns a list with components 

  length: A matrix with the total lengths of the shortest path between
          each pair of points.

middlePoints: A matrix giving a point in the middle of each shortest
          path (or 0 if the direct connection is the shortest path),
          this is mainly used as input for 'extractPath'.

     'extractPath' returns a vector of node numbers giving with the
     shortest path between two points.

_A_u_t_h_o_r(_s):

     Friedrich Leisch

_R_e_f_e_r_e_n_c_e_s:

     Kumar, V., Grama, A., Gupta, A. and Karypis, G. Introduction to
     Parallel Programming - Design and Analysis of Algorithms, Benjamin
     Cummings Publishing, 1994, ISBN 0-8053-3170-0

_E_x_a_m_p_l_e_s:

     ## build a graph with 5 nodes
     x <- matrix(NA, 5, 5)
     diag(x) <- 0
     x[1,2] <- 30; x[1,3] <- 10
     x[2,4] <- 70; x[2,5] <- 40
     x[3,4] <- 50; x[3,5] <- 20
     x[4,5] <- 60
     x[5,4] <- 10
     print(x)

     ## compute all path lengths
     z <- allShortestPaths(x)
     print(z)

     ## the following should give 1 -> 3 -> 5 -> 4
     extractPath(z, 1, 4)

