Skip to content

Commit

Permalink
factor out drt optimization constraint params from drt config group (m…
Browse files Browse the repository at this point in the history
…atsim-org#3252)

* factor out drt optimization constraint params from drt config group as preparatory work for service differentiation
* ensure backwards compatibility with previous drt config design
  • Loading branch information
nkuehnel committed May 11, 2024
1 parent b66d390 commit b4dd92c
Show file tree
Hide file tree
Showing 35 changed files with 462 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ private static void loadConfigGroups(Config config) {
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);

DrtConfigGroup drtCfg = new DrtConfigGroup();
drtCfg.maxWaitTime = 2 * 3600;
drtCfg.maxTravelTimeAlpha = 5;
drtCfg.maxTravelTimeBeta = 15 * 60;
drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime = 2 * 3600;
drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 5;
drtCfg.getDrtOptimizationConstraintsParam().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 @@ -147,7 +147,7 @@ public EmptyVehicleChargingScheduler get() {
bindModal(VehicleEntry.EntryFactory.class).toProvider(
EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider.class).asEagerSingleton();

bindModal(CostCalculationStrategy.class).to(drtCfg.rejectRequestIfMaxWaitOrTravelTimeViolated ?
bindModal(CostCalculationStrategy.class).to(drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated ?
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();

Expand Down Expand Up @@ -179,7 +179,7 @@ public EmptyVehicleRelocator get() {
getter.getModal(StopTimeCalculator.class), scheduleWaitBeforeDrive)))
.asEagerSingleton();

bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(drtCfg.maxAllowedPickupDelay)));
bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(drtCfg.getDrtOptimizationConstraintsParam().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 @@ -53,16 +53,16 @@ void test() {

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

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.run.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 @@ -56,16 +57,17 @@ void test() {

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

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.run.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,16 +46,17 @@ void test() {

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

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.run.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,16 +47,17 @@ void test() {

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

drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,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.maxWaitTime));
times, Pair.of(0., drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime));
// xAxis.setLowerBound(0);
// yAxis.setLowerBound(0);
ChartUtils.writeChartAsPNG(new FileOutputStream(plotFileName), chart2, 1500, 1500);
Expand Down Expand Up @@ -664,11 +664,11 @@ private static void analyseDetours(Network network, List<DrtLeg> legs, Map<Id<Re
ChartSaveUtils.saveAsPNG(chart, fileName + "_distancePlot", 1500, 1500);

final JFreeChart chart2 = DensityScatterPlots.createPlot("Travel Times", "travel time [s]", "unshared ride time [s]", travelTimes,
Pair.of(drtCfg.maxTravelTimeAlpha, drtCfg.maxTravelTimeBeta));
Pair.of(drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha, drtCfg.getDrtOptimizationConstraintsParam().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.maxTravelTimeAlpha, drtCfg.maxTravelTimeBeta));
Pair.of(drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha, drtCfg.getDrtOptimizationConstraintsParam().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.fare.DrtFareParams;
import org.matsim.contrib.drt.routing.DrtRoute;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtOptimizationConstraintsParams;
import org.matsim.core.utils.misc.OptionalTime;

/**
Expand All @@ -20,11 +20,12 @@ 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
double travelTime = Math.min(route.getDirectRideTime() + drtConfig.maxAbsoluteDetour,
route.getDirectRideTime() * drtConfig.maxTravelTimeAlpha);
DrtOptimizationConstraintsParams constraints = drtConfig.getDrtOptimizationConstraintsParam();
double travelTime = Math.min(route.getDirectRideTime() + constraints.maxAbsoluteDetour,
route.getDirectRideTime() * constraints.maxTravelTimeAlpha);

// for distance, also use the max travel time alpha
return new Estimate(route.getDistance() * drtConfig.maxTravelTimeAlpha, travelTime, drtConfig.maxWaitTime, 0);
return new Estimate(route.getDistance() * constraints.maxTravelTimeAlpha, travelTime, constraints.maxWaitTime, 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void configureQSim() {

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

bindModal(CostCalculationStrategy.class).to(drtCfg.rejectRequestIfMaxWaitOrTravelTimeViolated ?
bindModal(CostCalculationStrategy.class).to(drtCfg.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated ?
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();

Expand Down Expand Up @@ -148,7 +148,7 @@ public EmptyVehicleRelocator get() {
getter.getModal(StopTimeCalculator.class), scheduleWaitBeforeDrive)))
.asEagerSingleton();

bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(drtCfg.maxAllowedPickupDelay)));
bindModal(DefaultOfferAcceptor.class).toProvider(modalProvider(getter -> new DefaultOfferAcceptor(drtCfg.getDrtOptimizationConstraintsParam().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 @@ -61,7 +61,7 @@ public DrtRouteCreator(DrtConfigGroup drtCfg, Network modalNetwork,
* @return maximum travel time
*/
static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) {
return drtCfg.maxTravelTimeAlpha * unsharedRideTime + drtCfg.maxTravelTimeBeta;
return drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha * unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxTravelTimeBeta;
}

/**
Expand All @@ -72,7 +72,7 @@ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) {
* @return maximum ride time
*/
static double getMaxRideTime(DrtConfigGroup drtCfg, double unsharedRideTime) {
return Math.min(unsharedRideTime + drtCfg.maxAbsoluteDetour, drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta);
return Math.min(unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxAbsoluteDetour, drtCfg.getDrtOptimizationConstraintsParam().maxDetourAlpha * unsharedRideTime + drtCfg.getDrtOptimizationConstraintsParam().maxDetourBeta);
}

public Route createRoute(double departureTime, Link accessActLink, Link egressActLink, Person person,
Expand All @@ -89,7 +89,7 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc
route.setTravelTime(maxTravelTime);
route.setMaxRideTime(maxRideDuration);
route.setDirectRideTime(unsharedRideTime);
route.setMaxWaitTime(drtCfg.maxWaitTime);
route.setMaxWaitTime(drtCfg.getDrtOptimizationConstraintsParam().maxWaitTime);

if (this.drtCfg.storeUnsharedPath) {
route.setUnsharedPath(unsharedPath);
Expand Down
Loading

0 comments on commit b4dd92c

Please sign in to comment.