Class CostMatrix<T,C>
java.lang.Object
rgu.transport.algorithms.search.CostMatrix<T,C>
- Type Parameters:
T- the vertex typeC- the cost (edge) type
A precomputed cost matrix based on graph reachability search.
- Author:
- Lee A. Christie
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,C> CostMatrix <T, C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm) Constructs a cost matrix by searching the specified graph.static <T,C> CostMatrix <T, C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm, ProgressListener progress) Constructs a cost matrix by searching the specified graph.static <T,C> CostMatrix <T, C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm, ProgressListener progress, boolean subStageOnly) Constructs a cost matrix by searching the specified graph.booleanCheck if the specified vertex was contained in the cost matrix.Returns the cost from the specified source to the specified target.Returns the cost from the specified source to the specified target or the given infinity value if there was no route found.booleanisReachable(T source, T target) Check if there is a route from the specified source to the specified target.vertices()Returns the set of vertices as an unmodifiable set.
-
Method Details
-
construct
public static <T,C> CostMatrix<T,C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm) throws InterruptedExceptionConstructs a cost matrix by searching the specified graph.- Type Parameters:
T- the vertex typeC- the cost (edge) type- Parameters:
graph- the graph to search, not nullvertices- the vertices to include in the matrix, not nullalgorithm- the reachability algorithm, not null- Returns:
- the cost matrix
- Throws:
InterruptedException- if the current thread is interrupted while creating the cost matrixNoSuchElementException- if any of the specified vertices are not found in the graph
-
construct
public static <T,C> CostMatrix<T,C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm, ProgressListener progress) throws InterruptedExceptionConstructs a cost matrix by searching the specified graph.- Type Parameters:
T- the vertex typeC- the cost (edge) type- Parameters:
graph- the graph to search, not nullvertices- the vertices to include in the matrix, not nullalgorithm- the reachability algorithm, not nullprogress- listener for the progress between 0.0 and 1.0, not null- Returns:
- the cost matrix
- Throws:
InterruptedException- if the current thread is interrupted while creating the cost matrixNoSuchElementException- if any of the specified vertices are not found in the graph
-
construct
public static <T,C> CostMatrix<T,C> construct(Explorable<T, C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm, ProgressListener progress, boolean subStageOnly) throws InterruptedExceptionConstructs a cost matrix by searching the specified graph.- Type Parameters:
T- the vertex typeC- the cost (edge) type- Parameters:
graph- the graph to search, not nullvertices- the vertices to include in the matrix, not nullalgorithm- the reachability algorithm, not nullprogress- listener for the progress between 0.0 and 1.0, not nullsubStageOnly- if ture, will not call onNewStage or onCompletion on the progress listener- Returns:
- the cost matrix
- Throws:
InterruptedException- if the current thread is interrupted while creating the cost matrixNoSuchElementException- if any of the specified vertices are not found in the graph
-
cost
Returns the cost from the specified source to the specified target or the given infinity value if there was no route found.- Parameters:
source- the source vertex, not nulltarget- the target vertex, not nullinfinity- the value which should be returned if there is no source from source to target, for examplenullorDouble.POSITIVE_INFINITYas appropriate- Returns:
- the cost, or the value of
infinityif there was no route found - Throws:
NoSuchElementException- if either the source or target does not exist in the cost matrix
-
cost
Returns the cost from the specified source to the specified target.- Parameters:
source- the source vertex, not nulltarget- the target vertex, not null- Returns:
- the cost, or the value of
infinity - Throws:
NoSuchElementException- if either the source or target does not exist in the cost matrixTargetUnreachableException- if there was no route found
-
contains
Check if the specified vertex was contained in the cost matrix.- Parameters:
vertex- the vertex, not null- Returns:
- true if the vertex exists, false otherwise
-
isReachable
Check if there is a route from the specified source to the specified target.- Parameters:
source- the source vertex, not nulltarget- the target vertex, not null- Returns:
- true if there is a route, false otherwise
- Throws:
NoSuchElementException- if either the source or target does not exist in the cost matrix
-
vertices
-