Package org.insa.graphs.model
Class Path
- java.lang.Object
-
- org.insa.graphs.model.Path
-
public class Path extends java.lang.Object
-
-
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.
-
-
-
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.
-
-
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).
-
-