From 87a6887c30294c763422f2673a3fd5f4b3cc5dcc Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Fri, 6 Sep 2024 00:53:14 +0200 Subject: [PATCH] drt: allow final stay task without requests in preplanned scenarios --- .../optimizer/PreplannedDrtOptimizer.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java index 5dd5f1c8bf7..fd0f6672826 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java @@ -174,17 +174,22 @@ public void nextTask(DvrpVehicle vehicle) { } else { nonVisitedPreplannedStops.poll();//remove this stop from queue - var stopTask = taskFactory.createStopTask(vehicle, currentTime, currentTime + stopDuration, currentLink); - if (nextStop.pickup) { - var request = Preconditions.checkNotNull(openRequests.get(nextStop.preplannedRequest.key), - "Request (%s) has not been yet submitted", nextStop.preplannedRequest); - stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + if(nextStop.preplannedRequest.key.passengerIds.isEmpty() && nonVisitedPreplannedStops.isEmpty()) { + var stayTask = taskFactory.createStayTask(vehicle, currentTime, vehicle.getServiceEndTime(), currentLink); + schedule.addTask(stayTask); } else { - var request = Preconditions.checkNotNull(openRequests.remove(nextStop.preplannedRequest.key), - "Request (%s) has not been yet submitted", nextStop.preplannedRequest); - stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + var stopTask = taskFactory.createStopTask(vehicle, currentTime, currentTime + stopDuration, currentLink); + if (nextStop.pickup) { + var request = Preconditions.checkNotNull(openRequests.get(nextStop.preplannedRequest.key), + "Request (%s) has not been yet submitted", nextStop.preplannedRequest); + stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + } else { + var request = Preconditions.checkNotNull(openRequests.remove(nextStop.preplannedRequest.key), + "Request (%s) has not been yet submitted", nextStop.preplannedRequest); + stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + } + schedule.addTask(stopTask); } - schedule.addTask(stopTask); } // switch to the next task and update currentTasks