diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java new file mode 100644 index 00000000000..5d2dc57e189 --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/insertion/MaxDetourInsertionCostCalculator.java @@ -0,0 +1,30 @@ +package org.matsim.contrib.drt.optimizer.insertion; + +import org.matsim.contrib.drt.passenger.DrtRequest; + +/** + * This insertion cost calculator performs additional check on the maximum ride duration, on top of the original InsertionCostCalculator + * @author: Nico Kühnel (nkuehnel), Chengqi Lu (luchengqi7) + * */ +public class MaxDetourInsertionCostCalculator implements InsertionCostCalculator { + private final InsertionCostCalculator delegate; + + public MaxDetourInsertionCostCalculator(InsertionCostCalculator delegate) { + this.delegate = delegate; + } + + @Override + public double calculate(DrtRequest drtRequest, InsertionGenerator.Insertion insertion, InsertionDetourTimeCalculator.DetourTimeInfo detourTimeInfo) { + if (violatesDetour(drtRequest, detourTimeInfo)) { + return INFEASIBLE_SOLUTION_COST; + } + return delegate.calculate(drtRequest, insertion, detourTimeInfo); + } + + private boolean violatesDetour(DrtRequest drtRequest, InsertionDetourTimeCalculator.DetourTimeInfo detourTimeInfo) { + // Check if the max travel time constraint for the newly inserted request is violated + double rideDuration = detourTimeInfo.dropoffDetourInfo.arrivalTime - detourTimeInfo.pickupDetourInfo.departureTime; + return drtRequest.getMaxRideDuration() < rideDuration; + } + +} diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/AcceptedDrtRequest.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/AcceptedDrtRequest.java index 81dd831859a..89b594f3595 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/AcceptedDrtRequest.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/AcceptedDrtRequest.java @@ -38,6 +38,7 @@ public static AcceptedDrtRequest createFromOriginalRequest(DrtRequest request) { .earliestStartTime(request.getEarliestStartTime()) .latestStartTime(request.getLatestStartTime()) .latestArrivalTime(request.getLatestArrivalTime()) + .maxRideDuration(request.getMaxRideDuration()) .build(); } @@ -46,12 +47,14 @@ public static AcceptedDrtRequest createFromOriginalRequest(DrtRequest request) { private final double earliestStartTime; private final double latestStartTime; private final double latestArrivalTime; + private final double maxRideDuration; private AcceptedDrtRequest(Builder builder) { request = builder.request; earliestStartTime = builder.earliestStartTime; latestStartTime = builder.latestStartTime; latestArrivalTime = builder.latestArrivalTime; + maxRideDuration = builder.maxRideDuration; } public static Builder newBuilder() { @@ -64,6 +67,7 @@ public static Builder newBuilder(AcceptedDrtRequest copy) { builder.earliestStartTime = copy.getEarliestStartTime(); builder.latestStartTime = copy.getLatestStartTime(); builder.latestArrivalTime = copy.getLatestArrivalTime(); + builder.maxRideDuration = copy.getMaxRideDuration(); return builder; } @@ -82,6 +86,9 @@ public double getLatestStartTime() { public double getLatestArrivalTime() { return latestArrivalTime; } + public double getMaxRideDuration() { + return maxRideDuration; + } public Id getId() { return request.getId(); @@ -122,6 +129,7 @@ public static final class Builder { private double earliestStartTime; private double latestStartTime; private double latestArrivalTime; + private double maxRideDuration; private Builder() { } @@ -146,6 +154,11 @@ public Builder latestArrivalTime(double val) { return this; } + public Builder maxRideDuration(double val) { + this.maxRideDuration = val; + return this; + } + public AcceptedDrtRequest build() { return new AcceptedDrtRequest(this); } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequest.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequest.java index e1c034f2a92..510ad458013 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequest.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequest.java @@ -39,6 +39,7 @@ public class DrtRequest implements PassengerRequest { private final double earliestStartTime; private final double latestStartTime; private final double latestArrivalTime; + private final double maxRideDuration; private final List> passengerIds = new ArrayList<>(); private final String mode; @@ -52,6 +53,7 @@ private DrtRequest(Builder builder) { earliestStartTime = builder.earliestStartTime; latestStartTime = builder.latestStartTime; latestArrivalTime = builder.latestArrivalTime; + maxRideDuration = builder.maxRideDuration; passengerIds.addAll(builder.passengerIds); mode = builder.mode; fromLink = builder.fromLink; @@ -69,6 +71,7 @@ public static Builder newBuilder(DrtRequest copy) { builder.earliestStartTime = copy.getEarliestStartTime(); builder.latestStartTime = copy.getLatestStartTime(); builder.latestArrivalTime = copy.getLatestArrivalTime(); + builder.maxRideDuration = copy.getMaxRideDuration(); builder.passengerIds = new ArrayList<>(copy.getPassengerIds()); builder.mode = copy.getMode(); builder.fromLink = copy.getFromLink(); @@ -100,6 +103,10 @@ public double getLatestArrivalTime() { return latestArrivalTime; } + public double getMaxRideDuration() { + return maxRideDuration; + } + @Override public Link getFromLink() { return fromLink; @@ -133,6 +140,7 @@ public String toString() { .add("earliestStartTime", earliestStartTime) .add("latestStartTime", latestStartTime) .add("latestArrivalTime", latestArrivalTime) + .add("maxRideDuration", maxRideDuration) .add("passengerIds", passengerIds.stream().map(Object::toString).collect(Collectors.joining(","))) .add("mode", mode) .add("fromLink", fromLink) @@ -146,6 +154,7 @@ public static final class Builder { private double earliestStartTime; private double latestStartTime; private double latestArrivalTime; + private double maxRideDuration; private List> passengerIds = new ArrayList<>(); private String mode; private Link fromLink; @@ -179,6 +188,11 @@ public Builder latestArrivalTime(double val) { return this; } + public Builder maxRideDuration(double maxRideDuration) { + this.maxRideDuration = maxRideDuration; + return this; + } + public Builder passengerIds(List> val) { passengerIds = new ArrayList<>(val); return this; diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequestCreator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequestCreator.java index 8a2cff7227e..f076fa6c525 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequestCreator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DrtRequestCreator.java @@ -52,10 +52,11 @@ public DrtRequest createRequest(Id id, List> passengerIds, R DrtRoute drtRoute = (DrtRoute)route; double latestDepartureTime = departureTime + drtRoute.getMaxWaitTime(); double latestArrivalTime = departureTime + drtRoute.getTravelTime().seconds(); + double maxRideDuration = drtRoute.getMaxRideTime(); eventsManager.processEvent( new DrtRequestSubmittedEvent(submissionTime, mode, id, passengerIds, fromLink.getId(), toLink.getId(), - drtRoute.getDirectRideTime(), drtRoute.getDistance(), departureTime, latestDepartureTime, latestArrivalTime)); + drtRoute.getDirectRideTime(), drtRoute.getDistance(), departureTime, latestDepartureTime, latestArrivalTime, maxRideDuration)); DrtRequest request = DrtRequest.newBuilder() .id(id) @@ -66,6 +67,7 @@ public DrtRequest createRequest(Id id, List> passengerIds, R .earliestStartTime(departureTime) .latestStartTime(latestDepartureTime) .latestArrivalTime(latestArrivalTime) + .maxRideDuration(maxRideDuration) .submissionTime(submissionTime) .build(); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/MaxDetourOfferAcceptor.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/MaxDetourOfferAcceptor.java new file mode 100644 index 00000000000..00baac4565f --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/MaxDetourOfferAcceptor.java @@ -0,0 +1,23 @@ +package org.matsim.contrib.drt.passenger; + +import java.util.Optional; + +public class MaxDetourOfferAcceptor implements DrtOfferAcceptor{ + private final double promisedPickupTimeWindow; + + public MaxDetourOfferAcceptor(double promisedPickupTimeWindow) { + this.promisedPickupTimeWindow = promisedPickupTimeWindow; + } + + @Override + public Optional acceptDrtOffer(DrtRequest request, double departureTime, double arrivalTime) { + double updatedPickupTimeWindow = Math.min(departureTime + + promisedPickupTimeWindow, request.getLatestStartTime()); + return Optional.of(AcceptedDrtRequest + .newBuilder() + .request(request) + .earliestStartTime(request.getEarliestStartTime()) + .latestArrivalTime(Math.min(updatedPickupTimeWindow + request.getMaxRideDuration(), request.getLatestArrivalTime())) + .latestStartTime(updatedPickupTimeWindow).build()); + } +} diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/events/DrtRequestSubmittedEvent.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/events/DrtRequestSubmittedEvent.java index 09f04e814d9..6a5a320df1c 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/events/DrtRequestSubmittedEvent.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/events/DrtRequestSubmittedEvent.java @@ -40,6 +40,7 @@ public class DrtRequestSubmittedEvent extends PassengerRequestSubmittedEvent { public static final String ATTRIBUTE_EARLIEST_DEPARTURE_TIME = "earliestDepartureTime"; public static final String ATTRIBUTE_LATEST_PICKUP_TIME = "latestPickupTime"; public static final String ATTRIBUTE_LATEST_DROPOFF_TIME = "latestDropoffTime"; + public static final String ATTRIBUTE_MAX_RIDE_DURATION = "maxRideDuration"; private final double unsharedRideTime; private final double unsharedRideDistance; @@ -47,16 +48,18 @@ public class DrtRequestSubmittedEvent extends PassengerRequestSubmittedEvent { private final double earliestDepartureTime; private final double latestPickupTime; private final double latestDropoffTime; + private final double maxRideDuration; public DrtRequestSubmittedEvent(double time, String mode, Id requestId, List> personIds, Id fromLinkId, Id toLinkId, double unsharedRideTime, double unsharedRideDistance, - double earliestDepartureTime, double latestPickupTime, double latestDropoffTime) { + double earliestDepartureTime, double latestPickupTime, double latestDropoffTime, double maxRideDuration ) { super(time, mode, requestId, personIds, fromLinkId, toLinkId); this.unsharedRideTime = unsharedRideTime; this.unsharedRideDistance = unsharedRideDistance; this.earliestDepartureTime = earliestDepartureTime; this.latestPickupTime = latestPickupTime; this.latestDropoffTime = latestDropoffTime; + this.maxRideDuration = maxRideDuration; } @Override @@ -90,6 +93,9 @@ public final double getLatestDropoffTime() { return latestDropoffTime; } + public double getMaxRideDuration() { + return maxRideDuration; + } @Override public Map getAttributes() { Map attr = super.getAttributes(); @@ -98,6 +104,7 @@ public Map getAttributes() { attr.put(ATTRIBUTE_EARLIEST_DEPARTURE_TIME, earliestDepartureTime + ""); attr.put(ATTRIBUTE_LATEST_PICKUP_TIME, latestPickupTime + ""); attr.put(ATTRIBUTE_LATEST_DROPOFF_TIME, latestDropoffTime + ""); + attr.put(ATTRIBUTE_MAX_RIDE_DURATION, maxRideDuration + ""); return attr; } @@ -118,7 +125,8 @@ public static DrtRequestSubmittedEvent convert(GenericEvent event) { double earliestDepartureTime = Double.parseDouble(attributes.getOrDefault(ATTRIBUTE_EARLIEST_DEPARTURE_TIME, "NaN")); double latestPickupTime = Double.parseDouble(attributes.getOrDefault(ATTRIBUTE_LATEST_PICKUP_TIME, "NaN")); double latestDropoffTime = Double.parseDouble(attributes.getOrDefault(ATTRIBUTE_LATEST_DROPOFF_TIME, "NaN")); + double maxRideDuration = Double.parseDouble(attributes.getOrDefault(ATTRIBUTE_MAX_RIDE_DURATION, "NaN")); return new DrtRequestSubmittedEvent(time, mode, requestId, personIds, fromLinkId, toLinkId, unsharedRideTime, - unsharedRideDistance, earliestDepartureTime, latestPickupTime, latestDropoffTime); + unsharedRideDistance, earliestDepartureTime, latestPickupTime, latestDropoffTime, maxRideDuration); } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRoute.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRoute.java index 72f21260119..c375aee64a6 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRoute.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRoute.java @@ -72,6 +72,10 @@ public double getMaxTravelTime() { return getTravelTime().seconds(); // currently DrtRoute.travelTime is set to the max allowed travel time } + public double getMaxRideTime() { + return routeDescription.getMaxRideTime(); + } + public void setDirectRideTime(double directRideTime) { this.routeDescription.setDirectRideTime(directRideTime); } @@ -86,6 +90,10 @@ public void setUnsharedPath(VrpPathWithTravelData unsharedPath) { this.routeDescription.setUnsharedPath(links); } + public void setMaxRideTime(double maxRideTime) { + this.routeDescription.setMaxRideTime(maxRideTime); + } + @Override public String getRouteDescription() { @@ -149,12 +157,18 @@ public static class RouteDescription { private OptionalTime maxWaitTime = OptionalTime.undefined(); private OptionalTime directRideTime = OptionalTime.undefined(); private List unsharedPath = new ArrayList(); + private OptionalTime maxRideTime = OptionalTime.undefined(); @JsonProperty("directRideTime") public double getDirectRideTime() { return directRideTime.isUndefined() ? OptionalTime.undefined().seconds() : directRideTime.seconds(); } + @JsonProperty("maxRideTime") + public double getMaxRideTime() { + return maxRideTime.seconds(); + } + @JsonProperty("maxWaitTime") public double getMaxWaitTime() { return maxWaitTime.isUndefined() ? OptionalTime.undefined().seconds() : maxWaitTime.seconds(); @@ -169,6 +183,10 @@ public void setDirectRideTime(double directRideTime) { this.directRideTime = OptionalTime.defined(directRideTime); } + public void setMaxRideTime(double maxRideTime) { + this.maxRideTime = OptionalTime.defined(maxRideTime); + } + public void setMaxWaitTime(double maxWaitTime) { this.maxWaitTime = OptionalTime.defined(maxWaitTime); } @@ -176,6 +194,5 @@ public void setMaxWaitTime(double maxWaitTime) { public void setUnsharedPath(List unsharedPath) { this.unsharedPath = unsharedPath; } - } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java index 2c668199c5e..3f05ef097ea 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteCreator.java @@ -65,17 +65,30 @@ static double getMaxTravelTime(DrtConfigGroup drtCfg, double unsharedRideTime) { drtCfg.maxTravelTimeAlpha * unsharedRideTime + drtCfg.maxTravelTimeBeta); } + /** + * Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta + * + * @param drtCfg + * @param unsharedRideTime ride time of the direct (shortest-time) route + * @return maximum ride time + */ + static double getMaxRideTime(DrtConfigGroup drtCfg, double unsharedRideTime) { + return Math.min(unsharedRideTime + drtCfg.maxAbsoluteDetour, drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta); + } + public Route createRoute(double departureTime, Link accessActLink, Link egressActLink, Person person, Attributes tripAttributes, RouteFactories routeFactories) { VrpPathWithTravelData unsharedPath = VrpPaths.calcAndCreatePath(accessActLink, egressActLink, departureTime, router, travelTime); double unsharedRideTime = unsharedPath.getTravelTime();//includes first & last link double maxTravelTime = getMaxTravelTime(drtCfg, unsharedRideTime); + double maxRideDuration = getMaxRideTime(drtCfg, unsharedRideTime); double unsharedDistance = VrpPaths.calcDistance(unsharedPath);//includes last link DrtRoute route = routeFactories.createRoute(DrtRoute.class, accessActLink.getId(), egressActLink.getId()); route.setDistance(unsharedDistance); route.setTravelTime(maxTravelTime); + route.setMaxRideTime(maxRideDuration); route.setDirectRideTime(unsharedRideTime); route.setMaxWaitTime(drtCfg.maxWaitTime); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java index 03b9c551970..aa76c3bde41 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java @@ -113,6 +113,27 @@ public static DrtConfigGroup getSingleModeDrtConfig(Config config) { @PositiveOrZero public double maxAbsoluteDetour = Double.POSITIVE_INFINITY;// [s] + @Parameter + @Comment( + "Defines the maximum allowed absolute detour based on the unsharedRideTime. A linear combination similar to travel time constrain is used" + + "This is the ratio part") + @DecimalMin("1.0") + public double maxDetourAlpha = Double.POSITIVE_INFINITY; + + @Parameter + @Comment( + "Defines the maximum allowed absolute detour based on the unsharedRideTime. A linear combination similar to travel time constrain is used" + + "This is the constant part") + @PositiveOrZero + public double maxDetourBeta = Double.POSITIVE_INFINITY;// [s] + + @Parameter + @Comment( + "Defines the maximum delay allowed from the initial scheduled pick up time. Once a estimated pick up time is determined, the DRT optimizer" + + "should try to keep this promise. By default, this limit is disabled. If enabled, a value between 120 and 240 is a good choice.") + @PositiveOrZero + public double maxAllowedPickupDelay = Double.POSITIVE_INFINITY;// [s] + @Parameter @Comment("If true, the max travel and wait times of a submitted request" + " are considered hard constraints (the request gets rejected if one of the constraints is violated)." @@ -250,7 +271,7 @@ private void initSingletonParameterSets() { addDefinition(DrtRequestInsertionRetryParams.SET_NAME, DrtRequestInsertionRetryParams::new, () -> drtRequestInsertionRetryParams, params -> drtRequestInsertionRetryParams = (DrtRequestInsertionRetryParams)params); - + //prebooking (optional) addDefinition(PrebookingParams.SET_NAME, PrebookingParams::new, () -> prebookingParams, diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/fare/DrtFareHandlerTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/fare/DrtFareHandlerTest.java index 35e41f5d018..9e7e01e6780 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/fare/DrtFareHandlerTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/fare/DrtFareHandlerTest.java @@ -72,7 +72,7 @@ public void reset(int iteration) { { var requestId = Id.create(0, Request.class); events.processEvent(new DrtRequestSubmittedEvent(0.0, mode, requestId, List.of(personId), Id.createLinkId("12"), - Id.createLinkId("23"), 240, 1000, 0.0, 0.0, 0.0)); + Id.createLinkId("23"), 240, 1000, 0.0, 0.0, 0.0, 0.0)); events.processEvent(new PassengerDroppedOffEvent(300.0, mode, requestId, personId, null)); events.flush(); @@ -83,7 +83,7 @@ public void reset(int iteration) { // test minFarePerTrip var requestId = Id.create(1, Request.class); events.processEvent(new DrtRequestSubmittedEvent(0.0, mode, requestId, List.of(personId), Id.createLinkId("45"), - Id.createLinkId("56"), 24, 100, 0.0, 0.0, 0.0)); + Id.createLinkId("56"), 24, 100, 0.0, 0.0, 0.0, 0.0)); events.processEvent(new PassengerDroppedOffEvent(300.0, mode, requestId, personId, null)); events.finishProcessing(); diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java new file mode 100644 index 00000000000..6648bf65466 --- /dev/null +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/optimizer/MaxDetourConstraintTest.java @@ -0,0 +1,68 @@ +package org.matsim.contrib.drt.optimizer; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.matsim.contrib.drt.optimizer.insertion.CostCalculationStrategy; +import org.matsim.contrib.drt.optimizer.insertion.DefaultInsertionCostCalculator; +import org.matsim.contrib.drt.optimizer.insertion.InsertionCostCalculator; +import org.matsim.contrib.drt.optimizer.insertion.MaxDetourInsertionCostCalculator; +import org.matsim.contrib.drt.passenger.DrtOfferAcceptor; +import org.matsim.contrib.drt.passenger.MaxDetourOfferAcceptor; +import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.contrib.drt.run.DrtControlerCreator; +import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; +import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule; +import org.matsim.contrib.dvrp.run.DvrpConfigGroup; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.examples.ExamplesUtils; +import org.matsim.testcases.MatsimTestUtils; +import org.matsim.vis.otfvis.OTFVisConfigGroup; + +import java.net.URL; + +public class MaxDetourConstraintTest { + @RegisterExtension + public MatsimTestUtils utils = new MatsimTestUtils(); + + @Test + public void testMaxDetourConstraint() { + URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); + Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), + new OTFVisConfigGroup()); + MultiModeDrtConfigGroup multiModeDrtConfigGroup = MultiModeDrtConfigGroup.get(config); + DrtConfigGroup drtConfigGroup = DrtConfigGroup.getSingleModeDrtConfig(config); + + drtConfigGroup.maxDetourAlpha = 1.5; + drtConfigGroup.maxDetourBeta = 300; + + drtConfigGroup.maxWaitTime = 300; + + drtConfigGroup.maxAllowedPickupDelay = 180; + + // Make the max total travel time constraints very loose (i.e., similar to disabling it) + drtConfigGroup.maxTravelTimeAlpha = 10; + drtConfigGroup.maxTravelTimeBeta = 7200; + + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOutputDirectory(utils.getOutputDirectory()); + + Controler controler = DrtControlerCreator.createControler(config, false); + + for (DrtConfigGroup drtCfg : multiModeDrtConfigGroup.getModalElements()) { + controler.addOverridingQSimModule(new AbstractDvrpModeQSimModule(drtCfg.mode) { + @Override + protected void configureQSim() { + bindModal(InsertionCostCalculator.class).toProvider(modalProvider( + getter -> new MaxDetourInsertionCostCalculator((new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class)))))); + bindModal(DrtOfferAcceptor.class).toProvider(modalProvider(getter -> new MaxDetourOfferAcceptor(drtCfg.maxAllowedPickupDelay))); + } + }); + } + + controler.run(); + } +} diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/speedup/DrtSpeedUpTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/speedup/DrtSpeedUpTest.java index 1f08cf7c993..1bba2ad2e5a 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/speedup/DrtSpeedUpTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/speedup/DrtSpeedUpTest.java @@ -275,7 +275,7 @@ private EventSequence eventSequence(String id, double submittedTime, double wait var personId = Id.create(id, Person.class); var submittedEvent = new DrtRequestSubmittedEvent(submittedTime, MODE, requestId, List.of(personId), linkAB.getId(), - linkBC.getId(), Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); + linkBC.getId(), Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); var pickupEvent = new PassengerPickedUpEvent(submittedTime + waitTime, MODE, requestId, null, null); double rideTime = DistanceUtils.calculateDistance(linkBC, linkAB) / inVehicleSpeed; var dropoffEvent = new PassengerDroppedOffEvent(submittedTime + waitTime + rideTime, MODE, requestId, null, diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/util/DrtEventsReadersTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/util/DrtEventsReadersTest.java index 6ba4b41e0c8..1eb290b2d8a 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/util/DrtEventsReadersTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/util/DrtEventsReadersTest.java @@ -65,7 +65,7 @@ public class DrtEventsReadersTest { //standard dvrp events are tested in DvrpEventsReadersTest private final List drtEvents = List.of( - new DrtRequestSubmittedEvent(0, mode, request, List.of(person), link1, link2, 111, 222, 0.0, 412.0, 512.0),// + new DrtRequestSubmittedEvent(0, mode, request, List.of(person), link1, link2, 111, 222, 0.0, 412.0, 512.0, 555),// taskStarted(10, DrtDriveTask.TYPE, 0, link1),// taskEnded(30, DefaultDrtStopTask.TYPE, 1, link2), // taskStarted(50, DrtStayTask.TYPE, 2, link1),//