From 2bd89dc2d66ff4a50c63f328ee8914cbbd38d025 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Thu, 5 Sep 2024 18:36:26 +0200 Subject: [PATCH 1/6] drt: be less strict with vehicle ids set equality in preplanned scenarios --- .../extension/preplanned/optimizer/PreplannedDrtOptimizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java index 5dd5f1c8bf7..d3031a3aa50 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/preplanned/optimizer/PreplannedDrtOptimizer.java @@ -77,7 +77,7 @@ public PreplannedDrtOptimizer(DrtConfigGroup drtCfg, PreplannedSchedules preplan TravelTime travelTime, TravelDisutility travelDisutility, MobsimTimer timer, DrtTaskFactory taskFactory, EventsManager eventsManager, Fleet fleet, ScheduleTimingUpdater scheduleTimingUpdater) { Preconditions.checkArgument( - fleet.getVehicles().keySet().equals(preplannedSchedules.vehicleToPreplannedStops.keySet()), + fleet.getVehicles().keySet().containsAll(preplannedSchedules.vehicleToPreplannedStops.keySet()), "Some schedules are preplanned for vehicles outside the fleet"); this.mode = drtCfg.getMode(); From 6def4617937e0c3beb47943347cf77b26b62b097 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:14:04 +0000 Subject: [PATCH 2/6] Bump com.google.errorprone:error_prone_annotations from 2.29.2 to 2.31.0 Bumps [com.google.errorprone:error_prone_annotations](https://github.com/google/error-prone) from 2.29.2 to 2.31.0. - [Release notes](https://github.com/google/error-prone/releases) - [Commits](https://github.com/google/error-prone/compare/v2.29.2...v2.31.0) --- updated-dependencies: - dependency-name: com.google.errorprone:error_prone_annotations dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dbd5f639cc..b7a186339a6 100644 --- a/pom.xml +++ b/pom.xml @@ -205,7 +205,7 @@ com.google.errorprone error_prone_annotations - 2.29.2 + 2.31.0 From 498af6bc776c8d4c01be6df32a53f1cfb0923b9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 06:38:57 +0000 Subject: [PATCH 3/6] Bump org.apache.maven.plugins:maven-surefire-plugin from 3.3.1 to 3.5.0 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.3.1 to 3.5.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.1...surefire-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dbd5f639cc..4f86d863d88 100644 --- a/pom.xml +++ b/pom.xml @@ -420,7 +420,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.3.1 + 3.5.0 org.apache.maven.plugins From b66a78b0de2dbb539f23cb5c2ac470ad366134fb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:41:56 +0000 Subject: [PATCH 4/6] Bump org.mockito:mockito-core from 5.12.0 to 5.13.0 Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.12.0 to 5.13.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.12.0...v5.13.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dbd5f639cc..8164c9b8e3e 100644 --- a/pom.xml +++ b/pom.xml @@ -321,7 +321,7 @@ org.mockito mockito-core - 5.12.0 + 5.13.0 test From 47cd4baf750b8d949bff8b96b63774d1390a2a31 Mon Sep 17 00:00:00 2001 From: Tarek Chouaki Date: Fri, 13 Sep 2024 18:26:28 +0200 Subject: [PATCH 5/6] chore: default zoning params --- .../contrib/zone/skims/DvrpTravelTimeMatrixParams.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/DvrpTravelTimeMatrixParams.java b/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/DvrpTravelTimeMatrixParams.java index a12930c5d42..52c3c332f09 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/DvrpTravelTimeMatrixParams.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/DvrpTravelTimeMatrixParams.java @@ -20,6 +20,7 @@ package org.matsim.contrib.zone.skims; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.PositiveOrZero; import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets; import org.matsim.contrib.common.zones.ZoneSystemParams; @@ -55,6 +56,7 @@ public class DvrpTravelTimeMatrixParams extends ReflectiveConfigGroupWithConfigu + " The unit is seconds. Default value is 0 s (for backward compatibility).") @PositiveOrZero public double maxNeighborTravelTime = 0; //[s] + @NotNull private ZoneSystemParams zoneSystemParams; @@ -101,6 +103,11 @@ public void handleAddUnknownParam(String paramName, String value) { } public ZoneSystemParams getZoneSystemParams() { + if(this.zoneSystemParams == null) { + SquareGridZoneSystemParams squareGridZoneSystemParams = new SquareGridZoneSystemParams(); + squareGridZoneSystemParams.cellSize = 200; + this.zoneSystemParams = squareGridZoneSystemParams; + } return zoneSystemParams; } } From a60c7944f7cbdb03989537a70790a43b5ee7e089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Fri, 13 Sep 2024 18:51:32 +0200 Subject: [PATCH 6/6] feat: flexibilize structure of drt route constraints (#3479) --- .../constraints/DrtRouteConstraints.java | 12 +++ .../DefaultDrtRouteConstraintsCalculator.java | 76 ++++++++++--------- .../DrtRouteConstraintsCalculator.java | 17 ++++- .../contrib/drt/routing/DrtRouteCreator.java | 20 ++--- .../contrib/drt/run/DrtModeRoutingModule.java | 6 +- .../drt/routing/DrtRoutingModuleTest.java | 4 +- 6 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DrtRouteConstraints.java diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DrtRouteConstraints.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DrtRouteConstraints.java new file mode 100644 index 00000000000..68d0fb4ae2e --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/DrtRouteConstraints.java @@ -0,0 +1,12 @@ +package org.matsim.contrib.drt.optimizer.constraints; + +/** + * @author Sebastian Hörl, IRT SystemX + */ +public record DrtRouteConstraints( // + double maxTravelTime, // + double maxRideTime, // + double maxWaitTime// +) { + +} diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java index 039890d8801..f8e1f9b36eb 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java @@ -1,45 +1,53 @@ package org.matsim.contrib.drt.routing; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.Person; +import org.matsim.contrib.drt.optimizer.constraints.ConstraintSetChooser; import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet; import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet; +import org.matsim.contrib.drt.optimizer.constraints.DrtRouteConstraints; +import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.utils.objectattributes.attributable.Attributes; /** * @author nkuehnel / MOIA */ public class DefaultDrtRouteConstraintsCalculator implements DrtRouteConstraintsCalculator { - /** - * Calculates the maximum travel time defined as: drtCfg.getMaxTravelTimeAlpha() * unsharedRideTime + drtCfg.getMaxTravelTimeBeta() - * - * @param constraintsSet - * @param unsharedRideTime ride time of the direct (shortest-time) route - * @return maximum travel time - */ - @Override - public double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) { - if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { - return defaultSet.maxTravelTimeAlpha * unsharedRideTime - + defaultSet.maxTravelTimeBeta; - } else { - throw new IllegalArgumentException("Constraint set is not a default set"); - } - } - - /** - * Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta - * - * @param constraintsSet - * @param unsharedRideTime ride time of the direct (shortest-time) route - * @return maximum ride time - */ - @Override - public double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) { - if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { - return Math.min(unsharedRideTime + defaultSet.maxAbsoluteDetour, - defaultSet.maxDetourAlpha * unsharedRideTime - + defaultSet.maxDetourBeta); - } else { - throw new IllegalArgumentException("Constraint set is not a default set"); - } - } + private final DrtConfigGroup drtCfg; + private final ConstraintSetChooser constraintSetChooser; + + public DefaultDrtRouteConstraintsCalculator(DrtConfigGroup drtCfg, ConstraintSetChooser constraintSetChooser) { + this.drtCfg = drtCfg; + this.constraintSetChooser = constraintSetChooser; + } + + /** + * Calculates the maximum travel time defined as: drtCfg.getMaxTravelTimeAlpha() + * unsharedRideTime + drtCfg.getMaxTravelTimeBeta() + * + * Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * + * unsharedRideTime + drtCfg.maxDetourBeta + * + * @return DrtRouteConstraints constraints + */ + @Override + public DrtRouteConstraints calculateRouteConstraints(double departureTime, Link accessActLink, Link egressActLink, + Person person, Attributes tripAttributes, double unsharedRideTime, double unsharedDistance) { + DrtOptimizationConstraintsSet constraintsSet = constraintSetChooser + .chooseConstraintSet(departureTime, accessActLink, egressActLink, person, tripAttributes).orElse(drtCfg + .addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet()); + + if (constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { + double maxTravelTime = defaultSet.maxTravelTimeAlpha * unsharedRideTime + defaultSet.maxTravelTimeBeta; + double maxRideTime = Math.min(unsharedRideTime + defaultSet.maxAbsoluteDetour, + defaultSet.maxDetourAlpha * unsharedRideTime + defaultSet.maxDetourBeta); + double maxWaitTime = constraintsSet.maxWaitTime; + + return new DrtRouteConstraints(maxTravelTime, maxRideTime, maxWaitTime); + } else { + throw new IllegalArgumentException("Constraint set is not a default set"); + } + + } } \ No newline at end of file diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java index a22a942f35a..726d495fc1e 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java @@ -1,13 +1,24 @@ package org.matsim.contrib.drt.routing; -import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.Person; +import org.matsim.contrib.drt.optimizer.constraints.DrtRouteConstraints; +import org.matsim.utils.objectattributes.attributable.Attributes; /** * @author nkuehnel / MOIA + * @author Sebastian Hörl, IRT SystemX */ public interface DrtRouteConstraintsCalculator { - double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime); + DrtRouteConstraints calculateRouteConstraints( // + double departureTime, // + Link accessActLink, // + Link egressActLink, // + Person person, // + Attributes tripAttributes, // + double unsharedRideTime, // + double unsharedDistance // + ); - double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime); } 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 b646494a1fc..258f862785f 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 @@ -25,6 +25,7 @@ import org.matsim.api.core.v01.population.Route; import org.matsim.contrib.drt.optimizer.constraints.ConstraintSetChooser; import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet; +import org.matsim.contrib.drt.optimizer.constraints.DrtRouteConstraints; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; import org.matsim.contrib.dvrp.path.VrpPaths; @@ -40,6 +41,7 @@ * @author jbischoff * @author michalm (Michal Maciejewski) * @author Kai Nagel + * @author Sebastian Hörl, IRT SystemX */ public class DrtRouteCreator implements DefaultMainLegRouter.RouteCreator { private final DrtConfigGroup drtCfg; @@ -48,16 +50,13 @@ public class DrtRouteCreator implements DefaultMainLegRouter.RouteCreator { private final DrtRouteConstraintsCalculator routeConstraintsCalculator; - private final ConstraintSetChooser constraintSetChooser; - public DrtRouteCreator(DrtConfigGroup drtCfg, Network modalNetwork, LeastCostPathCalculatorFactory leastCostPathCalculatorFactory, TravelTime travelTime, TravelDisutilityFactory travelDisutilityFactory, - DrtRouteConstraintsCalculator routeConstraintsCalculator, ConstraintSetChooser constraintSetChooser) { + DrtRouteConstraintsCalculator routeConstraintsCalculator) { this.drtCfg = drtCfg; this.travelTime = travelTime; this.routeConstraintsCalculator = routeConstraintsCalculator; - this.constraintSetChooser = constraintSetChooser; router = leastCostPathCalculatorFactory.createPathCalculator(modalNetwork, travelDisutilityFactory.createTravelDisutility(travelTime), travelTime); } @@ -71,18 +70,15 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc double unsharedRideTime = unsharedPath.getTravelTime();//includes first & last link double unsharedDistance = VrpPaths.calcDistance(unsharedPath);//includes last link - DrtOptimizationConstraintsSet constraintsSet = - constraintSetChooser.chooseConstraintSet(departureTime, accessActLink, egressActLink, person, tripAttributes) - .orElse(drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet()); - double maxTravelTime = routeConstraintsCalculator.getMaxTravelTime(constraintsSet, unsharedRideTime); - double maxRideDuration = routeConstraintsCalculator.getMaxRideTime(constraintsSet, unsharedRideTime); + DrtRouteConstraints constraints = routeConstraintsCalculator.calculateRouteConstraints(departureTime, accessActLink, egressActLink, person, + tripAttributes, unsharedRideTime, unsharedDistance); DrtRoute route = routeFactories.createRoute(DrtRoute.class, accessActLink.getId(), egressActLink.getId()); route.setDistance(unsharedDistance); - route.setTravelTime(maxTravelTime); - route.setMaxRideTime(maxRideDuration); + route.setTravelTime(constraints.maxTravelTime()); + route.setMaxRideTime(constraints.maxRideTime()); route.setDirectRideTime(unsharedRideTime); - route.setMaxWaitTime(constraintsSet.maxWaitTime); + route.setMaxWaitTime(constraints.maxWaitTime()); if (this.drtCfg.storeUnsharedPath) { route.setUnsharedPath(unsharedPath); diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java index fcbc25faea1..68ae4523ec9 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtModeRoutingModule.java @@ -97,7 +97,8 @@ public void install() { // yyyy possibly not used for door2door; try to move inside the corresponding switch statement below. kai, feb'24 - bindModal(DrtRouteConstraintsCalculator.class).toProvider(modalProvider(getter -> new DefaultDrtRouteConstraintsCalculator())).in(Singleton.class); + bindModal(DrtRouteConstraintsCalculator.class).toProvider(modalProvider(getter -> new DefaultDrtRouteConstraintsCalculator( + drtCfg, getter.getModal(ConstraintSetChooser.class)))).in(Singleton.class); DrtOptimizationConstraintsSet optimizationConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet(); bindModal(ConstraintSetChooser.class).toProvider( () -> (departureTime, accessActLink, egressActLink, person, tripAttributes) @@ -159,8 +160,7 @@ public DrtRouteCreator get() { var travelTime = getModalInstance(TravelTime.class); return new DrtRouteCreator(drtCfg, getModalInstance(Network.class), leastCostPathCalculatorFactory, travelTime, getModalInstance(TravelDisutilityFactory.class), - getModalInstance(DrtRouteConstraintsCalculator.class), - getModalInstance(ConstraintSetChooser.class)); + getModalInstance(DrtRouteConstraintsCalculator.class)); } } diff --git a/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java b/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java index a9c0a735b47..9e2c2d2aad0 100644 --- a/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java +++ b/contribs/drt/src/test/java/org/matsim/contrib/drt/routing/DrtRoutingModuleTest.java @@ -95,8 +95,8 @@ void testCottbusClosestAccessEgressStopFinder() { scenario.getNetwork(), QuadTrees.createQuadTree(drtStops.values())); DrtRouteCreator drtRouteCreator = new DrtRouteCreator(drtCfg, scenario.getNetwork(), new SpeedyDijkstraFactory(), new FreeSpeedTravelTime(), TimeAsTravelDisutility::new, - new DefaultDrtRouteConstraintsCalculator(), - (departureTime, accessActLink, egressActLink, person, tripAttributes) -> Optional.of(defaultConstraintsSet)); + new DefaultDrtRouteConstraintsCalculator(drtCfg, + (departureTime, accessActLink, egressActLink, person, tripAttributes) -> Optional.of(defaultConstraintsSet))); DefaultMainLegRouter mainRouter = new DefaultMainLegRouter(drtMode, scenario.getNetwork(), scenario.getPopulation().getFactory(), drtRouteCreator); DvrpRoutingModule dvrpRoutingModule = new DvrpRoutingModule(mainRouter, walkRouter, walkRouter, stopFinder,