Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into network-improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed May 14, 2024
2 parents 9da5216 + e8458ed commit 4459dc7
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 524 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ private enum LanduseConfiguration {
useOnlyOSMLanduse, useOSMBuildingsAndLanduse
}

@CommandLine.Option(names = "--pathOutput", description = "Path for the output", defaultValue = "output/TestDistributionClass")
private Path output;
@CommandLine.Option(names = "--outputFacilityFile", description = "Path for the outputFacilityFile", defaultValue = "output/TestDistributionClass/commercialFacilities.xml.gz")
private Path outputFacilityFile;

@CommandLine.Option(names = "--outputDataDistributionFile", description = "Path for the outputDataDistributionFile", defaultValue = "output/TestDistributionClass/dataDistributionPerZone.csv")
private Path outputDataDistributionFile;

@CommandLine.Option(names = "--landuseConfiguration", description = "Set option of used OSM data. Options: useOnlyOSMLanduse, useOSMBuildingsAndLanduse, useExistingDataDistribution", defaultValue = "useOSMBuildingsAndLanduse")
private LanduseConfiguration usedLanduseConfiguration;
Expand Down Expand Up @@ -112,13 +115,13 @@ public Integer call() throws Exception {
ShpOptions.Index indexInvestigationAreaRegions = SmallScaleCommercialTrafficUtils.getIndexRegions(shapeFileRegionsPath, shapeCRS,
regionsShapeRegionColumn);

if(Files.notExists(output))
new File(output.toString()).mkdir();
if(Files.notExists(outputFacilityFile.getParent()))
new File(outputFacilityFile.toString()).mkdir();

landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection();

Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
.createInputDataDistribution(outputDataDistributionFile, landuseCategoriesAndDataConnection,
usedLanduseConfiguration.toString(), indexLanduse, indexZones,
indexBuildings, indexInvestigationAreaRegions, shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, shapeFileBuildingTypeColumn);

Expand All @@ -127,11 +130,10 @@ public Integer call() throws Exception {
ActivityFacilitiesFactory facilitiesFactory = facilities.getFactory();

calculateAreaSharesOfTheFacilities(facilities, facilitiesFactory);
Path facilityOutput = output.resolve("commercialFacilities.xml.gz");
log.info("Created {} facilities, writing to {}", facilities.getFacilities().size(), facilityOutput);
log.info("Created {} facilities, writing to {}", facilities.getFacilities().size(), outputFacilityFile);

FacilitiesWriter writer = new FacilitiesWriter(facilities);
writer.write(facilityOutput.toString());
writer.write(outputFacilityFile.toString());

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ public class LanduseBuildingAnalysis {
* Creates a distribution of the given input data for each zone based on the
* used OSM data.
*/
public static Map<String, Object2DoubleMap<String>> createInputDataDistribution(Path output,
public static Map<String, Object2DoubleMap<String>> createInputDataDistribution(Path outputDataDistributionFile,
Map<String, List<String>> landuseCategoriesAndDataConnection,
String usedLanduseConfiguration, Index indexLanduse,
Index indexZones,
Index indexBuildings, Index indexInvestigationAreaRegions,
String shapeFileZoneNameColumn,
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone,
Path pathToInvestigationAreaData, String shapeFileBuildingTypeColumn)
Path pathToInvestigationAreaData,
String shapeFileBuildingTypeColumn)
throws IOException {

Map<String, Object2DoubleMap<String>> resultingDataPerZone = new HashMap<>();
Map<String, String> zoneIdRegionConnection = new HashMap<>();
Path outputFileInOutputFolder = output.resolve("dataDistributionPerZone.csv");

log.info("New analyze for data distribution is started. The used method is: {}", usedLanduseConfiguration);
Map<String, Object2DoubleMap<String>> landuseCategoriesPerZone = new HashMap<>();
Expand All @@ -83,7 +83,7 @@ public static Map<String, Object2DoubleMap<String>> createInputDataDistribution(
createResultingDataForLanduseInZones(landuseCategoriesPerZone, investigationAreaData, resultingDataPerZone,
landuseCategoriesAndDataConnection, zoneIdRegionConnection);

writeResultOfDataDistribution(resultingDataPerZone, outputFileInOutputFolder,
writeResultOfDataDistribution(resultingDataPerZone, outputDataDistributionFile,
zoneIdRegionConnection);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException {

Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone = new HashMap<>();

Path output = Path.of(utils.getOutputDirectory());
assert(new File(output.resolve("calculatedData").toString()).mkdir());
Path outputDataDistributionFile = Path.of(utils.getOutputDirectory()).resolve("dataDistributionPerZone.csv");
assert(new File(outputDataDistributionFile.getParent().resolve("calculatedData").toString()).mkdir());
Path inputDataDirectory = Path.of(utils.getPackageInputDirectory());
String usedLanduseConfiguration = "useOSMBuildingsAndLanduse";
String shapeFileZoneNameColumn = "name";
Expand All @@ -70,7 +70,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException {
Map<String, List<String>> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection();

Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
.createInputDataDistribution(outputDataDistributionFile, landuseCategoriesAndDataConnection,
usedLanduseConfiguration,
SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory),
SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, shapeFileBuildingTypeColumn);
Expand All @@ -83,9 +83,9 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException {
TrafficVolumeGeneration.setInputParameters(usedTrafficType);

Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration
.createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_start(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);
Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_stop(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);

Assertions.assertEquals(3, trafficVolumePerTypeAndZone_start.size());
Assertions.assertEquals(3, trafficVolumePerTypeAndZone_stop.size());
Expand Down Expand Up @@ -138,9 +138,9 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException {
//test with different sample
sample = 0.25;
trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration
.createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_start(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);
trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_stop(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);

Assertions.assertEquals(3, trafficVolumePerTypeAndZone_start.size());
Assertions.assertEquals(3, trafficVolumePerTypeAndZone_stop.size());
Expand Down Expand Up @@ -190,8 +190,8 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException {

Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone = new HashMap<>();

Path output = Path.of(utils.getOutputDirectory());
assert(new File(output.resolve("calculatedData").toString()).mkdir());
Path outputDataDistributionFile = Path.of(utils.getOutputDirectory()).resolve("dataDistributionPerZone.csv");
assert(new File(outputDataDistributionFile.getParent().resolve("calculatedData").toString()).mkdir());
Path inputDataDirectory = Path.of(utils.getPackageInputDirectory());
String usedLanduseConfiguration = "useOSMBuildingsAndLanduse";
String shapeFileZoneNameColumn = "name";
Expand All @@ -201,7 +201,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException {
Map<String, List<String>> landuseCategoriesAndDataConnection = landuseDataConnectionCreator.createLanduseDataConnection();

Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
.createInputDataDistribution(outputDataDistributionFile, landuseCategoriesAndDataConnection,
usedLanduseConfiguration,
SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory),
SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, shapeFileBuildingTypeColumn);
Expand All @@ -213,9 +213,9 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException {
TrafficVolumeGeneration.setInputParameters(usedTrafficType);

Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration
.createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_start(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);
Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_stop(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);

Assertions.assertEquals(15, trafficVolumePerTypeAndZone_start.size());
Assertions.assertEquals(15, trafficVolumePerTypeAndZone_stop.size());
Expand Down Expand Up @@ -514,8 +514,8 @@ void testAddingExistingScenariosWithSample() throws Exception {
void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception {
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone = new HashMap<>();

Path output = Path.of(utils.getOutputDirectory());
assert(new File(output.resolve("calculatedData").toString()).mkdir());
Path outputDataDistributionFile = Path.of(utils.getOutputDirectory()).resolve("dataDistributionPerZone.csv");
assert(new File(outputDataDistributionFile.getParent().resolve("calculatedData").toString()).mkdir());
Path inputDataDirectory = Path.of(utils.getPackageInputDirectory());
String usedLanduseConfiguration = "useOSMBuildingsAndLanduse";
String networkPath = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml";
Expand All @@ -542,15 +542,15 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception {
Map<String, Map<String, List<ActivityFacility>>> facilitiesPerZone = new HashMap<>();

Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
.createInputDataDistribution(outputDataDistributionFile, landuseCategoriesAndDataConnection,
usedLanduseConfiguration,
SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory),
SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, shapeFileBuildingTypeColumn);

Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration
.createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_start(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);
Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_stop(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);

Map<String, Map<Id<Link>, Link>> linksPerZone = GenerateSmallScaleCommercialTrafficDemand
.filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), facilitiesPerZone, shapeFileZoneNameColumn);
Expand Down Expand Up @@ -680,8 +680,8 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone = new HashMap<>();
Map<String, Map<String, List<ActivityFacility>>> facilitiesPerZone = new HashMap<>();

Path output = Path.of(utils.getOutputDirectory());
assert(new File(output.resolve("calculatedData").toString()).mkdir());
Path outputDataDistributionFile = Path.of(utils.getOutputDirectory()).resolve("dataDistributionPerZone.csv");
assert(new File(outputDataDistributionFile.getParent().resolve("calculatedData").toString()).mkdir());
Path inputDataDirectory = Path.of(utils.getPackageInputDirectory());
String usedLanduseConfiguration = "useOSMBuildingsAndLanduse";
String networkPath = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml";
Expand All @@ -708,15 +708,15 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th


Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
.createInputDataDistribution(outputDataDistributionFile, landuseCategoriesAndDataConnection,
usedLanduseConfiguration,
SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory),
SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, shapeFileBuildingTypeColumn);

Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration
.createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_start(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);
Map<TrafficVolumeKey, Object2DoubleMap<Integer>> trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);
.createTrafficVolume_stop(resultingDataPerZone, outputDataDistributionFile.getParent(), sample, modesORvehTypes, usedTrafficType);

Map<String, Map<Id<Link>, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand
.filterLinksForZones(scenario, SCTUtils.getZoneIndex(inputDataDirectory), facilitiesPerZone, shapeFileZoneNameColumn);
Expand Down
Loading

0 comments on commit 4459dc7

Please sign in to comment.