diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java index 6ebdb73..72b61c1 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java @@ -8,7 +8,7 @@ import java.util.List; *
* Class representing a path between nodes in a graph. *
- * + * *
* A path is represented as a list of {@link Arc} with an origin and not a list
* of {@link Node} due to the multi-graph nature (multiple arcs between two
@@ -21,52 +21,83 @@ public class Path {
/**
* Create a new path that goes through the given list of nodes (in order),
* choosing the fastest route if multiple are available.
- *
+ *
* @param graph Graph containing the nodes in the list.
* @param nodes List of nodes to build the path.
- *
+ *
* @return A path that goes through the given list of nodes.
- *
+ *
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph.
- *
- * @deprecated Need to be implemented.
*/
public static Path createFastestPathFromNodes(Graph graph, List
*
- *
+ *
* @return true if the path is valid, false otherwise.
- *
- * @deprecated Need to be implemented.
*/
public boolean isValid() {
- // TODO:
- return false;
+ if (arcs.size() == 0) {
+ return true;
+ }
+ if (arcs.get(0).getOrigin() != origin)
+ return false;
+ else if (arcs.size() == 1)
+ return true;
+
+ for (int i = 1; i < arcs.size(); i++) {
+ if (arcs.get(i-1).getDestination() != arcs.get(i).getOrigin())
+ return false;
+ }
+ return true;
}
/**
* Compute the length of this path (in meters).
- *
+ *
* @return Total length of the path (in meters).
- *
- * @deprecated Need to be implemented.
*/
public float getLength() {
- // TODO:
- return 0;
+ float length = 0;
+ for (Arc arc: arcs) {
+ length += arc.getLength();
+ }
+ return length;
}
/**
* Compute the time required to travel this path if moving at the given speed.
- *
+ *
* @param speed Speed to compute the travel time.
- *
+ *
* @return Time (in seconds) required to travel this path at the given speed (in
* kilometers-per-hour).
- *
- * @deprecated Need to be implemented.
*/
public double getTravelTime(double speed) {
- // TODO:
- return 0;
+ double time = 0;
+ for (Arc arc : arcs) {
+ time += arc.getTravelTime(speed);
+ }
+ return time;
}
/**
* Compute the time to travel this path if moving at the maximum allowed speed
* on every arc.
- *
+ *
* @return Minimum travel time to travel this path (in seconds).
- *
- * @deprecated Need to be implemented.
*/
public double getMinimumTravelTime() {
- // TODO:
- return 0;
+ double time = 0;
+ for (Arc arc : arcs) {
+ time += arc.getMinimumTravelTime();
+ }
+ return time;
}
}