ajout: Implémentation de Path#createFastestPathFromNodes(Graph graph, List<Node> nodes)
This commit is contained in:
parent
370fe10947
commit
b820931b8f
1 changed files with 24 additions and 4 deletions
|
|
@ -25,13 +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 {
|
||||||
|
Path path = null;
|
||||||
|
if (nodes.size() <= 1) {
|
||||||
|
path = new Path(graph, nodes.isEmpty() ? null : nodes.get(0));
|
||||||
|
} else {
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
// TODO:
|
Node prev = null;
|
||||||
return new Path(graph, arcs);
|
for (Node next : nodes) {
|
||||||
|
if (prev != null) {
|
||||||
|
Arc choosen = null;
|
||||||
|
for (Arc arc : prev.getSuccessors()) {
|
||||||
|
if (arc.getDestination().equals(next)) {
|
||||||
|
if (choosen == null || choosen.getMinimumTravelTime() > arc.getMinimumTravelTime()) {
|
||||||
|
choosen = arc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (choosen == null) throw new IllegalArgumentException("Deux Nodes de la liste n'étaient pas connectés!");
|
||||||
|
arcs.add(choosen);
|
||||||
|
}
|
||||||
|
prev = next;
|
||||||
|
}
|
||||||
|
path = new Path(graph, arcs);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue