|
@@ -51,12 +51,34 @@ public class Path {
|
51
|
51
|
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
52
|
52
|
* consecutive nodes in the list are not connected in the graph.
|
53
|
53
|
*
|
54
|
|
- * @deprecated Need to be implemented.
|
55
|
54
|
*/
|
56
|
55
|
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
57
|
56
|
throws IllegalArgumentException {
|
58
|
57
|
List<Arc> arcs = new ArrayList<Arc>();
|
59
|
|
- // TODO:
|
|
58
|
+ 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
|
+ }
|
60
|
82
|
return new Path(graph, arcs);
|
61
|
83
|
}
|
62
|
84
|
|
|
@@ -198,11 +220,20 @@ public class Path {
|
198
|
220
|
*
|
199
|
221
|
* @return true if the path is valid, false otherwise.
|
200
|
222
|
*
|
201
|
|
- * @deprecated Need to be implemented.
|
202
|
223
|
*/
|
203
|
224
|
public boolean isValid() {
|
204
|
|
- // TODO:
|
205
|
|
- return false;
|
|
225
|
+ boolean bool=true;
|
|
226
|
+ if (!this.isEmpty() && !this.arcs.isEmpty()) {
|
|
227
|
+ if (this.origin!=this.arcs.get(0).getOrigin())
|
|
228
|
+ bool=false;
|
|
229
|
+ else if (this.arcs.size()>1) {
|
|
230
|
+ for (int i=0;i<this.arcs.size()-1;i++) {
|
|
231
|
+ if (this.arcs.get(i).getDestination()!=this.arcs.get(i+1).getOrigin())
|
|
232
|
+ bool=false;
|
|
233
|
+ }
|
|
234
|
+ }
|
|
235
|
+ }
|
|
236
|
+ return bool;
|
206
|
237
|
}
|
207
|
238
|
|
208
|
239
|
/**
|
|
@@ -227,11 +258,9 @@ public class Path {
|
227
|
258
|
* @return Time (in seconds) required to travel this path at the given speed (in
|
228
|
259
|
* kilometers-per-hour).
|
229
|
260
|
*
|
230
|
|
- * @deprecated Need to be implemented.
|
231
|
261
|
*/
|
232
|
262
|
public double getTravelTime(double speed) {
|
233
|
|
- // TODO:
|
234
|
|
- return 0;
|
|
263
|
+ return this.getLength()*3.6/speed;
|
235
|
264
|
}
|
236
|
265
|
|
237
|
266
|
/**
|
|
@@ -240,11 +269,13 @@ public class Path {
|
240
|
269
|
*
|
241
|
270
|
* @return Minimum travel time to travel this path (in seconds).
|
242
|
271
|
*
|
243
|
|
- * @deprecated Need to be implemented.
|
244
|
272
|
*/
|
245
|
273
|
public double getMinimumTravelTime() {
|
246
|
|
- // TODO:
|
247
|
|
- return 0;
|
|
274
|
+ double temps=0.0;
|
|
275
|
+ for (int i=0;i<this.arcs.size();i++) {
|
|
276
|
+ temps+=this.arcs.get(i).getMinimumTravelTime();
|
|
277
|
+ }
|
|
278
|
+ return temps;
|
248
|
279
|
}
|
249
|
280
|
|
250
|
281
|
}
|