path valide
This commit is contained in:
parent
fabaf846d0
commit
0deb15ea13
2 changed files with 53 additions and 12 deletions
|
@ -30,12 +30,35 @@ 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:
|
||||
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;
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue