From 6caa4d29886538bd9c3a79e9adcac6391c7b85ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Thu, 4 Jan 2024 17:37:43 +0100 Subject: [PATCH] remove WaitForStop task --- .../DefaultAlonsoMoraScheduler.java | 42 +++++++++++-------- .../scheduling/WaitForStopTask.java | 22 ---------- .../shifts/ShiftAlonsoMoraScheduler.java | 42 +++++++++++-------- 3 files changed, 50 insertions(+), 56 deletions(-) delete mode 100644 core/src/main/java/org/matsim/alonso_mora/scheduling/WaitForStopTask.java diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java index c7cc262..5cd3298 100644 --- a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java @@ -62,10 +62,10 @@ public class DefaultAlonsoMoraScheduler implements AlonsoMoraScheduler { private final StayTaskEndTimeCalculator endTimeCalculator; - public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, double vehicleStopDuration, - boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, - Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, - OperationalVoter operationalVoter) { + public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, + double vehicleStopDuration, boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, + TravelTime travelTime, Network network, StayTaskEndTimeCalculator endTimeCalculator, + LeastCostPathCalculator router, OperationalVoter operationalVoter) { this.taskFactory = taskFactory; this.vehicleStopDuration = vehicleStopDuration; this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes; @@ -171,10 +171,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { boolean isStayTask = task instanceof DrtStayTask; boolean isStopTask = task instanceof DrtStopTask; boolean isDriveTask = task instanceof DrtDriveTask; - boolean isWaitForStopTask = task instanceof WaitForStopTask; boolean isOperationalTask = operationalVoter.isOperationalTask(task); - Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask, + Verify.verify(isStayTask || isStopTask || isDriveTask || isOperationalTask, "Don't know what to do with this task"); } @@ -203,7 +202,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else if (currentTask instanceof StayTask) { currentLink = ((StayTask) currentTask).getLink(); - if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) { + if (currentTask instanceof DrtStayTask) { // If we are currently staying somewhere, end the stay task now currentTask.setEndTime(now); } @@ -265,18 +264,25 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { double earliestStartTime = stop.getRequest().getEarliestPickupTime(); if (earliestStartTime > currentTask.getEndTime()) { - currentTask = new WaitForStopTask(currentTask.getEndTime(), earliestStartTime, currentLink); - schedule.addTask(currentTask); + if (currentTask instanceof DrtStayTask) { + currentTask.setEndTime(earliestStartTime); + } else { + currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + earliestStartTime, currentLink); + schedule.addTask(currentTask); + } } } - + // Obtain the stop duration final double passengerStopDuration; - + if (stop.getType().equals(StopType.Pickup)) { - passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, stop.getRequest().getDrtRequest()); + passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, + stop.getRequest().getDrtRequest()); } else if (stop.getType().equals(StopType.Dropoff)) { - passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, stop.getRequest().getDrtRequest()); + passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, + stop.getRequest().getDrtRequest()); } else { throw new IllegalStateException(); } @@ -293,7 +299,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else { // Create a new stop task as we are not at a previously created stop double stopDuration = Math.max(vehicleStopDuration, passengerStopDuration); - + stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(), currentTask.getEndTime() + stopDuration, stop.getLink()); @@ -306,8 +312,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { if (stop.getType().equals(StopType.Pickup)) { stopTask.addPickupRequest(stop.getRequest().getAcceptedDrtRequest()); stop.getRequest().setPickupTask(vehicle, stopTask); - - double passengerDepartureTime = Math.max(stopTask.getBeginTime(), stop.getRequest().getEarliestPickupTime()); + + double passengerDepartureTime = Math.max(stopTask.getBeginTime(), + stop.getRequest().getEarliestPickupTime()); double passengerPickupTime = passengerDepartureTime + passengerStopDuration; stopTask.setEndTime(Math.max(stopTask.getEndTime(), passengerPickupTime)); @@ -320,7 +327,8 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else if (stop.getType().equals(StopType.Dropoff)) { stopTask.addDropoffRequest(stop.getRequest().getAcceptedDrtRequest()); stop.getRequest().setDropoffTask(vehicle, stopTask); - stopTask.setEndTime(Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration)); + stopTask.setEndTime( + Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration)); if (checkDeterminsticTravelTimes) { Verify.verify(stop.getTime() == stopTask.getBeginTime(), diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/WaitForStopTask.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/WaitForStopTask.java deleted file mode 100644 index fb190d4..0000000 --- a/core/src/main/java/org/matsim/alonso_mora/scheduling/WaitForStopTask.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.matsim.alonso_mora.scheduling; - -import static org.matsim.contrib.drt.schedule.DrtTaskBaseType.STAY; - -import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.schedule.DrtTaskType; -import org.matsim.contrib.dvrp.schedule.DefaultStayTask; - -import com.google.common.base.MoreObjects; - -public class WaitForStopTask extends DefaultStayTask { - public static final DrtTaskType TYPE = new DrtTaskType("WaitForStop", STAY); - - public WaitForStopTask(double beginTime, double endTime, Link link) { - super(TYPE, beginTime, endTime, link); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this).add("super", super.toString()).toString(); - } -} diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java index 4c8d911..4ebe041 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java @@ -11,7 +11,6 @@ import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler; -import org.matsim.alonso_mora.scheduling.WaitForStopTask; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask; @@ -66,9 +65,10 @@ public class ShiftAlonsoMoraScheduler implements AlonsoMoraScheduler { private final StayTaskEndTimeCalculator endTimeCalculator; - public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, double vehicleStopDuration, - boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, - Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, + public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, + double vehicleStopDuration, boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, + TravelTime travelTime, Network network, StayTaskEndTimeCalculator endTimeCalculator, + LeastCostPathCalculator router, org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter) { this.taskFactory = taskFactory; this.vehicleStopDuration = vehicleStopDuration; @@ -175,10 +175,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { boolean isStayTask = task instanceof DrtStayTask; boolean isStopTask = task instanceof DrtStopTask; boolean isDriveTask = task instanceof DrtDriveTask; - boolean isWaitForStopTask = task instanceof WaitForStopTask; boolean isOperationalTask = operationalVoter.isOperationalTask(task); - Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask, + Verify.verify(isStayTask || isStopTask || isDriveTask || isOperationalTask, "Don't know what to do with this task"); } @@ -207,7 +206,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else if (currentTask instanceof StayTask) { currentLink = ((StayTask) currentTask).getLink(); - if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) { + if (currentTask instanceof DrtStayTask) { // If we are currently staying somewhere, end the stay task now currentTask.setEndTime(now); } @@ -269,18 +268,25 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { double earliestStartTime = stop.getRequest().getEarliestPickupTime(); if (earliestStartTime > currentTask.getEndTime()) { - currentTask = new WaitForStopTask(currentTask.getEndTime(), earliestStartTime, currentLink); - schedule.addTask(currentTask); + if (currentTask instanceof DrtStayTask) { + currentTask.setEndTime(earliestStartTime); + } else { + currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + earliestStartTime, currentLink); + schedule.addTask(currentTask); + } } } - + // Obtain the stop duration final double passengerStopDuration; - + if (stop.getType().equals(StopType.Pickup)) { - passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, stop.getRequest().getDrtRequest()); + passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, + stop.getRequest().getDrtRequest()); } else if (stop.getType().equals(StopType.Dropoff)) { - passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, stop.getRequest().getDrtRequest()); + passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, + stop.getRequest().getDrtRequest()); } else { throw new IllegalStateException(); } @@ -297,7 +303,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else { // Create a new stop task as we are not at a previously created stop double stopDuration = Math.max(vehicleStopDuration, passengerStopDuration); - + stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(), currentTask.getEndTime() + stopDuration, stop.getLink()); @@ -311,10 +317,11 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { stopTask.addPickupRequest(stop.getRequest().getAcceptedDrtRequest()); stop.getRequest().setPickupTask(vehicle, stopTask); - double passengerDepartureTime = Math.max(stopTask.getBeginTime(), stop.getRequest().getEarliestPickupTime()); + double passengerDepartureTime = Math.max(stopTask.getBeginTime(), + stop.getRequest().getEarliestPickupTime()); double passengerPickupTime = passengerDepartureTime + passengerStopDuration; stopTask.setEndTime(Math.max(stopTask.getEndTime(), passengerPickupTime)); - + if (checkDeterminsticTravelTimes) { Verify.verify(stop.getTime() == stopTask.getEndTime(), "Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time."); @@ -324,7 +331,8 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { } else if (stop.getType().equals(StopType.Dropoff)) { stopTask.addDropoffRequest(stop.getRequest().getAcceptedDrtRequest()); stop.getRequest().setDropoffTask(vehicle, stopTask); - stopTask.setEndTime(Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration)); + stopTask.setEndTime( + Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration)); if (checkDeterminsticTravelTimes) { Verify.verify(stop.getTime() == stopTask.getBeginTime(),