diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/CreateDataDistributionOfStructureData.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/CreateDataDistributionOfStructureData.java index dd48b6c8206..c9ce08fe9b3 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/CreateDataDistributionOfStructureData.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/CreateDataDistributionOfStructureData.java @@ -29,6 +29,8 @@ public class CreateDataDistributionOfStructureData implements MATSimAppCommand { private static final Logger log = LogManager.getLogger(CreateDataDistributionOfStructureData.class); + private static LanduseDataConnectionCreator landuseDataConnectionCreator; + private enum LanduseConfiguration { useOnlyOSMLanduse, useOSMBuildingsAndLanduse } @@ -69,11 +71,20 @@ private enum LanduseConfiguration { @CommandLine.Option(names = "--pathToInvestigationAreaData", description = "Path to the investigation area data", defaultValue = "contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/investigationAreaData.csv") private Path pathToInvestigationAreaData; - private final Map> landuseCategoriesAndDataConnection = new HashMap<>(); + private Map> landuseCategoriesAndDataConnection; private final Map>> buildingsPerZone = new HashMap<>(); + public CreateDataDistributionOfStructureData(LanduseDataConnectionCreator landuseDataConnectionCreator) { + CreateDataDistributionOfStructureData.landuseDataConnectionCreator = landuseDataConnectionCreator; + log.info("Using LanduseDataConnectionCreator {} to connect the types of the landuse data to the categories of the small scale commercial traffic generation", landuseDataConnectionCreator.getClass().getSimpleName()); + } + public CreateDataDistributionOfStructureData() { + landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + log.info("Using default LanduseDataConnectionCreatorForOSM_Data to connect the types of the landuse data to the categories of the small scale commercial traffic generation"); + } + public static void main(String[] args) { - System.exit(new CommandLine(new CreateDataDistributionOfStructureData()).execute(args)); + System.exit(new CommandLine(new CreateDataDistributionOfStructureData(landuseDataConnectionCreator)).execute(args)); } @Override @@ -104,7 +115,7 @@ public Integer call() throws Exception { if(Files.notExists(output)) new File(output.toString()).mkdir(); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); //TODO: find way to import this connection + landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysis.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysis.java index e9d9b35e777..d26f95bde07 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysis.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysis.java @@ -90,24 +90,6 @@ public static Map> createInputDataDistribution( return resultingDataPerZone; } - public static void createDefaultDataConnectionForOSM(Map> landuseCategoriesAndDataConnection) { - landuseCategoriesAndDataConnection.put("Inhabitants", - new ArrayList<>(Arrays.asList("residential", "apartments", "dormitory", "dwelling_house", "house", - "retirement_home", "semidetached_house", "detached"))); - landuseCategoriesAndDataConnection.put("Employee Primary Sector", new ArrayList<>( - Arrays.asList("farmyard", "farmland", "farm", "farm_auxiliary", "greenhouse", "agricultural"))); - landuseCategoriesAndDataConnection.put("Employee Construction", - new ArrayList<>(List.of("construction"))); - landuseCategoriesAndDataConnection.put("Employee Secondary Sector Rest", - new ArrayList<>(Arrays.asList("industrial", "factory", "manufacture", "bakehouse"))); - landuseCategoriesAndDataConnection.put("Employee Retail", - new ArrayList<>(Arrays.asList("retail", "kiosk", "mall", "shop", "supermarket"))); - landuseCategoriesAndDataConnection.put("Employee Traffic/Parcels", new ArrayList<>( - Arrays.asList("commercial", "post_office", "storage", "storage_tank", "warehouse"))); - landuseCategoriesAndDataConnection.put("Employee Tertiary Sector Rest", new ArrayList<>( - Arrays.asList("commercial", "embassy", "foundation", "government", "office", "townhall"))); - } - /** * Creates the resulting data for each zone based on the landuse distribution * and the original data. @@ -138,10 +120,8 @@ private static void createResultingDataForLanduseInZones( resultingDataPerZone.get(zoneId).mergeDouble(categoryData, 0., Double::sum); if (landuseCategoriesAndDataConnection.get(categoryData).contains(categoryLanduse)) { double additionalArea = landuseCategoriesPerZone.get(zoneId).getDouble(categoryLanduse); - // because the category commercial is in two categories (traffic/parcels and - // Tertiary Sector Rest - if (categoryLanduse.equals("commercial")) - additionalArea = additionalArea * 0.5; +// // because the categoryLanduse can be in two categories (e.g., traffic/parcels and Tertiary Sector Rest + additionalArea = additionalArea / LanduseDataConnectionCreator.getNumberOfEmployeeCategoriesOfThisTyp(landuseCategoriesAndDataConnection, categoryLanduse); resultingDataPerZone.get(zoneId).mergeDouble(categoryData, additionalArea, Double::sum); totalSquareMetersPerCategory.get(regionOfZone).mergeDouble(categoryData, additionalArea, Double::sum); @@ -271,21 +251,31 @@ private static void createLanduseDistribution(Map> createLanduseDataConnection(); + + /** + * Counts the number of employee categories in which a type is represented. + * + * @return + */ + static int getNumberOfEmployeeCategoriesOfThisTyp(Map> landuseCategoriesAndDataConnection, String type) { + AtomicInteger count = new AtomicInteger(); + landuseCategoriesAndDataConnection.values().forEach(list -> { + if (list.contains(type)) { + count.getAndIncrement(); + } + }); + return count.get(); + } + + ; +} diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseDataConnectionCreatorForOSM_Data.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseDataConnectionCreatorForOSM_Data.java new file mode 100644 index 00000000000..904d4980492 --- /dev/null +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseDataConnectionCreatorForOSM_Data.java @@ -0,0 +1,32 @@ +package org.matsim.smallScaleCommercialTrafficGeneration.prepare; + +import java.util.*; + +/** + * This class creates the connection between the landuse categories of the OSM landuse data and the employee data. + * + * @author Ricardo Ewert + */ +public class LanduseDataConnectionCreatorForOSM_Data implements LanduseDataConnectionCreator{ + + @Override + public Map> createLanduseDataConnection() { + Map> landuseCategoriesAndDataConnection = new HashMap<>(); + landuseCategoriesAndDataConnection.put("Inhabitants", + new ArrayList<>(Arrays.asList("residential", "apartments", "dormitory", "dwelling_house", "house", + "retirement_home", "semidetached_house", "detached"))); + landuseCategoriesAndDataConnection.put("Employee Primary Sector", new ArrayList<>( + Arrays.asList("farmyard", "farmland", "farm", "farm_auxiliary", "greenhouse", "agricultural"))); + landuseCategoriesAndDataConnection.put("Employee Construction", + new ArrayList<>(List.of("construction"))); + landuseCategoriesAndDataConnection.put("Employee Secondary Sector Rest", + new ArrayList<>(Arrays.asList("industrial", "factory", "manufacture", "bakehouse"))); + landuseCategoriesAndDataConnection.put("Employee Retail", + new ArrayList<>(Arrays.asList("retail", "kiosk", "mall", "shop", "supermarket"))); + landuseCategoriesAndDataConnection.put("Employee Traffic/Parcels", new ArrayList<>( + Arrays.asList("commercial", "post_office", "storage", "storage_tank", "warehouse"))); + landuseCategoriesAndDataConnection.put("Employee Tertiary Sector Rest", new ArrayList<>( + Arrays.asList("commercial", "embassy", "foundation", "government", "office", "townhall"))); + return landuseCategoriesAndDataConnection; + } +} 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 3ac1b2f4b82..d6f82ae1e37 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 @@ -35,6 +35,8 @@ import org.matsim.freight.carriers.CarriersUtils; import org.matsim.smallScaleCommercialTrafficGeneration.TrafficVolumeGeneration.TrafficVolumeKey; import org.matsim.smallScaleCommercialTrafficGeneration.prepare.LanduseBuildingAnalysis; +import org.matsim.smallScaleCommercialTrafficGeneration.prepare.LanduseDataConnectionCreator; +import org.matsim.smallScaleCommercialTrafficGeneration.prepare.LanduseDataConnectionCreatorForOSM_Data; import org.matsim.testcases.MatsimTestUtils; import org.opengis.feature.simple.SimpleFeature; @@ -43,8 +45,6 @@ import java.nio.file.Path; import java.util.*; -import static org.matsim.smallScaleCommercialTrafficGeneration.prepare.LanduseBuildingAnalysis.createDefaultDataConnectionForOSM; - /** * @author Ricardo Ewert * @@ -57,7 +57,6 @@ public class TrafficVolumeGenerationTest { @Test void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Path output = Path.of(utils.getOutputDirectory()); @@ -67,7 +66,8 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { String shapeFileZoneNameColumn = "name"; String shapeFileBuildingTypeColumn = "type"; Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, @@ -188,7 +188,6 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { @Test void testTrafficVolumeGenerationGoodsTraffic() throws IOException { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Path output = Path.of(utils.getOutputDirectory()); @@ -198,7 +197,8 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { String shapeFileZoneNameColumn = "name"; String shapeFileBuildingTypeColumn = "type"; Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, @@ -510,7 +510,6 @@ void testAddingExistingScenariosWithSample() throws Exception { @Test void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Path output = Path.of(utils.getOutputDirectory()); @@ -523,7 +522,8 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { String shapeFileZoneNameColumn = "name"; String shapeFileBuildingTypeColumn = "type"; Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); ArrayList modesORvehTypes = new ArrayList<>( Arrays.asList("vehTyp1", "vehTyp2", "vehTyp3", "vehTyp4", "vehTyp5")); @@ -672,7 +672,6 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { @Test void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() throws Exception { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Map>> facilitiesPerZone = new HashMap<>(); @@ -697,7 +696,9 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th Scenario scenario = ScenarioUtils.loadScenario(config); TrafficVolumeGeneration.setInputParameters(usedTrafficType); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); + Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, usedLanduseConfiguration, diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysisTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysisTest.java index f119de1a96c..d380e832ddb 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysisTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/prepare/LanduseBuildingAnalysisTest.java @@ -34,8 +34,6 @@ import java.util.List; import java.util.Map; -import static org.matsim.smallScaleCommercialTrafficGeneration.prepare.LanduseBuildingAnalysis.createDefaultDataConnectionForOSM; - /** * @author Ricardo Ewert * @@ -47,7 +45,6 @@ public class LanduseBuildingAnalysisTest { @Test void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Path output = Path.of(utils.getOutputDirectory()); @@ -57,10 +54,10 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { String shapeFileZoneNameColumn = "name"; String shapeFileBuildingTypeColumn = "type"; Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).getParent().resolve("investigationAreaData.csv"); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); // Test if the reading of the existing data distribution works correctly - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); - Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, usedLanduseConfiguration, @@ -242,7 +239,6 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { @Test void testLanduseDistribution() throws IOException { - Map> landuseCategoriesAndDataConnection = new HashMap<>(); Map>> buildingsPerZone = new HashMap<>(); Path output = Path.of(utils.getOutputDirectory()); @@ -252,7 +248,8 @@ void testLanduseDistribution() throws IOException { String shapeFileZoneNameColumn = "name"; String shapeFileBuildingTypeColumn = "type"; Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).getParent().resolve("investigationAreaData.csv"); - createDefaultDataConnectionForOSM(landuseCategoriesAndDataConnection); + LanduseDataConnectionCreator landuseDataConnectionCreator = new LanduseDataConnectionCreatorForOSM_Data(); + Map> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection(); // Analyze resultingData per zone Map> resultingDataPerZone = LanduseBuildingAnalysis