From 790fede1def4c727b7d999a58e42a834c5fc6e27 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 28 Mar 2024 12:30:53 +0100 Subject: [PATCH 1/2] use configurable parameter for zone name column --- .../GenerateSmallScaleCommercialTrafficDemand.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java index e5b6a27b774..f3a25500443 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java @@ -908,8 +908,8 @@ private Id findPossibleLink(String zone, String selectedCategory, List, Link>> filterLinksForZones(Scenario scenario, Index indexZones, - Map>> buildingsPerZone) throws URISyntaxException { + Map, Link>> filterLinksForZones(Scenario scenario, Index indexZones, + Map>> buildingsPerZone) throws URISyntaxException { Map, Link>> regionLinksMap = new HashMap<>(); List links; log.info("Filtering and assign links to zones. This take some time..."); @@ -944,11 +944,11 @@ static Map, Link>> filterLinksForZones(Scenario scenario, I /** * Finds for areas without links the nearest Link if the area contains any building. */ - private static void findNearestLinkForZonesWithoutLinks(Network networkToChange, Map, Link>> regionLinksMap, - Index shpZones, - Map>> buildingsPerZone) { + private void findNearestLinkForZonesWithoutLinks(Network networkToChange, Map, Link>> regionLinksMap, + Index shpZones, + Map>> buildingsPerZone) { for (SimpleFeature singleArea : shpZones.getAllFeatures()) { - String zoneID = (String) singleArea.getAttribute("areaID"); + String zoneID = (String) singleArea.getAttribute(shapeFileZoneNameColumn); if (!regionLinksMap.containsKey(zoneID) && buildingsPerZone.get(zoneID) != null) { for (List buildingList : buildingsPerZone.get(zoneID).values()) { for (SimpleFeature building : buildingList) { From 1dd65cce328ef63beaa19f419115b49c4809915e Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 28 Mar 2024 12:46:46 +0100 Subject: [PATCH 2/2] make methods static again --- ...enerateSmallScaleCommercialTrafficDemand.java | 16 +++++++++------- .../SmallScaleCommercialTrafficUtilsTest.java | 2 +- .../TrafficVolumeGenerationTest.java | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java index f3a25500443..566a1214142 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java @@ -261,7 +261,7 @@ public Integer call() throws Exception { usedLanduseConfiguration.toString(), indexLanduse, indexZones, indexBuildings, indexInvestigationAreaRegions, shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); - Map, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone); + Map, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone, shapeFileZoneNameColumn); switch (usedSmallScaleCommercialTrafficType) { case commercialPersonTraffic, goodsTraffic -> @@ -908,8 +908,9 @@ private Id findPossibleLink(String zone, String selectedCategory, List, Link>> filterLinksForZones(Scenario scenario, Index indexZones, - Map>> buildingsPerZone) throws URISyntaxException { + static Map, Link>> filterLinksForZones(Scenario scenario, Index indexZones, + Map>> buildingsPerZone, + String shapeFileZoneNameColumn) throws URISyntaxException { Map, Link>> regionLinksMap = new HashMap<>(); List links; log.info("Filtering and assign links to zones. This take some time..."); @@ -936,7 +937,7 @@ Map, Link>> filterLinksForZones(Scenario scenario, Index in .computeIfAbsent((String) l.getAttributes().getAttribute("zone"), (k) -> new HashMap<>()) .put(l.getId(), l)); if (regionLinksMap.size() != indexZones.size()) - findNearestLinkForZonesWithoutLinks(networkToChange, regionLinksMap, indexZones, buildingsPerZone); + findNearestLinkForZonesWithoutLinks(networkToChange, regionLinksMap, indexZones, buildingsPerZone, shapeFileZoneNameColumn); return regionLinksMap; } @@ -944,9 +945,10 @@ Map, Link>> filterLinksForZones(Scenario scenario, Index in /** * Finds for areas without links the nearest Link if the area contains any building. */ - private void findNearestLinkForZonesWithoutLinks(Network networkToChange, Map, Link>> regionLinksMap, - Index shpZones, - Map>> buildingsPerZone) { + private static void findNearestLinkForZonesWithoutLinks(Network networkToChange, Map, Link>> regionLinksMap, + Index shpZones, + Map>> buildingsPerZone, + String shapeFileZoneNameColumn) { for (SimpleFeature singleArea : shpZones.getAllFeatures()) { String zoneID = (String) singleArea.getAttribute(shapeFileZoneNameColumn); if (!regionLinksMap.containsKey(zoneID) && buildingsPerZone.get(zoneID) != null) { diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtilsTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtilsTest.java index 5aa06d111fc..9af01ede414 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtilsTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtilsTest.java @@ -64,7 +64,7 @@ void findZoneOfLinksTest() throws IOException, URISyntaxException { Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), shapeFileZoneNameColumn), - buildingsPerZone); + buildingsPerZone, shapeFileZoneNameColumn); Assertions.assertEquals(3, regionLinksMap.size(), MatsimTestUtils.EPSILON); Assertions.assertEquals(60, regionLinksMap.get("area1").size(), MatsimTestUtils.EPSILON); diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGenerationTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGenerationTest.java index b680e568ffb..7b51453072a 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGenerationTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGenerationTest.java @@ -401,7 +401,7 @@ void testAddingExistingScenarios() throws Exception { Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), shapeFileZoneNameColumn), - buildingsPerZone); + buildingsPerZone, shapeFileZoneNameColumn); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); @@ -469,7 +469,7 @@ void testAddingExistingScenariosWithSample() throws Exception { Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), shapeFileZoneNameColumn), - buildingsPerZone); + buildingsPerZone, shapeFileZoneNameColumn); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); @@ -541,7 +541,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { .createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand - .filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), buildingsPerZone); + .filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), buildingsPerZone, shapeFileZoneNameColumn); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); @@ -701,7 +701,7 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th .createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand - .filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), buildingsPerZone); + .filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), buildingsPerZone, shapeFileZoneNameColumn); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);