forked from lebotlan/BE-Graphes
made createFastestPathFromNodes()
This commit is contained in:
parent
6613be4663
commit
684c8ea6ac
1 changed files with 23 additions and 2 deletions
|
|
@ -25,12 +25,33 @@ public class Path {
|
||||||
* @return A path that goes through the given list of nodes.
|
* @return A path that goes through the given list of nodes.
|
||||||
* @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:
|
|
||||||
|
if (nodes.size() == 1) { return new Path(graph, nodes.get(0)); }
|
||||||
|
|
||||||
|
for (int i = 0; i < nodes.size() - 1; i++) {
|
||||||
|
Arc bestArc = null;
|
||||||
|
double bestSpeed = Double.MAX_VALUE;
|
||||||
|
for (Arc arcsucc : nodes.get(i).getSuccessors()) {
|
||||||
|
if (arcsucc.getDestination().equals(nodes.get(i+1))) {
|
||||||
|
int succspeed = arcsucc.getRoadInformation().getMaximumSpeed();
|
||||||
|
if (arcsucc.getTravelTime(succspeed) < bestSpeed) {
|
||||||
|
bestArc = arcsucc;
|
||||||
|
bestSpeed = arcsucc.getTravelTime(succspeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (bestArc == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
} else {
|
||||||
|
arcs.add(bestArc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue