Package graphs
Class ToposortDAGSolver<V>
- java.lang.Object
 - 
- graphs.ToposortDAGSolver<V>
 
 
- 
- Type Parameters:
 V- the type of vertices.
- All Implemented Interfaces:
 ShortestPathSolver<V>
public class ToposortDAGSolver<V> extends Object implements ShortestPathSolver<V>
Topological sorting implementation of theShortestPathSolverinterface for directed acyclic graphs.- See Also:
 ShortestPathSolver
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from interface graphs.ShortestPathSolver
ShortestPathSolver.Constructor<V> 
 - 
 
- 
Constructor Summary
Constructors Constructor Description ToposortDAGSolver(Graph<V> graph, V start)Constructs a new instance by executing the toposort-DAG-shortest-paths algorithm on the graph from the start. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddfsPostOrder(Graph<V> graph, V start, Set<V> visited, List<V> result)Recursively adds nodes from the graph to the result in DFS postorder from the start vertex.List<V>solution(V goal)Returns the single-pair shortest path from a start defined inConstructor#run(Graph, V)to the goal. 
 - 
 
- 
- 
Method Detail
- 
dfsPostOrder
private void dfsPostOrder(Graph<V> graph, V start, Set<V> visited, List<V> result)
Recursively adds nodes from the graph to the result in DFS postorder from the start vertex.- Parameters:
 graph- the input graph.start- the start vertex.visited- the set of visited vertices.result- the destination for adding nodes.
 
- 
solution
public List<V> solution(V goal)
Description copied from interface:ShortestPathSolverReturns the single-pair shortest path from a start defined inConstructor#run(Graph, V)to the goal.- Specified by:
 solutionin interfaceShortestPathSolver<V>- Parameters:
 goal- the goal vertex.- Returns:
 - a list of vertices representing the shortest path.
 
 
 - 
 
 -