Skip to content

Commit

Permalink
add middleman for drt optimization constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel committed May 21, 2024
1 parent 70eec34 commit 12ca6a5
Show file tree
Hide file tree
Showing 26 changed files with 355 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandConfigGroup;
import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandModule;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtConfigs;
Expand Down Expand Up @@ -141,9 +142,10 @@ private static void loadConfigGroups(Config config) {
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);

DrtConfigGroup drtCfg = new DrtConfigGroup();
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 2 * 3600;
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 5;
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 15 * 60;
DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
defaultConstraintsSet.maxWaitTime = 2 * 3600;
defaultConstraintsSet.maxTravelTimeAlpha = 5;
defaultConstraintsSet.maxTravelTimeBeta = 15 * 60;
drtCfg.stopDuration = 60;
drtCfg.vehiclesFile = "jointDemand_vehicles.xml";
multiModeDrtConfigGroup.addParameterSet(drtCfg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@
import org.matsim.contrib.drt.extension.edrt.schedule.EDrtStayTaskEndTimeCalculator;
import org.matsim.contrib.drt.extension.edrt.schedule.EDrtTaskFactoryImpl;
import org.matsim.contrib.drt.extension.edrt.scheduler.EmptyVehicleChargingScheduler;
import org.matsim.contrib.drt.optimizer.DefaultDrtOptimizer;
import org.matsim.contrib.drt.optimizer.DrtModeOptimizerQSimModule;
import org.matsim.contrib.drt.optimizer.DrtOptimizer;
import org.matsim.contrib.drt.optimizer.DrtRequestInsertionRetryParams;
import org.matsim.contrib.drt.optimizer.DrtRequestInsertionRetryQueue;
import org.matsim.contrib.drt.optimizer.QSimScopeForkJoinPoolHolder;
import org.matsim.contrib.drt.optimizer.VehicleEntry;
import org.matsim.contrib.drt.optimizer.*;
import org.matsim.contrib.drt.optimizer.depot.DepotFinder;
import org.matsim.contrib.drt.optimizer.insertion.CostCalculationStrategy;
import org.matsim.contrib.drt.optimizer.insertion.DefaultInsertionCostCalculator;
Expand Down Expand Up @@ -147,8 +141,9 @@ public EmptyVehicleChargingScheduler get() {
bindModal(VehicleEntry.EntryFactory.class).toProvider(
EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider.class).asEagerSingleton();

DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
bindModal(CostCalculationStrategy.class)
.to(drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated
.to(defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated
?
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();
Expand Down Expand Up @@ -182,7 +177,7 @@ public EmptyVehicleRelocator get() {
.asEagerSingleton();

bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay)));
defaultConstraintsSet.maxAllowedPickupDelay)));
bindModal(DrtOfferAcceptor.class).to(modalKey(DefaultOfferAcceptor.class));

bindModal(ScheduleTimingUpdater.class).toProvider(modalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams;
import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams;
Expand Down Expand Up @@ -53,16 +54,17 @@ void test() {

DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup;
drtConfigGroup.mode = TransportMode.drt;
drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.5;
drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta = 10. * 60.;
drtConfigGroup.stopDuration = 30.;
drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWaitTime = 600.;
drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated = true;
DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
defaultConstraintsSet.maxTravelTimeAlpha = 1.5;
defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.;
defaultConstraintsSet.maxWaitTime = 600.;
defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
defaultConstraintsSet.maxWalkDistance = 1000.;
drtConfigGroup.useModeFilteredSubnetwork = false;
drtConfigGroup.vehiclesFile = fleetFile;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
drtConfigGroup.plotDetailedCustomerStats = true;
drtConfigGroup.getDefaultDrtOptimizationConstraintsParam().maxWalkDistance = 1000.;
drtConfigGroup.idleVehiclesReturnToDepots = false;

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import org.matsim.contrib.drt.extension.operations.EDrtOperationsControlerCreator;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams;
import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.ev.EvConfigGroup;
Expand Down Expand Up @@ -57,17 +57,17 @@ void test() {

DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup;
drtConfigGroup.mode = TransportMode.drt;
DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam();
constraintsParam.maxTravelTimeAlpha = 1.5;
constraintsParam.maxTravelTimeBeta = 10. * 60.;
DrtOptimizationConstraintsSet constraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
constraintsSet.maxTravelTimeAlpha = 1.5;
constraintsSet.maxTravelTimeBeta = 10. * 60.;
drtConfigGroup.stopDuration = 30.;
constraintsParam.maxWaitTime = 600.;
constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
constraintsSet.maxWaitTime = 600.;
constraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
drtConfigGroup.useModeFilteredSubnetwork = false;
drtConfigGroup.vehiclesFile = fleetFile;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
drtConfigGroup.plotDetailedCustomerStats = true;
constraintsParam.maxWalkDistance = 1000.;
constraintsSet.maxWalkDistance = 1000.;
drtConfigGroup.idleVehiclesReturnToDepots = false;

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import org.matsim.contrib.drt.extension.operations.DrtOperationsParams;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams;
import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams;
Expand Down Expand Up @@ -46,17 +46,17 @@ void test() {

DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup;
drtConfigGroup.mode = TransportMode.drt;
DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam();
constraintsParam.maxTravelTimeAlpha = 1.5;
constraintsParam.maxTravelTimeBeta = 10. * 60.;
DrtOptimizationConstraintsSet defaultConstraintsSet = drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
drtConfigGroup.stopDuration = 30.;
constraintsParam.maxWaitTime = 600.;
constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
defaultConstraintsSet.maxTravelTimeAlpha = 1.5;
defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.;
defaultConstraintsSet.maxWaitTime = 600.;
defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
defaultConstraintsSet.maxWalkDistance = 1000.;
drtConfigGroup.useModeFilteredSubnetwork = false;
drtConfigGroup.vehiclesFile = fleetFile;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
drtConfigGroup.plotDetailedCustomerStats = true;
constraintsParam.maxWalkDistance = 1000.;
drtConfigGroup.idleVehiclesReturnToDepots = false;

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams;
import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams;
Expand Down Expand Up @@ -45,39 +45,38 @@ void test() {

DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt");

DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup;
drtConfigGroup.mode = TransportMode.drt;
DrtOptimizationConstraintsParams constraintsParam = drtConfigGroup.getDefaultDrtOptimizationConstraintsParam();
constraintsParam.maxTravelTimeAlpha = 1.5;
constraintsParam.maxTravelTimeBeta = 10. * 60.;
drtConfigGroup.stopDuration = 30.;
constraintsParam.maxWaitTime = 600.;
constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
drtConfigGroup.useModeFilteredSubnetwork = false;
drtConfigGroup.vehiclesFile = fleetFile;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
drtConfigGroup.plotDetailedCustomerStats = true;
constraintsParam.maxWalkDistance = 1000.;
drtConfigGroup.idleVehiclesReturnToDepots = false;

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());

ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing");
drtConfigGroup.addParameterSet(rebalancing);
drtWithShiftsConfigGroup.mode = TransportMode.drt;
DrtOptimizationConstraintsSet defaultConstraintsSet = drtWithShiftsConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
drtWithShiftsConfigGroup.stopDuration = 30.;
defaultConstraintsSet.maxTravelTimeAlpha = 1.5;
defaultConstraintsSet.maxTravelTimeBeta = 10. * 60.;
defaultConstraintsSet.maxWaitTime = 600.;
defaultConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
defaultConstraintsSet.maxWalkDistance = 1000.;
drtWithShiftsConfigGroup.useModeFilteredSubnetwork = false;
drtWithShiftsConfigGroup.vehiclesFile = fleetFile;
drtWithShiftsConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
drtWithShiftsConfigGroup.plotDetailedCustomerStats = true;
drtWithShiftsConfigGroup.idleVehiclesReturnToDepots = false;

drtWithShiftsConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());

ConfigGroup rebalancing = drtWithShiftsConfigGroup.createParameterSet("rebalancing");
drtWithShiftsConfigGroup.addParameterSet(rebalancing);
((RebalancingParams) rebalancing).interval = 600;

MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams();
strategyParams.targetAlpha = 0.3;
strategyParams.targetBeta = 0.3;

drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams);
drtWithShiftsConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams);

DrtZoneSystemParams drtZoneSystemParams = new DrtZoneSystemParams();
SquareGridZoneSystemParams zoneParams = (SquareGridZoneSystemParams) drtZoneSystemParams.createParameterSet(SquareGridZoneSystemParams.SET_NAME);
zoneParams.cellSize = 500.;
drtZoneSystemParams.addParameterSet(zoneParams);
drtZoneSystemParams.targetLinkSelection = DrtZoneSystemParams.TargetLinkSelection.mostCentral;
drtConfigGroup.addParameterSet(drtZoneSystemParams);
drtWithShiftsConfigGroup.addParameterSet(drtZoneSystemParams);

multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.matsim.contrib.common.timeprofile.TimeProfileCharts;
import org.matsim.contrib.common.util.ChartSaveUtils;
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector.EventSequence;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.passenger.events.DrtRequestSubmittedEvent;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtStayTask;
Expand Down Expand Up @@ -400,7 +401,7 @@ private void writeAndPlotWaitTimeEstimateComparison(Collection<EventSequence> pe

if (createChart) {
final JFreeChart chart2 = DensityScatterPlots.createPlot("Wait times", "Actual wait time [s]", "Initially planned wait time [s]",
times, Pair.of(0., drtCfg.getDefaultDrtOptimizationConstraintsParam().maxWaitTime));
times, Pair.of(0., drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet().maxWaitTime));
// xAxis.setLowerBound(0);
// yAxis.setLowerBound(0);
ChartUtils.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500);
Expand Down Expand Up @@ -663,14 +664,15 @@ private static void analyseDetours(Network network, List<DrtLeg> legs, Map<Id<Re
distances);
ChartSaveUtils.saveAsPNG(chart, fileName + "_distancePlot", 1500, 1500);

DrtOptimizationConstraintsSet defaultConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
final JFreeChart chart2 = DensityScatterPlots.createPlot("Travel Times", "travel time [s]", "unshared ride time [s]", travelTimes,
Pair.of(drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha,
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta));
Pair.of(defaultConstraintsSet.maxTravelTimeAlpha,
defaultConstraintsSet.maxTravelTimeBeta));
ChartSaveUtils.saveAsPNG(chart2, fileName + "_travelTimePlot", 1500, 1500);

final JFreeChart chart3 = DensityScatterPlots.createPlot("Ride Times", "ride time [s]", "unshared ride time [s]", rideTimes,
Pair.of(drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeAlpha,
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxTravelTimeBeta));
Pair.of(defaultConstraintsSet.maxTravelTimeAlpha,
defaultConstraintsSet.maxTravelTimeBeta));
ChartSaveUtils.saveAsPNG(chart3, fileName + "_rideTimePlot", 1500, 1500);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.matsim.contrib.drt.estimator.impl;

import org.matsim.contrib.drt.estimator.DrtEstimator;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.routing.DrtRoute;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams;
import org.matsim.core.utils.misc.OptionalTime;

/**
Expand All @@ -20,7 +20,7 @@ public PessimisticDrtEstimator(DrtConfigGroup drtConfig) {
public Estimate estimate(DrtRoute route, OptionalTime departureTime) {
// If not estimates are present, use travel time alpha as detour
// beta is not used, because estimates are supposed to be minimums and not worst cases
DrtOptimizationConstraintsParams constraints = drtConfig.getDefaultDrtOptimizationConstraintsParam();
DrtOptimizationConstraintsSet constraints = drtConfig.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
double travelTime = Math.min(route.getDirectRideTime() + constraints.maxAbsoluteDetour,
route.getDirectRideTime() * constraints.maxTravelTimeAlpha);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ protected void configureQSim() {

bindModal(VehicleEntry.EntryFactory.class).toInstance(new VehicleDataEntryFactoryImpl());

DrtOptimizationConstraintsSet defaultOptimizationConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
bindModal(CostCalculationStrategy.class)
.to(drtCfg.getDefaultDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated
.to(defaultOptimizationConstraintsSet.rejectRequestIfMaxWaitOrTravelTimeViolated
?
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();
Expand Down Expand Up @@ -151,7 +152,7 @@ public EmptyVehicleRelocator get() {
.asEagerSingleton();

bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(
drtCfg.getDefaultDrtOptimizationConstraintsParam().maxAllowedPickupDelay)));
defaultOptimizationConstraintsSet.maxAllowedPickupDelay)));
bindModal(DrtOfferAcceptor.class).to(modalKey(DefaultOfferAcceptor.class));

bindModal(ScheduleTimingUpdater.class).toProvider(modalProvider(
Expand Down
Loading

0 comments on commit 12ca6a5

Please sign in to comment.