From 0730ed2eaf23c4bbf19820776594faaf25990427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Sat, 11 Nov 2023 01:19:12 +0100 Subject: [PATCH] factor out advanceRequestHorizon --- .../EDrtVehicleDataEntryFactory.java | 21 ++++++---------- .../extension/edrt/run/RunEDrtScenario.java | 2 +- .../run/ShiftEDrtModeOptimizerQSimModule.java | 2 +- .../run/ShiftDrtModeOptimizerQSimModule.java | 2 +- .../prebooking/PrebookingModule.java | 3 --- .../prebooking/PrebookingExampleIT.java | 4 +-- .../extension/prebooking/PrebookingTest.java | 1 - .../prebooking/PrebookingTestEnvironment.java | 1 - .../optimizer/DrtModeOptimizerQSimModule.java | 2 +- .../VehicleDataEntryFactoryImpl.java | 25 ------------------- .../contrib/drt/run/DrtConfigGroup.java | 3 --- .../contrib/taxi/run/MultiModeTaxiModule.java | 1 - .../drtAndPt/PtAlongALine2Test.java | 1 - 13 files changed, 12 insertions(+), 56 deletions(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java index 7174f562e15..f552fb3ecae 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java @@ -20,19 +20,18 @@ import java.util.List; -import org.matsim.contrib.drt.optimizer.VehicleEntry; +import org.matsim.contrib.drt.extension.edrt.schedule.EDrtChargingTask; import org.matsim.contrib.drt.optimizer.VehicleDataEntryFactoryImpl; -import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.contrib.drt.optimizer.VehicleEntry; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.Schedule.ScheduleStatus; import org.matsim.contrib.dvrp.schedule.Task; import org.matsim.contrib.dvrp.schedule.Task.TaskStatus; -import org.matsim.contrib.drt.extension.edrt.schedule.EDrtChargingTask; +import org.matsim.contrib.ev.fleet.Battery; import org.matsim.contrib.evrp.ETask; import org.matsim.contrib.evrp.EvDvrpVehicle; import org.matsim.contrib.evrp.tracker.ETaskTracker; -import org.matsim.contrib.ev.fleet.Battery; import com.google.inject.Provider; @@ -52,17 +51,13 @@ public EVehicleEntry(VehicleEntry entry, double socBeforeFinalStay) { private final double minimumRelativeSoc; private final VehicleDataEntryFactoryImpl entryFactory; - public EDrtVehicleDataEntryFactory(DrtConfigGroup drtCfg, double minimumRelativeSoc) { + public EDrtVehicleDataEntryFactory(double minimumRelativeSoc) { this.minimumRelativeSoc = minimumRelativeSoc; - entryFactory = new VehicleDataEntryFactoryImpl(drtCfg); + entryFactory = new VehicleDataEntryFactoryImpl(); } @Override public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { - if (entryFactory.isNotEligibleForRequestInsertion(vehicle, currentTime)) { - return null; - } - Schedule schedule = vehicle.getSchedule(); int taskCount = schedule.getTaskCount(); if (taskCount > 1) { @@ -100,17 +95,15 @@ public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { } public static class EDrtVehicleDataEntryFactoryProvider implements Provider { - private final DrtConfigGroup drtCfg; private final double minimumRelativeSoc; - public EDrtVehicleDataEntryFactoryProvider(DrtConfigGroup drtCfg, double minimumRelativeSoc) { - this.drtCfg = drtCfg; + public EDrtVehicleDataEntryFactoryProvider(double minimumRelativeSoc) { this.minimumRelativeSoc = minimumRelativeSoc; } @Override public EDrtVehicleDataEntryFactory get() { - return new EDrtVehicleDataEntryFactory(drtCfg, minimumRelativeSoc); + return new EDrtVehicleDataEntryFactory(minimumRelativeSoc); } } } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenario.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenario.java index 741a03e52b2..fb5c17674a8 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenario.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenario.java @@ -61,7 +61,7 @@ public static void run(Config config, boolean otfvis) { @Override public void install() { bind(EDrtVehicleDataEntryFactoryProvider.class).toInstance( - new EDrtVehicleDataEntryFactoryProvider(drtCfg, MIN_RELATIVE_SOC)); + new EDrtVehicleDataEntryFactoryProvider(MIN_RELATIVE_SOC)); } }); } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/run/ShiftEDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/run/ShiftEDrtModeOptimizerQSimModule.java index 4fc1aafaad1..b6ab4b5fd4e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/run/ShiftEDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/run/ShiftEDrtModeOptimizerQSimModule.java @@ -69,7 +69,7 @@ drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()), new EDrtAssignShiftToVehicleLogic(new DefaultAssignShiftToVehicleLogic(drtShiftParams), drtShiftParams)), getter.getModal(Fleet.class)))).asEagerSingleton(); - bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter -> new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(drtCfg, 0)))).asEagerSingleton(); + bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter -> new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0)))).asEagerSingleton(); final ShiftEDrtTaskFactoryImpl taskFactory = new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl()); bindModal(DrtTaskFactory.class).toInstance(taskFactory); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeOptimizerQSimModule.java index 1e3e8e1f485..7d4ddd747c2 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeOptimizerQSimModule.java @@ -131,7 +131,7 @@ shiftsParams, new DefaultShiftStartLogic(), new DefaultAssignShiftToVehicleLogic getter -> new ShiftInsertionCostCalculator(getter.get(MobsimTimer.class), new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class))))); - bindModal(VehicleEntry.EntryFactory.class).toInstance(new ShiftVehicleDataEntryFactory(new VehicleDataEntryFactoryImpl(drtCfg))); + bindModal(VehicleEntry.EntryFactory.class).toInstance(new ShiftVehicleDataEntryFactory(new VehicleDataEntryFactoryImpl())); final ShiftDrtTaskFactoryImpl taskFactory = new ShiftDrtTaskFactoryImpl(new DrtTaskFactoryImpl()); bindModal(DrtTaskFactory.class).toInstance(taskFactory); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/prebooking/PrebookingModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/prebooking/PrebookingModule.java index beaf14a6d97..fc48b2bb5f8 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/prebooking/PrebookingModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/prebooking/PrebookingModule.java @@ -35,9 +35,6 @@ public void install() { DrtWithExtensionsConfigGroup extensionsConfig = (DrtWithExtensionsConfigGroup) modeConfig; if (extensionsConfig.getDrtPrebookingParams().isPresent()) { - Verify.verify(modeConfig.advanceRequestPlanningHorizon == Double.POSITIVE_INFINITY, - "Prebooked modes should have advanceRequestPlanningHorizon set to Double.POSITIVE_INFINITY. The submission time to the optimizer will be managed by the prebooking logic."); - install(new PrebookingModeModule(modeConfig.getMode(), isElectric)); } } diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java index 931b8efd61b..5d1f58b7445 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java @@ -53,7 +53,6 @@ public void testDrtWithPrebooking() { for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { DrtWithExtensionsConfigGroup extensionsConfig = (DrtWithExtensionsConfigGroup) drtCfg; DrtPrebookingParams prebookingParams = new DrtPrebookingParams(); - extensionsConfig.advanceRequestPlanningHorizon = Double.POSITIVE_INFINITY; extensionsConfig.addParameterSet(prebookingParams); } @@ -95,13 +94,12 @@ public void testElectricDrtWithPrebooking() { @Override public void install() { bind(EDrtVehicleDataEntryFactoryProvider.class) - .toInstance(new EDrtVehicleDataEntryFactoryProvider(drtCfg, 0.2)); + .toInstance(new EDrtVehicleDataEntryFactoryProvider(0.2)); } }); DrtWithExtensionsConfigGroup extensionsConfig = (DrtWithExtensionsConfigGroup) drtCfg; DrtPrebookingParams prebookingParams = new DrtPrebookingParams(); - extensionsConfig.advanceRequestPlanningHorizon = Double.POSITIVE_INFINITY; extensionsConfig.addParameterSet(prebookingParams); } diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java index 21334a48049..b4e28043d74 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java @@ -52,7 +52,6 @@ private void installPrebooking(Controler controller) { DrtWithExtensionsConfigGroup drtConfig = (DrtWithExtensionsConfigGroup) MultiModeDrtConfigGroup .get(controller.getConfig()).getModalElements().stream().findFirst().get(); DrtPrebookingParams prebookingParams = new DrtPrebookingParams(); - drtConfig.advanceRequestPlanningHorizon = Double.POSITIVE_INFINITY; drtConfig.addParameterSet(prebookingParams); controller.addOverridingModule(new PrebookingModule()); AttributePrebookingLogic.install("drt", controller); diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTestEnvironment.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTestEnvironment.java index f136290c3c2..c6a39453015 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTestEnvironment.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTestEnvironment.java @@ -238,7 +238,6 @@ private void buildConfig(Config config) { modeConfig.stopDuration = stopDuration; modeConfig.idleVehiclesReturnToDepots = false; modeConfig.vehiclesFile = null; - modeConfig.advanceRequestPlanningHorizon = planningHorizon; DrtInsertionSearchParams searchParams = new SelectiveInsertionSearchParams(); modeConfig.addDrtInsertionSearchParams(searchParams); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtModeOptimizerQSimModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtModeOptimizerQSimModule.java index 026ff7dbd55..b74dcf2bf10 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtModeOptimizerQSimModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/DrtModeOptimizerQSimModule.java @@ -110,7 +110,7 @@ protected void configureQSim() { install(getInsertionSearchQSimModule(drtCfg)); - bindModal(VehicleEntry.EntryFactory.class).toInstance(new VehicleDataEntryFactoryImpl(drtCfg)); + bindModal(VehicleEntry.EntryFactory.class).toInstance(new VehicleDataEntryFactoryImpl()); bindModal(CostCalculationStrategy.class).to(drtCfg.rejectRequestIfMaxWaitOrTravelTimeViolated ? CostCalculationStrategy.RejectSoftConstraintViolations.class : diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImpl.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImpl.java index c687cd632db..663b480ff74 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImpl.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImpl.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; -import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.schedule.DrtStopTask; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.schedule.DriveTask; @@ -37,33 +36,13 @@ import org.matsim.contrib.dvrp.tracker.OnlineDriveTaskTracker; import org.matsim.contrib.dvrp.util.LinkTimePair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; /** * @author michalm */ public class VehicleDataEntryFactoryImpl implements VehicleEntry.EntryFactory { - private final double lookAhead; - - public VehicleDataEntryFactoryImpl(DrtConfigGroup drtCfg) { - if (drtCfg.rejectRequestIfMaxWaitOrTravelTimeViolated && drtCfg.advanceRequestPlanningHorizon == 0.0) { - lookAhead = drtCfg.maxWaitTime - drtCfg.stopDuration; - Preconditions.checkArgument(lookAhead >= 0, - "maxWaitTime must not be smaller than stopDuration"); - } else { - // if no rejection due to max wait time, the look ahead is infinite - // also if prebooking is used, because we may want to schedule prebooked - // requests to vehicles with service times starting in the future - lookAhead = Double.POSITIVE_INFINITY; - } - } - public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { - if (isNotEligibleForRequestInsertion(vehicle, currentTime)) { - return null; - } - Schedule schedule = vehicle.getSchedule(); final LinkTimePair start; final Task startTask; @@ -126,10 +105,6 @@ public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { ImmutableList.copyOf(stops), slackTimes, precedingStayTimes, currentTime); } - public boolean isNotEligibleForRequestInsertion(DvrpVehicle vehicle, double currentTime) { - return currentTime + lookAhead < vehicle.getServiceBeginTime() || currentTime >= vehicle.getServiceEndTime(); - } - static double[] computeSlackTimes(DvrpVehicle vehicle, double now, Waypoint.Stop[] stops, Waypoint.Stop start, List precedingStayTimes) { double[] slackTimes = new double[stops.length + 2]; diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java index c838bf0de74..6799262cfc8 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java @@ -191,9 +191,6 @@ public enum OperationalScheme { @Comment("Store planned unshared drt route as a link sequence") public boolean storeUnsharedPath = false; // If true, the planned unshared path is stored and exported in plans - @PositiveOrZero - public double advanceRequestPlanningHorizon = 0; // beta-feature; planning horizon for advance (prebooked) requests - @Parameter @Comment("When working with prebooked requests, defines whether vehicles drive immediately to the next" + "(prebooked) future task and wait for the planned stop to begin, or wait at the current" diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java index f371de6ed8e..31bf3440150 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/MultiModeTaxiModule.java @@ -81,7 +81,6 @@ public static DrtConfigGroup convertTaxiToDrtCfg(TaxiConfigGroup taxiCfg) { drtCfg.drtServiceAreaShapeFile = null; drtCfg.plotDetailedCustomerStats = taxiCfg.detailedStats || taxiCfg.timeProfiles; drtCfg.numberOfThreads = taxiCfg.numberOfThreads; - drtCfg.advanceRequestPlanningHorizon = 0; drtCfg.storeUnsharedPath = false; taxiCfg.getTaxiFareParams().ifPresent(taxiFareParams -> { diff --git a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java index ef0cc856096..f9daad794d9 100644 --- a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java +++ b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java @@ -235,7 +235,6 @@ public void testPtAlongALineWithRaptorAndDrtServiceArea() { drtConfigGroup.maxWaitTime = Double.MAX_VALUE; drtConfigGroup.rejectRequestIfMaxWaitOrTravelTimeViolated = false; drtConfigGroup.useModeFilteredSubnetwork = true; - drtConfigGroup.advanceRequestPlanningHorizon = 99999; drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); mm.addParameterSet(drtConfigGroup);