From a5c1f22fc96d9b1574d6d2ceac31faac7c961186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Sun, 25 Feb 2024 13:52:21 +0100 Subject: [PATCH] move dvrpMode to Task --- .../edrt/run/EDrtModeOptimizerQSimModule.java | 2 +- .../edrt/schedule/EDrtChargingTask.java | 4 ++-- .../edrt/schedule/EDrtDriveTask.java | 4 ++-- .../extension/edrt/schedule/EDrtStayTask.java | 4 ++-- .../extension/edrt/schedule/EDrtStopTask.java | 4 ++-- .../edrt/schedule/EDrtTaskFactoryImpl.java | 14 +++++++---- .../run/ShiftEDrtModeOptimizerQSimModule.java | 2 +- .../schedule/EDrtShiftBreakTaskImpl.java | 4 ++-- .../schedule/EDrtShiftChangeoverTaskImpl.java | 6 ++--- .../schedule/EDrtWaitForShiftStayTask.java | 4 ++-- .../schedule/ShiftEDrtTaskFactoryImpl.java | 24 ++++++++++--------- .../run/ShiftDrtModeOptimizerQSimModule.java | 2 +- .../shifts/schedule/ShiftBreakTaskImpl.java | 6 ++--- .../schedule/ShiftChangeoverTaskImpl.java | 6 ++--- .../schedule/ShiftDrtTaskFactoryImpl.java | 10 ++++---- .../shifts/schedule/WaitForShiftStayTask.java | 4 ++-- .../PreplannedDrtModeOptimizerQSimModule.java | 2 +- .../optimizer/PreplannedDrtOptimizer.java | 2 +- .../preplanned/optimizer/WaitForStopTask.java | 4 ++-- .../optimizer/DrtModeOptimizerQSimModule.java | 2 +- .../drt/schedule/DefaultDrtStopTask.java | 4 ++-- .../contrib/drt/schedule/DrtDriveTask.java | 4 ++-- .../contrib/drt/schedule/DrtStayTask.java | 4 ++-- .../drt/schedule/DrtTaskFactoryImpl.java | 12 +++++++--- .../VehicleDataEntryFactoryImplTest.java | 4 ++-- .../DefaultUnplannedRequestInserterTest.java | 4 ++-- .../InsertionDetourTimeCalculatorTest.java | 4 ++-- ...imeCalculatorWithVariableDurationTest.java | 4 ++-- .../insertion/InsertionGeneratorTest.java | 2 +- .../extensive/DetourPathDataCacheTest.java | 2 +- .../KNearestInsertionsAtEndFilterTest.java | 2 +- .../prebooking/ComplexUnschedulerTest.java | 2 +- .../examples/onetaxi/OneTaxiOptimizer.java | 12 +++++----- .../examples/onetaxi/OneTaxiServeTask.java | 4 ++-- .../examples/onetruck/OneTruckOptimizer.java | 8 +++---- .../examples/onetruck/OneTruckServeTask.java | 3 ++- .../contrib/dvrp/schedule/AbstractTask.java | 11 ++++++++- .../dvrp/schedule/DefaultDriveTask.java | 4 ++-- .../dvrp/schedule/DefaultStayTask.java | 4 ++-- .../matsim/contrib/dvrp/schedule/Task.java | 2 ++ .../contrib/dvrp/vrpagent/TaskEndedEvent.java | 4 ++-- .../dvrp/vrpagent/TaskStartedEvent.java | 4 ++-- .../contrib/dvrp/vrpagent/VrpAgentLogic.java | 8 +++---- .../contrib/dvrp/vrpagent/VrpAgentSource.java | 2 +- .../matsim/contrib/evrp/ChargingTaskImpl.java | 4 ++-- .../contrib/dvrp/router/DiversionTest.java | 4 ++-- .../dvrp/vrpagent/VrpAgentLogicTest.java | 18 +++++++------- .../contrib/etaxi/ETaxiChargingTask.java | 4 ++-- .../matsim/contrib/etaxi/ETaxiScheduler.java | 4 ++-- .../taxi/schedule/TaxiDropoffTask.java | 4 ++-- .../taxi/schedule/TaxiEmptyDriveTask.java | 4 ++-- .../taxi/schedule/TaxiOccupiedDriveTask.java | 4 ++-- .../contrib/taxi/schedule/TaxiPickupTask.java | 4 ++-- .../contrib/taxi/schedule/TaxiStayTask.java | 4 ++-- .../contrib/taxi/scheduler/TaxiScheduler.java | 19 ++++++++------- 55 files changed, 163 insertions(+), 134 deletions(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java index 71ee5abe1c1..2a21f5e761d 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java @@ -150,7 +150,7 @@ public EmptyVehicleChargingScheduler get() { CostCalculationStrategy.RejectSoftConstraintViolations.class : CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton(); - bindModal(DrtTaskFactory.class).toInstance(new EDrtTaskFactoryImpl()); + bindModal(DrtTaskFactory.class).toInstance(new EDrtTaskFactoryImpl(drtCfg.getMode())); bindModal(EmptyVehicleRelocator.class).toProvider( new ModalProviders.AbstractProvider<>(drtCfg.getMode(), DvrpModes::mode) { diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtChargingTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtChargingTask.java index e2dcfdba751..8d0a137ecd2 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtChargingTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtChargingTask.java @@ -27,7 +27,7 @@ public class EDrtChargingTask extends ChargingTaskImpl { public static final DrtTaskType TYPE = new DrtTaskType("CHARGING"); - public EDrtChargingTask(double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) { - super(TYPE, beginTime, endTime, charger, ev, totalEnergy); + public EDrtChargingTask(String dvrpMode, double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) { + super(dvrpMode, TYPE, beginTime, endTime, charger, ev, totalEnergy); } } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtDriveTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtDriveTask.java index f5336f8e8c0..c4774f399a9 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtDriveTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtDriveTask.java @@ -30,8 +30,8 @@ public class EDrtDriveTask extends DrtDriveTask implements ETask { private final double consumedEnergy; - public EDrtDriveTask(VrpPathWithTravelData path, DrtTaskType taskType, double consumedEnergy) { - super(path, taskType); + public EDrtDriveTask(String dvrpMode, VrpPathWithTravelData path, DrtTaskType taskType, double consumedEnergy) { + super(dvrpMode, path, taskType); this.consumedEnergy = consumedEnergy; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStayTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStayTask.java index c596a0ee2d7..a8c4823133f 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStayTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStayTask.java @@ -29,8 +29,8 @@ public class EDrtStayTask extends DrtStayTask implements ETask { private final double consumedEnergy; - public EDrtStayTask(double beginTime, double endTime, Link link, double consumedEnergy) { - super(beginTime, endTime, link); + public EDrtStayTask(String dvrpMode, double beginTime, double endTime, Link link, double consumedEnergy) { + super(dvrpMode, beginTime, endTime, link); this.consumedEnergy = consumedEnergy; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStopTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStopTask.java index f86da043c05..0a5151cbcdd 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStopTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtStopTask.java @@ -29,8 +29,8 @@ public class EDrtStopTask extends DefaultDrtStopTask implements ETask { private final double consumedEnergy; - public EDrtStopTask(double beginTime, double endTime, Link link, double consumedEnergy) { - super(beginTime, endTime, link); + public EDrtStopTask(String dvrpMode, double beginTime, double endTime, Link link, double consumedEnergy) { + super(dvrpMode, beginTime, endTime, link); this.consumedEnergy = consumedEnergy; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtTaskFactoryImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtTaskFactoryImpl.java index 4ec83dc7a15..82fc5a79314 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtTaskFactoryImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/schedule/EDrtTaskFactoryImpl.java @@ -33,11 +33,17 @@ * @author michalm */ public class EDrtTaskFactoryImpl implements DrtTaskFactory { + private final String dvrpMode; + + public EDrtTaskFactoryImpl(String dvrpMode) { + this.dvrpMode = dvrpMode; + } + @Override public EDrtDriveTask createDriveTask(DvrpVehicle vehicle, VrpPathWithTravelData path, DrtTaskType taskType) { ElectricVehicle ev = ((EvDvrpVehicle)vehicle).getElectricVehicle(); double totalEnergy = VrpPathEnergyConsumptions.calcTotalEnergy(ev, path, path.getDepartureTime()); - return new EDrtDriveTask(path, taskType, totalEnergy); + return new EDrtDriveTask(dvrpMode, path, taskType, totalEnergy); } @Override @@ -45,12 +51,12 @@ public EDrtStopTask createStopTask(DvrpVehicle vehicle, double beginTime, double ElectricVehicle ev = ((EvDvrpVehicle)vehicle).getElectricVehicle(); double auxEnergy = ev.getAuxEnergyConsumption() .calcEnergyConsumption(beginTime, endTime - beginTime, link.getId()); - return new EDrtStopTask(beginTime, endTime, link, auxEnergy); + return new EDrtStopTask(dvrpMode, beginTime, endTime, link, auxEnergy); } @Override public EDrtStayTask createStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) { - return new EDrtStayTask(beginTime, endTime, link, 0);// no energy consumption during STAY + return new EDrtStayTask(dvrpMode, beginTime, endTime, link, 0);// no energy consumption during STAY } @Override @@ -60,7 +66,7 @@ public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime, public EDrtChargingTask createChargingTask(DvrpVehicle vehicle, double beginTime, double endTime, Charger charger, double totalEnergy) { - return new EDrtChargingTask(beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), + return new EDrtChargingTask(dvrpMode, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); } } 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 fdc06e3cb8b..0269c992a77 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 @@ -77,7 +77,7 @@ drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()), bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter -> new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0)))).asEagerSingleton(); - bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))).in(Singleton.class); + bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(drtCfg.getMode(), new EDrtTaskFactoryImpl(drtCfg.getMode()), getter.getModal(OperationFacilities.class)))).in(Singleton.class); bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class)))); bindModal(ShiftTaskScheduler.class).toProvider(modalProvider( diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftBreakTaskImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftBreakTaskImpl.java index c471b3cdde0..466797cdb46 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftBreakTaskImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftBreakTaskImpl.java @@ -16,9 +16,9 @@ public class EDrtShiftBreakTaskImpl extends ShiftBreakTaskImpl implements ShiftB private final double consumedEnergy; private final ChargingTask chargingTask; - public EDrtShiftBreakTaskImpl(double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, + public EDrtShiftBreakTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, double consumedEnergy, ChargingTask chargingTask, OperationFacility facility) { - super(beginTime, endTime, link, shiftBreak, facility); + super(dvrpMode, beginTime, endTime, link, shiftBreak, facility); this.consumedEnergy = consumedEnergy; this.chargingTask = chargingTask; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftChangeoverTaskImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftChangeoverTaskImpl.java index 007a9f2fe3f..52d4086be06 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftChangeoverTaskImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtShiftChangeoverTaskImpl.java @@ -33,11 +33,11 @@ public class EDrtShiftChangeoverTaskImpl extends DefaultStayTask implements Shif private final DrtStopTask delegate; - public EDrtShiftChangeoverTaskImpl(double beginTime, double endTime, Link link, + public EDrtShiftChangeoverTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShift shift, double consumedEnergy, ChargingTask chargingTask, OperationFacility facility) { - super(TYPE, beginTime, endTime, link); - this.delegate = new DefaultDrtStopTask(beginTime, endTime, link); + super(dvrpMode, TYPE, beginTime, endTime, link); + this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link); this.shift = shift; this.consumedEnergy = consumedEnergy; this.chargingTask = chargingTask; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtWaitForShiftStayTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtWaitForShiftStayTask.java index c60e0214f1d..bd122b968ca 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtWaitForShiftStayTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/EDrtWaitForShiftStayTask.java @@ -15,10 +15,10 @@ public class EDrtWaitForShiftStayTask extends WaitForShiftStayTask implements ET private final ChargingTask chargingTask; - public EDrtWaitForShiftStayTask(double beginTime, double endTime, Link link, + public EDrtWaitForShiftStayTask(String dvrpMode, double beginTime, double endTime, Link link, double consumedEnergy, OperationFacility facility, ChargingTask chargingTask) { - super(beginTime, endTime, link, facility); + super(dvrpMode, beginTime, endTime, link, facility); this.consumedEnergy = consumedEnergy; this.chargingTask = chargingTask; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/ShiftEDrtTaskFactoryImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/ShiftEDrtTaskFactoryImpl.java index 5e0c085c1bb..b60b66319d1 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/ShiftEDrtTaskFactoryImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/eshifts/schedule/ShiftEDrtTaskFactoryImpl.java @@ -35,12 +35,14 @@ */ public class ShiftEDrtTaskFactoryImpl implements ShiftDrtTaskFactory { + private final String dvrpMode; private final EDrtTaskFactoryImpl delegate; private final OperationFacilities operationFacilities; - public ShiftEDrtTaskFactoryImpl(EDrtTaskFactoryImpl delegate, OperationFacilities operationFacilities) { - this.delegate = delegate; + public ShiftEDrtTaskFactoryImpl(String dvrpMode, EDrtTaskFactoryImpl delegate, OperationFacilities operationFacilities) { + this.dvrpMode = dvrpMode; + this.delegate = delegate; this.operationFacilities = operationFacilities; } @@ -82,38 +84,38 @@ public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime, @Override public ShiftBreakTask createShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) { - return new EDrtShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, 0, null, facility); + return new EDrtShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, 0, null, facility); } @Override public ShiftChangeOverTask createShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) { - return new EDrtShiftChangeoverTaskImpl(beginTime, endTime, link, shift, 0, null, facility); + return new EDrtShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, 0, null, facility); } @Override public WaitForShiftStayTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, OperationFacility facility) { - return new EDrtWaitForShiftStayTask(beginTime, endTime, link, 0, facility, null); + return new EDrtWaitForShiftStayTask(dvrpMode, beginTime, endTime, link, 0, facility, null); } public WaitForShiftStayTask createChargingWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, OperationFacility facility, double totalEnergy, Charger charger) { - ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); - return new EDrtWaitForShiftStayTask(beginTime, endTime, link, totalEnergy, facility, chargingTask); + ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); + return new EDrtWaitForShiftStayTask(dvrpMode, beginTime, endTime, link, totalEnergy, facility, chargingTask); } public EDrtShiftBreakTaskImpl createChargingShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, Charger charger, double totalEnergy, OperationFacility facility) { - ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); - return new EDrtShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, totalEnergy, chargingTask, facility); + ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); + return new EDrtShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, totalEnergy, chargingTask, facility); } public ShiftChangeOverTask createChargingShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, Charger charger, double totalEnergy, DrtShift shift, OperationFacility facility) { - ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); - return new EDrtShiftChangeoverTaskImpl(beginTime, endTime, link, shift, totalEnergy, chargingTask, facility); + ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy); + return new EDrtShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, totalEnergy, chargingTask, facility); } } 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 e7f4f58b391..eb39ebcbbba 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 @@ -125,7 +125,7 @@ shiftsParams, new DefaultShiftStartLogic(), new DefaultAssignShiftToVehicleLogic bindModal(VehicleEntry.EntryFactory.class).toInstance(new ShiftVehicleDataEntryFactory(new VehicleDataEntryFactoryImpl())); - bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftDrtTaskFactoryImpl(new DrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))); + bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftDrtTaskFactoryImpl(drtCfg.getMode(), new DrtTaskFactoryImpl(drtCfg.getMode()), getter.getModal(OperationFacilities.class)))); bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class)))); bindModal(ShiftTaskScheduler.class).toProvider(modalProvider( diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftBreakTaskImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftBreakTaskImpl.java index b718954da1b..e00dc903583 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftBreakTaskImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftBreakTaskImpl.java @@ -27,9 +27,9 @@ public class ShiftBreakTaskImpl extends DefaultStayTask implements ShiftBreakTas private final DrtStopTask delegate; - public ShiftBreakTaskImpl(double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) { - super(TYPE, beginTime, endTime, link); - this.delegate = new DefaultDrtStopTask(beginTime, endTime, link); + public ShiftBreakTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) { + super(dvrpMode, TYPE, beginTime, endTime, link); + this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link); this.shiftBreak = shiftBreak; this.facility = facility; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftChangeoverTaskImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftChangeoverTaskImpl.java index 0af9ed0b7bf..3a8de865504 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftChangeoverTaskImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftChangeoverTaskImpl.java @@ -28,9 +28,9 @@ public class ShiftChangeoverTaskImpl extends DefaultStayTask implements ShiftCha private final DrtStopTask delegate; - public ShiftChangeoverTaskImpl(double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) { - super(TYPE, beginTime, endTime, link); - this.delegate = new DefaultDrtStopTask(beginTime, endTime, link); + public ShiftChangeoverTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) { + super(dvrpMode, TYPE, beginTime, endTime, link); + this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link); this.shift = shift; this.facility = facility; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftDrtTaskFactoryImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftDrtTaskFactoryImpl.java index 57460d2bee6..4bd937a3a14 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftDrtTaskFactoryImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/ShiftDrtTaskFactoryImpl.java @@ -22,10 +22,12 @@ */ public class ShiftDrtTaskFactoryImpl implements ShiftDrtTaskFactory { + private final String dvrpMode; private final DrtTaskFactory delegate; private final OperationFacilities operationFacilities; - public ShiftDrtTaskFactoryImpl(DrtTaskFactory delegate, OperationFacilities operationFacilities) { + public ShiftDrtTaskFactoryImpl(String dvrpMode, DrtTaskFactory delegate, OperationFacilities operationFacilities) { + this.dvrpMode = dvrpMode; this.delegate = delegate; this.operationFacilities = operationFacilities; } @@ -48,19 +50,19 @@ public DrtStayTask createStayTask(DvrpVehicle vehicle, double beginTime, double @Override public ShiftBreakTask createShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) { - return new ShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, facility); + return new ShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, facility); } @Override public ShiftChangeOverTask createShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) { - return new ShiftChangeoverTaskImpl(beginTime, endTime, link, shift, facility); + return new ShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, facility); } @Override public WaitForShiftStayTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link, OperationFacility facility) { - return new WaitForShiftStayTask(beginTime, endTime, link, facility); + return new WaitForShiftStayTask(dvrpMode, beginTime, endTime, link, facility); } public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) { diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/WaitForShiftStayTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/WaitForShiftStayTask.java index 25556e16db7..24bd7e68135 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/WaitForShiftStayTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/schedule/WaitForShiftStayTask.java @@ -16,8 +16,8 @@ public class WaitForShiftStayTask extends DefaultStayTask implements Operational private final OperationFacility facility; - public WaitForShiftStayTask(double beginTime, double endTime, Link link, OperationFacility facility) { - super(TYPE, beginTime, endTime, link); + public WaitForShiftStayTask(String dvrpMode, double beginTime, double endTime, Link link, OperationFacility facility) { + super(dvrpMode, TYPE, beginTime, endTime, link); this.facility = facility; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtModeOptimizerQSimModule.java index d5b560d31fc..8aeb3bb6549 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtModeOptimizerQSimModule.java @@ -65,7 +65,7 @@ protected void configureQSim() { getter.getModal(DrtTaskFactory.class), getter.get(EventsManager.class), getter.getModal(Fleet.class), getter.getModal(ScheduleTimingUpdater.class)))); - bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl()); + bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl(drtCfg.getMode())); bindModal(VrpLegFactory.class).toProvider(modalProvider(getter -> { DvrpConfigGroup dvrpCfg = getter.get(DvrpConfigGroup.class); 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..93c17272ce6 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 @@ -170,7 +170,7 @@ public void nextTask(DvrpVehicle vehicle) { // otherwise we may not be able to get the request and insert it to the stop task // TODO currently assuming the mobsim time step is 1 s schedule.addTask( - new WaitForStopTask(currentTime, nextStop.preplannedRequest.earliestStartTime + 1, currentLink)); + new WaitForStopTask(mode, currentTime, nextStop.preplannedRequest.earliestStartTime + 1, currentLink)); } else { nonVisitedPreplannedStops.poll();//remove this stop from queue diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/WaitForStopTask.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/WaitForStopTask.java index 3ade5a8687c..8d2e89fb1cb 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/WaitForStopTask.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/WaitForStopTask.java @@ -33,7 +33,7 @@ public class WaitForStopTask extends DefaultStayTask { public static final DrtTaskType TYPE = new DrtTaskType("WAIT_FOR_STOP", STAY); - public WaitForStopTask(double beginTime, double endTime, Link link) { - super(TYPE, beginTime, endTime, link); + public WaitForStopTask(String dvrpMode, double beginTime, double endTime, Link link) { + super(dvrpMode, TYPE, beginTime, endTime, link); } } 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 8534468ce81..7dfe22b1790 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 @@ -119,7 +119,7 @@ protected void configureQSim() { CostCalculationStrategy.RejectSoftConstraintViolations.class : CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton(); - bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl()); + bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl(drtCfg.getMode())); bindModal(EmptyVehicleRelocator.class).toProvider( new ModalProviders.AbstractProvider<>(drtCfg.getMode(), DvrpModes::mode) { diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DefaultDrtStopTask.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DefaultDrtStopTask.java index 6efeb3fff96..33704e766f4 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DefaultDrtStopTask.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DefaultDrtStopTask.java @@ -46,8 +46,8 @@ public class DefaultDrtStopTask extends DefaultStayTask implements DrtStopTask { private final Map, AcceptedDrtRequest> dropoffRequests = new LinkedHashMap<>(); private final Map, AcceptedDrtRequest> pickupRequests = new LinkedHashMap<>(); - public DefaultDrtStopTask(double beginTime, double endTime, Link link) { - super(TYPE, beginTime, endTime, link); + public DefaultDrtStopTask(String dvrpMode, double beginTime, double endTime, Link link) { + super(dvrpMode, TYPE, beginTime, endTime, link); } /** diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtDriveTask.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtDriveTask.java index c3af3fb22db..3881076329a 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtDriveTask.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtDriveTask.java @@ -30,7 +30,7 @@ public class DrtDriveTask extends DefaultDriveTask { public static final DrtTaskType TYPE = new DrtTaskType(DRIVE); - public DrtDriveTask(VrpPathWithTravelData path, DrtTaskType taskType) { - super(taskType, path); + public DrtDriveTask(String dvrpMode, VrpPathWithTravelData path, DrtTaskType taskType) { + super(dvrpMode, taskType, path); } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtStayTask.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtStayTask.java index bef0ce14e8a..035734456ff 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtStayTask.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtStayTask.java @@ -30,7 +30,7 @@ public class DrtStayTask extends DefaultStayTask { public static final DrtTaskType TYPE = new DrtTaskType(STAY); - public DrtStayTask(double beginTime, double endTime, Link link) { - super(TYPE, beginTime, endTime, link); + public DrtStayTask(String dvrpMode, double beginTime, double endTime, Link link) { + super(dvrpMode, TYPE, beginTime, endTime, link); } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtTaskFactoryImpl.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtTaskFactoryImpl.java index de227a74da4..3a824f815cd 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtTaskFactoryImpl.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/schedule/DrtTaskFactoryImpl.java @@ -27,19 +27,25 @@ * @author michalm */ public class DrtTaskFactoryImpl implements DrtTaskFactory { + private final String dvrpMode; + + public DrtTaskFactoryImpl(String dvrpMode) { + this.dvrpMode = dvrpMode; + } + @Override public DrtDriveTask createDriveTask(DvrpVehicle vehicle, VrpPathWithTravelData path, DrtTaskType taskType) { - return new DrtDriveTask(path, taskType); + return new DrtDriveTask(dvrpMode, path, taskType); } @Override public DrtStopTask createStopTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) { - return new DefaultDrtStopTask(beginTime, endTime, link); + return new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link); } @Override public DrtStayTask createStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) { - return new DrtStayTask(beginTime, endTime, link); + return new DrtStayTask(dvrpMode, beginTime, endTime, link); } @Override diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImplTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImplTest.java index e74e3334a71..4adb154319f 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImplTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/VehicleDataEntryFactoryImplTest.java @@ -124,7 +124,7 @@ void computeSlackTimes_withPrecedingStayTimes() { } private Stop stop(double beginTime, double latestArrivalTime, double endTime, double latestDepartureTime) { - return new Stop(new DefaultDrtStopTask(beginTime, endTime, null), latestArrivalTime, latestDepartureTime, 0); + return new Stop(new DefaultDrtStopTask("drt", beginTime, endTime, null), latestArrivalTime, latestDepartureTime, 0); } private DvrpVehicle vehicle(double vehicleEndTime, double lastStayTaskBeginTime) { @@ -137,7 +137,7 @@ private DvrpVehicle vehicle(double vehicleEndTime, double lastStayTaskBeginTime) .build(), depot); vehicle.getSchedule() .addTask( - new DrtStayTask(lastStayTaskBeginTime, Math.max(lastStayTaskBeginTime, vehicleEndTime), depot)); + new DrtStayTask("drt", lastStayTaskBeginTime, Math.max(lastStayTaskBeginTime, vehicleEndTime), depot)); return vehicle; } } diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DefaultUnplannedRequestInserterTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DefaultUnplannedRequestInserterTest.java index 58637acaddc..13c1a473063 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DefaultUnplannedRequestInserterTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/DefaultUnplannedRequestInserterTest.java @@ -224,9 +224,9 @@ void acceptedRequest() { double pickupEndTime = now + 20; double dropoffBeginTime = now + 40; RequestInsertionScheduler insertionScheduler = (request, insertion) -> { - var pickupTask = new DefaultDrtStopTask(pickupEndTime - 10, pickupEndTime, request1.getFromLink()); + var pickupTask = new DefaultDrtStopTask("drt", pickupEndTime - 10, pickupEndTime, request1.getFromLink()); pickupTask.addPickupRequest(acceptedDrtRequest1); - var dropoffTask = new DefaultDrtStopTask(dropoffBeginTime, dropoffBeginTime + 10, request1.getToLink()); + var dropoffTask = new DefaultDrtStopTask("drt", dropoffBeginTime, dropoffBeginTime + 10, request1.getToLink()); dropoffTask.addPickupRequest(acceptedDrtRequest1); return new PickupDropoffTaskPair(pickupTask, dropoffTask); }; diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorTest.java index 756682854b0..71c6606c1e4 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorTest.java @@ -76,7 +76,7 @@ void detourTimeLoss_start_pickup_dropoff() { void detourTimeLoss_ongoingStopAsStart_pickup_dropoff() { //similar to detourTmeLoss_start_pickup_dropoff(), but the pickup is appended to the ongoing STOP task // sh 03/08/23: Changed this test, according to VehicleDataEntryFactoryImpl the start time should be end time of stop task - Waypoint.Start start = start(new DefaultDrtStopTask(20, 20 + STOP_DURATION, fromLink), 20 + STOP_DURATION, fromLink); + Waypoint.Start start = start(new DefaultDrtStopTask("drt", 20, 20 + STOP_DURATION, fromLink), 20 + STOP_DURATION, fromLink); VehicleEntry entry = entry(start); var detour = detourData(0., 15., Double.NaN, 0.);//toPickup/Dropoff unused var insertion = insertion(entry, 0, 0, detour); @@ -229,7 +229,7 @@ private Waypoint.Start start(Task task, double time, Link link) { } private Waypoint.Stop stop(double beginTime, Link link) { - return new Waypoint.Stop(new DefaultDrtStopTask(beginTime, beginTime + STOP_DURATION, link), 0); + return new Waypoint.Stop(new DefaultDrtStopTask("drt", beginTime, beginTime + STOP_DURATION, link), 0); } private VehicleEntry entry(Waypoint.Start start, Waypoint.Stop... stops) { diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorWithVariableDurationTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorWithVariableDurationTest.java index fcfa03962bd..3e6f78ec02a 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorWithVariableDurationTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionDetourTimeCalculatorWithVariableDurationTest.java @@ -110,7 +110,7 @@ void detourTimeLoss_start_pickup_dropoff() { @Test void detourTimeLoss_ongoingStopAsStart_pickup_dropoff() { //similar to detourTmeLoss_start_pickup_dropoff(), but the pickup is appended to the ongoing STOP task - DrtStopTask stopTask = new DefaultDrtStopTask(20, 20 + STOP_DURATION_INITIAL, fromLink); + DrtStopTask stopTask = new DefaultDrtStopTask("drt", 20, 20 + STOP_DURATION_INITIAL, fromLink); stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequestInitial)); // sh 03/08/23: Updated this test, according to VehicleDataEntryFactoryImpl start time should be task end time Waypoint.Start start = start(stopTask, 20 + STOP_DURATION_INITIAL, fromLink); @@ -269,7 +269,7 @@ private Waypoint.Start start(Task task, double time, Link link) { } private Waypoint.Stop stop(double beginTime, Link link) { - DrtStopTask stopTask = new DefaultDrtStopTask(beginTime, beginTime + STOP_DURATION_INITIAL, link); + DrtStopTask stopTask = new DefaultDrtStopTask("drt", beginTime, beginTime + STOP_DURATION_INITIAL, link); stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequestInitial)); return new Waypoint.Stop(stopTask, 0); } diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionGeneratorTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionGeneratorTest.java index 6ffde35326c..8e0947f2d99 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionGeneratorTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/InsertionGeneratorTest.java @@ -521,7 +521,7 @@ private void assertInsertionsOnly(DrtRequest drtRequest, VehicleEntry entry, Ins } private Waypoint.Stop stop(double beginTime, Link link, int outgoingOccupancy) { - return new Waypoint.Stop(new DefaultDrtStopTask(beginTime, beginTime + STOP_DURATION, link), outgoingOccupancy); + return new Waypoint.Stop(new DefaultDrtStopTask("drt", beginTime, beginTime + STOP_DURATION, link), outgoingOccupancy); } private VehicleEntry entry(Waypoint.Start start, Waypoint.Stop... stops) { diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/DetourPathDataCacheTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/DetourPathDataCacheTest.java index fcc8928de9c..e4a5bdefc76 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/DetourPathDataCacheTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/DetourPathDataCacheTest.java @@ -135,6 +135,6 @@ private VehicleEntry entry(Link startLink, Link... stopLinks) { } private Waypoint.Stop stop(Link link) { - return new Waypoint.Stop(new DefaultDrtStopTask(0, 60, link), 0); + return new Waypoint.Stop(new DefaultDrtStopTask("drt", 0, 60, link), 0); } } diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/KNearestInsertionsAtEndFilterTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/KNearestInsertionsAtEndFilterTest.java index 02a92a9588b..ab78599a108 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/KNearestInsertionsAtEndFilterTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/insertion/extensive/KNearestInsertionsAtEndFilterTest.java @@ -117,7 +117,7 @@ private Waypoint.Start start(double endTime) { } private Waypoint.Stop stop(double endTime) { - return new Waypoint.Stop(new DefaultDrtStopTask(endTime - 10, endTime, null), 0); + return new Waypoint.Stop(new DefaultDrtStopTask("drt", endTime - 10, endTime, null), 0); } private VehicleEntry vehicleEntry(String id, Waypoint.Start start, Waypoint.Stop... stops) { diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java index 93a59a769bd..0667d707211 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/prebooking/ComplexUnschedulerTest.java @@ -591,7 +591,7 @@ private class Fixture { private Link currentLink; private double currentTime; - private final DrtTaskFactory taskFactory = new DrtTaskFactoryImpl(); + private final DrtTaskFactory taskFactory = new DrtTaskFactoryImpl("drt"); private final LeastCostPathCalculator router; private final TravelTime travelTime = new FreeSpeedTravelTime(); diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiOptimizer.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiOptimizer.java index ee5f38811fe..3e0007130c6 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiOptimizer.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiOptimizer.java @@ -79,7 +79,7 @@ public OneTaxiOptimizer(EventsManager eventsManager, @DvrpMode(TransportMode.tax vehicle = fleet.getVehicles().values().iterator().next(); vehicle.getSchedule() - .addTask(new DefaultStayTask(OneTaxiTaskType.WAIT, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), + .addTask(new DefaultStayTask(TransportMode.taxi, OneTaxiTaskType.WAIT, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), vehicle.getStartLink())); } @@ -114,22 +114,22 @@ public void requestSubmitted(Request request) { VrpPathWithTravelData pathToCustomer = VrpPaths.calcAndCreatePath(lastTask.getLink(), fromLink, t0, router, travelTime); - schedule.addTask(new DefaultDriveTask(OneTaxiTaskType.EMPTY_DRIVE, pathToCustomer)); + schedule.addTask(new DefaultDriveTask(TransportMode.taxi, OneTaxiTaskType.EMPTY_DRIVE, pathToCustomer)); double t1 = pathToCustomer.getArrivalTime(); double t2 = t1 + PICKUP_DURATION;// 2 minutes for picking up the passenger - schedule.addTask(new OneTaxiServeTask(OneTaxiTaskType.PICKUP, t1, t2, fromLink, req)); + schedule.addTask(new OneTaxiServeTask(TransportMode.taxi, OneTaxiTaskType.PICKUP, t1, t2, fromLink, req)); VrpPathWithTravelData pathWithCustomer = VrpPaths.calcAndCreatePath(fromLink, toLink, t2, router, travelTime); - schedule.addTask(new DefaultDriveTask(OneTaxiTaskType.OCCUPIED_DRIVE, pathWithCustomer)); + schedule.addTask(new DefaultDriveTask(TransportMode.taxi, OneTaxiTaskType.OCCUPIED_DRIVE, pathWithCustomer)); double t3 = pathWithCustomer.getArrivalTime(); double t4 = t3 + DROPOFF_DURATION;// 1 minute for dropping off the passenger - schedule.addTask(new OneTaxiServeTask(OneTaxiTaskType.DROPOFF, t3, t4, toLink, req)); + schedule.addTask(new OneTaxiServeTask(TransportMode.taxi, OneTaxiTaskType.DROPOFF, t3, t4, toLink, req)); // just wait (and be ready) till the end of the vehicle's time window (T1) double tEnd = Math.max(t4, vehicle.getServiceEndTime()); - schedule.addTask(new DefaultStayTask(OneTaxiTaskType.WAIT, t4, tEnd, toLink)); + schedule.addTask(new DefaultStayTask(TransportMode.taxi, OneTaxiTaskType.WAIT, t4, tEnd, toLink)); eventsManager.processEvent( new PassengerRequestScheduledEvent(timer.getTimeOfDay(), TransportMode.taxi, request.getId(), diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiServeTask.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiServeTask.java index f4e58ba103f..82fad83da4f 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiServeTask.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetaxi/OneTaxiServeTask.java @@ -30,9 +30,9 @@ public class OneTaxiServeTask extends DefaultStayTask { private final OneTaxiRequest request; - public OneTaxiServeTask(OneTaxiTaskType taskType, double beginTime, double endTime, Link link, + public OneTaxiServeTask(String dvrpMode, OneTaxiTaskType taskType, double beginTime, double endTime, Link link, OneTaxiRequest request) { - super(taskType, beginTime, endTime, link); + super(dvrpMode, taskType, beginTime, endTime, link); this.request = request; } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckOptimizer.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckOptimizer.java index ffc9641123b..538201cc02c 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckOptimizer.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckOptimizer.java @@ -75,7 +75,7 @@ public OneTruckOptimizer(@DvrpMode(TransportMode.truck) Network network, @DvrpMo vehicle = fleet.getVehicles().values().iterator().next(); vehicle.getSchedule() - .addTask(new DefaultStayTask(OneTruckTaskType.WAIT, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), + .addTask(new DefaultStayTask(TransportMode.truck, OneTruckTaskType.WAIT, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), vehicle.getStartLink())); } @@ -109,14 +109,14 @@ public void requestSubmitted(Request request) { VrpPathWithTravelData pathToCustomer = VrpPaths.calcAndCreatePath(lastTask.getLink(), fromLink, t0, router, travelTime); - schedule.addTask(new DefaultDriveTask(OneTruckTaskType.EMPTY_DRIVE, pathToCustomer)); + schedule.addTask(new DefaultDriveTask(TransportMode.truck, OneTruckTaskType.EMPTY_DRIVE, pathToCustomer)); double t1 = pathToCustomer.getArrivalTime(); double t2 = t1 + PICKUP_DURATION;// 2 minutes for the pickup schedule.addTask(new OneTruckServeTask(OneTruckTaskType.PICKUP, t1, t2, fromLink, req)); VrpPathWithTravelData pathWithCustomer = VrpPaths.calcAndCreatePath(fromLink, toLink, t2, router, travelTime); - schedule.addTask(new DefaultDriveTask(OneTruckTaskType.LOADED_DRIVE, pathWithCustomer)); + schedule.addTask(new DefaultDriveTask(TransportMode.truck, OneTruckTaskType.LOADED_DRIVE, pathWithCustomer)); double t3 = pathWithCustomer.getArrivalTime(); double t4 = t3 + DELIVERY_DURATION;// 1 minute for the delivery @@ -124,7 +124,7 @@ public void requestSubmitted(Request request) { // just wait (and be ready) till the end of the vehicle's time window (T1) double tEnd = Math.max(t4, vehicle.getServiceEndTime()); - schedule.addTask(new DefaultStayTask(OneTruckTaskType.WAIT, t4, tEnd, toLink)); + schedule.addTask(new DefaultStayTask(TransportMode.truck, OneTruckTaskType.WAIT, t4, tEnd, toLink)); } @Override diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckServeTask.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckServeTask.java index 5b7c5c00591..ba1710c120f 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckServeTask.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/examples/onetruck/OneTruckServeTask.java @@ -21,6 +21,7 @@ import static org.matsim.contrib.dvrp.examples.onetruck.OneTruckOptimizer.OneTruckTaskType; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.dvrp.schedule.DefaultStayTask; @@ -32,7 +33,7 @@ public class OneTruckServeTask extends DefaultStayTask { public OneTruckServeTask(OneTruckTaskType taskType, double beginTime, double endTime, Link link, OneTruckRequest request) { - super(taskType, beginTime, endTime, link); + super(TransportMode.truck, taskType, beginTime, endTime, link); this.request = request; } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/AbstractTask.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/AbstractTask.java index 1aaa550937e..cf6c68c31ac 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/AbstractTask.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/AbstractTask.java @@ -39,9 +39,12 @@ public abstract class AbstractTask implements Task { private double endTime; private TaskTracker taskTracker; + + private final String dvrpMode; - AbstractTask(TaskType taskType, double beginTime, double endTime) { + AbstractTask(String dvrpMode, TaskType taskType, double beginTime, double endTime) { Preconditions.checkArgument(beginTime <= endTime, "beginTime=%s; endTime=%s", beginTime, endTime); + this.dvrpMode = dvrpMode; this.taskType = Preconditions.checkNotNull(taskType); this.beginTime = beginTime; this.endTime = endTime; @@ -97,10 +100,16 @@ public final void initTaskTracker(TaskTracker taskTracker) { Preconditions.checkState(status == TaskStatus.STARTED, "Allowed only for STARTED tasks"); this.taskTracker = taskTracker; } + + @Override + public String getDvrpMode() { + return dvrpMode; + } @Override public String toString() { return MoreObjects.toStringHelper(this) + .add("dvrpMode", dvrpMode) .add("taskType", taskType) .add("taskIdx", taskIdx) .add("status", status) diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultDriveTask.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultDriveTask.java index e1066582b5a..2e6bfa2811e 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultDriveTask.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultDriveTask.java @@ -31,8 +31,8 @@ public class DefaultDriveTask extends AbstractTask implements DriveTask { private VrpPath path; - public DefaultDriveTask(TaskType taskType, VrpPathWithTravelData path) { - super(taskType, path.getDepartureTime(), path.getArrivalTime()); + public DefaultDriveTask(String dvrpMode, TaskType taskType, VrpPathWithTravelData path) { + super(dvrpMode, taskType, path.getDepartureTime(), path.getArrivalTime()); this.path = path; } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultStayTask.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultStayTask.java index eff45e00f24..501abe38bb8 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultStayTask.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/DefaultStayTask.java @@ -29,8 +29,8 @@ public class DefaultStayTask extends AbstractTask implements StayTask { private final Link link; - public DefaultStayTask(TaskType taskType, double beginTime, double endTime, Link link) { - super(taskType, beginTime, endTime); + public DefaultStayTask(String dvrpMode, TaskType taskType, double beginTime, double endTime, Link link) { + super(dvrpMode, taskType, beginTime, endTime); this.link = link; } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/Task.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/Task.java index a2d7daea9ac..514711a4929 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/Task.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/schedule/Task.java @@ -86,4 +86,6 @@ enum TaskStatus { * (TaskStatus == STARTED) can be tracked. */ void initTaskTracker(TaskTracker taskTracker); + + public String getDvrpMode(); } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskEndedEvent.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskEndedEvent.java index 5770e976ff9..94fd22156db 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskEndedEvent.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskEndedEvent.java @@ -38,8 +38,8 @@ public class TaskEndedEvent extends AbstractTaskEvent { public static final String EVENT_TYPE = "dvrpTaskEnded"; - public TaskEndedEvent(double time, String dvrpMode, Id dvrpVehicleId, Id driverId, Task task) { - this(time, dvrpMode, dvrpVehicleId, driverId, task.getTaskType(), task.getTaskIdx(), + public TaskEndedEvent(double time, Id dvrpVehicleId, Id driverId, Task task) { + this(time, task.getDvrpMode(), dvrpVehicleId, driverId, task.getTaskType(), task.getTaskIdx(), Tasks.getEndLink(task).getId()); } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskStartedEvent.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskStartedEvent.java index 75197ebe9c7..d4ef5ac642f 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskStartedEvent.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/TaskStartedEvent.java @@ -38,9 +38,9 @@ public class TaskStartedEvent extends AbstractTaskEvent { public static final String EVENT_TYPE = "dvrpTaskStarted"; - public TaskStartedEvent(double time, String dvrpMode, Id dvrpVehicleId, Id driverId, + public TaskStartedEvent(double time, Id dvrpVehicleId, Id driverId, Task task) { - this(time, dvrpMode, dvrpVehicleId, driverId, task.getTaskType(), task.getTaskIdx(), + this(time, task.getDvrpMode(), dvrpVehicleId, driverId, task.getTaskType(), task.getTaskIdx(), Tasks.getBeginLink(task).getId()); } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogic.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogic.java index 159fe9be4f9..5da39d934bb 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogic.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogic.java @@ -44,16 +44,14 @@ public interface DynActionCreator { private final VrpOptimizer optimizer; private final DynActionCreator dynActionCreator; private final DvrpVehicle vehicle; - private final String dvrpMode; private final EventsManager eventsManager; private DynAgent agent; public VrpAgentLogic(VrpOptimizer optimizer, DynActionCreator dynActionCreator, DvrpVehicle vehicle, - String dvrpMode, EventsManager eventsManager) { + EventsManager eventsManager) { this.optimizer = optimizer; this.dynActionCreator = dynActionCreator; this.vehicle = vehicle; - this.dvrpMode = dvrpMode; this.eventsManager = eventsManager; } @@ -85,7 +83,7 @@ public DynAction computeNextAction(DynAction oldAction, double now) { case STARTED: Task task = schedule.getCurrentTask(); - eventsManager.processEvent(new TaskEndedEvent(now, dvrpMode, vehicle.getId(), agent.getId(), task)); + eventsManager.processEvent(new TaskEndedEvent(now, vehicle.getId(), agent.getId(), task)); break; case PLANNED: @@ -102,7 +100,7 @@ public DynAction computeNextAction(DynAction oldAction, double now) { case STARTED: Task task = schedule.getCurrentTask(); eventsManager.processEvent( - new TaskStartedEvent(now, dvrpMode, vehicle.getId(), agent.getId(), task)); + new TaskStartedEvent(now, vehicle.getId(), agent.getId(), task)); return dynActionCreator.createAction(agent, vehicle, now); case COMPLETED: diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentSource.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentSource.java index b5ab8b34fa3..544f3098540 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentSource.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentSource.java @@ -60,7 +60,7 @@ public void insertAgentsIntoMobsim() { Id id = dvrpVehicle.getId(); Id startLinkId = dvrpVehicle.getStartLink().getId(); - VrpAgentLogic vrpAgentLogic = new VrpAgentLogic(optimizer, nextActionCreator, dvrpVehicle, dvrpMode, + VrpAgentLogic vrpAgentLogic = new VrpAgentLogic(optimizer, nextActionCreator, dvrpVehicle, qSim.getEventsManager()); DynAgent vrpAgent = new DynAgent(Id.createPersonId(id), startLinkId, qSim.getEventsManager(), vrpAgentLogic); diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/evrp/ChargingTaskImpl.java b/contribs/dvrp/src/main/java/org/matsim/contrib/evrp/ChargingTaskImpl.java index 969fa50da00..2f74dbce82e 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/evrp/ChargingTaskImpl.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/evrp/ChargingTaskImpl.java @@ -37,9 +37,9 @@ public class ChargingTaskImpl extends DefaultStayTask implements ChargingTask { private Double chargingStartedTime; private final double totalEnergy; - public ChargingTaskImpl(TaskType taskType, double beginTime, double endTime, Charger charger, ElectricVehicle ev, + public ChargingTaskImpl(String dvrpMode, TaskType taskType, double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) { - super(taskType, beginTime, endTime, charger.getLink()); + super(dvrpMode, taskType, beginTime, endTime, charger.getLink()); Preconditions.checkArgument(totalEnergy < 0, "Total energy consumption is not negative: %s", totalEnergy); this.chargingLogic = (ChargingWithAssignmentLogic)charger.getLogic(); diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java index 2aa72304e53..f28ff534a06 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java @@ -353,7 +353,7 @@ private void insertDriveTask() { travelTime); // ... and we add it as the first and only task to the schedule - DriveTask driveTask = new DefaultDriveTask(() -> "drive", path); + DriveTask driveTask = new DefaultDriveTask(MODE, () -> "drive", path); schedule.addTask(driveTask); // Track the initially obtained arrival time @@ -612,7 +612,7 @@ private void insertDriveTask() { router, travelTime); // ... and we add it as the first and only task to the schedule - DriveTask driveTask = new DefaultDriveTask(() -> "drive", path); + DriveTask driveTask = new DefaultDriveTask(MODE, () -> "drive", path); schedule.addTask(driveTask); // Track the initially obtained arrival time diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogicTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogicTest.java index 9546a1ce4e4..89d7774df97 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogicTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/vrpagent/VrpAgentLogicTest.java @@ -81,7 +81,7 @@ public void nextTask(DvrpVehicle vehicle) { private final DvrpVehicle vehicle = new DvrpVehicleImpl(vehicleSpecification, startLink); private final DynAgentLogic dynAgentLogic = new VrpAgentLogic(optimizer, VrpAgentLogicTest::createAction, vehicle, - DVRP_MODE, eventsManager); + eventsManager); private final DynAgent dynAgent = new DynAgent(Id.createPersonId(vehicleSpecification.getId()), startLink.getId(), null, dynAgentLogic); @@ -98,7 +98,7 @@ void testInitialActivity_unplanned() { void testInitialActivity_planned() { DynActivity initialActivity = dynAgentLogic.computeInitialActivity(dynAgent); - StayTask task0 = new DefaultStayTask(TestTaskType.TYPE, 10, 90, startLink); + StayTask task0 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, 10, 90, startLink); vehicle.getSchedule().addTask(task0); assertThat(initialActivity.getActivityType()).isEqualTo(BEFORE_SCHEDULE_ACTIVITY_TYPE); @@ -110,7 +110,7 @@ void testInitialActivity_planned() { void testInitialActivity_started_failure() { DynActivity initialActivity = dynAgentLogic.computeInitialActivity(dynAgent); - StayTask task0 = new DefaultStayTask(TestTaskType.TYPE, 10, 90, startLink); + StayTask task0 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, 10, 90, startLink); vehicle.getSchedule().addTask(task0); vehicle.getSchedule().nextTask(); @@ -133,7 +133,7 @@ void testNextAction_unplanned_completed() { @Test void testNextAction_planned_started() { double time = 10; - StayTask task0 = new DefaultStayTask(TestTaskType.TYPE, time, 90, startLink); + StayTask task0 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, time, 90, startLink); vehicle.getSchedule().addTask(task0); DynActivity nextActivity = (DynActivity)dynAgentLogic.computeNextAction(null, time); @@ -144,9 +144,9 @@ void testNextAction_planned_started() { @Test void testNextAction_started_started() { double time = 50; - StayTask task0 = new DefaultStayTask(TestTaskType.TYPE, 10, time, startLink); + StayTask task0 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, 10, time, startLink); vehicle.getSchedule().addTask(task0); - StayTask task1 = new DefaultStayTask(TestTaskType.TYPE, time, 90, startLink); + StayTask task1 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, time, 90, startLink); vehicle.getSchedule().addTask(task1); vehicle.getSchedule().nextTask();//current: task0 @@ -158,7 +158,7 @@ void testNextAction_started_started() { @Test void testNextAction_started_completed() { double time = 90; - StayTask task0 = new DefaultStayTask(TestTaskType.TYPE, 10, time, startLink); + StayTask task0 = new DefaultStayTask(DVRP_MODE, TestTaskType.TYPE, 10, time, startLink); vehicle.getSchedule().addTask(task0); vehicle.getSchedule().nextTask();//current: task0 @@ -185,10 +185,10 @@ private void verifyEvents(AbstractTaskEvent... events) { } private TaskStartedEvent taskStartedEvent(double time, Task task) { - return new TaskStartedEvent(time, DVRP_MODE, vehicleSpecification.getId(), dynAgent.getId(), task); + return new TaskStartedEvent(time, vehicleSpecification.getId(), dynAgent.getId(), task); } private TaskEndedEvent taskEndedEvent(double time, Task task) { - return new TaskEndedEvent(time, DVRP_MODE, vehicleSpecification.getId(), dynAgent.getId(), task); + return new TaskEndedEvent(time, vehicleSpecification.getId(), dynAgent.getId(), task); } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiChargingTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiChargingTask.java index 8f7f9b018ca..c683411232c 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiChargingTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiChargingTask.java @@ -27,8 +27,8 @@ public class ETaxiChargingTask extends ChargingTaskImpl { public static final TaxiTaskType TYPE = new TaxiTaskType("CHARGING"); - public ETaxiChargingTask(double beginTime, double endTime, Charger charger, ElectricVehicle ev, + public ETaxiChargingTask(String dvrpMode, double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) { - super(TYPE, beginTime, endTime, charger, ev, totalEnergy); + super(dvrpMode, TYPE, beginTime, endTime, charger, ev, totalEnergy); } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiScheduler.java b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiScheduler.java index 79999d4b140..b0efd54f762 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiScheduler.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/ETaxiScheduler.java @@ -68,7 +68,7 @@ public void scheduleCharging(DvrpVehicle vehicle, ElectricVehicle ev, Charger ch double chargingEndTime = vrpPath.getArrivalTime() + ChargingEstimations.estimateMaxWaitTimeForNextVehicle( charger)// TODO not precise!!! + logic.getChargingStrategy().calcRemainingTimeToCharge(ev);// TODO not precise !!! (SOC will be lower) - schedule.addTask(new ETaxiChargingTask(vrpPath.getArrivalTime(), chargingEndTime, charger, ev, + schedule.addTask(new ETaxiChargingTask(dvrpMode, vrpPath.getArrivalTime(), chargingEndTime, charger, ev, -logic.getChargingStrategy().calcRemainingEnergyToCharge(ev)));// TODO not precise !!! (ditto) logic.assignVehicle(ev); @@ -145,7 +145,7 @@ protected void removePlannedTasks(DvrpVehicle vehicle, int newLastTaskIdx) { // the right endTime is set in TaxiScheduler.removeAwaitingRequestsImpl() double chargeEndTime = lastTask.getEndTime(); Link chargeLink = ((ETaxiChargingTask)lastTask).getLink(); - schedule.addTask(new TaxiStayTask(chargeEndTime, chargeEndTime, chargeLink)); + schedule.addTask(new TaxiStayTask(dvrpMode, chargeEndTime, chargeEndTime, chargeLink)); } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiDropoffTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiDropoffTask.java index 73bdeff7bef..fac6431a90e 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiDropoffTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiDropoffTask.java @@ -31,8 +31,8 @@ public class TaxiDropoffTask extends DefaultStayTask { private final DrtRequest request; - public TaxiDropoffTask(double beginTime, double endTime, DrtRequest request) { - super(TYPE, beginTime, endTime, request.getToLink()); + public TaxiDropoffTask(String dvrpMode, double beginTime, double endTime, DrtRequest request) { + super(dvrpMode, TYPE, beginTime, endTime, request.getToLink()); this.request = request; } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiEmptyDriveTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiEmptyDriveTask.java index 93a1abf9c4e..e3d30172b22 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiEmptyDriveTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiEmptyDriveTask.java @@ -29,8 +29,8 @@ public class TaxiEmptyDriveTask extends DefaultDriveTask { public static final TaxiTaskType TYPE = new TaxiTaskType(EMPTY_DRIVE); - public TaxiEmptyDriveTask(VrpPathWithTravelData path, TaxiTaskType taskType) { - super(taskType, path); + public TaxiEmptyDriveTask(String dvrpMode, VrpPathWithTravelData path, TaxiTaskType taskType) { + super(dvrpMode, taskType, path); Preconditions.checkArgument(taskType.baseType().get() == EMPTY_DRIVE); } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiOccupiedDriveTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiOccupiedDriveTask.java index 969aa3d1218..87e13550aba 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiOccupiedDriveTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiOccupiedDriveTask.java @@ -28,8 +28,8 @@ public class TaxiOccupiedDriveTask extends DefaultDriveTask { public static final TaxiTaskType TYPE = new TaxiTaskType(OCCUPIED_DRIVE); - public TaxiOccupiedDriveTask(VrpPathWithTravelData path, DrtRequest request) { - super(TYPE, path); + public TaxiOccupiedDriveTask(String dvrpMode, VrpPathWithTravelData path, DrtRequest request) { + super(dvrpMode, TYPE, path); if (request.getFromLink() != path.getFromLink() && request.getToLink() != path.getToLink()) { throw new IllegalArgumentException(); } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiPickupTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiPickupTask.java index 7842c4c6284..51dd6d0a7ae 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiPickupTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiPickupTask.java @@ -31,8 +31,8 @@ public class TaxiPickupTask extends DefaultStayTask { private final DrtRequest request; - public TaxiPickupTask(double beginTime, double endTime, DrtRequest request) { - super(TYPE, beginTime, endTime, request.getFromLink()); + public TaxiPickupTask(String dvrpMode, double beginTime, double endTime, DrtRequest request) { + super(dvrpMode, TYPE, beginTime, endTime, request.getFromLink()); this.request = request; } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiStayTask.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiStayTask.java index d800ced8663..c165bcd7ed4 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiStayTask.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/schedule/TaxiStayTask.java @@ -27,7 +27,7 @@ public class TaxiStayTask extends DefaultStayTask { public static final TaxiTaskType TYPE = new TaxiTaskType(STAY); - public TaxiStayTask(double beginTime, double endTime, Link link) { - super(TYPE, beginTime, endTime, link); + public TaxiStayTask(String dvrpMode, double beginTime, double endTime, Link link) { + super(dvrpMode, TYPE, beginTime, endTime, link); } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/scheduler/TaxiScheduler.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/scheduler/TaxiScheduler.java index eb9df3f0bd1..aad896c9daa 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/scheduler/TaxiScheduler.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/scheduler/TaxiScheduler.java @@ -66,6 +66,8 @@ public class TaxiScheduler implements MobsimBeforeCleanupListener { protected final TaxiConfigGroup taxiCfg; + protected final String dvrpMode; + private final Fleet fleet; private final TravelTime travelTime; private final LeastCostPathCalculator router; @@ -90,6 +92,7 @@ public TaxiScheduler(TaxiConfigGroup taxiCfg, Fleet fleet, TaxiScheduleInquiry t this.travelTime = travelTime; this.eventsManager = eventsManager; this.mobsimTimer = mobsimTimer; + this.dvrpMode = taxiCfg.mode; router = routerCreator.get(); @@ -105,7 +108,7 @@ public TaxiScheduler(TaxiConfigGroup taxiCfg, Fleet fleet, TaxiScheduleInquiry t private void initFleet() { for (DvrpVehicle veh : fleet.getVehicles().values()) { veh.getSchedule() - .addTask(new TaxiStayTask(veh.getServiceBeginTime(), veh.getServiceEndTime(), veh.getStartLink())); + .addTask(new TaxiStayTask(dvrpMode, veh.getServiceBeginTime(), veh.getServiceEndTime(), veh.getStartLink())); } } @@ -121,7 +124,7 @@ public void scheduleRequest(DvrpVehicle vehicle, DrtRequest request, VrpPathWith double pickupEndTime = Math.max(vrpPath.getArrivalTime(), request.getEarliestStartTime()) + taxiCfg.pickupDuration; - schedule.addTask(new TaxiPickupTask(vrpPath.getArrivalTime(), pickupEndTime, request)); + schedule.addTask(new TaxiPickupTask(dvrpMode, vrpPath.getArrivalTime(), pickupEndTime, request)); Link reqFromLink = request.getFromLink(); Link reqToLink = request.getToLink(); @@ -184,7 +187,7 @@ protected void scheduleDrive(Schedule schedule, TaxiStayTask lastTask, VrpPathWi } if (vrpPath.getLinkCount() > 1) { - schedule.addTask(new TaxiEmptyDriveTask(vrpPath, taskType)); + schedule.addTask(new TaxiEmptyDriveTask(dvrpMode, vrpPath, taskType)); } } @@ -245,11 +248,11 @@ public void updateBeforeNextTask(DvrpVehicle vehicle) { } protected void appendOccupiedDriveAndDropoff(Schedule schedule, DrtRequest req, VrpPathWithTravelData path) { - schedule.addTask(new TaxiOccupiedDriveTask(path, req)); + schedule.addTask(new TaxiOccupiedDriveTask(dvrpMode, path, req)); double arrivalTime = path.getArrivalTime(); double departureTime = arrivalTime + taxiCfg.dropoffDuration; - schedule.addTask(new TaxiDropoffTask(arrivalTime, departureTime, req)); + schedule.addTask(new TaxiDropoffTask(dvrpMode, arrivalTime, departureTime, req)); } protected VrpPathWithTravelData calcPath(Link fromLink, Link toLink, double departureTime) { @@ -265,7 +268,7 @@ protected void appendStayTask(DvrpVehicle vehicle) { double tBegin = schedule.getEndTime(); double tEnd = Math.max(tBegin, vehicle.getServiceEndTime());// even 0-second WAIT Link link = Schedules.getLastLinkInSchedule(vehicle); - schedule.addTask(new TaxiStayTask(tBegin, tEnd, link)); + schedule.addTask(new TaxiStayTask(dvrpMode, tBegin, tEnd, link)); } // ========================================================================================= @@ -357,7 +360,7 @@ protected void taskRemovedFromSchedule(DvrpVehicle vehicle, Task task) { private void cleanupScheduleAfterTaskRemoval(DvrpVehicle vehicle) { Schedule schedule = vehicle.getSchedule(); if (schedule.getStatus() == ScheduleStatus.UNPLANNED) { - schedule.addTask(new TaxiStayTask(vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), + schedule.addTask(new TaxiStayTask(dvrpMode, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(), vehicle.getStartLink())); return; } @@ -372,7 +375,7 @@ private void cleanupScheduleAfterTaskRemoval(DvrpVehicle vehicle) { case DROPOFF -> { Link link = Schedules.getLastLinkInSchedule(vehicle); - schedule.addTask(new TaxiStayTask(tBegin, tEnd, link)); + schedule.addTask(new TaxiStayTask(dvrpMode, tBegin, tEnd, link)); } case EMPTY_DRIVE -> {