Skip to content

Commit

Permalink
merge PrebookingPassengerEngine into DefaultPassengerEngine, introduc…
Browse files Browse the repository at this point in the history
…e AdvanceRequestProvider
  • Loading branch information
sebhoerl committed Nov 11, 2023
1 parent 0730ed2 commit ea6f0a8
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.matsim.contrib.drt.stops.PassengerStopDurationProvider;
import org.matsim.contrib.drt.vrpagent.DrtActionCreator;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.passenger.PassengerEngine;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.schedule.Task;
import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic;
import org.matsim.contrib.dynagent.DynAction;
Expand All @@ -24,13 +26,13 @@
*/
public class PrebookingActionCreator implements VrpAgentLogic.DynActionCreator {
private final VrpAgentLogic.DynActionCreator delegate;
private final PrebookingPassengerEngine passengerEngine;
private final PassengerHandler passengerHandler;
private final PassengerStopDurationProvider stopDurationProvider;

public PrebookingActionCreator(PrebookingPassengerEngine passengerEngine, VrpAgentLogic.DynActionCreator delegate,
public PrebookingActionCreator(PassengerHandler passengerHandler, VrpAgentLogic.DynActionCreator delegate,
PassengerStopDurationProvider stopDurationProvider) {
this.delegate = delegate;
this.passengerEngine = passengerEngine;
this.passengerHandler = passengerHandler;
this.stopDurationProvider = stopDurationProvider;
}

Expand All @@ -40,7 +42,7 @@ public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now

if (getBaseTypeOrElseThrow(task).equals(DrtTaskBaseType.STOP)) {
DrtStopTask stopTask = (DrtStopTask) task;
return new PrebookingStopActivity(passengerEngine, dynAgent, stopTask, stopTask.getDropoffRequests(),
return new PrebookingStopActivity(passengerHandler, dynAgent, stopTask, stopTask.getDropoffRequests(),
stopTask.getPickupRequests(), DrtActionCreator.DRT_STOP_NAME, () -> stopTask.getEndTime(), stopDurationProvider, vehicle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.Nullable;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.IdMap;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -15,6 +17,7 @@
import org.matsim.contrib.drt.extension.prebooking.events.PassengerRequestBookedEvent;
import org.matsim.contrib.dvrp.optimizer.Request;
import org.matsim.contrib.dvrp.optimizer.VrpOptimizer;
import org.matsim.contrib.dvrp.passenger.AdvanceRequestProvider;
import org.matsim.contrib.dvrp.passenger.PassengerRequest;
import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator;
import org.matsim.contrib.dvrp.passenger.PassengerRequestRejectedEvent;
Expand Down Expand Up @@ -46,7 +49,7 @@
*
* @author Sebastian Hörl (sebhoerl), IRT SystemX
*/
public class PrebookingManager implements MobsimEngine {
public class PrebookingManager implements MobsimEngine, AdvanceRequestProvider {
private final String mode;

private final Network network;
Expand Down Expand Up @@ -156,7 +159,9 @@ private record QueueItem(MobsimAgent person, Leg leg, double earliestDepartureTi

// Interface with PassengerEngine

PassengerRequest retrievePrebookedRequest(MobsimAgent agent, Leg leg) {
@Override
@Nullable
public PassengerRequest retrieveRequest(MobsimAgent agent, Leg leg) {
Verify.verify(leg.getMode().equals(mode), "Invalid mode for this prebooking manager");

Id<Request> requestId = getRequestId(leg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void install() {
}));

// install QSim bindings / overrides
installOverridingQSimModule(new PrebookingModeQSimModule(getMode(), drtConfig, isElectric));
installOverridingQSimModule(new PrebookingModeQSimModule(getMode(), isElectric));

// analysis
install(new PrebookingModeAnalysisModule(getMode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.extension.edrt.EDrtActionCreator;
import org.matsim.contrib.drt.extension.prebooking.electric.ElectricPrebookingActionCreator;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.stops.PassengerStopDurationProvider;
import org.matsim.contrib.drt.vrpagent.DrtActionCreator;
import org.matsim.contrib.dvrp.optimizer.VrpOptimizer;
import org.matsim.contrib.dvrp.passenger.AdvanceRequestProvider;
import org.matsim.contrib.dvrp.passenger.PassengerEngine;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator;
Expand All @@ -20,63 +20,43 @@

class PrebookingModeQSimModule extends AbstractDvrpModeQSimModule {
private final boolean isElectric;
private final DrtConfigGroup drtConfig;

PrebookingModeQSimModule(String mode, DrtConfigGroup drtConfig, boolean isElectric) {
PrebookingModeQSimModule(String mode, boolean isElectric) {
super(mode);

this.isElectric = isElectric;
this.drtConfig = drtConfig;
}

@Override
protected void configureQSim() {
// bind the custom PrebookingActionCreator
if (!isElectric) {
bindModal(PrebookingActionCreator.class).toProvider(modalProvider(getter -> {
PrebookingPassengerEngine passengerEngine = (PrebookingPassengerEngine) getter
.getModal(PassengerHandler.class);
PassengerHandler passengerHandler = (PassengerEngine) getter.getModal(PassengerHandler.class);
DrtActionCreator delegate = getter.getModal(DrtActionCreator.class);
PassengerStopDurationProvider stopDurationProvider = getter
.getModal(PassengerStopDurationProvider.class);

return new PrebookingActionCreator(passengerEngine, delegate, stopDurationProvider);
return new PrebookingActionCreator(passengerHandler, delegate, stopDurationProvider);
})).in(Singleton.class);
bindModal(VrpAgentLogic.DynActionCreator.class).to(modalKey(PrebookingActionCreator.class));
} else {
bindModal(ElectricPrebookingActionCreator.class).toProvider(modalProvider(getter -> {
// delegate to edrt instead of drt
EDrtActionCreator delegate = getter.getModal(EDrtActionCreator.class);

PrebookingPassengerEngine passengerEngine = (PrebookingPassengerEngine) getter
.getModal(PassengerHandler.class);
PassengerHandler passengerHandler = getter.getModal(PassengerHandler.class);
PassengerStopDurationProvider stopDurationProvider = getter
.getModal(PassengerStopDurationProvider.class);
MobsimTimer timer = getter.get(MobsimTimer.class);
PrebookingManager prebookingManager = getter.getModal(PrebookingManager.class);

return new ElectricPrebookingActionCreator(passengerEngine, delegate, stopDurationProvider, timer,
return new ElectricPrebookingActionCreator(passengerHandler, delegate, stopDurationProvider, timer,
prebookingManager);
})).in(Singleton.class);
bindModal(VrpAgentLogic.DynActionCreator.class).to(modalKey(ElectricPrebookingActionCreator.class));
}

// override the PassengerEngine
bindModal(PrebookingPassengerEngine.class).toProvider(modalProvider(getter -> {
EventsManager eventsManager = getter.get(EventsManager.class);
MobsimTimer mobsimTimer = getter.get(MobsimTimer.class);

PassengerRequestCreator requestCreator = getter.getModal(PassengerRequestCreator.class);
VrpOptimizer optimizer = getter.getModal(VrpOptimizer.class);
Network network = getter.getModal(Network.class);
PassengerRequestValidator requestValidator = getter.getModal(PassengerRequestValidator.class);
PrebookingManager prebookingManager = getter.getModal(PrebookingManager.class);

return new PrebookingPassengerEngine(getMode(), eventsManager, mobsimTimer, requestCreator, optimizer,
network, requestValidator, prebookingManager);
})).in(Singleton.class);
bindModal(PassengerEngine.class).to(modalKey(PrebookingPassengerEngine.class));

// bind the prebooking manager
bindModal(PrebookingManager.class).toProvider(modalProvider(getter -> {
Network network = getter.getModal(Network.class);
Expand All @@ -89,5 +69,6 @@ protected void configureQSim() {
eventsManager);
})).in(Singleton.class);
addModalQSimComponentBinding().to(modalKey(PrebookingManager.class));
bindModal(AdvanceRequestProvider.class).to(modalKey(PrebookingManager.class));
}
}
Loading

0 comments on commit ea6f0a8

Please sign in to comment.