Skip to content

Commit

Permalink
factor out RequestQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Nov 10, 2023
1 parent d97cae0 commit f44764d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.matsim.contrib.drt.optimizer.insertion.UnplannedRequestInserter;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingStrategy;
import org.matsim.contrib.drt.passenger.DrtOfferAcceptor;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
import org.matsim.contrib.drt.scheduler.DefaultRequestInsertionScheduler;
Expand All @@ -55,9 +54,7 @@
import org.matsim.contrib.drt.stops.StopTimeCalculator;
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.optimizer.VrpOptimizer;
import org.matsim.contrib.dvrp.passenger.DefaultRequestQueue;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.passenger.RequestQueue;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
Expand Down Expand Up @@ -93,13 +90,11 @@ protected void configureQSim() {

bindModal(DefaultDrtOptimizer.class).toProvider(modalProvider(
getter -> {
RequestQueue<DrtRequest> requestQueue = DefaultRequestQueue.withLimitedAdvanceRequestPlanningHorizon(drtCfg.advanceRequestPlanningHorizon);

return new DefaultDrtOptimizer(drtCfg, getter.getModal(Fleet.class), getter.get(MobsimTimer.class),
getter.getModal(DepotFinder.class), getter.getModal(RebalancingStrategy.class),
getter.getModal(DrtScheduleInquiry.class), getter.getModal(ScheduleTimingUpdater.class),
getter.getModal(EmptyVehicleRelocator.class), getter.getModal(UnplannedRequestInserter.class),
getter.getModal(DrtRequestInsertionRetryQueue.class), requestQueue);
getter.getModal(DrtRequestInsertionRetryQueue.class));
})).asEagerSingleton();

bindModal(ChargingInfrastructure.class).toProvider(modalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.matsim.contrib.drt.optimizer.insertion.InsertionCostCalculator;
import org.matsim.contrib.drt.optimizer.insertion.UnplannedRequestInserter;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingStrategy;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtStayTaskEndTimeCalculator;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
Expand All @@ -54,9 +53,7 @@
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.fleet.FleetSpecification;
import org.matsim.contrib.dvrp.fleet.Fleets;
import org.matsim.contrib.dvrp.passenger.DefaultRequestQueue;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.passenger.RequestQueue;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
Expand Down Expand Up @@ -112,14 +109,12 @@ public DrtShifts get() {

addModalComponent(DrtOptimizer.class, modalProvider(
getter -> {
RequestQueue<DrtRequest> requestQueue = DefaultRequestQueue.withLimitedAdvanceRequestPlanningHorizon(drtCfg.advanceRequestPlanningHorizon);

return new ShiftDrtOptimizer(
new DefaultDrtOptimizer(drtCfg, getter.getModal(Fleet.class), getter.get(MobsimTimer.class),
getter.getModal(DepotFinder.class), getter.getModal(RebalancingStrategy.class),
getter.getModal(DrtScheduleInquiry.class), getter.getModal(ScheduleTimingUpdater.class),
getter.getModal(EmptyVehicleRelocator.class), getter.getModal(UnplannedRequestInserter.class),
getter.getModal(DrtRequestInsertionRetryQueue.class), requestQueue
getter.getModal(DrtRequestInsertionRetryQueue.class)
),
getter.getModal(DrtShiftDispatcher.class),
getter.getModal(ScheduleTimingUpdater.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
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.passenger.DrtRequest;
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.DefaultRequestQueue;
import org.matsim.contrib.dvrp.passenger.PassengerEngine;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator;
import org.matsim.contrib.dvrp.passenger.PassengerRequestValidator;
import org.matsim.contrib.dvrp.passenger.RequestQueue;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.mobsim.framework.MobsimTimer;

import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;

class PrebookingModeQSimModule extends AbstractDvrpModeQSimModule {
private final boolean isElectric;
Expand Down Expand Up @@ -93,15 +89,5 @@ protected void configureQSim() {
eventsManager);
})).in(Singleton.class);
addModalQSimComponentBinding().to(modalKey(PrebookingManager.class));

bindModal(new TypeLiteral<RequestQueue<DrtRequest>>() {
}).toProvider(modalProvider(getter -> {
PrebookingManager prebookingManager = getter.getModal(PrebookingManager.class);
RequestQueue<DrtRequest> delegate = DefaultRequestQueue
.withLimitedAdvanceRequestPlanningHorizon(drtConfig.advanceRequestPlanningHorizon);

return new PrebookingRequestQueue<>(prebookingManager, delegate);
})).in(Singleton.class);

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

package org.matsim.contrib.drt.optimizer;

import static org.matsim.contrib.drt.schedule.DrtTaskBaseType.STAY;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
Expand All @@ -37,13 +41,10 @@
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.optimizer.Request;
import org.matsim.contrib.dvrp.passenger.RequestQueue;
import org.matsim.contrib.dvrp.schedule.ScheduleTimingUpdater;
import org.matsim.core.mobsim.framework.MobsimTimer;
import org.matsim.core.mobsim.framework.events.MobsimBeforeSimStepEvent;

import static org.matsim.contrib.drt.schedule.DrtTaskBaseType.STAY;

/**
* @author michalm
*/
Expand All @@ -62,12 +63,11 @@ public class DefaultDrtOptimizer implements DrtOptimizer {
private final UnplannedRequestInserter requestInserter;
private final DrtRequestInsertionRetryQueue insertionRetryQueue;

private final RequestQueue<DrtRequest> unplannedRequests;
private final Queue<DrtRequest> unplannedRequests = new LinkedList<>();

public DefaultDrtOptimizer(DrtConfigGroup drtCfg, Fleet fleet, MobsimTimer mobsimTimer, DepotFinder depotFinder,
RebalancingStrategy rebalancingStrategy, DrtScheduleInquiry scheduleInquiry, ScheduleTimingUpdater scheduleTimingUpdater,
EmptyVehicleRelocator relocator, UnplannedRequestInserter requestInserter, DrtRequestInsertionRetryQueue insertionRetryQueue,
RequestQueue<DrtRequest> requestQueue) {
EmptyVehicleRelocator relocator, UnplannedRequestInserter requestInserter, DrtRequestInsertionRetryQueue insertionRetryQueue) {
this.drtCfg = drtCfg;
this.fleet = fleet;
this.mobsimTimer = mobsimTimer;
Expand All @@ -78,23 +78,20 @@ public DefaultDrtOptimizer(DrtConfigGroup drtCfg, Fleet fleet, MobsimTimer mobsi
this.relocator = relocator;
this.requestInserter = requestInserter;
this.insertionRetryQueue = insertionRetryQueue;
this.unplannedRequests = requestQueue;

rebalancingInterval = drtCfg.getRebalancingParams().map(rebalancingParams -> rebalancingParams.interval).orElse(null);
}

@Override
public void notifyMobsimBeforeSimStep(@SuppressWarnings("rawtypes") MobsimBeforeSimStepEvent e) {
unplannedRequests.updateQueuesOnNextTimeSteps(e.getSimulationTime());

boolean scheduleTimingUpdated = false;
if (!unplannedRequests.getSchedulableRequests().isEmpty() || insertionRetryQueue.hasRequestsToRetryNow(e.getSimulationTime())) {
if (!unplannedRequests.isEmpty() || insertionRetryQueue.hasRequestsToRetryNow(e.getSimulationTime())) {
for (DvrpVehicle v : fleet.getVehicles().values()) {
scheduleTimingUpdater.updateTimings(v);
}
scheduleTimingUpdated = true;

requestInserter.scheduleUnplannedRequests(unplannedRequests.getSchedulableRequests());
requestInserter.scheduleUnplannedRequests(unplannedRequests);
}

relocateVehiclesToDepot(drtCfg.returnToDepotEvaluationInterval, drtCfg.returnToDepotTimeout);
Expand Down Expand Up @@ -127,7 +124,7 @@ private void rebalanceFleet() {

@Override
public void requestSubmitted(Request request) {
unplannedRequests.addRequest((DrtRequest)request);
unplannedRequests.add((DrtRequest)request);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.matsim.contrib.drt.optimizer.insertion.selective.SelectiveInsertionSearchQSimModule;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingStrategy;
import org.matsim.contrib.drt.passenger.DrtOfferAcceptor;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtStayTaskEndTimeCalculator;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
Expand All @@ -51,9 +50,7 @@
import org.matsim.contrib.drt.vrpagent.DrtActionCreator;
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.optimizer.VrpOptimizer;
import org.matsim.contrib.dvrp.passenger.DefaultRequestQueue;
import org.matsim.contrib.dvrp.passenger.PassengerHandler;
import org.matsim.contrib.dvrp.passenger.RequestQueue;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
Expand All @@ -67,7 +64,6 @@
import org.matsim.core.router.util.TravelTime;

import com.google.inject.Inject;
import com.google.inject.TypeLiteral;

/**
* @author Michal Maciejewski (michalm)
Expand All @@ -88,13 +84,8 @@ protected void configureQSim() {
getter.getModal(DepotFinder.class), getter.getModal(RebalancingStrategy.class),
getter.getModal(DrtScheduleInquiry.class), getter.getModal(ScheduleTimingUpdater.class),
getter.getModal(EmptyVehicleRelocator.class), getter.getModal(UnplannedRequestInserter.class),
getter.getModal(DrtRequestInsertionRetryQueue.class),
getter.getModal(new TypeLiteral<RequestQueue<DrtRequest>>() {}));
getter.getModal(DrtRequestInsertionRetryQueue.class));
}));

bindModal(new TypeLiteral<RequestQueue<DrtRequest>>() {}).toProvider(modalProvider(getter -> {
return DefaultRequestQueue.withLimitedAdvanceRequestPlanningHorizon(drtCfg.advanceRequestPlanningHorizon);
}));

bindModal(DepotFinder.class).toProvider(
modalProvider(getter -> new NearestStartLinkAsDepot(getter.getModal(Fleet.class)))).asEagerSingleton();
Expand Down

This file was deleted.

Loading

0 comments on commit f44764d

Please sign in to comment.