question: private ChartSpan < Integer > calculateAllPairsShortestPath ( ) { ChartSpan < Integer > distance = new ChartSpan < > ( nodes . size ( ) - 1 , Integer . MAX_VALUE ) ; distance . setDiagonal ( 0 ) ; for ( Node < Value > tail : nodes ) { for ( Arc < Value > arc : tail . getOutgoingArcs ( ) ) { Node < Value > head = arc . getHead ( ) ; distance . set ( tail . id ( ) , head . id ( ) , 1 ) ; } } int size = nodes . size ( ) ; for ( int width = 2 ; width <= size ; width ++ ) { for ( int i = 0 ; i < size - width ; i ++ ) { int j = i + width ; for ( int k = i + 1 ; k < j ; k ++ ) { distance . set ( i , j , Math . min ( distance . get ( i , j ) , distance . get ( i , k ) + distance . get ( k , j ) ) ) ; } } } return distance ; }
target:  Calculate the all-pairs shortest path for all pairs of nodes. <p> Note: This method assumes no backward arcs. If there are backward arcs, the returned shortest path costs for that node may not be accurate.