/** * Get shortest paths from a vertex to all other vertices in the graph. * * @param v the originating vertex * @return List of paths */ public List<GraphPath<V, E>> getShortestPaths(V v) { lazyCalculatePaths(); List<GraphPath<V, E>> found = new ArrayList<GraphPath<V, E>>(); // TODO: two-level map for paths so that we don't have to // iterate over all paths here! for (VertexPair<V> pair : paths.keySet()) { if (pair.getFirst().equals(v)) { found.add(paths.get(pair)); } } return found; }
/** @return total number of shortest paths */ public int getShortestPathsCount() { lazyCalculatePaths(); return nShortestPaths; }
/** * Get all shortest paths in the graph. * * @return List of paths */ public Collection<GraphPath<V, E>> getShortestPaths() { lazyCalculatePaths(); return paths.values(); }
/** * Get the shortest path between two vertices. Note: The paths are calculated using a recursive * algorithm. It *will* give problems on paths longer than the stack allows. * * @param a From vertice * @param b To vertice * @return the path, or null if none found */ public GraphPath<V, E> getShortestPath(V a, V b) { lazyCalculatePaths(); return getShortestPathImpl(a, b); }