fastest path

This commit is contained in:
Georgia Koutsodima 2023-03-29 16:14:06 +02:00
parent bd9d89eaf5
commit 4345b03ba0

View file

@ -36,6 +36,34 @@ public class Path {
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
List <Node> nodes2=nodes;
Arc candidat = null; //arc candidat à être le plus rapide entre deux nodes
if(nodes.size()==0){
return new Path(graph);
}
else if(nodes.size()==1){
return new Path(graph,nodes.get(0));
}
else{
Node deb = nodes2.get(0);
for(Node fin : nodes2){
if(!fin.equals(deb)){
double time = Float.MAX_VALUE;
for(Arc a : deb.getSuccessors()){
if(a.getDestination().equals(fin)&&time>a.getMinimumTravelTime()){
time = a.getMinimumTravelTime();
candidat=a;
}
}
if(time==Float.MAX_VALUE){
throw new IllegalArgumentException("Liste de noeuds non valide");
}
arcs.add(candidat);
deb = fin;
}
}
}
return new Path(graph, arcs);
}