diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunPrebookingShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunPrebookingShiftDrtScenarioIT.java index 2ef3b6d6d1b..01f5e27b837 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunPrebookingShiftDrtScenarioIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunPrebookingShiftDrtScenarioIT.java @@ -37,6 +37,8 @@ import org.matsim.contrib.dvrp.fleet.FleetSpecificationImpl; import org.matsim.contrib.dvrp.fleet.ImmutableDvrpVehicleSpecification; import org.matsim.contrib.dvrp.passenger.PassengerRequestRejectedEventHandler; +import org.matsim.contrib.dvrp.passenger.PassengerRequestScheduledEventHandler; +import org.matsim.contrib.dvrp.passenger.PassengerRequestSubmittedEventHandler; import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; @@ -71,10 +73,15 @@ void testWithReattempts() { DrtWithExtensionsConfigGroup drtWithShiftsConfigGroup = (DrtWithExtensionsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); final Controler run = prepare(drtWithShiftsConfigGroup, multiModeDrtConfigGroup); + Multiset> submittedPersons = HashMultiset.create(); + Multiset> scheduledPersons = HashMultiset.create(); Multiset> rejectedPersons = HashMultiset.create(); + run.addOverridingModule(new AbstractModule() { @Override public void install() { + addEventHandlerBinding().toInstance((PassengerRequestSubmittedEventHandler) event -> submittedPersons.addAll(event.getPersonIds())); + addEventHandlerBinding().toInstance((PassengerRequestScheduledEventHandler) event -> scheduledPersons.addAll(event.getPersonIds())); addEventHandlerBinding().toInstance((PassengerRequestRejectedEventHandler) event -> rejectedPersons.addAll(event.getPersonIds())); } }); @@ -91,11 +98,25 @@ public void install() { run.run(); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(1) )); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(3))); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(1))); + Assertions.assertEquals(2, submittedPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(3))); + Assertions.assertEquals(2, submittedPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(2, submittedPersons.count(Id.createPersonId(6))); + + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(1))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(3))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(0, scheduledPersons.count(Id.createPersonId(6))); + + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(1))); Assertions.assertEquals(1, rejectedPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(3))); Assertions.assertEquals(1, rejectedPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(5))); Assertions.assertEquals(2, rejectedPersons.count(Id.createPersonId(6))); } @@ -106,10 +127,15 @@ void testWithoutReattempts() { DrtWithExtensionsConfigGroup drtWithShiftsConfigGroup = (DrtWithExtensionsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); final Controler run = prepare(drtWithShiftsConfigGroup, multiModeDrtConfigGroup); + Multiset> submittedPersons = HashMultiset.create(); + Multiset> scheduledPersons = HashMultiset.create(); Multiset> rejectedPersons = HashMultiset.create(); + run.addOverridingModule(new AbstractModule() { @Override public void install() { + addEventHandlerBinding().toInstance((PassengerRequestSubmittedEventHandler) event -> submittedPersons.addAll(event.getPersonIds())); + addEventHandlerBinding().toInstance((PassengerRequestScheduledEventHandler) event -> scheduledPersons.addAll(event.getPersonIds())); addEventHandlerBinding().toInstance((PassengerRequestRejectedEventHandler) event -> rejectedPersons.addAll(event.getPersonIds())); } }); @@ -126,11 +152,25 @@ public void install() { run.run(); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(1) )); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(3))); - Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(1))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(3))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(1, submittedPersons.count(Id.createPersonId(6))); + + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(1))); + Assertions.assertEquals(0, scheduledPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(3))); + Assertions.assertEquals(0, scheduledPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(1, scheduledPersons.count(Id.createPersonId(5))); + Assertions.assertEquals(0, scheduledPersons.count(Id.createPersonId(6))); + + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(1))); Assertions.assertEquals(1, rejectedPersons.count(Id.createPersonId(2))); + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(3))); Assertions.assertEquals(1, rejectedPersons.count(Id.createPersonId(4))); + Assertions.assertEquals(0, rejectedPersons.count(Id.createPersonId(5))); Assertions.assertEquals(1, rejectedPersons.count(Id.createPersonId(6))); } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtEventSequenceCollector.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtEventSequenceCollector.java index b8b095cd1dc..90836e785cc 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtEventSequenceCollector.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtEventSequenceCollector.java @@ -159,7 +159,7 @@ public List getDrtFares() { } public boolean isCompleted() { - return personEvents.values().stream().allMatch(pe -> pe.droppedOff != null); + return submitted.getPersonIds().stream().allMatch(personId -> personEvents.get(personId).droppedOff != null); } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingManager.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingManager.java index b610ececae7..04d8df45161 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingManager.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/prebooking/PrebookingManager.java @@ -395,9 +395,13 @@ private void processRejections(double now) { if(abortRejectedPrebookings) { for (Id passengerId : item.request.getPassengerIds()) { MobsimAgent agent = internalInterface.getMobsim().getAgents().get(passengerId); - ((HasModifiablePlan) agent).resetCaches(); - agent.setStateToAbort(mobsimTimer.getTimeOfDay()); - internalInterface.arrangeNextAgentState(agent); + PlanElement planElement = WithinDayAgentUtils.getCurrentPlanElement(agent); + if(planElement instanceof Activity activity) { + activity.setEndTime(Double.POSITIVE_INFINITY); + activity.setMaximumDurationUndefined(); + ((HasModifiablePlan) agent).resetCaches(); + internalInterface.getMobsim().rescheduleActivityEnd(agent); + } eventsManager.processEvent(new PersonStuckEvent(now, agent.getId(), agent.getCurrentLinkId(), this.mode)); internalInterface.getMobsim().getAgentCounter().incLost(); diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngine.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngine.java index 7406ceaa359..96571f584da 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngine.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngine.java @@ -153,7 +153,7 @@ private void handleGroupDepartures(double now) { private void handleDepartureImpl(double now, List group) { List> groupIds = group.stream().map(Identifiable::getId).toList(); - MobsimPassengerAgent representative = group.get(0); + MobsimPassengerAgent representative = group.getFirst(); Id fromLinkId = representative.getCurrentLinkId(); Id toLinkId = representative.getDestinationLinkId();