tests TP2 OK (avec une séance de retard donc)
This commit is contained in:
parent
93fbf88d99
commit
d0f90b37fe
1 changed files with 70 additions and 28 deletions
|
@ -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;
|
||||
|
||||
for (int i=0;i<nodes.size()-1;i++) {
|
||||
|
||||
if (nodes.get(i).getNumberOfSuccessors()<=0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
bonarc=Node.linkNodes(null, null, Float.MAX_VALUE, null, null);
|
||||
|
||||
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).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);
|
||||
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();
|
||||
|
||||
Float floatest=Float.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).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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue