Class Path


  • public class Path
    extends java.lang.Object

    Class representing a path between nodes in a graph.

    A path is represented as a list of Arc with an origin and not a list of Node due to the multi-graph nature (multiple arcs between two nodes) of the considered graphs.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<Arc> arcs  
      private Graph graph  
      private Node origin  
    • Constructor Summary

      Constructors 
      Constructor Description
      Path​(Graph graph)
      Create an empty path corresponding to the given graph.
      Path​(Graph graph, java.util.List<Arc> arcs)
      Create a new path with the given list of arcs.
      Path​(Graph graph, Node node)
      Create a new path containing a single node.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Path concatenate​(Path... paths)
      Concatenate the given paths.
      static Path createFastestPathFromNodes​(Graph graph, java.util.List<Node> nodes)
      Create a new path that goes through the given list of nodes (in order), choosing the fastest route if multiple are available.
      static Path createShortestPathFromNodes​(Graph graph, java.util.List<Node> nodes)
      Create a new path that goes through the given list of nodes (in order), choosing the shortest route if multiple are available.
      java.util.List<Arc> getArcs()  
      Node getDestination()  
      Graph getGraph()  
      float getLength()
      Compute the length of this path (in meters).
      double getMinimumTravelTime()
      Compute the time to travel this path if moving at the maximum allowed speed on every arc.
      Node getOrigin()  
      double getTravelTime​(double speed)
      Compute the time required to travel this path if moving at the given speed.
      boolean isEmpty()
      Check if this path is empty (it does not contain any node).
      boolean isValid()
      Check if this path is valid.
      int size()
      Get the number of nodes in this path.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • graph

        private final Graph graph
      • origin

        private final Node origin
      • arcs

        private final java.util.List<Arc> arcs
    • Constructor Detail

      • Path

        public Path​(Graph graph)
        Create an empty path corresponding to the given graph.
        Parameters:
        graph - Graph containing the path.
      • Path

        public Path​(Graph graph,
                    Node node)
        Create a new path containing a single node.
        Parameters:
        graph - Graph containing the path.
        node - Single node of the path.
      • Path

        public Path​(Graph graph,
                    java.util.List<Arc> arcs)
        Create a new path with the given list of arcs.
        Parameters:
        graph - Graph containing the path.
        arcs - Arcs to construct the path.
    • Method Detail

      • createFastestPathFromNodes

        public static Path createFastestPathFromNodes​(Graph graph,
                                                      java.util.List<Node> nodes)
                                               throws java.lang.IllegalArgumentException
        Create a new path that goes through the given list of nodes (in order), choosing the fastest route if multiple are available.
        Parameters:
        graph - Graph containing the nodes in the list.
        nodes - List of nodes to build the path.
        Returns:
        A path that goes through the given list of nodes.
        Throws:
        java.lang.IllegalArgumentException - If the list of nodes is not valid, i.e. two consecutive nodes in the list are not connected in the graph.
      • createShortestPathFromNodes

        public static Path createShortestPathFromNodes​(Graph graph,
                                                       java.util.List<Node> nodes)
                                                throws java.lang.IllegalArgumentException
        Create a new path that goes through the given list of nodes (in order), choosing the shortest route if multiple are available.
        Parameters:
        graph - Graph containing the nodes in the list.
        nodes - List of nodes to build the path.
        Returns:
        A path that goes through the given list of nodes.
        Throws:
        java.lang.IllegalArgumentException - If the list of nodes is not valid, i.e. two consecutive nodes in the list are not connected in the graph.
      • concatenate

        public static Path concatenate​(Path... paths)
                                throws java.lang.IllegalArgumentException
        Concatenate the given paths.
        Parameters:
        paths - Array of paths to concatenate.
        Returns:
        Concatenated path.
        Throws:
        java.lang.IllegalArgumentException - if the paths cannot be concatenated (IDs of map do not match, or the end of a path is not the beginning of the next).
      • getGraph

        public Graph getGraph()
        Returns:
        Graph containing the path.
      • getOrigin

        public Node getOrigin()
        Returns:
        First node of the path.
      • getDestination

        public Node getDestination()
        Returns:
        Last node of the path.
      • getArcs

        public java.util.List<Arc> getArcs()
        Returns:
        List of arcs in the path.
      • isEmpty

        public boolean isEmpty()
        Check if this path is empty (it does not contain any node).
        Returns:
        true if this path is empty, false otherwise.
      • size

        public int size()
        Get the number of nodes in this path.
        Returns:
        Number of nodes in this path.
      • isValid

        public boolean isValid()
        Check if this path is valid. A path is valid if any of the following is true:
        • it is empty;
        • it contains a single node (without arcs);
        • the first arc has for origin the origin of the path and, for two consecutive arcs, the destination of the first one is the origin of the second one.
        Returns:
        true if the path is valid, false otherwise.
      • getLength

        public float getLength()
        Compute the length of this path (in meters).
        Returns:
        Total length of the path (in meters).
      • getTravelTime

        public double getTravelTime​(double speed)
        Compute the time required to travel this path if moving at the given speed.
        Parameters:
        speed - Speed to compute the travel time.
        Returns:
        Time (in seconds) required to travel this path at the given speed (in kilometers-per-hour).
      • getMinimumTravelTime

        public double getMinimumTravelTime()
        Compute the time to travel this path if moving at the maximum allowed speed on every arc.
        Returns:
        Minimum travel time to travel this path (in seconds).