Class CostMatrix<T,C>

java.lang.Object
rgu.transport.algorithms.search.CostMatrix<T,C>
Type Parameters:
T - the vertex type
C - the cost (edge) type

public final class CostMatrix<T,C> extends Object
A precomputed cost matrix based on graph reachability search.
Author:
Lee A. Christie
  • Method Details

    • construct

      public static <T,C> CostMatrix<T,C> construct(Explorable<T,C> graph, Set<T> vertices, ReachabilityAlgorithm<C> algorithm) throws InterruptedException
      Constructs a cost matrix by searching the specified graph.
      Type Parameters:
      T - the vertex type
      C - the cost (edge) type
      Parameters:
      graph - the graph to search, not null
      vertices - the vertices to include in the matrix, not null
      algorithm - the reachability algorithm, not null
      Returns:
      the cost matrix
      Throws:
      InterruptedException - if the current thread is interrupted while creating the cost matrix
      NoSuchElementException - 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 InterruptedException
      Constructs a cost matrix by searching the specified graph.
      Type Parameters:
      T - the vertex type
      C - the cost (edge) type
      Parameters:
      graph - the graph to search, not null
      vertices - the vertices to include in the matrix, not null
      algorithm - the reachability algorithm, not null
      progress - 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 matrix
      NoSuchElementException - 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 InterruptedException
      Constructs a cost matrix by searching the specified graph.
      Type Parameters:
      T - the vertex type
      C - the cost (edge) type
      Parameters:
      graph - the graph to search, not null
      vertices - the vertices to include in the matrix, not null
      algorithm - the reachability algorithm, not null
      progress - listener for the progress between 0.0 and 1.0, not null
      subStageOnly - 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 matrix
      NoSuchElementException - if any of the specified vertices are not found in the graph
    • cost

      public C cost(T source, T target, C infinity) throws NoSuchElementException
      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 null
      target - the target vertex, not null
      infinity - the value which should be returned if there is no source from source to target, for example null or Double.POSITIVE_INFINITY as appropriate
      Returns:
      the cost, or the value of infinity if there was no route found
      Throws:
      NoSuchElementException - if either the source or target does not exist in the cost matrix
    • cost

      public C cost(T source, T target) throws TargetUnreachableException
      Returns the cost from the specified source to the specified target.
      Parameters:
      source - the source vertex, not null
      target - 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 matrix
      TargetUnreachableException - if there was no route found
    • contains

      public boolean contains(T vertex)
      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

      public boolean isReachable(T source, T target)
      Check if there is a route from the specified source to the specified target.
      Parameters:
      source - the source vertex, not null
      target - 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

      public Set<T> vertices()
      Returns the set of vertices as an unmodifiable set.
      Returns:
      the set of vertices