Skip to content

Commit

Permalink
Merge branch 'master' into ssct-durations
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp authored May 13, 2024
2 parents 4aa48e2 + 138f63a commit 032e9aa
Show file tree
Hide file tree
Showing 47 changed files with 601 additions and 304 deletions.
2 changes: 1 addition & 1 deletion contribs/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.5</version>
<version>4.7.6</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.matsim.application.prepare.network;

import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.application.MATSimAppCommand;
import org.matsim.core.network.DisallowedNextLinks;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.algorithms.MultimodalNetworkCleaner;
import picocli.CommandLine;
Expand All @@ -25,11 +27,30 @@ public class CleanNetwork implements MATSimAppCommand {
@CommandLine.Option(names = "--modes", description = "List of modes to clean", split = ",", defaultValue = TransportMode.car)
private Set<String> modes;

@CommandLine.Option(names = "--remove-turn-restrictions", description = "Remove turn restrictions for specified modes.", defaultValue = "false")
private boolean rmTurnRestrictions;

public static void main(String[] args) {
new CleanNetwork().execute(args);
}

@Override
public Integer call() throws Exception {

Network network = NetworkUtils.readNetwork(input.toString());

if (rmTurnRestrictions) {
for (Link link : network.getLinks().values()) {
DisallowedNextLinks disallowed = NetworkUtils.getDisallowedNextLinks(link);
if (disallowed != null) {
modes.forEach(disallowed::removeDisallowedLinkSequences);
if (disallowed.isEmpty()) {
NetworkUtils.removeDisallowedNextLinks(link);
}
}
}
}

var cleaner = new MultimodalNetworkCleaner(network);

for (String m : modes) {
Expand Down
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 032e9aa

Please sign in to comment.