Class DirectedGraphAlgorithms<V>
java.lang.Object
com.github.yellowstonegames.path.Algorithms<V>
com.github.yellowstonegames.path.DirectedGraphAlgorithms<V>
- Type Parameters:
V- the vertex type; oftenCoord
Algorithms specific to directed graphs, like
CostlyGraph, as well as general Algorithms.
Currently, this only adds a topologicalSort() method and its overload.-
Method Summary
Modifier and TypeMethodDescriptionbooleanSort the vertices of this graph in topological order.booleantopologicalSort(com.github.tommyettinger.ds.ObjectList<V> sortedVertices) Perform a topological sort on the graph, and puts the sorted vertices in the supplied list.Methods inherited from class Algorithms
breadthFirstSearch, breadthFirstSearch, containsCycle, depthFirstSearch, depthFirstSearch, findMinimumDistance, findMinimumDistance, findShortestPath, findShortestPath, findShortestPath, isConnected, lastRunID, setRunID
-
Method Details
-
topologicalSort
public boolean topologicalSort()Sort the vertices of this graph in topological order. That is, for every edge from vertex u to vertex v, u comes before v in the ordering. This is reflected in the iteration order of the collection returned byGraph.getVertices(). Note that the graph cannot contain any cycles for a topological order to exist. If a cycle exists, this method will do nothing.- Returns:
- true if the sort was successful, false if the graph contains a cycle
-
topologicalSort
Perform a topological sort on the graph, and puts the sorted vertices in the supplied list. That is, for every edge from vertex u to vertex v, u will come before v in the supplied list. Note that the graph cannot contain any cycles for a topological order to exist. If a cycle exists, the sorting procedure will terminate and the supplied list will only contain the vertices up until the point of termination.- Parameters:
sortedVertices- an ObjectList of V vertices that will be cleared and modified in-place- Returns:
- true if the sort was successful, false if the graph contains a cycle
-