From 87a6887c30294c763422f2673a3fd5f4b3cc5dcc Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Fri, 6 Sep 2024 00:53:14 +0200 Subject: [PATCH 01/14] drt: allow final stay task without requests in preplanned scenarios --- .../optimizer/PreplannedDrtOptimizer.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) 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..fd0f6672826 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 @@ -174,17 +174,22 @@ public void nextTask(DvrpVehicle vehicle) { } else { nonVisitedPreplannedStops.poll();//remove this stop from queue - var stopTask = taskFactory.createStopTask(vehicle, currentTime, currentTime + stopDuration, currentLink); - if (nextStop.pickup) { - var request = Preconditions.checkNotNull(openRequests.get(nextStop.preplannedRequest.key), - "Request (%s) has not been yet submitted", nextStop.preplannedRequest); - stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + if(nextStop.preplannedRequest.key.passengerIds.isEmpty() && nonVisitedPreplannedStops.isEmpty()) { + var stayTask = taskFactory.createStayTask(vehicle, currentTime, vehicle.getServiceEndTime(), currentLink); + schedule.addTask(stayTask); } else { - var request = Preconditions.checkNotNull(openRequests.remove(nextStop.preplannedRequest.key), - "Request (%s) has not been yet submitted", nextStop.preplannedRequest); - stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + var stopTask = taskFactory.createStopTask(vehicle, currentTime, currentTime + stopDuration, currentLink); + if (nextStop.pickup) { + var request = Preconditions.checkNotNull(openRequests.get(nextStop.preplannedRequest.key), + "Request (%s) has not been yet submitted", nextStop.preplannedRequest); + stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + } else { + var request = Preconditions.checkNotNull(openRequests.remove(nextStop.preplannedRequest.key), + "Request (%s) has not been yet submitted", nextStop.preplannedRequest); + stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(request)); + } + schedule.addTask(stopTask); } - schedule.addTask(stopTask); } // switch to the next task and update currentTasks From ab554dad76f562cae7cc62f76384d78902faea8e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:05:36 +0000 Subject: [PATCH 02/14] Bump org.codehaus.mojo:buildnumber-maven-plugin from 3.2.0 to 3.2.1 Bumps [org.codehaus.mojo:buildnumber-maven-plugin](https://github.com/mojohaus/buildnumber-maven-plugin) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/mojohaus/buildnumber-maven-plugin/releases) - [Commits](https://github.com/mojohaus/buildnumber-maven-plugin/compare/3.2.0...3.2.1) --- updated-dependencies: - dependency-name: org.codehaus.mojo:buildnumber-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cdecc6341d7..c0f2d866e2d 100644 --- a/pom.xml +++ b/pom.xml @@ -455,7 +455,7 @@ org.codehaus.mojo buildnumber-maven-plugin - 3.2.0 + 3.2.1 validate From 692231f2793ec77f023e414907b1f963a56b6ca9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:05:37 +0000 Subject: [PATCH 03/14] Bump log4j.version from 2.23.1 to 2.24.0 Bumps `log4j.version` from 2.23.1 to 2.24.0. Updates `org.apache.logging.log4j:log4j-api` from 2.23.1 to 2.24.0 Updates `org.apache.logging.log4j:log4j-core` from 2.23.1 to 2.24.0 Updates `org.apache.logging.log4j:log4j-slf4j2-impl` from 2.23.1 to 2.24.0 --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-api dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-slf4j2-impl 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 cdecc6341d7..323157754c1 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 21 - 2.23.1 + 2.24.0 31.3 0.49.2 1.20.0 From f3695136e608f66d3e1c5dfe7449759f612eea1c Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 10 Sep 2024 22:45:19 +0200 Subject: [PATCH 04/14] drt: add back in max ride time to offer acceptor --- .../matsim/contrib/drt/passenger/DefaultOfferAcceptor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DefaultOfferAcceptor.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DefaultOfferAcceptor.java index 9eeed624139..c45e04db6ca 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DefaultOfferAcceptor.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/passenger/DefaultOfferAcceptor.java @@ -28,7 +28,9 @@ public Optional acceptDrtOffer(DrtRequest request, double de .newBuilder() .request(request) .earliestStartTime(request.getEarliestStartTime()) + .maxRideDuration(request.getMaxRideDuration()) .latestArrivalTime(Math.min(updatedLatestStartTime + request.getMaxRideDuration(), request.getLatestArrivalTime())) - .latestStartTime(updatedLatestStartTime).build()); + .latestStartTime(updatedLatestStartTime) + .build()); } } From 8290192dece478caa1dfa4817e1efd283021f6e0 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 10 Sep 2024 22:52:47 +0200 Subject: [PATCH 05/14] dvrp: allow fixed dvrp offline travel time estimation --- .../contrib/dvrp/run/DvrpConfigGroup.java | 32 +++++++++++-------- .../DvrpOfflineTravelTimeEstimator.java | 6 ++-- .../DvrpTravelTimeModule.java | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java index 25cc051ece8..671b12f8846 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java @@ -19,23 +19,20 @@ package org.matsim.contrib.dvrp.run; -import java.util.Set; - -import javax.annotation.Nullable; - +import jakarta.validation.constraints.DecimalMax; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.TransportMode; -import org.matsim.contrib.dynagent.run.DynQSimConfigConsistencyChecker; import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets; +import org.matsim.contrib.dynagent.run.DynQSimConfigConsistencyChecker; import org.matsim.contrib.zone.skims.DvrpTravelTimeMatrixParams; import org.matsim.core.config.Config; -import jakarta.validation.constraints.DecimalMax; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Positive; -import jakarta.validation.constraints.PositiveOrZero; +import javax.annotation.Nullable; +import java.util.Set; public class DvrpConfigGroup extends ReflectiveConfigGroupWithConfigurableParameterSets { private static final Logger log = LogManager.getLogger(DvrpConfigGroup.class); @@ -68,13 +65,14 @@ public static DvrpConfigGroup get(Config config) { @Parameter @Comment("Used for OFFLINE estimation of travel times for VrpOptimizer" + " by means of the exponential moving average." - + " The weighting decrease, alpha, must be in (0,1]." + + " The weighting decrease, alpha, must be in [0,1]." + " We suggest small values of alpha, e.g. 0.05." + " The averaging starts from the initial travel time estimates. If not provided," - + " the free-speed TTs is used as the initial estimates") - @Positive + + " the free-speed TTs is used as the initial estimates. If alpha is set to 0, the initial" + + "travel times stay fixed.") + @PositiveOrZero @DecimalMax("1.0") - public double travelTimeEstimationAlpha = 0.05; // [-], 1 ==> TTs from the last iteration only + public double travelTimeEstimationAlpha = 0.05; // [-], 1 ==> TTs from the last iteration only, 0 ==> initial TTs only @Parameter @Comment("" @@ -146,6 +144,12 @@ protected void checkConsistency(Config config) { if (!config.eventsManager().getSynchronizeOnSimSteps()) { throw new RuntimeException("Synchronization on sim steps is required"); } + if(initialTravelTimesFile == null && travelTimeEstimationAlpha == 0.0) { + throw new RuntimeException("Initial travel times file is required if travel times should not be updated."); + } + if(travelTimeEstimationAlpha == 0.0 && travelTimeEstimationBeta > 0) { + throw new RuntimeException("Online estimation beta should be 0 if travel time should not be updated."); + } } public DvrpTravelTimeMatrixParams getTravelTimeMatrixParams() { diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpOfflineTravelTimeEstimator.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpOfflineTravelTimeEstimator.java index 5d80e161462..efd03ff8c0a 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpOfflineTravelTimeEstimator.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpOfflineTravelTimeEstimator.java @@ -90,7 +90,7 @@ public DvrpOfflineTravelTimeEstimator(TravelTime initialTT, TravelTime observedT this.delimiter = delimiter; alpha = travelTimeEstimationAlpha; - checkArgument(alpha > 0 && alpha <= 1, "travelTimeEstimationAlpha must be in (0,1]"); + checkArgument(alpha >= 0 && alpha <= 1, "travelTimeEstimationAlpha must be in [0,1]"); linkTravelTimes = DvrpOfflineTravelTimes.convertToLinkTravelTimeMatrix(initialTT, network.getLinks().values(), timeDiscretizer); @@ -114,7 +114,9 @@ private int getIdx(double time) { @Override public void notifyMobsimBeforeCleanup(@SuppressWarnings("rawtypes") MobsimBeforeCleanupEvent e) { - updateTTs(observedTT, alpha); + if(alpha > 0) { + updateTTs(observedTT, alpha); + } } @Override diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpTravelTimeModule.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpTravelTimeModule.java index c295c70ac6a..2ac35955346 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpTravelTimeModule.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/trafficmonitoring/DvrpTravelTimeModule.java @@ -64,7 +64,7 @@ public void install() { addMobsimListenerBinding().to(DvrpOfflineTravelTimeEstimator.class); addControlerListenerBinding().to(DvrpOfflineTravelTimeEstimator.class); - if (dvrpCfg.travelTimeEstimationBeta > 0) {// online estimation + if (dvrpCfg.travelTimeEstimationBeta > 0 && dvrpCfg.travelTimeEstimationAlpha > 0) {// online estimation bind(DvrpOnlineTravelTimeEstimator.class).asEagerSingleton(); addMobsimListenerBinding().to(DvrpOnlineTravelTimeEstimator.class); bind(DvrpTravelTimeEstimator.class).to(DvrpOnlineTravelTimeEstimator.class); From 13b8beb7d70fd5efc29c8c6581f72446339fb989 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 05:52:27 +0000 Subject: [PATCH 06/14] Bump io.grpc:grpc-all from 1.65.1 to 1.66.0 Bumps [io.grpc:grpc-all](https://github.com/grpc/grpc-java) from 1.65.1 to 1.66.0. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.65.1...v1.66.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-all dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- contribs/hybridsim/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index b480aa197dd..58663b4a20b 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -11,7 +11,7 @@ 4.28.0 - 1.65.1 + 1.66.0 From 2b34584eb6dd2a149ba7de586a9cf1e8f72aa296 Mon Sep 17 00:00:00 2001 From: u229187 Date: Wed, 11 Sep 2024 08:03:09 +0200 Subject: [PATCH 07/14] avoid maven trouble by adding io.opentelemetry-sdk explicitly --- contribs/hybridsim/pom.xml | 141 +++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index 58663b4a20b..ac7da45f5b5 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -1,77 +1,82 @@ - - org.matsim - contrib - 2025.0-SNAPSHOT - - 4.0.0 - org.matsim.contrib - hybridsim - hybridsim + + org.matsim + contrib + 2025.0-SNAPSHOT + + 4.0.0 + org.matsim.contrib + hybridsim + hybridsim - - 4.28.0 - 1.66.0 - + + 4.28.0 + 1.66.0 + - + - - com.google.protobuf - protobuf-java - ${protobuf.version} - + + com.google.protobuf + protobuf-java + ${protobuf.version} + - - io.grpc - grpc-all - ${grpc.version} - + + io.grpc + grpc-all + ${grpc.version} + - - javax.annotation - javax.annotation-api - 1.3.2 - + + javax.annotation + javax.annotation-api + 1.3.2 + + + io.opentelemetry + opentelemetry-sdk + 1.40.0 + - + - - - - kr.motd.maven - os-maven-plugin - 1.7.1 - - - initialize - - detect - - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} - - grpc-java - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - true - - - - - compile - compile-custom - - - - - - + + + + kr.motd.maven + os-maven-plugin + 1.7.1 + + + initialize + + detect + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} + + true + + + + + compile + compile-custom + + + + + + From 641ea3fc195eba0c50ffa6dc3462d2984bd55cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Wed, 11 Sep 2024 08:24:40 +0200 Subject: [PATCH 08/14] feat: allow defining initial link id of vehicle explicitly --- .../qsim/agents/PopulationAgentSource.java | 12 ++++++++++-- .../java/org/matsim/vehicles/VehicleUtils.java | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/matsim/src/main/java/org/matsim/core/mobsim/qsim/agents/PopulationAgentSource.java b/matsim/src/main/java/org/matsim/core/mobsim/qsim/agents/PopulationAgentSource.java index 0d5260068b6..54a862f8fd4 100644 --- a/matsim/src/main/java/org/matsim/core/mobsim/qsim/agents/PopulationAgentSource.java +++ b/matsim/src/main/java/org/matsim/core/mobsim/qsim/agents/PopulationAgentSource.java @@ -155,7 +155,7 @@ private void insertVehicles(Person person) { } // find the link ID of where to place the vehicle: - Id vehicleLinkId = findVehicleLink(person); + Id vehicleLinkId = findVehicleLink(person, vehicle); // Checking if the vehicle has been seen before: Id result = this.seenVehicleIds.get( vehicleId ) ; @@ -190,7 +190,15 @@ private void insertVehicles(Person person) { * than to ask agent.getCurrentLinkId() after creation. * @param person TODO */ - private Id findVehicleLink(Person person ) { + private Id findVehicleLink(Person person, Vehicle vehicle) { + /* + * Manual case: the initial link id of the vehicle is saved as an attribute + */ + Id initialLinkId = VehicleUtils.getInitialLinkId(vehicle); + if (initialLinkId != null) { + return initialLinkId; + } + /* Cases that come to mind: * (1) multiple persons share car located at home, but possibly brought to different place by someone else. * This is treated by the following algo. diff --git a/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java b/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java index 70027f8a0b5..aac3e537da9 100644 --- a/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java +++ b/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java @@ -20,17 +20,18 @@ package org.matsim.vehicles; +import java.util.HashMap; +import java.util.Map; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; import org.matsim.core.gbl.Gbl; import org.matsim.utils.objectattributes.attributable.AttributesUtils; -import java.util.HashMap; -import java.util.Map; - /** * @author nagel @@ -57,6 +58,7 @@ public final class VehicleUtils { private static final String COST_PER_SECOND_WAITING = "costsPerSecondWaiting"; private static final String COST_PER_SECOND_INSERVICE = "costsPerSecondInService"; private static final String FUEL_TYPE = "fuelType"; + private static final String INITIAL_LINK_ID = "initialLinkId"; public static VehicleType createVehicleType( Id typeId ){ return new VehicleType( typeId ); @@ -432,4 +434,13 @@ public static void writeVehicles( Vehicles vehicles, String filename ) { new MatsimVehicleWriter( vehicles ).writeFile( filename ); } + + public static Id getInitialLinkId(Vehicle vehicle) { + String attribute = (String) vehicle.getAttributes().getAttribute(INITIAL_LINK_ID); + return attribute == null ? null : Id.createLinkId(attribute); + } + + public static void setInitialLinkId(Vehicle vehicle, Id initialLinkId) { + vehicle.getAttributes().putAttribute(INITIAL_LINK_ID, initialLinkId.toString()); + } } From c09e8700fe68afb275bc79f33d763e95f9f878db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20K=C3=BChnel?= Date: Wed, 11 Sep 2024 08:53:46 +0200 Subject: [PATCH 09/14] Update DvrpConfigGroup.java --- .../main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java index 671b12f8846..306b61d62b3 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpConfigGroup.java @@ -69,7 +69,7 @@ public static DvrpConfigGroup get(Config config) { + " We suggest small values of alpha, e.g. 0.05." + " The averaging starts from the initial travel time estimates. If not provided," + " the free-speed TTs is used as the initial estimates. If alpha is set to 0, the initial" - + "travel times stay fixed.") + + " travel times stay fixed.") @PositiveOrZero @DecimalMax("1.0") public double travelTimeEstimationAlpha = 0.05; // [-], 1 ==> TTs from the last iteration only, 0 ==> initial TTs only From 1e31b879c1b45947e1b9cbe3d64179c7933f9562 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:13:52 +0000 Subject: [PATCH 10/14] Bump io.opentelemetry:opentelemetry-sdk from 1.40.0 to 1.42.1 Bumps [io.opentelemetry:opentelemetry-sdk](https://github.com/open-telemetry/opentelemetry-java) from 1.40.0 to 1.42.1. - [Release notes](https://github.com/open-telemetry/opentelemetry-java/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-java/compare/v1.40.0...v1.42.1) --- updated-dependencies: - dependency-name: io.opentelemetry:opentelemetry-sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- contribs/hybridsim/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index ac7da45f5b5..bed620d598d 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -36,7 +36,7 @@ io.opentelemetry opentelemetry-sdk - 1.40.0 + 1.42.1 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 11/14] 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 12/14] 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 13/14] 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 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 14/14] 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,