tests TP2 OK (avec une séance de retard donc)

This commit is contained in:
Favary Pierre 2021-03-31 17:56:43 +02:00
parent 93fbf88d99
commit d0f90b37fe

View file

@ -30,14 +30,46 @@ 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);
}
boolean suiv;
Arc bonarc=null;
if (nodes.size()>1) {
for (int i=0;i<nodes.size()-1;i++) {
if (nodes.get(i).getNumberOfSuccessors()<=0)
throw new IllegalArgumentException();
double doublest=Double.MAX_VALUE;
suiv=false;
for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
suiv=true;
if (nodes.get(i).getSuccessors().get(parcourt).getMinimumTravelTime()<doublest) {
bonarc=nodes.get(i).getSuccessors().get(parcourt);
doublest=nodes.get(i).getSuccessors().get(parcourt).getMinimumTravelTime();
}
}
if (!suiv)
throw new IllegalArgumentException();
}
arcs.add(bonarc);
}
return new Path(graph, arcs);
}else if (nodes.isEmpty()){
return new Path(graph);
} else {
return new Path(graph, nodes.get(0));
}
}
/**
* Create a new path that goes through the given list of nodes (in order),
@ -56,30 +88,40 @@ public class Path {
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
boolean suiv;
Arc bonarc;
Arc bonarc=null;
for (int i=0;i<nodes.size()-1;i++) {
if (nodes.size()>1) {
for (int i=0;i<nodes.size()-1;i++) {
if (nodes.get(i).getNumberOfSuccessors()<=0)
throw new IllegalArgumentException();
if (nodes.get(i).getNumberOfSuccessors()<=0)
throw new IllegalArgumentException();
bonarc=Node.linkNodes(null, null, Float.MAX_VALUE, null, null);
Float floatest=Float.MAX_VALUE;
suiv=false;
for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
suiv=false;
if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
if (nodes.get(i).getSuccessors().get(parcourt).getLength()<bonarc.getLength()) {
bonarc=nodes.get(i).getSuccessors().get(parcourt);
suiv=true;
}
}
if (!suiv)
throw new IllegalArgumentException();
}
arcs.add(bonarc);
}
return new Path(graph, arcs);
if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
suiv=true;
if (nodes.get(i).getSuccessors().get(parcourt).getLength()<floatest) {
bonarc=nodes.get(i).getSuccessors().get(parcourt);
floatest=nodes.get(i).getSuccessors().get(parcourt).getLength();
}
}
if (!suiv)
throw new IllegalArgumentException();
}
arcs.add(bonarc);
}
return new Path(graph, arcs);
}else if (nodes.isEmpty()){
return new Path(graph);
} else {
return new Path(graph, nodes.get(0));
}
}
/**