|
@@ -30,14 +30,46 @@ public class Path {
|
30
|
30
|
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
31
|
31
|
* consecutive nodes in the list are not connected in the graph.
|
32
|
32
|
*
|
33
|
|
- * @deprecated Need to be implemented.
|
34
|
33
|
*/
|
35
|
34
|
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
36
|
35
|
throws IllegalArgumentException {
|
37
|
36
|
List<Arc> arcs = new ArrayList<Arc>();
|
38
|
|
- // TODO:
|
39
|
|
- return new Path(graph, arcs);
|
40
|
|
- }
|
|
37
|
+ boolean suiv;
|
|
38
|
+ Arc bonarc=null;
|
|
39
|
+
|
|
40
|
+ if (nodes.size()>1) {
|
|
41
|
+ for (int i=0;i<nodes.size()-1;i++) {
|
|
42
|
+
|
|
43
|
+ if (nodes.get(i).getNumberOfSuccessors()<=0)
|
|
44
|
+ throw new IllegalArgumentException();
|
|
45
|
+
|
|
46
|
+ double doublest=Double.MAX_VALUE;
|
|
47
|
+ suiv=false;
|
|
48
|
+
|
|
49
|
+ for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
|
|
50
|
+
|
|
51
|
+ if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
|
|
52
|
+
|
|
53
|
+ suiv=true;
|
|
54
|
+
|
|
55
|
+ if (nodes.get(i).getSuccessors().get(parcourt).getMinimumTravelTime()<doublest) {
|
|
56
|
+ bonarc=nodes.get(i).getSuccessors().get(parcourt);
|
|
57
|
+ doublest=nodes.get(i).getSuccessors().get(parcourt).getMinimumTravelTime();
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+ if (!suiv)
|
|
61
|
+ throw new IllegalArgumentException();
|
|
62
|
+ }
|
|
63
|
+ arcs.add(bonarc);
|
|
64
|
+ }
|
|
65
|
+ return new Path(graph, arcs);
|
|
66
|
+
|
|
67
|
+ }else if (nodes.isEmpty()){
|
|
68
|
+ return new Path(graph);
|
|
69
|
+ } else {
|
|
70
|
+ return new Path(graph, nodes.get(0));
|
|
71
|
+ }
|
|
72
|
+ }
|
41
|
73
|
|
42
|
74
|
/**
|
43
|
75
|
* Create a new path that goes through the given list of nodes (in order),
|
|
@@ -56,30 +88,40 @@ public class Path {
|
56
|
88
|
throws IllegalArgumentException {
|
57
|
89
|
List<Arc> arcs = new ArrayList<Arc>();
|
58
|
90
|
boolean suiv;
|
59
|
|
- Arc bonarc;
|
60
|
|
-
|
61
|
|
- for (int i=0;i<nodes.size()-1;i++) {
|
62
|
|
-
|
63
|
|
- if (nodes.get(i).getNumberOfSuccessors()<=0)
|
64
|
|
- throw new IllegalArgumentException();
|
65
|
|
-
|
66
|
|
- bonarc=Node.linkNodes(null, null, Float.MAX_VALUE, null, null);
|
67
|
|
-
|
68
|
|
- for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
|
69
|
|
- suiv=false;
|
70
|
|
- if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
|
71
|
|
-
|
72
|
|
- if (nodes.get(i).getSuccessors().get(parcourt).getLength()<bonarc.getLength()) {
|
73
|
|
- bonarc=nodes.get(i).getSuccessors().get(parcourt);
|
74
|
|
- suiv=true;
|
75
|
|
- }
|
76
|
|
- }
|
77
|
|
- if (!suiv)
|
78
|
|
- throw new IllegalArgumentException();
|
79
|
|
- }
|
80
|
|
- arcs.add(bonarc);
|
81
|
|
- }
|
82
|
|
- return new Path(graph, arcs);
|
|
91
|
+ Arc bonarc=null;
|
|
92
|
+
|
|
93
|
+ if (nodes.size()>1) {
|
|
94
|
+ for (int i=0;i<nodes.size()-1;i++) {
|
|
95
|
+
|
|
96
|
+ if (nodes.get(i).getNumberOfSuccessors()<=0)
|
|
97
|
+ throw new IllegalArgumentException();
|
|
98
|
+
|
|
99
|
+ Float floatest=Float.MAX_VALUE;
|
|
100
|
+ suiv=false;
|
|
101
|
+
|
|
102
|
+ for (int parcourt=0; parcourt<nodes.get(i).getNumberOfSuccessors(); parcourt++) {
|
|
103
|
+
|
|
104
|
+ if (nodes.get(i).getSuccessors().get(parcourt).getDestination()==nodes.get(i+1)) {
|
|
105
|
+
|
|
106
|
+ suiv=true;
|
|
107
|
+
|
|
108
|
+ if (nodes.get(i).getSuccessors().get(parcourt).getLength()<floatest) {
|
|
109
|
+ bonarc=nodes.get(i).getSuccessors().get(parcourt);
|
|
110
|
+ floatest=nodes.get(i).getSuccessors().get(parcourt).getLength();
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+ if (!suiv)
|
|
114
|
+ throw new IllegalArgumentException();
|
|
115
|
+ }
|
|
116
|
+ arcs.add(bonarc);
|
|
117
|
+ }
|
|
118
|
+ return new Path(graph, arcs);
|
|
119
|
+
|
|
120
|
+ }else if (nodes.isEmpty()){
|
|
121
|
+ return new Path(graph);
|
|
122
|
+ } else {
|
|
123
|
+ return new Path(graph, nodes.get(0));
|
|
124
|
+ }
|
83
|
125
|
}
|
84
|
126
|
|
85
|
127
|
/**
|