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,13 +30,45 @@ public class Path {
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph. * 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) public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException { throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: 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); return new Path(graph, arcs);
}else if (nodes.isEmpty()){
return new Path(graph);
} else {
return new Path(graph, nodes.get(0));
}
} }
/** /**
@ -56,22 +88,26 @@ public class Path {
throws IllegalArgumentException { throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
boolean suiv; boolean suiv;
Arc bonarc; Arc bonarc=null;
if (nodes.size()>1) {
for (int i=0;i<nodes.size()-1;i++) { for (int i=0;i<nodes.size()-1;i++) {
if (nodes.get(i).getNumberOfSuccessors()<=0) if (nodes.get(i).getNumberOfSuccessors()<=0)
throw new IllegalArgumentException(); 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++) { for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
suiv=false;
if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) { if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
if (nodes.get(i).getSuccessors().get(parcourt).getLength()<bonarc.getLength()) {
bonarc=nodes.get(i).getSuccessors().get(parcourt);
suiv=true; 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) if (!suiv)
@ -80,6 +116,12 @@ public class Path {
arcs.add(bonarc); arcs.add(bonarc);
} }
return new Path(graph, arcs); return new Path(graph, arcs);
}else if (nodes.isEmpty()){
return new Path(graph);
} else {
return new Path(graph, nodes.get(0));
}
} }
/** /**