|
@@ -35,7 +35,31 @@ public class Path {
|
35
|
35
|
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
36
|
36
|
throws IllegalArgumentException {
|
37
|
37
|
List<Arc> arcs = new ArrayList<Arc>();
|
38
|
|
- // TODO:
|
|
38
|
+ if(nodes.size()==1) {
|
|
39
|
+ return new Path(graph, nodes.get(0));
|
|
40
|
+ }
|
|
41
|
+ for(int i=0; i<nodes.size()-1; i++) { // Parcours des noeuds dans l'orde
|
|
42
|
+ Node node_actuel= nodes.get(i);
|
|
43
|
+ if(node_actuel.hasSuccessors()) { // Véridie si le noeud a une succeseur
|
|
44
|
+ List<Arc> arc_suiv = node_actuel.getSuccessors();
|
|
45
|
+ double travel_time = 10000000;
|
|
46
|
+ int num=0;
|
|
47
|
+ boolean successor_found = false ;
|
|
48
|
+ for(int j=0; j<arc_suiv.size();j++) {
|
|
49
|
+ if((arc_suiv.get(j).getDestination().compareTo(nodes.get(i+1)) == 0 ) && (arc_suiv.get(j).getMinimumTravelTime()< travel_time)) {
|
|
50
|
+ num=j;
|
|
51
|
+ travel_time=arc_suiv.get(num).getMinimumTravelTime();
|
|
52
|
+ successor_found = true;
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+ if(successor_found== false) {
|
|
56
|
+ throw new IllegalArgumentException();
|
|
57
|
+ }
|
|
58
|
+ arcs.add(arc_suiv.get(num));
|
|
59
|
+ }else {
|
|
60
|
+ throw new IllegalArgumentException();
|
|
61
|
+ }
|
|
62
|
+ }
|
39
|
63
|
return new Path(graph, arcs);
|
40
|
64
|
}
|
41
|
65
|
|
|
@@ -55,8 +79,32 @@ public class Path {
|
55
|
79
|
*/
|
56
|
80
|
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
57
|
81
|
throws IllegalArgumentException {
|
58
|
|
- List<Arc> arcs = new ArrayList<Arc>();
|
59
|
|
- // TODO:
|
|
82
|
+ List<Arc> arcs = new ArrayList<Arc>();
|
|
83
|
+ if(nodes.size()==1) {
|
|
84
|
+ return new Path(graph, nodes.get(0));
|
|
85
|
+ }
|
|
86
|
+ for(int i=0; i<nodes.size()-1; i++) { // Parcours des noeuds dans l'orde
|
|
87
|
+ Node node_actuel= nodes.get(i);
|
|
88
|
+ if(node_actuel.hasSuccessors()) { // Véridie si le noeud a une succeseur
|
|
89
|
+ List<Arc> arc_suiv = node_actuel.getSuccessors();
|
|
90
|
+ int num=0;
|
|
91
|
+ double length = 1000000;
|
|
92
|
+ boolean successor_found = false ;
|
|
93
|
+ for(int j=0; j<arc_suiv.size();j++) {
|
|
94
|
+ if((arc_suiv.get(j).getDestination().compareTo(nodes.get(i+1)) == 0) && (arc_suiv.get(j).getLength() < length)) {
|
|
95
|
+ num = j;
|
|
96
|
+ length = arc_suiv.get(num).getLength();
|
|
97
|
+ successor_found = true;
|
|
98
|
+ }
|
|
99
|
+ }
|
|
100
|
+ if(successor_found== false) {
|
|
101
|
+ throw new IllegalArgumentException();
|
|
102
|
+ }
|
|
103
|
+ arcs.add(arc_suiv.get(num));
|
|
104
|
+ }else {
|
|
105
|
+ throw new IllegalArgumentException();
|
|
106
|
+ }
|
|
107
|
+ }
|
60
|
108
|
return new Path(graph, arcs);
|
61
|
109
|
}
|
62
|
110
|
|