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..afbf606fc1d 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 @@ -68,7 +68,8 @@ protected void configureQSim() { bindModal(DrtShiftDispatcher.class).toProvider(modalProvider( getter -> new EDrtShiftDispatcherImpl(((EShiftTaskScheduler) getter.getModal(ShiftTaskScheduler.class)), getter.getModal(ChargingInfrastructure.class), - drtShiftParams, getter.getModal(OperationFacilities.class), new DrtShiftDispatcherImpl(getter.getModal(DrtShifts.class), getter.getModal(Fleet.class), + drtShiftParams, getter.getModal(OperationFacilities.class), new DrtShiftDispatcherImpl(getMode(), + getter.getModal(DrtShifts.class), getter.getModal(Fleet.class), getter.get(MobsimTimer.class), getter.getModal(OperationFacilities.class), getter.getModal(OperationFacilityFinder.class), getter.getModal(ShiftTaskScheduler.class), getter.getModal(Network.class), getter.get(EventsManager.class), drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()), diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/BreakCorridorXY.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/BreakCorridorXY.java index 320b23977f9..6c4887e965e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/BreakCorridorXY.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/BreakCorridorXY.java @@ -24,12 +24,15 @@ */ public class BreakCorridorXY implements DrtShiftBreakStartedEventHandler, DrtShiftBreakEndedEventHandler { + private final String mode; + private final Provider shifts; private final Map, Tuple> shift2plannedVsActualBreakStart = new HashMap<>(); private final Map, Tuple> shift2plannedVsActualBreakEnd = new HashMap<>(); - public BreakCorridorXY(Provider shifts) { + public BreakCorridorXY(String mode, Provider shifts) { super(); + this.mode = mode; this.shifts = shifts; reset(0); } @@ -38,16 +41,20 @@ public BreakCorridorXY(Provider shifts) { @Override public void handleEvent(DrtShiftBreakStartedEvent event) { - final DrtShiftBreakSpecification drtShiftBreak = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); - final double earliestBreakStartTime = drtShiftBreak.getEarliestBreakStartTime(); - shift2plannedVsActualBreakStart.put(event.getShiftId(), new Tuple<>(earliestBreakStartTime, event.getTime())); + if (event.getMode().equals(mode)) { + final DrtShiftBreakSpecification drtShiftBreak = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); + final double earliestBreakStartTime = drtShiftBreak.getEarliestBreakStartTime(); + shift2plannedVsActualBreakStart.put(event.getShiftId(), new Tuple<>(earliestBreakStartTime, event.getTime())); + } } @Override public void handleEvent(DrtShiftBreakEndedEvent event) { - final DrtShiftBreakSpecification drtShiftBreak = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); - final double latestBreakEndTime = drtShiftBreak.getLatestBreakEndTime(); - shift2plannedVsActualBreakEnd.put(event.getShiftId(), new Tuple<>(latestBreakEndTime, event.getTime())); + if (event.getMode().equals(mode)) { + final DrtShiftBreakSpecification drtShiftBreak = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); + final double latestBreakEndTime = drtShiftBreak.getLatestBreakEndTime(); + shift2plannedVsActualBreakEnd.put(event.getShiftId(), new Tuple<>(latestBreakEndTime, event.getTime())); + } } @Override diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftDurationXY.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftDurationXY.java index d2ff4dda184..809e4385323 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftDurationXY.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftDurationXY.java @@ -30,9 +30,12 @@ public class ShiftDurationXY implements DrtShiftStartedEventHandler, DrtShiftEnd private final Map, Tuple> shift2plannedVsActualDuration = new HashMap<>(); private final Map, Tuple> shift2plannedVsActualBreakDuration = new HashMap<>(); - public ShiftDurationXY(Provider shifts) { + private final String mode; + + public ShiftDurationXY(Provider shifts, String mode) { super(); this.shifts = shifts; + this.mode = mode; reset(0); } @@ -40,30 +43,38 @@ public ShiftDurationXY(Provider shifts) { @Override public void handleEvent(final DrtShiftStartedEvent event) { - shift2StartTime.put(event.getShiftId(), event.getTime()); + if (event.getMode().equals(mode)) { + shift2StartTime.put(event.getShiftId(), event.getTime()); + } } @Override public void handleEvent(DrtShiftBreakStartedEvent event) { - shift2BreakStartTime.put(event.getShiftId(), event.getTime()); + if (event.getMode().equals(mode)) { + shift2BreakStartTime.put(event.getShiftId(), event.getTime()); + } } @Override public void handleEvent(final DrtShiftEndedEvent event) { - final Double start = shift2StartTime.get(event.getShiftId()); - double duration = event.getTime() - start; - final DrtShiftSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()); - double plannedDuration = drtShift.getEndTime() - drtShift.getStartTime(); - shift2plannedVsActualDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration)); + if (event.getMode().equals(mode)) { + final Double start = shift2StartTime.get(event.getShiftId()); + double duration = event.getTime() - start; + final DrtShiftSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()); + double plannedDuration = drtShift.getEndTime() - drtShift.getStartTime(); + shift2plannedVsActualDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration)); + } } @Override public void handleEvent(DrtShiftBreakEndedEvent event) { - final Double start = shift2BreakStartTime.get(event.getShiftId()); - double duration = event.getTime() - start; - final DrtShiftBreakSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); - double plannedDuration = drtShift.getDuration(); - shift2plannedVsActualBreakDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration)); + if (event.getMode().equals(mode)) { + final Double start = shift2BreakStartTime.get(event.getShiftId()); + double duration = event.getTime() - start; + final DrtShiftBreakSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow(); + double plannedDuration = drtShift.getDuration(); + shift2plannedVsActualBreakDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration)); + } } @Override diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftHistogram.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftHistogram.java index ce228469e50..00dc4e85a02 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftHistogram.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/ShiftHistogram.java @@ -20,6 +20,8 @@ public class ShiftHistogram implements DrtShiftStartedEventHandler, DrtShiftEndedEventHandler, DrtShiftBreakStartedEventHandler, DrtShiftBreakEndedEventHandler { + private final String mode; + public static final int DEFAULT_END_TIME = 30 * 3600; public static final int DEFAULT_BIN_SIZE = 300; @@ -30,9 +32,10 @@ public class ShiftHistogram implements DrtShiftStartedEventHandler, DrtShiftEnde private DataFrame data = null; - public ShiftHistogram(Population population, Config config) { + public ShiftHistogram(Population population, String mode, Config config) { super(); - this.binSize = DEFAULT_BIN_SIZE; + this.mode = mode; + this.binSize = DEFAULT_BIN_SIZE; this.nofBins = ((int) config.qsim().getEndTime().orElse(DEFAULT_END_TIME) ) / this.binSize + 1; reset(0); if (population == null) { @@ -46,8 +49,9 @@ public ShiftHistogram(Population population, Config config) { * @param binSize The size of a time bin in seconds. * @param nofBins The number of time bins for this analysis. */ - public ShiftHistogram(final int binSize, final int nofBins) { + public ShiftHistogram(String mode, final int binSize, final int nofBins) { super(); + this.mode = mode; this.binSize = binSize; this.nofBins = nofBins; reset(0); @@ -57,34 +61,42 @@ public ShiftHistogram(final int binSize, final int nofBins) { @Override public void handleEvent(final DrtShiftStartedEvent event) { - int index = getBinIndex(event.getTime()); - if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) { - DataFrame dataFrame = getData(); - dataFrame.countsStart[index]++; + if (event.getMode().equals(mode)) { + int index = getBinIndex(event.getTime()); + if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) { + DataFrame dataFrame = getData(); + dataFrame.countsStart[index]++; + } } } @Override public void handleEvent(final DrtShiftEndedEvent event) { - int index = getBinIndex(event.getTime()); - if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) { - DataFrame dataFrame = getData(); - dataFrame.countsEnd[index]++; + if (event.getMode().equals(mode)) { + int index = getBinIndex(event.getTime()); + if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) { + DataFrame dataFrame = getData(); + dataFrame.countsEnd[index]++; + } } } @Override public void handleEvent(DrtShiftBreakStartedEvent event) { - int index = getBinIndex(event.getTime()); - DataFrame dataFrame = getData(); - dataFrame.countsBreaksStart[index]++; + if (event.getMode().equals(mode)) { + int index = getBinIndex(event.getTime()); + DataFrame dataFrame = getData(); + dataFrame.countsBreaksStart[index]++; + } } @Override public void handleEvent(DrtShiftBreakEndedEvent event) { - int index = getBinIndex(event.getTime()); - DataFrame dataFrame = getData(); - dataFrame.countsBreaksEnd[index]++; + if (event.getMode().equals(mode)) { + int index = getBinIndex(event.getTime()); + DataFrame dataFrame = getData(); + dataFrame.countsBreaksEnd[index]++; + } } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java index e339db2fb30..d8f4db9f33e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java @@ -31,7 +31,7 @@ public DrtShiftEfficiencyModeModule(DrtConfigGroup drtConfigGroup) { @Override public void install() { bindModal(ShiftEfficiencyTracker.class).toProvider(modalProvider(getter -> - new ShiftEfficiencyTracker())).asEagerSingleton(); + new ShiftEfficiencyTracker(getMode()))).asEagerSingleton(); addEventHandlerBinding().to(modalKey(ShiftEfficiencyTracker.class)); bindModal(ShiftEfficiencyAnalysisControlerListener.class).toProvider(modalProvider(getter -> new ShiftEfficiencyAnalysisControlerListener(drtConfigGroup, diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java index 7ccb1edbbfc..c7963f13ca5 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java @@ -37,6 +37,7 @@ public final class ShiftEfficiencyTracker implements PersonMoneyEventHandler, PassengerDroppedOffEventHandler, DrtShiftStartedEventHandler, DrtShiftEndedEventHandler { + private final String mode; private Map, Double> revenueByShift; private Map, Id> shiftByRequest; @@ -63,8 +64,9 @@ public Map, Id> getFinishedShifts() { } } - public ShiftEfficiencyTracker() { - this.revenueByShift = new HashMap<>(); + public ShiftEfficiencyTracker(String mode) { + this.mode = mode; + this.revenueByShift = new HashMap<>(); this.shiftByRequest = new HashMap<>(); this.finishedShifts = new HashMap<>(); this.currentRecord = new Record(revenueByShift, shiftByRequest, finishedShifts); @@ -72,35 +74,43 @@ public ShiftEfficiencyTracker() { @Override public void handleEvent(PersonMoneyEvent personMoneyEvent) { - if (DrtFareHandler.PERSON_MONEY_EVENT_PURPOSE_DRT_FARE.equals(personMoneyEvent.getPurpose())) { - Id key = shiftByRequest.get(Id.create(personMoneyEvent.getReference(), DrtRequest.class)); - if(key != null) { - revenueByShift.merge(key, -personMoneyEvent.getAmount(), Double::sum); + if(personMoneyEvent.getTransactionPartner().equals(mode)) { + if (DrtFareHandler.PERSON_MONEY_EVENT_PURPOSE_DRT_FARE.equals(personMoneyEvent.getPurpose())) { + Id key = shiftByRequest.get(Id.create(personMoneyEvent.getReference(), DrtRequest.class)); + if (key != null) { + revenueByShift.merge(key, -personMoneyEvent.getAmount(), Double::sum); + } } } } @Override public void handleEvent(PassengerDroppedOffEvent event) { - Id vehicleId = event.getVehicleId(); - Gbl.assertIf(activeShifts.containsKey(vehicleId)); - Id drtShiftId = activeShifts.get(vehicleId); - shiftByRequest.put(event.getRequestId(), drtShiftId); + if(event.getMode().equals(mode)) { + Id vehicleId = event.getVehicleId(); + Gbl.assertIf(activeShifts.containsKey(vehicleId)); + Id drtShiftId = activeShifts.get(vehicleId); + shiftByRequest.put(event.getRequestId(), drtShiftId); + } } @Override public void handleEvent(DrtShiftStartedEvent event) { - revenueByShift.put(event.getShiftId(), 0.); - if(activeShifts.containsKey(event.getVehicleId())) { - throw new RuntimeException("Vehicle is already registered for another shift"); + if(event.getMode().equals(mode)) { + revenueByShift.put(event.getShiftId(), 0.); + if (activeShifts.containsKey(event.getVehicleId())) { + throw new RuntimeException("Vehicle is already registered for another shift"); + } + activeShifts.put(event.getVehicleId(), event.getShiftId()); } - activeShifts.put(event.getVehicleId(), event.getShiftId()); } @Override public void handleEvent(DrtShiftEndedEvent event) { - activeShifts.remove(event.getVehicleId()); - finishedShifts.put(event.getShiftId(), event.getVehicleId()); + if(event.getMode().equals(mode)) { + activeShifts.remove(event.getVehicleId()); + finishedShifts.put(event.getShiftId(), event.getVehicleId()); + } } @Override diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcherImpl.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcherImpl.java index 4c070bc1ebf..c32b5d1b12b 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcherImpl.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/dispatcher/DrtShiftDispatcherImpl.java @@ -49,6 +49,8 @@ public class DrtShiftDispatcherImpl implements DrtShiftDispatcher { private final static Logger logger = LogManager.getLogger(DrtShiftDispatcherImpl.class); + private final String mode; + private Queue unscheduledShifts; private Queue assignedShifts; private Queue activeShifts; @@ -74,10 +76,11 @@ public class DrtShiftDispatcherImpl implements DrtShiftDispatcher { private final ShiftStartLogic shiftStartLogic; private final AssignShiftToVehicleLogic assignShiftToVehicleLogic; - public DrtShiftDispatcherImpl(DrtShifts shifts, Fleet fleet, MobsimTimer timer, OperationFacilities operationFacilities, - OperationFacilityFinder breakFacilityFinder, ShiftTaskScheduler shiftTaskScheduler, - Network network, EventsManager eventsManager, ShiftsParams drtShiftParams, - ShiftStartLogic shiftStartLogic, AssignShiftToVehicleLogic assignShiftToVehicleLogic) { + public DrtShiftDispatcherImpl(String mode, DrtShifts shifts, Fleet fleet, MobsimTimer timer, OperationFacilities operationFacilities, + OperationFacilityFinder breakFacilityFinder, ShiftTaskScheduler shiftTaskScheduler, + Network network, EventsManager eventsManager, ShiftsParams drtShiftParams, + ShiftStartLogic shiftStartLogic, AssignShiftToVehicleLogic assignShiftToVehicleLogic) { + this.mode = mode; this.shifts = shifts; this.fleet = fleet; this.timer = timer; @@ -140,7 +143,7 @@ private void checkBreaks() { OperationFacility breakFacility = decideOnBreak(activeShift); if (breakFacility != null) { shiftTaskScheduler.relocateForBreak(activeShift.vehicle(), breakFacility, shift); - eventsManager.processEvent(new DrtShiftBreakScheduledEvent(timer.getTimeOfDay(), shift.getId(), + eventsManager.processEvent(new DrtShiftBreakScheduledEvent(timer.getTimeOfDay(), mode, shift.getId(), activeShift.vehicle().getId(), breakFacility.getLinkId(), shift.getBreak().orElseThrow().getScheduledLatestArrival())); } @@ -169,7 +172,7 @@ private void startShifts(double timeStep) { iterator.remove(); logger.debug("Started shift " + next.shift()); StayTask currentTask = (StayTask) next.vehicle().getSchedule().getCurrentTask(); - eventsManager.processEvent(new DrtShiftStartedEvent(timeStep, next.shift().getId(), next.vehicle().getId(), + eventsManager.processEvent(new DrtShiftStartedEvent(timeStep, mode, next.shift().getId(), next.vehicle().getId(), currentTask.getLink().getId())); } } @@ -262,7 +265,7 @@ private void assignShiftToVehicle(DrtShift shift, ShiftDvrpVehicle vehicle) { Gbl.assertNotNull(vehicle); vehicle.addShift(shift); assignedShifts.add(new ShiftEntry(shift, vehicle)); - eventsManager.processEvent(new DrtShiftAssignedEvent(timer.getTimeOfDay(), shift.getId(), vehicle.getId())); + eventsManager.processEvent(new DrtShiftAssignedEvent(timer.getTimeOfDay(), mode, shift.getId(), vehicle.getId())); } private void endShifts(double timeStep) { @@ -370,7 +373,7 @@ private void updateShiftEnd(ShiftEntry next) { shiftChangeFacility.register(next.vehicle().getId()); changeOverTask.getFacility().deregisterVehicle(next.vehicle().getId()); eventsManager.processEvent(new ShiftFacilityRegistrationEvent(timer.getTimeOfDay(), - next.vehicle().getId(), shiftChangeFacility.getId())); + mode, next.vehicle().getId(), shiftChangeFacility.getId())); } } } @@ -426,7 +429,7 @@ private void scheduleShiftEnd(ShiftEntry endingShift) { if (shiftChangeoverFacility != null && shiftChangeoverFacility.register(endingShift.vehicle().getId())) { shiftTaskScheduler.relocateForShiftChange(endingShift.vehicle(), network.getLinks().get(shiftChangeoverFacility.getLinkId()), endingShift.shift(), shiftChangeoverFacility); - eventsManager.processEvent(new ShiftFacilityRegistrationEvent(timer.getTimeOfDay(), endingShift.vehicle().getId(), + eventsManager.processEvent(new ShiftFacilityRegistrationEvent(timer.getTimeOfDay(), mode, endingShift.vehicle().getId(), shiftChangeoverFacility.getId())); } else { throw new RuntimeException("Could not find shift end location!"); @@ -458,7 +461,7 @@ private OperationFacility decideOnBreak(ShiftEntry activeShift) { } if (shiftBreakFacility.register(activeShift.vehicle().getId())) { eventsManager.processEvent(new ShiftFacilityRegistrationEvent(timer.getTimeOfDay(), - activeShift.vehicle().getId(), shiftBreakFacility.getId())); + mode, activeShift.vehicle().getId(), shiftBreakFacility.getId())); return shiftBreakFacility; } } @@ -471,7 +474,7 @@ public void endShift(ShiftDvrpVehicle vehicle, Id id, Id linkId) { - eventsManager.processEvent(new DrtShiftBreakStartedEvent(timer.getTimeOfDay(), vehicle.getShifts().peek().getId(), vehicle.getId(), linkId)); + eventsManager.processEvent( + new DrtShiftBreakStartedEvent(timer.getTimeOfDay(), mode, + vehicle.getShifts().peek().getId(), vehicle.getId(), linkId) + ); } private boolean isSchedulable(DrtShift shift, double timeStep) { diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/AbstractShiftEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/AbstractShiftEvent.java new file mode 100644 index 00000000000..8627017c565 --- /dev/null +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/AbstractShiftEvent.java @@ -0,0 +1,43 @@ +package org.matsim.contrib.drt.extension.operations.shifts.events; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.Event; +import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShift; + +import java.util.Map; + +/** + * @author nkuehnel / MOIA + */ +public abstract class AbstractShiftEvent extends Event { + + public static final String ATTRIBUTE_MODE = "mode"; + private final Id shiftId; + + public static final String ATTRIBUTE_SHIFT_ID = "shift_id"; + + + private final String mode; + + public AbstractShiftEvent(double time, String mode, Id id) { + super(time); + this.mode = mode; + shiftId = id; + } + + public String getMode() { + return mode; + } + + public Id getShiftId() { + return shiftId; + } + + @Override + public Map getAttributes() { + Map attr = super.getAttributes(); + attr.put(ATTRIBUTE_MODE, mode); + attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); + return attr; + } +} diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftAssignedEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftAssignedEvent.java index 29678467dd1..b867f305a83 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftAssignedEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftAssignedEvent.java @@ -10,20 +10,18 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftAssignedEvent extends Event { +public class DrtShiftAssignedEvent extends AbstractShiftEvent { + - private final Id shiftId; private final Id vehicleId; - public static final String ATTRIBUTE_SHIFT_ID = "id"; public static final String ATTRIBUTE_VEHICLE_ID = "vehicle"; public static final String EVENT_TYPE = "DRT shift assigned"; - public DrtShiftAssignedEvent(double timeOfDay, Id id, Id id1) { - super(timeOfDay); - shiftId = id; - vehicleId = id1; + public DrtShiftAssignedEvent(double timeOfDay, String mode, Id shiftId, Id vehicleId) { + super(timeOfDay, mode, shiftId); + this.vehicleId = vehicleId; } @Override @@ -34,7 +32,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); return attr; } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakEndedEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakEndedEvent.java index 1bad8287e06..1881907b00e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakEndedEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakEndedEvent.java @@ -11,28 +11,22 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftBreakEndedEvent extends Event { +public class DrtShiftBreakEndedEvent extends AbstractShiftEvent { - private final Id shiftId; private final Id vehicleId; private final Id linkId; public static final String ATTRIBUTE_LINK = "link"; - public static final String ATTRIBUTE_SHIFT_ID = "id"; public static final String ATTRIBUTE_VEHICLE_ID = "vehicle"; public static final String EVENT_TYPE = "DRT shift break ended"; - public DrtShiftBreakEndedEvent(double time, Id shiftId, Id vehicleId, Id linkId) { - super(time); - this.shiftId = shiftId; + public DrtShiftBreakEndedEvent(double time, String mode, Id shiftId, Id vehicleId, Id linkId) { + super(time, mode, shiftId); this.vehicleId = vehicleId; this.linkId = linkId; } - public Id getShiftId() { - return shiftId; - } public Id getVehicleId() { return vehicleId; @@ -50,7 +44,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_LINK, linkId + ""); return attr; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakScheduledEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakScheduledEvent.java index 3e1ac8189dc..c734b5d4078 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakScheduledEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakScheduledEvent.java @@ -11,9 +11,8 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftBreakScheduledEvent extends Event { +public class DrtShiftBreakScheduledEvent extends AbstractShiftEvent { - private final Id shiftId; private final Id vehicleId; private final Id linkId; private final double latestArrival; @@ -25,10 +24,9 @@ public class DrtShiftBreakScheduledEvent extends Event { public static final String EVENT_TYPE = "DRT shift break scheduled"; - public DrtShiftBreakScheduledEvent(double timeOfDay, Id id, Id id1, Id linkId, double latestArrival) { - super(timeOfDay); - shiftId = id; - vehicleId = id1; + public DrtShiftBreakScheduledEvent(double timeOfDay, String mode, Id shiftId, Id vehicleId, Id linkId, double latestArrival) { + super(timeOfDay, mode, shiftId); + this.vehicleId = vehicleId; this.linkId = linkId; this.latestArrival = latestArrival; } @@ -41,7 +39,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_LINK_ID, linkId + ""); attr.put(ATTRIBUTE_LATEST_ARRIVAL, latestArrival + ""); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakStartedEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakStartedEvent.java index a089c150375..22a9a4e7854 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakStartedEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftBreakStartedEvent.java @@ -11,9 +11,8 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftBreakStartedEvent extends Event { +public class DrtShiftBreakStartedEvent extends AbstractShiftEvent { - private final Id shiftId; private final Id vehicleId; private final Id linkId; @@ -23,16 +22,12 @@ public class DrtShiftBreakStartedEvent extends Event { public static final String EVENT_TYPE = "DRT shift break started"; - public DrtShiftBreakStartedEvent(double time, Id shiftId, Id vehicleId, Id linkId) { - super(time); - this.shiftId = shiftId; + public DrtShiftBreakStartedEvent(double time, String mode, Id shiftId, Id vehicleId, Id linkId) { + super(time, mode, shiftId); this.vehicleId = vehicleId; this.linkId = linkId; } - public Id getShiftId() { - return shiftId; - } public Id getVehicleId() { return vehicleId; @@ -50,7 +45,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_LINK, linkId + ""); return attr; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftEndedEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftEndedEvent.java index 98f584f2fd0..2794a123314 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftEndedEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftEndedEvent.java @@ -12,9 +12,8 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftEndedEvent extends Event { +public class DrtShiftEndedEvent extends AbstractShiftEvent { - private final Id shiftId; private final Id vehicleId; private final Id linkId; private final Id operationFacilityId; @@ -26,18 +25,14 @@ public class DrtShiftEndedEvent extends Event { public static final String EVENT_TYPE = "DRT shift ended"; - public DrtShiftEndedEvent(double time, Id shiftId, Id vehicleId, - Id linkId, Id operationFacilityId) { - super(time); - this.shiftId = shiftId; + public DrtShiftEndedEvent(double time, String mode, Id shiftId, Id vehicleId, + Id linkId, Id operationFacilityId) { + super(time, mode, shiftId); this.vehicleId = vehicleId; this.linkId = linkId; this.operationFacilityId = operationFacilityId; } - public Id getShiftId() { - return shiftId; - } public Id getVehicleId() { return vehicleId; @@ -59,7 +54,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_LINK, linkId + ""); attr.put(ATTRIBUTE_OPERATION_FACILITY, operationFacilityId + ""); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftStartedEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftStartedEvent.java index 4f49d8610dc..9b2d1a0da2c 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftStartedEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/DrtShiftStartedEvent.java @@ -11,9 +11,8 @@ /** * @author nkuehnel / MOIA */ -public class DrtShiftStartedEvent extends Event { +public class DrtShiftStartedEvent extends AbstractShiftEvent { - private final Id shiftId; private final Id vehicleId; private final Id linkId; @@ -23,17 +22,12 @@ public class DrtShiftStartedEvent extends Event { public static final String EVENT_TYPE = "DRT shift started"; - public DrtShiftStartedEvent(double time, Id shiftId, Id vehicleId, Id linkId) { - super(time); - this.shiftId = shiftId; + public DrtShiftStartedEvent(double time, String mode, Id shiftId, Id vehicleId, Id linkId) { + super(time, mode, shiftId); this.vehicleId = vehicleId; this.linkId = linkId; } - public Id getShiftId() { - return shiftId; - } - public Id getVehicleId() { return vehicleId; } @@ -50,7 +44,6 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_SHIFT_ID, shiftId + ""); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_LINK, linkId + ""); return attr; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/ShiftFacilityRegistrationEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/ShiftFacilityRegistrationEvent.java index 8e6d5cb5f22..237eeca279f 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/ShiftFacilityRegistrationEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/ShiftFacilityRegistrationEvent.java @@ -12,20 +12,28 @@ */ public class ShiftFacilityRegistrationEvent extends Event { + private final String mode; private final Id vehicleId; private final Id facilityId; + public static final String ATTRIBUTE_MODE = "mode"; + public static final String ATTRIBUTE_FACILITY = "facility"; public static final String ATTRIBUTE_VEHICLE_ID = "vehicle"; public static final String EVENT_TYPE = "Vehicle registered at shift facility"; - public ShiftFacilityRegistrationEvent(double time, Id vehicleId, Id facilityId) { + public ShiftFacilityRegistrationEvent(double time, String mode, Id vehicleId, Id facilityId) { super(time); + this.mode = mode; this.facilityId = facilityId; this.vehicleId = vehicleId; } + public String getMode() { + return mode; + } + @Override public String getEventType() { return EVENT_TYPE; @@ -34,6 +42,7 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); + attr.put(ATTRIBUTE_MODE, mode); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_FACILITY, facilityId + ""); return attr; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/VehicleLeftShiftFacilityEvent.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/VehicleLeftShiftFacilityEvent.java index bc141818ddc..a9742c45bf9 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/VehicleLeftShiftFacilityEvent.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/events/VehicleLeftShiftFacilityEvent.java @@ -12,16 +12,20 @@ */ public class VehicleLeftShiftFacilityEvent extends Event { + private final String mode; private final Id vehicleId; private final Id facilityId; + public static final String ATTRIBUTE_MODE = "mode"; + public static final String ATTRIBUTE_FACILITY = "facility"; public static final String ATTRIBUTE_VEHICLE_ID = "vehicle"; public static final String EVENT_TYPE = "Vehicle left shift facility"; - public VehicleLeftShiftFacilityEvent(double time, Id vehicleId, Id facilityId) { + public VehicleLeftShiftFacilityEvent(double time, String mode, Id vehicleId, Id facilityId) { super(time); + this.mode = mode; this.facilityId = facilityId; this.vehicleId = vehicleId; } @@ -34,6 +38,7 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); + attr.put(ATTRIBUTE_MODE, mode); attr.put(ATTRIBUTE_VEHICLE_ID, vehicleId + ""); attr.put(ATTRIBUTE_FACILITY, facilityId + ""); return attr; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeModule.java index 5005c8227c9..91e324456d1 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/run/ShiftDrtModeModule.java @@ -91,15 +91,15 @@ public void install() { } bindModal(ShiftDurationXY.class).toProvider(modalProvider( - getter -> new ShiftDurationXY(getter.getModal(new TypeLiteral>(){})) + getter -> new ShiftDurationXY(getter.getModal(new TypeLiteral>(){}), getMode()) )).asEagerSingleton(); bindModal(BreakCorridorXY.class).toProvider(modalProvider( - getter -> new BreakCorridorXY(getter.getModal(new TypeLiteral>(){})) + getter -> new BreakCorridorXY(getMode(), getter.getModal(new TypeLiteral>(){})) )).asEagerSingleton(); bindModal(ShiftHistogram.class).toProvider(modalProvider( - getter -> new ShiftHistogram(getter.get(Population.class), getter.get(Config.class)))).asEagerSingleton(); + getter -> new ShiftHistogram(getter.get(Population.class), getMode(), getter.get(Config.class)))).asEagerSingleton(); addEventHandlerBinding().to(modalKey(ShiftDurationXY.class)); addEventHandlerBinding().to(modalKey(BreakCorridorXY.class)); 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 5fbae488eec..a10c6e409e3 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 @@ -113,7 +113,7 @@ public DrtShifts get() { })); bindModal(DrtShiftDispatcher.class).toProvider(modalProvider( - getter -> new DrtShiftDispatcherImpl(getter.getModal(DrtShifts.class), getter.getModal(Fleet.class), + getter -> new DrtShiftDispatcherImpl(getMode(), getter.getModal(DrtShifts.class), getter.getModal(Fleet.class), getter.get(MobsimTimer.class), getter.getModal(OperationFacilities.class), getter.getModal(OperationFacilityFinder.class), getter.getModal(ShiftTaskScheduler.class), getter.getModal(Network.class), getter.get(EventsManager.class), shiftsParams, new DefaultShiftStartLogic(), new DefaultAssignShiftToVehicleLogic(shiftsParams))) diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java index b3e8db5e38d..0679adaefb8 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java @@ -41,7 +41,7 @@ public class ShiftEfficiencyTest { void testDrtShiftEfficiency() { EventsManager events = new EventsManagerImpl(); - ShiftEfficiencyTracker shiftEfficiencyTracker = new ShiftEfficiencyTracker(); + ShiftEfficiencyTracker shiftEfficiencyTracker = new ShiftEfficiencyTracker("drt"); events.addHandler(shiftEfficiencyTracker); events.initProcessing(); @@ -50,11 +50,11 @@ void testDrtShiftEfficiency() { Id vehicle1 = Id.create("vehicle1", DvrpVehicle.class); Id operationFacility1 = Id.create("operationFacility1", OperationFacility.class); - events.processEvent(new DrtShiftStartedEvent(10 * 3600, shift1, vehicle1, link1) + events.processEvent(new DrtShiftStartedEvent(10 * 3600, "drt", shift1, vehicle1, link1) ); // should throw because vehicle is already registered with another shift Assertions.assertThrows(RuntimeException.class, () -> { - events.processEvent(new DrtShiftStartedEvent(10 * 3600, shift1, vehicle1, link1)); + events.processEvent(new DrtShiftStartedEvent(10 * 3600, "drt", shift1, vehicle1, link1)); }); Id request1 = Id.create("request1", Request.class); @@ -69,7 +69,7 @@ void testDrtShiftEfficiency() { Assertions.assertEquals(FARE, shiftEfficiencyTracker.getCurrentRecord().getRevenueByShift().get(shift1), MatsimTestUtils.EPSILON); Assertions.assertFalse(shiftEfficiencyTracker.getCurrentRecord().getFinishedShifts().containsKey(shift1)); - events.processEvent(new DrtShiftEndedEvent(20 * 3600, shift1, vehicle1, link1, operationFacility1)); + events.processEvent(new DrtShiftEndedEvent(20 * 3600, "drt", shift1, vehicle1, link1, operationFacility1)); Assertions.assertTrue(shiftEfficiencyTracker.getCurrentRecord().getFinishedShifts().containsKey(shift1)); } }