Methode fastestpath

This commit is contained in:
Auriane Lartigue 2020-03-16 16:19:20 +01:00
parent 5457c37ba7
commit 0fcee12cd3

View file

@ -30,14 +30,42 @@ public class Path {
* @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.
* 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));
}
else {
for (int i = 0 ; i < nodes.size()-1; i++) {
double min = Double.POSITIVE_INFINITY;
boolean found = false;
if (nodes.get(i).getSuccessors().size() >= 1) {
Arc min_arc = null;
for(Arc a : nodes.get(i).getSuccessors()) {
if( a.getDestination()==nodes.get(i+1) ) {
if( a.getMinimumTravelTime() < min) {
min_arc = a ; // choose fastest route
min = a.getMinimumTravelTime() ;
}
found = true;
}
}
if (!found) {
throw new IllegalArgumentException("two consecutive nodes in the list are not connected in the graph.");
}
arcs.add( min_arc );
}
}
return new Path(graph, arcs);
}
}
/**
* Create a new path that goes through the given list of nodes (in order),