jcommon.graph
Interface ITopologicalSortStrategy<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

Type Parameters:
TVertex - Type of IVertex that a topological sort will operate on.
All Known Implementing Classes:
SimpleTopologicalSort

public interface ITopologicalSortStrategy<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

Provides a strategy for implementing a topological sort of an IGraph. A IGraph is first transformed into an adjacency list of type IAdjacencyList. That is then used to topologically sort the graph. Two versions are provided: one will synchronously traverse the graph and provide the ordered list of vertices to visit and the second will asynchronously process the graph executing in parallel as many as possible given the size of a thread pool and the ordering.

See Also:
http://en.wikipedia.org/wiki/Topological_sorting

Field Summary
static String STANDARD_CYCLE_MESSAGE
          String available for use when throwing CyclicGraphExceptions.
 
Method Summary
 List<TValue> sort(IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList)
          Given an instance of IAdjacencyList, topologically sorts the graph.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor, IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList, ITopologicalSortCallback<TValue,TProcessedValue> callback, ITopologicalSortErrorCallback<TValue> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 

Field Detail

STANDARD_CYCLE_MESSAGE

static final String STANDARD_CYCLE_MESSAGE
String available for use when throwing CyclicGraphExceptions.

See Also:
Constant Field Values
Method Detail

sort

List<TValue> sort(IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList)
                  throws CyclicGraphException
Given an instance of IAdjacencyList, topologically sorts the graph.

Parameters:
adjacencyList - An instance of IAdjacencyList.
Returns:
The topologically sorted IGraph.
Throws:
CyclicGraphException - A CyclicGraphException is thrown if a cycle is detected during the sort.
See Also:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                              IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList,
                                                              ITopologicalSortCallback<TValue,TProcessedValue> callback,
                                                              ITopologicalSortErrorCallback<TValue> errorCallback)
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Parameters:
executor - An instance of ExecutorService that will be used to submit tasks for processing vertices.
adjacencyList - An instance of IAdjacencyList.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(Object, ITopologicalSortInput, IVertex, ITopologicalSortCoordinator) method or in the sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
http://en.wikipedia.org/wiki/Topological_sorting


Copyright © 2012-2013. All Rights Reserved.