From a77fcef08b0c0348cebc9bd2316640b1e11e4eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Thu, 1 Feb 2024 19:46:40 +0100 Subject: [PATCH] feat: let DefaultPassengerEngine respond to multiple modes (#3083) --- .../dvrp/passenger/DefaultPassengerEngine.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 7e11e5e8dd8..7406ceaa359 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 @@ -53,6 +53,8 @@ public final class DefaultPassengerEngine implements PassengerEngine, PassengerRequestRejectedEventHandler { private final String mode; + private final Set departureModes; + private final MobsimTimer mobsimTimer; private final EventsManager eventsManager; @@ -79,9 +81,10 @@ public final class DefaultPassengerEngine implements PassengerEngine, PassengerR private final Map, List> groupDepartureStage = new LinkedHashMap<>(); - DefaultPassengerEngine(String mode, EventsManager eventsManager, MobsimTimer mobsimTimer, PassengerRequestCreator requestCreator, + DefaultPassengerEngine(String mode, Set departureModes, EventsManager eventsManager, MobsimTimer mobsimTimer, PassengerRequestCreator requestCreator, VrpOptimizer optimizer, Network network, PassengerRequestValidator requestValidator, AdvanceRequestProvider advanceRequestProvider, PassengerGroupIdentifier passengerGroupIdentifier) { this.mode = mode; + this.departureModes = departureModes; this.mobsimTimer = mobsimTimer; this.requestCreator = requestCreator; this.optimizer = optimizer; @@ -197,7 +200,7 @@ public void afterSim() { @Override public boolean handleDeparture(double now, MobsimAgent agent, Id fromLinkId) { - if (!agent.getMode().equals(mode)) { + if (!departureModes.contains(agent.getMode())) { return false; } @@ -285,8 +288,12 @@ public void handleEvent(PassengerRequestRejectedEvent event) { rejectedRequestsEvents.add(event); } } - + public static Provider createProvider(String mode) { + return createProvider(mode, Collections.singleton(mode)); + } + + public static Provider createProvider(String mode, Set departureModes) { return new ModalProviders.AbstractProvider<>(mode, DvrpModes::mode) { @Inject private EventsManager eventsManager; @@ -296,7 +303,7 @@ public static Provider createProvider(String mode) { @Override public DefaultPassengerEngine get() { - return new DefaultPassengerEngine(getMode(), eventsManager, mobsimTimer, getModalInstance(PassengerRequestCreator.class), + return new DefaultPassengerEngine(getMode(), departureModes, eventsManager, mobsimTimer, getModalInstance(PassengerRequestCreator.class), getModalInstance(VrpOptimizer.class), getModalInstance(Network.class), getModalInstance(PassengerRequestValidator.class), getModalInstance(AdvanceRequestProvider.class), getModalInstance(PassengerGroupIdentifier.class)); }