1
0
Fork 0

made createFastestPathFromNodes()

This commit is contained in:
Sebastien Moll 2026-04-15 17:38:08 +02:00
parent 6613be4663
commit 684c8ea6ac

View file

@ -25,12 +25,33 @@ public class 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<Node> nodes)
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
if (nodes.size() == 1) { return new Path(graph, nodes.get(0)); }
for (int i = 0; i < nodes.size() - 1; i++) {
Arc bestArc = null;
double bestSpeed = Double.MAX_VALUE;
for (Arc arcsucc : nodes.get(i).getSuccessors()) {
if (arcsucc.getDestination().equals(nodes.get(i+1))) {
int succspeed = arcsucc.getRoadInformation().getMaximumSpeed();
if (arcsucc.getTravelTime(succspeed) < bestSpeed) {
bestArc = arcsucc;
bestSpeed = arcsucc.getTravelTime(succspeed);
}
}
}
if (bestArc == null) {
throw new IllegalArgumentException();
} else {
arcs.add(bestArc);
}
}
return new Path(graph, arcs);
}