Skip to content

Commit

Permalink
Merge pull request #115 from moia-oss/master
Browse files Browse the repository at this point in the history
Update MATSim CW36
  • Loading branch information
mfrawley-moia authored Sep 2, 2024
2 parents c520f0b + 2cbbf82 commit 815d3bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,10 +73,15 @@ void testWithReattempts() {
DrtWithExtensionsConfigGroup drtWithShiftsConfigGroup = (DrtWithExtensionsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt");
final Controler run = prepare(drtWithShiftsConfigGroup, multiModeDrtConfigGroup);

Multiset<Id<Person>> submittedPersons = HashMultiset.create();
Multiset<Id<Person>> scheduledPersons = HashMultiset.create();
Multiset<Id<Person>> 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()));
}
});
Expand All @@ -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)));
}

Expand All @@ -106,10 +127,15 @@ void testWithoutReattempts() {
DrtWithExtensionsConfigGroup drtWithShiftsConfigGroup = (DrtWithExtensionsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt");
final Controler run = prepare(drtWithShiftsConfigGroup, multiModeDrtConfigGroup);

Multiset<Id<Person>> submittedPersons = HashMultiset.create();
Multiset<Id<Person>> scheduledPersons = HashMultiset.create();
Multiset<Id<Person>> 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()));
}
});
Expand All @@ -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)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<PersonMoneyEvent> getDrtFares() {
}

public boolean isCompleted() {
return personEvents.values().stream().allMatch(pe -> pe.droppedOff != null);
return submitted.getPersonIds().stream().allMatch(personId -> personEvents.get(personId).droppedOff != null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ private void processRejections(double now) {
if(abortRejectedPrebookings) {
for (Id<Person> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void handleGroupDepartures(double now) {
private void handleDepartureImpl(double now, List<MobsimPassengerAgent> group) {
List<Id<Person>> groupIds = group.stream().map(Identifiable::getId).toList();

MobsimPassengerAgent representative = group.get(0);
MobsimPassengerAgent representative = group.getFirst();

Id<Link> fromLinkId = representative.getCurrentLinkId();
Id<Link> toLinkId = representative.getDestinationLinkId();
Expand Down

0 comments on commit 815d3bd

Please sign in to comment.