From c316aa5af2af5dd7eadd77ab3d5e320e8b059eec Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Sun, 11 Aug 2024 22:17:07 +0200 Subject: [PATCH] fix nasty insertion scheduler bug --- .../drt/scheduler/DefaultRequestInsertionScheduler.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/scheduler/DefaultRequestInsertionScheduler.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/scheduler/DefaultRequestInsertionScheduler.java index 8b3755ba082..72082906255 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/scheduler/DefaultRequestInsertionScheduler.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/scheduler/DefaultRequestInsertionScheduler.java @@ -128,8 +128,7 @@ private void verifyConstraints(InsertionWithDetourData insertion) { Schedule schedule = insertion.insertion.vehicleEntry.vehicle.getSchedule(); for (Task task : schedule.getTasks()) { - if (task instanceof DrtStopTask) { - DrtStopTask stopTask = (DrtStopTask) task; + if (task instanceof DrtStopTask stopTask) { for (AcceptedDrtRequest request : stopTask.getPickupRequests().values()) { Verify.verify(stopTask.getEndTime() <= request.getLatestStartTime()); @@ -211,12 +210,16 @@ private DrtStopTask insertPickup(AcceptedDrtRequest request, InsertionWithDetour beforePickupTask = insertWait(vehicleEntry.vehicle, currentTask, dropoffIdx); } } + if(!stops.isEmpty() && stops.size() + 1 > pickupIdx) { + //there is an existing stop which was scheduled earlier and was not the destination of the already diverted drive task + removeBetween(schedule, beforePickupTask, stops.get(pickupIdx).task); + } } else { // insert pickup after an existing stop/stay task StayTask stayTask = null; DrtStopTask stopTask = null; if (pickupIdx == 0) { if (scheduleStatus == ScheduleStatus.PLANNED) {// PLANNED schedule - stayTask = (StayTask)schedule.getTasks().get(0); + stayTask = (StayTask)schedule.getTasks().getFirst(); stayTask.setEndTime(stayTask.getBeginTime());// could get later removed with ScheduleTimingUpdater } else if (STAY.isBaseTypeOf(currentTask)) { stayTask = (StayTask)currentTask; // ongoing stay task