package graphs.shortestpaths; import graphs.BaseEdge; import graphs.Edge; import graphs.Graph; import java.util.Map; /** * A shortest path finder that works by first constructing a shortest paths from the given start * vertex in the given graph, then using it to compute a shortest path. * * @param The graph type. Must be a subtype of {@link Graph}. * @param The vertex type. * @param The edge type. Must be a subtype of {@link Edge}. * * @see ShortestPathFinder */ public abstract class SPTShortestPathFinder, V, E extends BaseEdge> implements ShortestPathFinder { @Override public ShortestPath findShortestPath(G graph, V start, V end) { Map spt = constructShortestPathsTree(graph, start, end); return extractShortestPath(spt, start, end); } /** * Returns a (partial) shortest paths tree (a map from vertex to preceding edge) containing * the shortest path from start to end in given graph. * * The start vertex will NOT have an entry in the SPT. * If start and end are the same, the SPT will be empty. * If there is no path from start to end, the SPT will include all vertices reachable from start. */ protected abstract Map constructShortestPathsTree(G graph, V start, V end); /** * Extracts the shortest path from start to end (to be output by {@link #findShortestPath} * from given shortest paths tree (as output by {@link #constructShortestPathsTree}). */ protected abstract ShortestPath extractShortestPath(Map spt, V start, V end); }