Merge branch 'master' of https://git.etud.insa-toulouse.fr/alejeune/BE_Graphe_alejeune_rlacroix
Travail a plusieurs, ajout des fonctions faites par Aurélia
這個提交存在於:
當前提交
7fedb6de7a
共有 1 個檔案被更改,包括 56 行新增 和 4 行删除
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
載入中…
新增問題並參考