forked from lebotlan/BE-Graphes
Compare commits
No commits in common. "a9165c3bfc0797bcb9ce7a75a0ce5d069fa5800b" and "6f126202ca85062d3f6d28c500327a719be1bcd4" have entirely different histories.
a9165c3bfc
...
6f126202ca
1 changed files with 2 additions and 11 deletions
|
|
@ -2,7 +2,6 @@ package org.insa.graphs.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
|
@ -65,20 +64,12 @@ 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 createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if (nodes.size() == 0) {
|
|
||||||
return new Path(graph);
|
|
||||||
}
|
|
||||||
if (nodes.size() == 1) {
|
|
||||||
return new Path(graph, nodes.getFirst());
|
|
||||||
}
|
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
for (int i=0; i<nodes.size()-1; i++) {
|
// TODO:
|
||||||
int j = i;
|
|
||||||
arcs.add(nodes.get(i).getSuccessors().stream().filter(a -> a.getDestination().equals(nodes.get(j+1))).min(Comparator.comparing(Arc::getLength)).orElseThrow(() -> new IllegalArgumentException("Invalid list of nodes")));
|
|
||||||
}
|
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue