Class DijkstraManyToManyShortestPaths<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type
    All Implemented Interfaces:
    ManyToManyShortestPathsAlgorithm<V,​E>, ShortestPathAlgorithm<V,​E>

    public class DijkstraManyToManyShortestPaths<V,​E>
    extends java.lang.Object
    Naive algorithm for many-to-many shortest paths problem using DijkstraClosestFirstIterator.

    Complexity of the algorithm is $O(min(|S|,|T|)*(V\log V + E))$, where $S$ is the set of source vertices, $T$ is the set of target vertices, $V$ is the set of graph vertices and $E$ is the set of graph edges of the graph.

    For each source vertex a single source shortest paths search is performed, which is stopped as soon as all target vertices are reached. Shortest paths trees are constructed using DijkstraClosestFirstIterator.

    Author:
    Semen Chudakov
    • Field Detail

      • graph

        protected final Graph<V,​E> graph
    • Constructor Detail

      • DijkstraManyToManyShortestPaths

        public DijkstraManyToManyShortestPaths​(Graph<V,​E> graph)
        Constructs an instance of the algorithm for a given graph.
        Parameters:
        graph - underlying graph
    • Method Detail

      • getManyToManyPaths

        public ManyToManyShortestPathsAlgorithm.ManyToManyShortestPaths<V,​E> getManyToManyPaths​(java.util.Set<V> sources,
                                                                                                      java.util.Set<V> targets)
        Computes shortest paths from all vertices in sources to all vertices in targets.
        Parameters:
        sources - list of sources vertices
        targets - list of target vertices
        Returns:
        computed shortest paths
      • getPath

        public GraphPath<V,​E> getPath​(V source,
                                            V sink)
        Get a shortest path from a source vertex to a sink vertex.
        Specified by:
        getPath in interface ShortestPathAlgorithm<V,​E>
        Parameters:
        source - the source vertex
        sink - the target vertex
        Returns:
        a shortest path or null if no path exists
      • getPathWeight

        public double getPathWeight​(V source,
                                    V sink)
        Get the weight of the shortest path from a source vertex to a sink vertex. Returns Double.POSITIVE_INFINITY if no path exists.
        Specified by:
        getPathWeight in interface ShortestPathAlgorithm<V,​E>
        Parameters:
        source - the source vertex
        sink - the sink vertex
        Returns:
        the weight of the shortest path from a source vertex to a sink vertex, or Double.POSITIVE_INFINITY if no path exists
      • getShortestPathsTree

        protected static <V,​E> ShortestPathAlgorithm.SingleSourcePaths<V,​E> getShortestPathsTree​(Graph<V,​E> graph,
                                                                                                             V source,
                                                                                                             java.util.Set<V> targets)
        Computes shortest paths tree starting at source and stopping as soon as all of the targets are reached. Here the DijkstraClosestFirstIterator is used.
        Type Parameters:
        V - the graph vertex type
        E - the graph edge type
        Parameters:
        graph - a graph
        source - source vertex
        targets - target vertices
        Returns:
        shortest paths starting from source and reaching all targets