2
2
3
3
import static org .matsim .contrib .drt .schedule .DrtTaskBaseType .STOP ;
4
4
5
- import javax .annotation .Nullable ;
5
+ import jakarta .annotation .Nullable ;
6
6
7
7
import org .matsim .contrib .drt .optimizer .VehicleEntry ;
8
8
import org .matsim .contrib .drt .optimizer .insertion .InsertionGenerator .Insertion ;
@@ -61,7 +61,7 @@ public PickupDetourInfo calcPickupDetourInfo(VehicleEntry vEntry, InsertionPoint
61
61
var times = calculatePickupIfSameLink (vEntry , pickup .index , toPickupDepartureTime , drtRequest );
62
62
return new PickupDetourInfo (times .departureTime , times .additionalStopDuration );
63
63
}
64
-
64
+
65
65
double arrivalTime = toPickupDepartureTime + toPickupTT ;
66
66
double departureTime = stopTimeCalculator .initEndTimeForPickup (vEntry .vehicle , arrivalTime , drtRequest );
67
67
double stopDuration = departureTime - arrivalTime ;
@@ -83,13 +83,13 @@ public DropoffDetourInfo calcDropoffDetourInfo(Insertion insertion, double toDro
83
83
if (dropoff .newWaypoint .getLink () == dropoff .previousWaypoint .getLink ()) {
84
84
double remainingPickupTimeLoss = calculateRemainingPickupTimeLossAtDropoff (insertion , pickupDetourInfo );
85
85
double arrivalTime = dropoff .previousWaypoint .getArrivalTime () + remainingPickupTimeLoss ;
86
-
86
+
87
87
DrtStopTask stopTask = findStopTaskIfSameLinkAsPrevious (vEntry , dropoff .index );
88
88
double departureTime = stopTimeCalculator .updateEndTimeForDropoff (vEntry .vehicle , stopTask , arrivalTime , drtRequest );
89
-
89
+
90
90
double initialStopDuration = stopTask .getEndTime () - stopTask .getBeginTime ();
91
91
double additionalStopDuration = departureTime - arrivalTime - initialStopDuration ;
92
-
92
+
93
93
return new DropoffDetourInfo (arrivalTime , additionalStopDuration );
94
94
}
95
95
@@ -109,7 +109,7 @@ private PickupDetourInfo calcPickupDetourInfoIfPickupToDropoffDetour(VehicleEntr
109
109
110
110
final double departureTime ;
111
111
final double additionalStopDuration ;
112
-
112
+
113
113
if (pickup .newWaypoint .getLink () == pickup .previousWaypoint .getLink ()) {
114
114
// no drive to pickup, but possible additional stop duration
115
115
var times = calculatePickupIfSameLink (vEntry , pickup .index , toPickupDepartureTime , drtRequest );
@@ -119,7 +119,7 @@ private PickupDetourInfo calcPickupDetourInfoIfPickupToDropoffDetour(VehicleEntr
119
119
departureTime = stopTimeCalculator .initEndTimeForPickup (vEntry .vehicle , toPickupDepartureTime + toPickupTT , drtRequest );
120
120
additionalStopDuration = departureTime - toPickupDepartureTime - toPickupTT ;
121
121
}
122
-
122
+
123
123
double replacedDriveTT = calculateReplacedDriveDuration (vEntry , pickup .index , toPickupDepartureTime );
124
124
double pickupTimeLoss = toPickupTT + additionalStopDuration + fromPickupTT - replacedDriveTT ;
125
125
return new PickupDetourInfo (departureTime , pickupTimeLoss );
@@ -133,10 +133,10 @@ private DropoffDetourInfo calcDropoffDetourInfoIfPickupToDropoffDetour(double fr
133
133
double dropoffTimeLoss = stopDuration + fromDropoffTT ;
134
134
return new DropoffDetourInfo (arrivalTime , dropoffTimeLoss );
135
135
}
136
-
136
+
137
137
private PickupTimeInfo calculatePickupIfSameLink (VehicleEntry vEntry , int pickupIndex , double toPickupDepartureTime , DrtRequest request ) {
138
138
DrtStopTask stopTask = findStopTaskIfSameLinkAsPrevious (vEntry , pickupIndex );
139
-
139
+
140
140
if (stopTask == null ) {
141
141
// case 1: previous waypoint is a drive, we create a new stop
142
142
// insertion time is the end time of previous waypoint
@@ -160,11 +160,11 @@ private PickupTimeInfo calculatePickupIfSameLink(VehicleEntry vEntry, int pickup
160
160
return new PickupTimeInfo (departureTime , additionalStopDuration );
161
161
}
162
162
}
163
-
163
+
164
164
private DrtStopTask findStopTaskIfSameLinkAsPrevious (VehicleEntry vEntry , int insertionIdx ) {
165
165
if (insertionIdx == 0 ) {
166
166
var startTask = vEntry .start .task ;
167
-
167
+
168
168
if (startTask .isPresent () && STOP .isBaseTypeOf (startTask .get ())) {
169
169
// case 1: we have a preceding and ongoing (started) stop task
170
170
return (DrtStopTask ) startTask .get ();
@@ -173,7 +173,7 @@ private DrtStopTask findStopTaskIfSameLinkAsPrevious(VehicleEntry vEntry, int in
173
173
// case 2: we have a preceding (planned) stop task
174
174
return (DrtStopTask ) vEntry .stops .get (insertionIdx - 1 ).task ;
175
175
}
176
-
176
+
177
177
return null ; // otherwise, there is no stop task before
178
178
}
179
179
@@ -190,32 +190,32 @@ private double calculateReplacedDriveDuration(VehicleEntry vEntry, int insertion
190
190
191
191
double replacedDriveStartTime = vEntry .getWaypoint (insertionIdx ).getDepartureTime ();
192
192
double replacedDriveEndTime = vEntry .stops .get (insertionIdx ).task .getBeginTime ();
193
-
193
+
194
194
// reduce by the idle time before the next stop, to get the actual drive time
195
195
return replacedDriveEndTime - replacedDriveStartTime - vEntry .getPrecedingStayTime (insertionIdx );
196
196
}
197
-
197
+
198
198
/*
199
199
* When inserting a pickup, we generate a "pickup loss" which describes by how
200
200
* much time we have to shift all following tasks to the future.
201
- *
201
+ *
202
202
* In the case that some of the following stops are prebooked, however, there
203
203
* may be a stay time buffer between the insertion point and the stop. Hence, if
204
204
* a following stop only happens in four hours, we may not need to shift the
205
205
* task to the future. A preceding stay time, hence, reduces the introduced
206
206
* pickup loss.
207
- *
207
+ *
208
208
* The present function calculates the remaining pickup loss at the dropoff
209
209
* insertion point after deducting all the stay times up to the dropoff.
210
210
*/
211
211
public static double calculateRemainingPickupTimeLossAtDropoff (Insertion insertion , PickupDetourInfo pickupDetourInfo ) {
212
212
VehicleEntry vEntry = insertion .vehicleEntry ;
213
213
double remainingPickupTimeLoss = pickupDetourInfo .pickupTimeLoss ;
214
-
214
+
215
215
for (int i = insertion .pickup .index + 1 ; i < insertion .dropoff .index ; i ++) {
216
216
remainingPickupTimeLoss = Math .max (remainingPickupTimeLoss - vEntry .getPrecedingStayTime (i ), 0.0 );
217
217
}
218
-
218
+
219
219
return remainingPickupTimeLoss ;
220
220
}
221
221
@@ -285,7 +285,7 @@ public String toString() {
285
285
.toString ();
286
286
}
287
287
}
288
-
288
+
289
289
private record PickupTimeInfo (double departureTime , double additionalStopDuration ) {
290
290
}
291
291
}
0 commit comments