From 03487d53036285840019d00ee472196fbac0692a Mon Sep 17 00:00:00 2001 From: steffenaxer <26229392+steffenaxer@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:43:39 +0100 Subject: [PATCH 01/12] Make StringConverter threadsafe --- .../attributeconverters/StringConverter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java index 07ede6e8bd5..3a600e82bc1 100644 --- a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java +++ b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.matsim.utils.objectattributes.AttributeConverter; @@ -29,7 +30,7 @@ * @author mrieser */ public class StringConverter implements AttributeConverter { - private final Map stringCache = new HashMap(1000); + private final Map stringCache = new ConcurrentHashMap<>(1000); @Override public String convert(String value) { String s = this.stringCache.get(value); @@ -44,4 +45,4 @@ public String convert(String value) { public String convertToString(Object o) { return (String) o; } -} \ No newline at end of file +} From 632e5ece7fa2ea1f19d66a67fc8cb050a4009f53 Mon Sep 17 00:00:00 2001 From: simei94 <67737999+simei94@users.noreply.github.com> Date: Tue, 12 Mar 2024 02:50:56 -0600 Subject: [PATCH 02/12] preserve possibility to run converter without shp file (#3158) Co-authored-by: Michal Maciejewski --- .../prepare/network/CreateNetworkFromSumo.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateNetworkFromSumo.java b/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateNetworkFromSumo.java index b4a3521e48d..62f21e24314 100644 --- a/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateNetworkFromSumo.java +++ b/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateNetworkFromSumo.java @@ -74,7 +74,15 @@ public static void main(String[] args) { @Override public Integer call() throws Exception { - SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, Path.of(shp.getShapeFile()), crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor); +// since ShpOptions.getShapeFile() no longer is a path but a string, we have to check if it is defined before creating SumoNetworkConverter to +// preserve the possibility to run the converter without a shp file, otherwise, when calling Path.of(shp.getShapeFile) a NullPointerException is caused -sme0324 + Path path = null; + + if (shp.isDefined()) { + path = Path.of(shp.getShapeFile()); + } + + SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, path, crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor); Network network = NetworkUtils.createNetwork(); Lanes lanes = LanesUtils.createLanesContainer(); From 44eb25b42be8230d97c21a30cd8bc585ed4c7616 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 12 Mar 2024 11:08:01 +0100 Subject: [PATCH 03/12] change drt wait stats to gpkg --- .../zonal/DrtZonalWaitTimesAnalyzer.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java index fd0fb66d20f..129c952ec09 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java @@ -24,13 +24,7 @@ import java.io.IOException; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.apache.logging.log4j.LogManager; @@ -159,10 +153,12 @@ private Map createZonalStats() { public void notifyShutdown(ShutdownEvent event) { String crs = event.getServices().getConfig().global().getCoordinateSystem(); Collection features = convertGeometriesToSimpleFeatures(crs); - String fileName = event.getServices() + if(!features.isEmpty()) { + String fileName = event.getServices() .getControlerIO() - .getOutputFilename("drt_waitStats" + "_" + drtCfg.getMode() + "_zonal.shp"); - GeoFileWriter.writeGeometries(features, fileName); + .getOutputFilename("drt_waitStats" + "_" + drtCfg.getMode() + "_zonal.gpkg"); + GeoFileWriter.writeGeometries(features, fileName); + } } private Collection convertGeometriesToSimpleFeatures(String targetCoordinateSystem) { @@ -172,9 +168,10 @@ private Collection convertGeometriesToSimpleFeatures(String targe } catch (IllegalArgumentException e) { log.warn("Coordinate reference system \"" + targetCoordinateSystem - + "\" is unknown. Please set a crs in config global. Will try to create drt_waitStats_" + + "\" is unknown. Please set a crs in config global. Will not create drt_waitStats_" + drtCfg.getMode() - + "_zonal.shp anyway."); + + "_zonal.gpkg."); + return Collections.emptyList(); } simpleFeatureBuilder.setName("drtZoneFeature"); From 04fd77595ab8608303d8e6086eb40471b21db344 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:45:21 +0000 Subject: [PATCH 04/12] build(deps): bump com.fasterxml.jackson:jackson-bom Bumps [com.fasterxml.jackson:jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.16.1 to 2.16.2. - [Commits](https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.16.1...jackson-bom-2.16.2) --- updated-dependencies: - dependency-name: com.fasterxml.jackson:jackson-bom 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 515d4772954..f9162d3cf81 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 0.49.2 1.19.0 7.0.0 - 2.16.1 + 2.16.2 2.5.0 5.10.2 From e2eb1df426b55856537075b1db7ebf13e57a9bdf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:14:30 +0000 Subject: [PATCH 05/12] build(deps): bump org.apache.maven.plugins:maven-assembly-plugin Bumps [org.apache.maven.plugins:maven-assembly-plugin](https://github.com/apache/maven-assembly-plugin) from 3.6.0 to 3.7.0. - [Commits](https://github.com/apache/maven-assembly-plugin/compare/maven-assembly-plugin-3.6.0...maven-assembly-plugin-3.7.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-assembly-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- matsim/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matsim/pom.xml b/matsim/pom.xml index e5716bead27..ba989fc0dff 100644 --- a/matsim/pom.xml +++ b/matsim/pom.xml @@ -344,7 +344,7 @@ org.apache.maven.plugins maven-assembly-plugin - 3.6.0 + 3.7.0 src/main/assembly/assembly-release.xml From 29519a5bd2b2b623e396d4a973c1d7f807a6f922 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Tue, 12 Mar 2024 12:20:24 +0100 Subject: [PATCH 06/12] make memory observer interval configurable --- .../config/groups/ControllerConfigGroup.java | 19 +++++++++++++++++++ .../core/controler/AbstractController.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java b/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java index 9cbde96f1e3..c84d9eee16c 100644 --- a/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java +++ b/matsim/src/main/java/org/matsim/core/config/groups/ControllerConfigGroup.java @@ -79,6 +79,8 @@ public enum CleanIterations { private static final String COMPRESSION_TYPE = "compressionType"; private static final String EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS = "createScoringFunctionType"; + private static final String MEMORY_OBSERVER_INTERVAL = "memoryObserverInterval"; + /*package*/ static final String MOBSIM = "mobsim"; public enum MobsimType {qsim, JDEQSim, hermes} @@ -109,6 +111,8 @@ public enum MobsimType {qsim, JDEQSim, hermes} private CleanIterations cleanItersAtEnd = CleanIterations.keep; + private int memoryObserverInterval = 60; + public ControllerConfigGroup() { super(GROUP_NAME); } @@ -151,6 +155,7 @@ public final Map getComments() { "to a file. `0' disables snapshots writing completely"); map.put(DUMP_DATA_AT_END, "true if at the end of a run, plans, network, config etc should be dumped to a file"); map.put(CLEAN_ITERS_AT_END, "Defines what should be done with the ITERS directory when a simulation finished successfully"); + map.put(MEMORY_OBSERVER_INTERVAL, "Defines the interval for printing memory usage to the log in [seconds]. Must be positive. Defaults to 60."); return map; } @@ -427,6 +432,17 @@ public EventTypeToCreateScoringFunctions getEventTypeToCreateScoringFunctions() public void setEventTypeToCreateScoringFunctions(EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions) { this.eventTypeToCreateScoringFunctions = eventTypeToCreateScoringFunctions; } + + @StringGetter(MEMORY_OBSERVER_INTERVAL) + public int getMemoryObserverInterval() { + return memoryObserverInterval; + } + + @StringSetter(MEMORY_OBSERVER_INTERVAL) + public void setMemoryObserverInterval(int memoryObserverInterval) { + this.memoryObserverInterval = memoryObserverInterval; + } + // --- int writePlansUntilIteration = 1 ; public int getWritePlansUntilIteration() { @@ -450,5 +466,8 @@ protected void checkConsistency(Config config) { log.warn( "this is not recommended, as it might result in a directory containing output from several model runs" ); log.warn( "prefer the options "+OverwriteFileSetting.deleteDirectoryIfExists+" or "+OverwriteFileSetting.failIfDirectoryExists ); } + if(config.controller().getMemoryObserverInterval() < 0) { + log.warn("Memory observer interval is negative. Simulation will most likely crash."); + } } } diff --git a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java index 93c1680a231..a1c008e31ba 100644 --- a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java +++ b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java @@ -73,7 +73,7 @@ final void setupOutputDirectory(OutputDirectoryHierarchy controlerIO) { } protected final void run(final Config config) { - MemoryObserver.start(60); + MemoryObserver.start(config.controller().getMemoryObserverInterval()); MatsimRuntimeModifications.MyRunnable runnable = new MatsimRuntimeModifications.MyRunnable() { @Override public void run() throws MatsimRuntimeModifications.UnexpectedShutdownException { From 9a23a70109becd374ef28381eb32be034fa226de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:08:38 +0000 Subject: [PATCH 07/12] build(deps): bump org.apache.commons:commons-compress Bumps org.apache.commons:commons-compress from 1.26.0 to 1.26.1. --- updated-dependencies: - dependency-name: org.apache.commons:commons-compress 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 f9162d3cf81..57f6383f137 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.apache.commons commons-compress - 1.26.0 + 1.26.1 commons-logging From a85a586c5d17c67b2df45f914b24df4b38395a9a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:30:53 +0000 Subject: [PATCH 08/12] build(deps): bump log4j.version from 2.23.0 to 2.23.1 Bumps `log4j.version` from 2.23.0 to 2.23.1. Updates `org.apache.logging.log4j:log4j-api` from 2.23.0 to 2.23.1 Updates `org.apache.logging.log4j:log4j-core` from 2.23.0 to 2.23.1 Updates `org.apache.logging.log4j:log4j-slf4j2-impl` from 2.23.0 to 2.23.1 --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-api dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.logging.log4j:log4j-core dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.logging.log4j:log4j-slf4j2-impl 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 57f6383f137..097895e66b4 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 17 - 2.23.0 + 2.23.1 29.5 0.49.2 1.19.0 From 84bd1810cc03ec05126ffba9073cf9ee7fabe302 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:05:38 +0000 Subject: [PATCH 09/12] build(deps): bump com.google.errorprone:error_prone_annotations Bumps [com.google.errorprone:error_prone_annotations](https://github.com/google/error-prone) from 2.25.0 to 2.26.1. - [Release notes](https://github.com/google/error-prone/releases) - [Commits](https://github.com/google/error-prone/compare/v2.25.0...v2.26.1) --- 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 097895e66b4..8ab3815ad40 100644 --- a/pom.xml +++ b/pom.xml @@ -200,7 +200,7 @@ com.google.errorprone error_prone_annotations - 2.25.0 + 2.26.1 From d7bd8fed4c1567976626994b868ef73820ea7a68 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:56:23 +0100 Subject: [PATCH 10/12] Pass person and vehicle to travel time query in FISS --- .../java/org/matsim/contrib/drt/extension/fiss/FISS.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java index 58705f89cb3..9dbd91f2f0a 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java @@ -15,6 +15,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.Person; import org.matsim.contrib.dynagent.DynAgent; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.controler.MatsimServices; @@ -94,13 +95,16 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id linkId) { Leg currentLeg = (Leg) planAgent.getCurrentPlanElement(); Gbl.assertIf(this.fissConfigGroup.sampledModes.contains(currentLeg.getMode())); NetworkRoute networkRoute = (NetworkRoute) currentLeg.getRoute(); + Person person = planAgent.getCurrentPlan().getPerson(); + Vehicle vehicle = this.matsimServices.getScenario().getVehicles().getVehicles() + .get(networkRoute.getVehicleId()); // update travel time with travel times of last iteration double newTravelTime = 0.0; // start and end link are not consideres in NetworkRoutingModule for travel time for (Id routeLinkId : networkRoute.getLinkIds()) { newTravelTime += this.travelTime.getLinkTravelTime(network.getLinks().get(routeLinkId), - now + newTravelTime, null, null); + now + newTravelTime, person, vehicle); } LOG.debug("New travelTime: {}, was {}", newTravelTime, networkRoute.getTravelTime().orElseGet(() -> Double.NaN)); From 1aa9b21a447e09ccf8198a21701966efbdf1b930 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:58:14 +0100 Subject: [PATCH 11/12] Tiny code lint --- .../java/org/matsim/contrib/drt/extension/fiss/FISS.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java index 9dbd91f2f0a..6ce932ecebc 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/fiss/FISS.java @@ -101,7 +101,7 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id linkId) { // update travel time with travel times of last iteration double newTravelTime = 0.0; - // start and end link are not consideres in NetworkRoutingModule for travel time + // start and end link are not considered in NetworkRoutingModule for travel time for (Id routeLinkId : networkRoute.getLinkIds()) { newTravelTime += this.travelTime.getLinkTravelTime(network.getLinks().get(routeLinkId), now + newTravelTime, person, vehicle); @@ -112,8 +112,8 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id linkId) { } // remove vehicle of teleported agent from parking spot QVehicle removedVehicle = null; - if (agent instanceof MobsimDriverAgent) { - Id vehicleId = ((MobsimDriverAgent) agent).getPlannedVehicleId(); + if (agent instanceof MobsimDriverAgent driverAgent) { + Id vehicleId = driverAgent.getPlannedVehicleId(); QVehicle vehicle = qNetsimEngine.getVehicles().get(vehicleId); QLinkI qLinkI = (QLinkI) this.qNetsimEngine.getNetsimNetwork().getNetsimLink(linkId); removedVehicle = qLinkI.removeParkedVehicle(vehicleId); From 5f4ad5edf50bbbabff70d6fe1e99f97c86658448 Mon Sep 17 00:00:00 2001 From: steffenaxer <26229392+steffenaxer@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:18:29 +0100 Subject: [PATCH 12/12] Use computeIfAbsent for stringCache --- .../attributeconverters/StringConverter.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java index 3a600e82bc1..bf9a209818a 100644 --- a/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java +++ b/matsim/src/main/java/org/matsim/utils/objectattributes/attributeconverters/StringConverter.java @@ -31,14 +31,10 @@ */ public class StringConverter implements AttributeConverter { private final Map stringCache = new ConcurrentHashMap<>(1000); + @Override public String convert(String value) { - String s = this.stringCache.get(value); - if (s == null) { - s = value; - this.stringCache.put(s, s); - } - return s; + return stringCache.computeIfAbsent(value, k -> k); } @Override