path valide

This commit is contained in:
Bensouda Idriss 2023-03-28 17:22:22 +02:00
parent fabaf846d0
commit 0deb15ea13
2 changed files with 53 additions and 12 deletions

View file

@ -30,13 +30,36 @@ 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.
*
*/
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
return new Path(graph, arcs);
List<Arc> arcs = new ArrayList<Arc>();
Arc a = null;
if (nodes.isEmpty()){
return new Path(graph);
} else if (nodes.size() == 1){
return new Path(graph, nodes.get(0));
}
for (int i=0;i<nodes.size()-1;i++){
double min = Double.MAX_VALUE;
Node origine=nodes.get(i);
Node dest = nodes.get(i+1);
if(origine.getNumberOfSuccessors() == 0){
throw (new IllegalArgumentException());
}
for (Arc suivant : origine.getSuccessors()){
if (suivant.getMinimumTravelTime()<min && suivant.getDestination() == dest){
min = suivant.getMinimumTravelTime();
a = suivant;
}
}
if (a == null){
throw (new IllegalArgumentException());
}
arcs.add(a);
}
return new Path(graph, arcs);
}
/**
@ -51,12 +74,36 @@ 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.
*
*/
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
Arc a = null;
if (nodes.isEmpty()){
return new Path(graph);
} else if (nodes.size() == 1){
return new Path(graph, nodes.get(0));
}
for (int i=0;i<nodes.size()-1;i++){
float min = Float.MAX_VALUE;
Node origine=nodes.get(i);
Node dest = nodes.get(i+1);
if(origine.getNumberOfSuccessors() == 0){
throw (new IllegalArgumentException());
}
for (Arc suivant : origine.getSuccessors()){
if (suivant.getLength()<min && suivant.getDestination() == dest){
min = suivant.getLength();
a = suivant;
}
}
if (a == null){
throw (new IllegalArgumentException());
}
arcs.add(a);
}
return new Path(graph, arcs);
}
@ -242,12 +289,6 @@ public class Path {
=======
<<<<<<< HEAD
*
*
>>>>>>> 052958ee6eb4821ebbb9c903780d467d62617fd2
>>>>>>> 661162456a46270c315c09521ce09f85f0020150
>>>>>>> 534e0b728e13a532d629312ec48c8c6185679721
>>>>>>> 9512825678cb119a068d94f8af261d356638dbdd
*/
public double getTravelTime(double speed) {
double TotalTime = 0;