From e46f87c2a4a950ac0ff84ee0c22fc3c5f642be6b Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Thu, 24 Nov 2022 11:27:55 +0100 Subject: [PATCH] adjust to updates in drt operations and make WaitForStopTask creation more flexible with factory --- .../alonso_mora/AlonsoMoraModeQSimModule.java | 9 ++++----- .../scheduling/AlonsoMoraTaskFactory.java | 13 +++++++++++++ .../scheduling/DefaultAlonsoMoraScheduler.java | 11 +++++++---- .../scheduling/DefaultAlonsoMoraTaskFactory.java | 14 ++++++++++++++ .../alonso_mora/shifts/ShiftAlonsoMoraModule.java | 6 +++++- .../shifts/ShiftAlonsoMoraScheduler.java | 9 +++++++-- .../alonso_mora/run/AlonsoMoraExamplesIT.java | 8 ++++++++ 7 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/org/matsim/alonso_mora/scheduling/AlonsoMoraTaskFactory.java create mode 100644 core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraTaskFactory.java diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java index e562772..13fc421 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java @@ -16,12 +16,9 @@ import org.matsim.alonso_mora.algorithm.relocation.CbcMpsRelocationSolver; import org.matsim.alonso_mora.algorithm.relocation.GlpkMpsRelocationSolver; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver; -import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler; -import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler; +import org.matsim.alonso_mora.scheduling.*; import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.NoopOperationalVoter; import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; -import org.matsim.alonso_mora.scheduling.ParallelLeastCostPathCalculator; -import org.matsim.alonso_mora.scheduling.StandardRebalancer; import org.matsim.alonso_mora.travel_time.*; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.optimizer.DrtOptimizer; @@ -308,6 +305,8 @@ protected void configureQSim() { return new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropOffRequests, pickupRequests) -> drtConfig.stopDuration); })); + bindModal(AlonsoMoraTaskFactory.class).toInstance(new DefaultAlonsoMoraTaskFactory()); + bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> { StayTaskEndTimeCalculator endTimeCalculator = getter.getModal(StayTaskEndTimeCalculator.class); DrtTaskFactory taskFactory = getter.getModal(DrtTaskFactory.class); @@ -320,7 +319,7 @@ protected void configureQSim() { return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration, amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime, - network, endTimeCalculator, router, operationalVoter); + network, endTimeCalculator, router, operationalVoter, getter.getModal(AlonsoMoraTaskFactory.class)); })); bindModal(OperationalVoter.class).toInstance(new NoopOperationalVoter()); diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/AlonsoMoraTaskFactory.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/AlonsoMoraTaskFactory.java new file mode 100644 index 0000000..37caaf7 --- /dev/null +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/AlonsoMoraTaskFactory.java @@ -0,0 +1,13 @@ +package org.matsim.alonso_mora.scheduling; + +import org.matsim.api.core.v01.network.Link; + +/** + * @author mga, nkuehnel / MOIA + */ +public interface AlonsoMoraTaskFactory { + + + WaitForStopTask createWaitForStopTask(double beginTime, double endTime, Link link); + +} 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 cb1c42b..ed24156 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 @@ -56,10 +56,12 @@ public class DefaultAlonsoMoraScheduler implements AlonsoMoraScheduler { private final StayTaskEndTimeCalculator endTimeCalculator; + private final AlonsoMoraTaskFactory alonsoMoraTaskFactory; + public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration, - boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, - Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, - OperationalVoter operationalVoter) { + boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, + Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, + OperationalVoter operationalVoter, AlonsoMoraTaskFactory alonsoMoraTaskFactory) { this.taskFactory = taskFactory; this.stopDuration = stopDuration; this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes; @@ -68,6 +70,7 @@ public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuratio this.travelTime = travelTime; this.router = router; this.operationalVoter = operationalVoter; + this.alonsoMoraTaskFactory = alonsoMoraTaskFactory; } /** @@ -258,7 +261,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration; if (expectedStartTime > currentTask.getEndTime()) { - currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); + currentTask = alonsoMoraTaskFactory.createWaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); schedule.addTask(currentTask); } } diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraTaskFactory.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraTaskFactory.java new file mode 100644 index 0000000..322bf6a --- /dev/null +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraTaskFactory.java @@ -0,0 +1,14 @@ +package org.matsim.alonso_mora.scheduling; + +import org.matsim.api.core.v01.network.Link; + +/** + * @author mga, nkuehnel / MOIA + */ +public class DefaultAlonsoMoraTaskFactory implements AlonsoMoraTaskFactory { + + @Override + public WaitForStopTask createWaitForStopTask(double beginTime, double endTime, Link link) { + return new WaitForStopTask(beginTime, endTime, link); + } +} diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java index df71d2d..e34450b 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java @@ -5,7 +5,9 @@ import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicleFactory; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.Constraint; import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler; +import org.matsim.alonso_mora.scheduling.AlonsoMoraTaskFactory; import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; +import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraTaskFactory; import org.matsim.alonso_mora.travel_time.TravelTimeEstimator; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; @@ -58,6 +60,8 @@ protected void configureQSim() { modalProvider((getter) -> new ShiftDrtOptimizer(getter.getModal(AlonsoMoraOptimizer.class), getter.getModal(DrtShiftDispatcher.class), getter.getModal(ScheduleTimingUpdater.class)))); + bindModal(AlonsoMoraTaskFactory.class).toInstance(new DefaultAlonsoMoraTaskFactory()); + bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> { StayTaskEndTimeCalculator endTimeCalculator = getter.getModal(StayTaskEndTimeCalculator.class); DrtTaskFactory taskFactory = getter.getModal(DrtTaskFactory.class); @@ -70,7 +74,7 @@ protected void configureQSim() { return new ShiftAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration, amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime, - network, endTimeCalculator, router, operationalVoter); + network, endTimeCalculator, router, operationalVoter, getter.getModal(AlonsoMoraTaskFactory.class)); })); } } 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 413eabd..6e453e8 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 @@ -6,6 +6,8 @@ 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.AlonsoMoraTaskFactory; +import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler; import org.matsim.alonso_mora.scheduling.WaitForStopTask; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; @@ -60,10 +62,12 @@ public class ShiftAlonsoMoraScheduler implements AlonsoMoraScheduler { private final StayTaskEndTimeCalculator endTimeCalculator; + private final AlonsoMoraTaskFactory alonsoMoraTaskFactory; + public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration, boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, - org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter) { + DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter, AlonsoMoraTaskFactory alonsoMoraTaskFactory) { this.taskFactory = taskFactory; this.stopDuration = stopDuration; this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes; @@ -72,6 +76,7 @@ public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration, this.travelTime = travelTime; this.router = router; this.operationalVoter = operationalVoter; + this.alonsoMoraTaskFactory = alonsoMoraTaskFactory; } /** @@ -262,7 +267,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration; if (expectedStartTime > currentTask.getEndTime()) { - currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); + currentTask = alonsoMoraTaskFactory.createWaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); schedule.addTask(currentTask); } } diff --git a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java index fd3e934..5b917a2 100644 --- a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java +++ b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java @@ -32,6 +32,7 @@ import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; import org.matsim.contrib.drt.extension.operations.operationFacilities.*; +import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeModule; import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeOptimizerQSimModule; import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDvrpFleetQsimModule; @@ -137,6 +138,12 @@ public void testRunAlonsoMoraWithShifts() { DrtOperationsParams operationsParams = (DrtOperationsParams) drtConfig.createParameterSet(DrtOperationsParams.SET_NAME); drtConfig.addParameterSet(operationsParams); + ShiftsParams shiftParams = new ShiftsParams(); + OperationFacilitiesParams operationFacilitiesParams = new OperationFacilitiesParams(); + + operationsParams.addParameterSet(shiftParams); + operationsParams.addParameterSet(operationFacilitiesParams); + // Load scenario Scenario scenario = ScenarioUtils.createScenario(config); scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class, @@ -212,6 +219,7 @@ public void testRunAlonsoMoraWithShifts() { for (DrtConfigGroup drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { controller.addOverridingModule(new ShiftDrtModeModule(drtCfg)); + controller.addOverridingQSimModule(new OperationFacilitiesQSimModule(drtCfg)); controller.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg))); controller.addOverridingQSimModule(new ShiftDvrpFleetQsimModule(drtCfg.getMode())); }