Methode fastestpath
This commit is contained in:
parent
5457c37ba7
commit
0fcee12cd3
1 changed files with 32 additions and 4 deletions
|
@ -30,13 +30,41 @@ 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.
|
* 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:
|
if (nodes.size()==1){
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, nodes.get(0));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = 0 ; i < nodes.size()-1; i++) {
|
||||||
|
double min = Double.POSITIVE_INFINITY;
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
if (nodes.get(i).getSuccessors().size() >= 1) {
|
||||||
|
Arc min_arc = null;
|
||||||
|
for(Arc a : nodes.get(i).getSuccessors()) {
|
||||||
|
if( a.getDestination()==nodes.get(i+1) ) {
|
||||||
|
|
||||||
|
if( a.getMinimumTravelTime() < min) {
|
||||||
|
min_arc = a ; // choose fastest route
|
||||||
|
min = a.getMinimumTravelTime() ;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
throw new IllegalArgumentException("two consecutive nodes in the list are not connected in the graph.");
|
||||||
|
}
|
||||||
|
arcs.add( min_arc );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return new Path(graph, arcs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue