Travail a plusieurs, ajout des fonctions faites par Aurélia
這個提交存在於:
alejeune 2022-03-27 21:38:11 +02:00
當前提交 7fedb6de7a

查看文件

@ -30,12 +30,38 @@ 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.
*/ */
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes) public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException { throws IllegalArgumentException {
if (nodes.size() == 1) {
return new Path(graph, nodes.get(0));
}
if (nodes.size() == 1) {
return new Path(graph);
}
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: for (int i = 0 ; i < nodes.size(); i++) {
Node currNode = nodes.get(i);
if (i < nodes.size() -1) {
Node nextNode = nodes.get(i+1);
if (currNode.hasSuccessors()) {
Arc better = null;
for (Arc j : currNode.getSuccessors()) {
if (j.getDestination() == nextNode) {
if (better == null || better.getMinimumTravelTime() > j.getMinimumTravelTime()) {
better = j;
}
}
}
if (better == null) {
throw (new IllegalArgumentException());
} else {
arcs.add(better);
}
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }
@ -51,12 +77,38 @@ 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.
*/ */
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() == 1) {
return new Path(graph, nodes.get(0));
}
if (nodes.size() == 1) {
return new Path(graph);
}
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: for (int i = 0 ; i < nodes.size(); i++) {
Node currNode = nodes.get(i);
if (i < nodes.size() -1) {
Node nextNode = nodes.get(i+1);
if (currNode.hasSuccessors()) {
Arc better = null;
for (Arc j : currNode.getSuccessors()) {
if (j.getDestination() == nextNode) {
if (better == null || better.getLength() > j.getLength()) {
better = j;
}
}
}
if (better == null) {
throw (new IllegalArgumentException());
} else {
arcs.add(better);
}
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }