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 b15a3d7d99c..e5b6a27b774 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 @@ -36,25 +36,17 @@ import org.matsim.api.core.v01.population.Activity; import org.matsim.api.core.v01.population.Leg; import org.matsim.application.MATSimAppCommand; -import org.matsim.application.options.ShpOptions; import org.matsim.application.options.ShpOptions.Index; -import org.matsim.core.config.consistency.UnmaterializedConfigGroupChecker; -import org.matsim.core.gbl.MatsimRandom; -import org.matsim.core.scenario.ProjectionUtils; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.core.utils.geometry.CoordinateTransformation; -import org.matsim.freight.carriers.*; -import org.matsim.freight.carriers.controler.*; -import org.matsim.freight.carriers.CarrierCapabilities.FleetSize; -import org.matsim.freight.carriers.usecases.chessboard.CarrierTravelDisutilities; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.consistency.UnmaterializedConfigGroupChecker; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.config.groups.VspExperimentalConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.gbl.Gbl; +import org.matsim.core.gbl.MatsimRandom; import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.replanning.GenericPlanStrategyImpl; @@ -64,10 +56,17 @@ import org.matsim.core.router.util.LeastCostPathCalculatorFactory; import org.matsim.core.router.util.TravelDisutility; import org.matsim.core.router.util.TravelTime; +import org.matsim.core.scenario.ProjectionUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.scoring.ScoringFunction; import org.matsim.core.scoring.SumScoringFunction; +import org.matsim.core.utils.geometry.CoordUtils; +import org.matsim.core.utils.geometry.CoordinateTransformation; import org.matsim.core.utils.geometry.geotools.MGC; +import org.matsim.freight.carriers.*; +import org.matsim.freight.carriers.CarrierCapabilities.FleetSize; +import org.matsim.freight.carriers.controler.*; +import org.matsim.freight.carriers.usecases.chessboard.CarrierTravelDisutilities; import org.matsim.vehicles.CostInformation; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; @@ -77,7 +76,6 @@ import java.io.File; import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -101,6 +99,7 @@ public class GenerateSmallScaleCommercialTrafficDemand implements MATSimAppComma // Option 3: Leerkamp (nur in RVR Modell). + // Option: Add prepare class with OSM Analyse and create facility file with results private static final Logger log = LogManager.getLogger(GenerateSmallScaleCommercialTrafficDemand.class); private enum CreationOption { @@ -118,6 +117,12 @@ private enum SmallScaleCommercialTrafficType { @CommandLine.Parameters(arity = "1", paramLabel = "INPUT", description = "Path to the config for small scale commercial generation") private Path configPath; + @CommandLine.Option(names = "--pathToInvestigationAreaData", description = "Path to the investigation area data") + private Path pathToInvestigationAreaData; + + @CommandLine.Option(names = "--pathToExistingDataDistributionToZones", description = "Path to the existing data distribution to zones. This is only needed if the option useExistingDataDistribution is selected.") + private Path pathToExistingDataDistributionToZones; + @CommandLine.Option(names = "--sample", description = "Scaling factor of the small scale commercial traffic (0, 1)", required = true) private double sample; @@ -136,15 +141,30 @@ private enum SmallScaleCommercialTrafficType { @CommandLine.Option(names = "--includeExistingModels", description = "If models for some segments exist they can be included.") private boolean includeExistingModels; + @CommandLine.Option(names = "--regionsShapeFileName", description = "Path of the region shape file.") + private Path shapeFileRegionsPath; + + @CommandLine.Option(names = "--regionsShapeRegionColumn", description = "Name of the region column in the region shape file.") + private String regionsShapeRegionColumn; + @CommandLine.Option(names = "--zoneShapeFileName", description = "Path of the zone shape file.") private Path shapeFileZonePath; + @CommandLine.Option(names = "--zoneShapeFileNameColumn", description = "Name of the unique column of the name/Id of each zone in the zones shape file.") + private String shapeFileZoneNameColumn; + @CommandLine.Option(names = "--buildingsShapeFileName", description = "Path of the buildings shape file") private Path shapeFileBuildingsPath; + @CommandLine.Option(names = "--shapeFileBuildingTypeColumn", description = "Name of the unique column of the building type in the buildings shape file.") + private String shapeFileBuildingTypeColumn; + @CommandLine.Option(names = "--landuseShapeFileName", description = "Path of the landuse shape file") private Path shapeFileLandusePath; + @CommandLine.Option(names = "--shapeFileLanduseTypeColumn", description = "Name of the unique column of the landuse type in the landuse shape file.") + private String shapeFileLanduseTypeColumn; + @CommandLine.Option(names = "--shapeCRS", description = "CRS of the three input shape files (zones, landuse, buildings") private String shapeCRS; @@ -170,6 +190,7 @@ private enum SmallScaleCommercialTrafficType { private Index indexZones; private Index indexBuildings; private Index indexLanduse; + private Index indexInvestigationAreaRegions; public static void main(String[] args) { System.exit(new CommandLine(new GenerateSmallScaleCommercialTrafficDemand()).execute(args)); @@ -226,29 +247,32 @@ public Integer call() throws Exception { if (!Files.exists(shapeFileZonePath)) { throw new Exception("Required districts shape file {} not found" + shapeFileZonePath.toString()); } - Path inputDataDirectory = Path.of(config.getContext().toURI()).getParent(); + if (!Files.exists(shapeFileRegionsPath)) { + throw new Exception("Required regions shape file {} not found" + shapeFileRegionsPath.toString()); + } - indexZones = SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, shapeCRS); - indexBuildings = SmallScaleCommercialTrafficUtils.getIndexBuildings(shapeFileBuildingsPath, shapeCRS); - indexLanduse = SmallScaleCommercialTrafficUtils.getIndexLanduse(shapeFileLandusePath, shapeCRS); + indexZones = SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, shapeCRS, shapeFileZoneNameColumn); + indexBuildings = SmallScaleCommercialTrafficUtils.getIndexBuildings(shapeFileBuildingsPath, shapeCRS, shapeFileBuildingTypeColumn); + indexLanduse = SmallScaleCommercialTrafficUtils.getIndexLanduse(shapeFileLandusePath, shapeCRS, shapeFileLanduseTypeColumn); + indexInvestigationAreaRegions = SmallScaleCommercialTrafficUtils.getIndexRegions(shapeFileRegionsPath, shapeCRS, regionsShapeRegionColumn); Map> resultingDataPerZone = LanduseBuildingAnalysis - .createInputDataDistribution(output, landuseCategoriesAndDataConnection, inputDataDirectory, + .createInputDataDistribution(output, landuseCategoriesAndDataConnection, usedLanduseConfiguration.toString(), indexLanduse, indexZones, - indexBuildings, buildingsPerZone); - - Map, Link>> regionLinksMap = filterLinksForZones(scenario, indexZones, buildingsPerZone); + indexBuildings, indexInvestigationAreaRegions, shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, + pathToExistingDataDistributionToZones); + Map, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone); switch (usedSmallScaleCommercialTrafficType) { case commercialPersonTraffic, goodsTraffic -> - createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap, + createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone, usedSmallScaleCommercialTrafficType.toString(), includeExistingModels); case completeSmallScaleCommercialTraffic -> { - createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap, "commercialPersonTraffic", + createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone, "commercialPersonTraffic", includeExistingModels); includeExistingModels = false; // because already included in the step before - createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap, "goodsTraffic", + createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone, "goodsTraffic", includeExistingModels); } default -> throw new RuntimeException("No traffic type selected."); @@ -260,7 +284,7 @@ public Integer call() throws Exception { new CarrierPlanWriter(CarriersUtils.addOrGetCarriers(scenario)) .write(scenario.getConfig().controller().getOutputDirectory() + "/" + scenario.getConfig().controller().getRunId() + ".output_CarrierDemand.xml"); - solveSeparatedVRPs(scenario, regionLinksMap); + solveSeparatedVRPs(scenario, linksPerZone); } } if (config.controller().getRunId() == null) @@ -424,7 +448,7 @@ private void solveSeparatedVRPs(Scenario originalScenario, Map> resultingDataPerZone, - Map, Link>> regionLinksMap, String smallScaleCommercialTrafficType, + Map, Link>> linksPerZone, String smallScaleCommercialTrafficType, boolean includeExistingModels) throws Exception { ArrayList modesORvehTypes; @@ -444,13 +468,13 @@ else if (smallScaleCommercialTrafficType.equals("commercialPersonTraffic")) .createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, smallScaleCommercialTrafficType); if (includeExistingModels) { - SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); - TrafficVolumeGeneration.reduceDemandBasedOnExistingCarriers(scenario, regionLinksMap, smallScaleCommercialTrafficType, + SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, linksPerZone); + TrafficVolumeGeneration.reduceDemandBasedOnExistingCarriers(scenario, linksPerZone, smallScaleCommercialTrafficType, trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop); } final TripDistributionMatrix odMatrix = createTripDistribution(trafficVolumePerTypeAndZone_start, - trafficVolumePerTypeAndZone_stop, smallScaleCommercialTrafficType, scenario, output, regionLinksMap); - createCarriers(scenario, odMatrix, resultingDataPerZone, smallScaleCommercialTrafficType, regionLinksMap); + trafficVolumePerTypeAndZone_stop, smallScaleCommercialTrafficType, scenario, output, linksPerZone); + createCarriers(scenario, odMatrix, resultingDataPerZone, smallScaleCommercialTrafficType, linksPerZone); } /** @@ -970,7 +994,7 @@ private TripDistributionMatrix createTripDistribution( Collections.shuffle(listOfZones, rnd); for (String stopZone : listOfZones) { odMatrix.setTripDistributionValue(startZone, stopZone, modeORvehType, purpose, smallScaleCommercialTrafficType, - network, regionLinksMap, resistanceFactor); + network, regionLinksMap, resistanceFactor, shapeFileZoneNameColumn); } } } diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysis.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysis.java index faffac894c1..7e26668438e 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysis.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysis.java @@ -54,13 +54,17 @@ public class LanduseBuildingAnalysis { * used OSM data. */ static Map> createInputDataDistribution(Path output, - Map> landuseCategoriesAndDataConnection, Path inputDataDirectory, + Map> landuseCategoriesAndDataConnection, String usedLanduseConfiguration, Index indexLanduse, Index indexZones, - Index indexBuildings, Map>> buildingsPerZone) - throws IOException { + Index indexBuildings, Index indexInvestigationAreaRegions, + String shapeFileZoneNameColumn, + Map>> buildingsPerZone, + Path pathToInvestigationAreaData, + Path pathToExistingDataDistributionToZones) + throws IOException { Map> resultingDataPerZone = new HashMap<>(); - Map zoneIdNameConnection = new HashMap<>(); + Map zoneIdRegionConnection = new HashMap<>(); Path outputFileInOutputFolder = output.resolve("calculatedData").resolve("dataDistributionPerZone.csv"); landuseCategoriesAndDataConnection.put("Inhabitants", @@ -80,18 +84,17 @@ static Map> createInputDataDistribution(Path ou Arrays.asList("commercial", "embassy", "foundation", "government", "office", "townhall"))); if (usedLanduseConfiguration.equals("useExistingDataDistribution")) { - Path existingDataDistribution = inputDataDirectory.resolve("dataDistributionPerZone.csv"); - if (!Files.exists(existingDataDistribution)) { - log.error("Required data per zone file {} not found", existingDataDistribution); + if (!Files.exists(pathToExistingDataDistributionToZones)) { + log.error("Required data per zone file {} not found", pathToExistingDataDistributionToZones); } - try (BufferedReader reader = IOUtils.getBufferedReader(existingDataDistribution.toString())) { + try (BufferedReader reader = IOUtils.getBufferedReader(pathToExistingDataDistributionToZones.toString())) { CSVParser parse = CSVFormat.Builder.create(CSVFormat.DEFAULT).setDelimiter('\t').setHeader() .setSkipHeaderRecord(true).build().parse(reader); for (CSVRecord record : parse) { - String zoneID = record.get("areaID"); + String zoneID = record.get("zoneID"); resultingDataPerZone.put(zoneID, new Object2DoubleOpenHashMap<>()); for (int n = 2; n < parse.getHeaderMap().size(); n++) { resultingDataPerZone.get(zoneID).mergeDouble(parse.getHeaderNames().get(n), @@ -100,8 +103,8 @@ static Map> createInputDataDistribution(Path ou } } log.info("Data distribution for " + resultingDataPerZone.size() + " zones was imported from " + - existingDataDistribution); - Files.copy(existingDataDistribution, outputFileInOutputFolder, StandardCopyOption.COPY_ATTRIBUTES); + pathToExistingDataDistributionToZones); + Files.copy(pathToExistingDataDistributionToZones, outputFileInOutputFolder, StandardCopyOption.COPY_ATTRIBUTES); } else { @@ -109,18 +112,18 @@ static Map> createInputDataDistribution(Path ou log.info("New analyze for data distribution is started. The used method is: " + usedLanduseConfiguration); Map> landuseCategoriesPerZone = new HashMap<>(); - createLanduseDistribution(landuseCategoriesPerZone, indexLanduse, indexZones, + createLanduseDistribution(landuseCategoriesPerZone, indexLanduse, indexZones, indexInvestigationAreaRegions, usedLanduseConfiguration, indexBuildings, landuseCategoriesAndDataConnection, - buildingsPerZone, zoneIdNameConnection); + buildingsPerZone, shapeFileZoneNameColumn, zoneIdRegionConnection); Map> investigationAreaData = new HashMap<>(); - readAreaData(investigationAreaData, inputDataDirectory); + readAreaData(investigationAreaData, pathToInvestigationAreaData); createResultingDataForLanduseInZones(landuseCategoriesPerZone, investigationAreaData, resultingDataPerZone, - landuseCategoriesAndDataConnection); + landuseCategoriesAndDataConnection, zoneIdRegionConnection); SmallScaleCommercialTrafficUtils.writeResultOfDataDistribution(resultingDataPerZone, outputFileInOutputFolder, - zoneIdNameConnection); + zoneIdRegionConnection); } return resultingDataPerZone; @@ -131,10 +134,10 @@ static Map> createInputDataDistribution(Path ou * and the original data. */ private static void createResultingDataForLanduseInZones( - Map> landuseCategoriesPerZone, - Map> investigationAreaData, - Map> resultingDataPerZone, - Map> landuseCategoriesAndDataConnection) { + Map> landuseCategoriesPerZone, + Map> investigationAreaData, + Map> resultingDataPerZone, + Map> landuseCategoriesAndDataConnection, Map zoneIdRegionConnection) { Map> totalSquareMetersPerCategory = new HashMap>(); Map> totalEmployeesInCategoriesPerZone = new HashMap>(); @@ -149,7 +152,7 @@ private static void createResultingDataForLanduseInZones( // connects the collected landuse data with the needed categories for (String zoneId : landuseCategoriesPerZone.keySet()) { - String investigationArea = zoneId.split("_")[0]; + String regionOfZone = zoneIdRegionConnection.get(zoneId); resultingDataPerZone.put(zoneId, new Object2DoubleOpenHashMap<>()); for (String categoryLanduse : landuseCategoriesPerZone.get(zoneId).keySet()) for (String categoryData : landuseCategoriesAndDataConnection.keySet()) { @@ -161,7 +164,7 @@ private static void createResultingDataForLanduseInZones( if (categoryLanduse.equals("commercial")) additionalArea = additionalArea * 0.5; resultingDataPerZone.get(zoneId).mergeDouble(categoryData, additionalArea, Double::sum); - totalSquareMetersPerCategory.get(investigationArea).mergeDouble(categoryData, additionalArea, + totalSquareMetersPerCategory.get(regionOfZone).mergeDouble(categoryData, additionalArea, Double::sum); } } @@ -176,12 +179,12 @@ private static void createResultingDataForLanduseInZones( .forEach(c -> checkPercentages.computeIfAbsent(c, k -> new Object2DoubleOpenHashMap<>())); for (String zoneId : resultingDataPerZone.keySet()) for (String categoryData : resultingDataPerZone.get(zoneId).keySet()) { - String investigationArea = zoneId.split("_")[0]; + String regionOfZone = zoneIdRegionConnection.get(zoneId); double newValue = resultingDataPerZone.get(zoneId).getDouble(categoryData) - / totalSquareMetersPerCategory.get(investigationArea).getDouble(categoryData); + / totalSquareMetersPerCategory.get(regionOfZone).getDouble(categoryData); resultingDataPerZone.get(zoneId).replace(categoryData, resultingDataPerZone.get(zoneId).getDouble(categoryData), newValue); - checkPercentages.get(investigationArea).mergeDouble(categoryData, + checkPercentages.get(regionOfZone).mergeDouble(categoryData, resultingDataPerZone.get(zoneId).getDouble(categoryData), Double::sum); } // tests the result @@ -193,21 +196,21 @@ private static void createResultingDataForLanduseInZones( } // calculates the data per zone and category data for (String zoneId : resultingDataPerZone.keySet()) { - String investigationArea = zoneId.split("_")[0]; + String regionOfZone = zoneIdRegionConnection.get(zoneId); for (String categoryData : resultingDataPerZone.get(zoneId).keySet()) { double percentageValue = resultingDataPerZone.get(zoneId).getDouble(categoryData); - int inputDataForCategory = investigationAreaData.get(investigationArea).get(categoryData); + int inputDataForCategory = investigationAreaData.get(regionOfZone).get(categoryData); double resultingNumberPerCategory = percentageValue * inputDataForCategory; resultingDataPerZone.get(zoneId).replace(categoryData, percentageValue, resultingNumberPerCategory); - totalEmployeesPerCategories.get(investigationArea).mergeDouble(categoryData, resultingNumberPerCategory, + totalEmployeesPerCategories.get(regionOfZone).mergeDouble(categoryData, resultingNumberPerCategory, Double::sum); if (!categoryData.equals("Inhabitants")) - totalEmployeesInCategoriesPerZone.get(investigationArea).mergeDouble(zoneId, + totalEmployeesInCategoriesPerZone.get(regionOfZone).mergeDouble(zoneId, resultingNumberPerCategory, Double::sum); } - if (totalEmployeesInCategoriesPerZone.get(investigationArea).getDouble(zoneId) != 0) + if (totalEmployeesInCategoriesPerZone.get(regionOfZone).getDouble(zoneId) != 0) resultingDataPerZone.get(zoneId).mergeDouble("Employee", - totalEmployeesInCategoriesPerZone.get(investigationArea).getDouble(zoneId), Double::sum); + totalEmployeesInCategoriesPerZone.get(regionOfZone).getDouble(zoneId), Double::sum); } } @@ -216,23 +219,30 @@ private static void createResultingDataForLanduseInZones( * the sum of this category in all zones of the zone shape file */ private static void createLanduseDistribution(Map> landuseCategoriesPerZone, - Index indexLanduse, Index indexZones, String usedLanduseConfiguration, + Index indexLanduse, Index indexZones, Index indexInvestigationAreaRegions, String usedLanduseConfiguration, Index indexBuildings, Map> landuseCategoriesAndDataConnection, Map>> buildingsPerZone, - Map zoneIdNameConnection) { + String shapeFileZoneNameColumn, Map zoneIdRegionConnection) { List neededLanduseCategories = List.of("residential", "industrial", "commercial", "retail", "farmyard", "farmland", "construction"); List landuseFeatures = indexLanduse.getAllFeatures(); List zonesFeatures = indexZones.getAllFeatures(); - - for (SimpleFeature singleZone : zonesFeatures) { - Object2DoubleMap landusePerCategory = new Object2DoubleOpenHashMap<>(); - landuseCategoriesPerZone.put((String) singleZone.getAttribute("areaID"), landusePerCategory); - zoneIdNameConnection.put((String) singleZone.getAttribute("areaID"), - (String) singleZone.getAttribute("name")); + // get the region of the zone + Coord middleCoordOfZone = MGC.point2Coord(((Geometry) singleZone.getDefaultGeometry()).getCentroid()); + String regionName = indexInvestigationAreaRegions.query(middleCoordOfZone); + if (regionName != null) { + Object2DoubleMap landusePerCategory = new Object2DoubleOpenHashMap<>(); + String zoneID = (String) singleZone.getAttribute(shapeFileZoneNameColumn); + var previousValue = landuseCategoriesPerZone.putIfAbsent(zoneID, landusePerCategory); + if (previousValue != null) { + throw new IllegalStateException( + "Key " + zoneID + " already exists in the zone map. This should not happen. Please check if the data in the column " + shapeFileZoneNameColumn + " is unique."); + } + zoneIdRegionConnection.put(zoneID, regionName); + } } if (usedLanduseConfiguration.equals("useOSMBuildingsAndLanduse")) { @@ -279,14 +289,13 @@ private static void createLanduseDistribution(Map> areaData, Path inputDataDirectory) + private static void readAreaData(Map> areaData, Path pathToInvestigationAreaData) throws IOException { - Path areaDataPath = inputDataDirectory.resolve("investigationAreaData.csv"); - if (!Files.exists(areaDataPath)) { - log.error("Required input data file {} not found", areaDataPath); + if (!Files.exists(pathToInvestigationAreaData)) { + log.error("Required input data file {} not found", pathToInvestigationAreaData); } - try (CSVParser parser = new CSVParser(Files.newBufferedReader(areaDataPath), + try (CSVParser parser = new CSVParser(Files.newBufferedReader(pathToInvestigationAreaData), CSVFormat.Builder.create(CSVFormat.TDF).setHeader().setSkipHeaderRecord(true).build())) { for (CSVRecord record : parser) { @@ -295,7 +304,7 @@ private static void readAreaData(Map> areaData, Pat if (parser.getHeaderMap().get(csvRecord) > 0) lookUpTable.put(csvRecord, Integer.valueOf(record.get(csvRecord))); } - areaData.put(record.get("Area"), lookUpTable); + areaData.put(record.get("Region"), lookUpTable); } } } diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtils.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtils.java index 1ea26e82ee3..f00dcd020e5 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtils.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/SmallScaleCommercialTrafficUtils.java @@ -77,52 +77,90 @@ public class SmallScaleCommercialTrafficUtils { /** * Creates and return the Index of the zone shape. * + * @param shapeFileZonePath Path to the shape file of the zones + * @param shapeCRS CRS of the shape file + * @param shapeFileZoneNameColumn Column name of the zone in the shape file * @return indexZones */ - static Index getIndexZones(Path shapeFileZonePath, String shapeCRS) { + static Index getIndexZones(Path shapeFileZonePath, String shapeCRS, String shapeFileZoneNameColumn) { ShpOptions shpZones = new ShpOptions(shapeFileZonePath, shapeCRS, StandardCharsets.UTF_8); - return shpZones.createIndex(shapeCRS, "areaID"); + if (shpZones.readFeatures().iterator().next().getAttribute(shapeFileZoneNameColumn) == null) + throw new NullPointerException("The column '" + shapeFileZoneNameColumn + "' does not exist in the zones shape file. Please check the input."); + return shpZones.createIndex(shapeCRS, shapeFileZoneNameColumn); } /** * Creates and return the Index of the landuse shape. * - * @return indexLanduse + * @param shapeFileLandusePath Path to the shape file of the landuse + * @param shapeCRS CRS of the shape file + * @param shapeFileLanduseTypeColumn Column name of the landuse in the shape file + * @return indexLanduse */ - static Index getIndexLanduse(Path shapeFileLandusePath, String shapeCRS) { - + static Index getIndexLanduse(Path shapeFileLandusePath, String shapeCRS, String shapeFileLanduseTypeColumn) { ShpOptions shpLanduse = new ShpOptions(shapeFileLandusePath, shapeCRS, StandardCharsets.UTF_8); - return shpLanduse.createIndex(shapeCRS, "fclass"); + if (shpLanduse.readFeatures().iterator().next().getAttribute(shapeFileLanduseTypeColumn) == null) + throw new NullPointerException("The column '" + shapeFileLanduseTypeColumn + "' does not exist in the landuse shape file. Please check the input."); + return shpLanduse.createIndex(shapeCRS, shapeFileLanduseTypeColumn); } /** * Creates and return the Index of the building shape. * - * @return indexBuildings + * @param shapeFileBuildingsPath Path to the shape file of the buildings + * @param shapeCRS CRS of the shape file + * @param shapeFileBuildingTypeColumn Column name of the building in the shape file + * @return indexBuildings */ - static Index getIndexBuildings(Path shapeFileBuildingsPath, String shapeCRS) { + static Index getIndexBuildings(Path shapeFileBuildingsPath, String shapeCRS, String shapeFileBuildingTypeColumn) { + ShpOptions shpBuildings = new ShpOptions(shapeFileBuildingsPath, shapeCRS, StandardCharsets.UTF_8); + if (shpBuildings.readFeatures().iterator().next().getAttribute(shapeFileBuildingTypeColumn) == null) + throw new NullPointerException("The column '" + shapeFileBuildingTypeColumn + "' does not exist in the building shape file. Please check the input."); + + return shpBuildings.createIndex(shapeCRS, shapeFileBuildingTypeColumn); + } - ShpOptions shpLanduse = new ShpOptions(shapeFileBuildingsPath, shapeCRS, StandardCharsets.UTF_8); - return shpLanduse.createIndex(shapeCRS, "type"); + /** + * Creates and return the Index of the regions shape. + * + * @param shapeFileRegionsPath Path to the shape file of the regions + * @param shapeCRS CRS of the shape file + * @param regionsShapeRegionColumn Column name of the region in the shape file + * @return indexRegions + */ + public static Index getIndexRegions(Path shapeFileRegionsPath, String shapeCRS, String regionsShapeRegionColumn) { + ShpOptions shpRegions = new ShpOptions(shapeFileRegionsPath, shapeCRS, StandardCharsets.UTF_8); + if (shpRegions.readFeatures().iterator().next().getAttribute(regionsShapeRegionColumn) == null) + throw new NullPointerException("The column '" + regionsShapeRegionColumn + "' does not exist in the region shape file. Please check the input."); + return shpRegions.createIndex(shapeCRS, regionsShapeRegionColumn); } /** * Writes a csv file with the result of the distribution per zone of the input data. */ static void writeResultOfDataDistribution(Map> resultingDataPerZone, - Path outputFileInOutputFolder, Map zoneIdNameConnection) + Path outputFileInOutputFolder, Map zoneIdRegionConnection) throws IOException { - writeCSVWithCategoryHeader(resultingDataPerZone, outputFileInOutputFolder, zoneIdNameConnection); + writeCSVWithCategoryHeader(resultingDataPerZone, outputFileInOutputFolder, zoneIdRegionConnection); log.info("The data distribution is finished and written to: " + outputFileInOutputFolder); } - static Id findNearestPossibleLink(String zone, List noPossibleLinks, Map, Link>> regionLinksMap, + /** Finds the nearest possible link for the building polygon. + * @param zone + * @param noPossibleLinks + * @param linksPerZone + * @param newLink + * @param centroidPointOfBuildingPolygon + * @param numberOfPossibleLinks + * @return + */ + static Id findNearestPossibleLink(String zone, List noPossibleLinks, Map, Link>> linksPerZone, Id newLink, Coord centroidPointOfBuildingPolygon, int numberOfPossibleLinks) { double minDistance = Double.MAX_VALUE; searchLink: - for (Link possibleLink : regionLinksMap.get(zone).values()) { + for (Link possibleLink : linksPerZone.get(zone).values()) { if (possibleLink.getToNode().getOutLinks() == null) continue; if (noPossibleLinks != null && numberOfPossibleLinks > noPossibleLinks.size()) @@ -140,7 +178,7 @@ static Id findNearestPossibleLink(String zone, List noPossibleLink } } if (newLink == null && numberOfPossibleLinks > 0) { - for (Link possibleLink : regionLinksMap.get(zone).values()) { + for (Link possibleLink : linksPerZone.get(zone).values()) { double distance = NetworkUtils.getEuclideanDistance(centroidPointOfBuildingPolygon, (Coord) possibleLink.getAttributes().getAttribute("newCoord")); if (distance < minDistance) { @@ -158,11 +196,11 @@ static Id findNearestPossibleLink(String zone, List noPossibleLink */ private static void writeCSVWithCategoryHeader(Map> resultingDataPerZone, Path outputFileInInputFolder, - Map zoneIdNameConnection) throws MalformedURLException { + Map zoneIdRegionConnection) throws MalformedURLException { BufferedWriter writer = IOUtils.getBufferedWriter(outputFileInInputFolder.toUri().toURL(), StandardCharsets.UTF_8, true); try { - String[] header = new String[]{"areaID", "areaName", "Inhabitants", "Employee", "Employee Primary Sector", + String[] header = new String[]{"zoneID", "region", "Inhabitants", "Employee", "Employee Primary Sector", "Employee Construction", "Employee Secondary Sector Rest", "Employee Retail", "Employee Traffic/Parcels", "Employee Tertiary Sector Rest"}; JOIN.appendTo(writer, header); @@ -170,9 +208,9 @@ private static void writeCSVWithCategoryHeader(Map row = new ArrayList<>(); row.add(zone); - row.add(zoneIdNameConnection.get(zone)); + row.add(zoneIdRegionConnection.get(zone)); for (String category : header) { - if (!category.equals("areaID") && !category.equals("areaName")) + if (!category.equals("zoneID") && !category.equals("region")) row.add(String.valueOf((int) Math.round(resultingDataPerZone.get(zone).getDouble(category)))); } JOIN.appendTo(writer, row); @@ -189,7 +227,6 @@ private static void writeCSVWithCategoryHeader(Map vehicleId = Id.createVehicleId(person.getId().toString()); - VehicleUtils.insertVehicleIdsIntoAttributes(newPerson, Map.of(mode, vehicleId)); - VehicleUtils.insertVehicleTypesIntoAttributes(newPerson, Map.of(mode, allVehicles.getVehicles().get(vehicleId).getType().getId())); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(newPerson, Map.of(mode, vehicleId)); + VehicleUtils.insertVehicleTypesIntoPersonAttributes(newPerson, Map.of(mode, allVehicles.getVehicles().get(vehicleId).getType().getId())); population.addPerson(newPerson); } @@ -297,7 +334,7 @@ static String getSampleNameOfOutputFolder(double sample) { * dispersedTraffic will be added additionally. */ static void readExistingModels(Scenario scenario, double sampleScenario, - Map, Link>> regionLinksMap) throws Exception { + Map, Link>> linksPerZone) throws Exception { Path existingModelsFolder = Path.of(scenario.getConfig().getContext().toURI()).getParent().resolve("existingModels"); String locationOfExistingModels = existingModelsFolder.resolve("existingModels.csv").toString(); @@ -498,7 +535,7 @@ else if (!carrier.getShipments().isEmpty()) List startAreas = new ArrayList<>(); for (ScheduledTour tour : newCarrier.getSelectedPlan().getScheduledTours()) { - String tourStartZone = findZoneOfLink(tour.getTour().getStartLinkId(), regionLinksMap); + String tourStartZone = findZoneOfLink(tour.getTour().getStartLinkId(), linksPerZone); if (!startAreas.contains(tourStartZone)) startAreas.add(tourStartZone); } @@ -526,9 +563,9 @@ else if (!carrier.getShipments().isEmpty()) /** * Find the zone where the link is located */ - static String findZoneOfLink(Id linkId, Map, Link>> regionLinksMap) { - for (String area : regionLinksMap.keySet()) { - if (regionLinksMap.get(area).containsKey(linkId)) + static String findZoneOfLink(Id linkId, Map, Link>> linksPerZone) { + for (String area : linksPerZone.keySet()) { + if (linksPerZone.get(area).containsKey(linkId)) return area; } return null; diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGeneration.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGeneration.java index a4633cfaf10..b376d16d176 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGeneration.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TrafficVolumeGeneration.java @@ -221,7 +221,7 @@ private static void writeCSVTrafficVolume(Map, Link>> regionLinksMap, String smallScaleCommercialTrafficType, + Map, Link>> linksPerZone, String smallScaleCommercialTrafficType, Map> trafficVolumePerTypeAndZone_start, Map> trafficVolumePerTypeAndZone_stop) { @@ -290,11 +290,11 @@ static void reduceDemandBasedOnExistingCarriers(Scenario scenario, if (carrier.getSelectedPlan() != null) { for (ScheduledTour tour : carrier.getSelectedPlan().getScheduledTours()) { String startZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(tour.getTour().getStartLinkId(), - regionLinksMap); + linksPerZone); for (TourElement tourElement : tour.getTour().getTourElements()) { if (tourElement instanceof ServiceActivity service) { String stopZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(service.getLocation(), - regionLinksMap); + linksPerZone); try { reduceVolumeForThisExistingJobElement(trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop, modeORvehType, purpose, startZone, stopZone); @@ -306,9 +306,9 @@ static void reduceDemandBasedOnExistingCarriers(Scenario scenario, } if (tourElement instanceof Pickup pickup) { startZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(pickup.getShipment().getFrom(), - regionLinksMap); + linksPerZone); String stopZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(pickup.getShipment().getTo(), - regionLinksMap); + linksPerZone); try { reduceVolumeForThisExistingJobElement(trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop, modeORvehType, purpose, startZone, stopZone); @@ -325,13 +325,13 @@ static void reduceDemandBasedOnExistingCarriers(Scenario scenario, List possibleStartAreas = new ArrayList<>(); for (CarrierVehicle vehicle : carrier.getCarrierCapabilities().getCarrierVehicles().values()) { possibleStartAreas - .add(SmallScaleCommercialTrafficUtils.findZoneOfLink(vehicle.getLinkId(), regionLinksMap)); + .add(SmallScaleCommercialTrafficUtils.findZoneOfLink(vehicle.getLinkId(), linksPerZone)); } for (CarrierService service : carrier.getServices().values()) { String startZone = (String) possibleStartAreas.toArray()[MatsimRandom.getRandom() .nextInt(possibleStartAreas.size())]; String stopZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(service.getLocationLinkId(), - regionLinksMap); + linksPerZone); try { reduceVolumeForThisExistingJobElement(trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop, modeORvehType, purpose, startZone, stopZone); @@ -344,9 +344,9 @@ static void reduceDemandBasedOnExistingCarriers(Scenario scenario, } else if (!carrier.getShipments().isEmpty()) { for (CarrierShipment shipment : carrier.getShipments().values()) { String startZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(shipment.getFrom(), - regionLinksMap); + linksPerZone); String stopZone = SmallScaleCommercialTrafficUtils.findZoneOfLink(shipment.getTo(), - regionLinksMap); + linksPerZone); try { reduceVolumeForThisExistingJobElement(trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop, modeORvehType, purpose, startZone, stopZone); diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrix.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrix.java index ce06aa2b34c..f577c73deaa 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrix.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrix.java @@ -284,23 +284,24 @@ private TripDistributionMatrix(Builder builder) { * Calculates the traffic volume between two zones for a specific modeORvehType * and purpose. * - * @param startZone start zone - * @param stopZone stop zone - * @param modeORvehType selected mode or vehicle type - * @param purpose selected purpose + * @param startZone start zone + * @param stopZone stop zone + * @param modeORvehType selected mode or vehicle type + * @param purpose selected purpose * @param smallScaleCommercialTrafficType goodsTraffic or commercialPersonTraffic - * @param regionLinksMap links in each zone + * @param linksPerZone links in each zone + * @param shapeFileZoneNameColumn Name of the unique column of the name/Id of each zone in the zones shape file */ void setTripDistributionValue(String startZone, String stopZone, String modeORvehType, Integer purpose, String smallScaleCommercialTrafficType, Network network, - Map, Link>> regionLinksMap, double resistanceFactor) { + Map, Link>> linksPerZone, double resistanceFactor, String shapeFileZoneNameColumn) { double volumeStart = trafficVolume_start.get(TrafficVolumeGeneration.makeTrafficVolumeKey(startZone, modeORvehType)).getDouble(purpose); double volumeStop = trafficVolume_stop.get(TrafficVolumeGeneration.makeTrafficVolumeKey(stopZone, modeORvehType)).getDouble(purpose); int roundedVolume; if (volumeStart != 0 && volumeStop != 0) { - double resistanceValue = getResistanceFunktionValue(startZone, stopZone, network, regionLinksMap, resistanceFactor); - double gravityConstantA = getGravityConstant(stopZone, trafficVolume_start, modeORvehType, purpose, network, regionLinksMap, - resistanceFactor); + double resistanceValue = getResistanceFunktionValue(startZone, stopZone, network, linksPerZone, resistanceFactor, shapeFileZoneNameColumn); + double gravityConstantA = getGravityConstant(stopZone, trafficVolume_start, modeORvehType, purpose, network, linksPerZone, + resistanceFactor, shapeFileZoneNameColumn); roundingError.computeIfAbsent(stopZone, (k) -> new Object2DoubleOpenHashMap<>()); //Bisher: Gravity model mit fixem Zielverkehr @@ -336,11 +337,13 @@ Integer getTripDistributionValue(String startZone, String stopZone, String modeO /** * Calculates the values of the resistance function between two zones. * - * @param startZone start zone - * @param stopZone stop zone - * @param regionLinksMap links for each zone + * @param startZone start zone + * @param stopZone stop zone + * @param linksPerZone links for each zone + * @param shapeFileZoneNameColumn Name of the unique column of the name/Id of each zone in the zones shape file */ - private Double getResistanceFunktionValue(String startZone, String stopZone, Network network, Map, Link>> regionLinksMap, double resistanceFactor) { + private Double getResistanceFunktionValue(String startZone, String stopZone, Network network, Map, Link>> linksPerZone, + double resistanceFactor, String shapeFileZoneNameColumn) { //if false the calculation is faster; e.g. for debugging boolean useNetworkRoutesForResistanceFunction = true; @@ -353,11 +356,11 @@ private Double getResistanceFunktionValue(String startZone, String stopZone, Net } if (!resistanceFunktionCache.containsKey(makeResistanceFunktionKey(startZone, stopZone))) for (SimpleFeature startZoneFeature : zonesFeatures) { - String zone1 = String.valueOf(startZoneFeature.getAttribute("areaID")); + String zone1 = String.valueOf(startZoneFeature.getAttribute(shapeFileZoneNameColumn)); if (!startZone.equals(zone1)) continue; for (SimpleFeature stopZoneFeature : zonesFeatures) { - String zone2 = String.valueOf(stopZoneFeature.getAttribute("areaID")); + String zone2 = String.valueOf(stopZoneFeature.getAttribute(shapeFileZoneNameColumn)); if (!stopZone.equals(zone2)) continue; double distance = Double.MAX_VALUE; @@ -368,8 +371,8 @@ private Double getResistanceFunktionValue(String startZone, String stopZone, Net } else { if (useNetworkRoutesForResistanceFunction) { - Location startLocation = Location.newInstance(regionLinksMap.get(startZone).keySet().iterator().next().toString()); - Location stopLocation = Location.newInstance(regionLinksMap.get(stopZone).keySet().iterator().next().toString()); + Location startLocation = Location.newInstance(linksPerZone.get(startZone).keySet().iterator().next().toString()); + Location stopLocation = Location.newInstance(linksPerZone.get(stopZone).keySet().iterator().next().toString()); Vehicle exampleVehicle = getExampleVehicle(startLocation); // distance = netBasedCosts.getDistance(startLocation, stopLocation, 21600., exampleVehicle); travelCosts = netBasedCosts.getTransportCost(startLocation, stopLocation, 21600., null, exampleVehicle); @@ -443,16 +446,17 @@ private VehicleImpl getExampleVehicle(Location fromId) { /** * Calculates the gravity constant. * - * @param baseZone base zone - * @param trafficVolume volume of the traffic - * @param modeORvehType selected mode or vehicle type - * @param purpose selected purpose - * @param regionLinksMap links for each zone + * @param baseZone base zone + * @param trafficVolume volume of the traffic + * @param modeORvehType selected mode or vehicle type + * @param purpose selected purpose + * @param linksPerZone links for each zone + * @param shapeFileZoneNameColumn Name of the unique column of the name/Id of each zone in the zones shape file * @return gravity constant */ private double getGravityConstant(String baseZone, Map> trafficVolume, String modeORvehType, - Integer purpose, Network network, Map, Link>> regionLinksMap, double resistanceFactor) { + Integer purpose, Network network, Map, Link>> linksPerZone, double resistanceFactor, String shapeFileZoneNameColumn) { GravityConstantKey gravityKey = makeGravityKey(baseZone, modeORvehType, purpose); if (!gravityConstantACache.containsKey(gravityKey)) { @@ -464,7 +468,7 @@ private double getGravityConstant(String baseZone, continue; else { double resistanceValue = getResistanceFunktionValue(baseZone, trafficVolumeKey.getZone(), network, - regionLinksMap, resistanceFactor); + linksPerZone, resistanceFactor, shapeFileZoneNameColumn); sum = sum + (volume * resistanceValue); } } @@ -601,7 +605,7 @@ void writeODMatrices(Path output, String smallScaleCommercialTrafficType) throws try { List headerRow = new ArrayList<>(); - headerRow.add(""); + headerRow.add("O/D"); headerRow.addAll(usedZones); JOIN.appendTo(writer, headerRow); writer.write("\n"); diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysisTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysisTest.java index be97112e74c..fa640744c92 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysisTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/LanduseBuildingAnalysisTest.java @@ -51,18 +51,22 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { assert(new File(output.resolve("calculatedData").toString()).mkdir()); Path inputDataDirectory = Path.of(utils.getPackageInputDirectory()); String usedLanduseConfiguration = "useExistingDataDistribution"; - + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); // Test if the reading of the existing data distribution works correctly + Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); Assertions.assertEquals(3, resultingDataPerZone.size(), MatsimTestUtils.EPSILON); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea1_area1")); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea1_area2")); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea2_area3")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area1")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area2")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area3")); for (String zone : resultingDataPerZone.keySet()) { Object2DoubleMap categories = resultingDataPerZone.get(zone); @@ -86,60 +90,64 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { Assertions.assertEquals(categories.getDouble("Employee"), employeeSum, MatsimTestUtils.EPSILON); - if (zone.equals("testArea1_area1")) { - Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(3500, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(0, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } - if (zone.equals("testArea1_area2")) { - Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(6500, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(2000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } - if (zone.equals("testArea2_area3")) { - Assertions.assertEquals(800, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(50, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(100, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(150, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(300, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } + switch (zone) { + case "area1" -> { + Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(3500, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(0, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + case "area2" -> { + Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(6500, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(2000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + case "area3" -> { + Assertions.assertEquals(800, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(50, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(100, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(150, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(300, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + default -> Assertions.fail("Zone not found"); + } + } // tests if the reading of the buildings works correctly @@ -149,12 +157,12 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { landuseCategoriesAndDataConnection, SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory)); Assertions.assertEquals(3, buildingsPerZone.size(), MatsimTestUtils.EPSILON); - Assertions.assertTrue(buildingsPerZone.containsKey("testArea1_area1")); - Assertions.assertTrue(buildingsPerZone.containsKey("testArea1_area2")); - Assertions.assertTrue(buildingsPerZone.containsKey("testArea2_area3")); + Assertions.assertTrue(buildingsPerZone.containsKey("area1")); + Assertions.assertTrue(buildingsPerZone.containsKey("area2")); + Assertions.assertTrue(buildingsPerZone.containsKey("area3")); // test for area1 - Map> builingsPerArea1 = buildingsPerZone.get("testArea1_area1"); + Map> builingsPerArea1 = buildingsPerZone.get("area1"); Assertions.assertEquals(7, builingsPerArea1.size(), MatsimTestUtils.EPSILON); List inhabitantsBuildings = builingsPerArea1.get("Inhabitants"); Assertions.assertEquals(4, inhabitantsBuildings.size(), MatsimTestUtils.EPSILON); @@ -184,7 +192,7 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { Assertions.assertEquals(6, builingsPerArea1.get("Employee").size(), MatsimTestUtils.EPSILON); // test for area2 - Map> builingsPerArea2 = buildingsPerZone.get("testArea1_area2"); + Map> builingsPerArea2 = buildingsPerZone.get("area2"); Assertions.assertEquals(8, builingsPerArea2.size(), MatsimTestUtils.EPSILON); List employeeRetail = builingsPerArea2.get("Employee Retail"); Assertions.assertEquals(2, employeeRetail.size(), MatsimTestUtils.EPSILON); @@ -208,7 +216,7 @@ void testReadOfDataDistributionPerZoneAndBuildingAnalysis() throws IOException { Assertions.assertEquals(8, builingsPerArea2.get("Employee").size(), MatsimTestUtils.EPSILON); // test for area3 - Map> builingsPerArea3 = buildingsPerZone.get("testArea2_area3"); + Map> builingsPerArea3 = buildingsPerZone.get("area3"); Assertions.assertEquals(8, builingsPerArea3.size(), MatsimTestUtils.EPSILON); List tertiaryRetail = builingsPerArea3.get("Employee Tertiary Sector Rest"); Assertions.assertEquals(1, tertiaryRetail.size(), MatsimTestUtils.EPSILON); @@ -238,18 +246,20 @@ void testLanduseDistribution() throws IOException { assert(new File(output.resolve("calculatedData").toString()).mkdir()); Path inputDataDirectory = Path.of(utils.getPackageInputDirectory()); String usedLanduseConfiguration = "useOSMBuildingsAndLanduse"; - + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); // Analyze resultingData per zone Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, null); Assertions.assertEquals(3, resultingDataPerZone.size(), MatsimTestUtils.EPSILON); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea1_area1")); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea1_area2")); - Assertions.assertTrue(resultingDataPerZone.containsKey("testArea2_area3")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area1")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area2")); + Assertions.assertTrue(resultingDataPerZone.containsKey("area3")); for (String zone : resultingDataPerZone.keySet()) { Object2DoubleMap categories = resultingDataPerZone.get(zone); @@ -273,60 +283,63 @@ void testLanduseDistribution() throws IOException { Assertions.assertEquals(categories.getDouble("Employee"), employeeSum, MatsimTestUtils.EPSILON); - if (zone.equals("testArea1_area1")) { - Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(3500, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(0, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } - if (zone.equals("testArea1_area2")) { - Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(6500, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(2000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } - if (zone.equals("testArea2_area3")) { - Assertions.assertEquals(800, resultingDataPerZone.get(zone).getDouble("Inhabitants"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(50, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Construction"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(100, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(150, resultingDataPerZone.get(zone).getDouble("Employee Retail"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), - MatsimTestUtils.EPSILON); - Assertions.assertEquals(300, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), - MatsimTestUtils.EPSILON); - } + switch (zone) { + case "area1" -> { + Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(3500, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(0, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + case "area2" -> { + Assertions.assertEquals(4000, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(6500, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(500, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1500, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(2000, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + case "area3" -> { + Assertions.assertEquals(800, resultingDataPerZone.get(zone).getDouble("Inhabitants"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(1000, resultingDataPerZone.get(zone).getDouble("Employee"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(50, resultingDataPerZone.get(zone).getDouble("Employee Primary Sector"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Construction"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(100, resultingDataPerZone.get(zone).getDouble("Employee Secondary Sector Rest"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(150, resultingDataPerZone.get(zone).getDouble("Employee Retail"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(200, resultingDataPerZone.get(zone).getDouble("Employee Traffic/Parcels"), + MatsimTestUtils.EPSILON); + Assertions.assertEquals(300, resultingDataPerZone.get(zone).getDouble("Employee Tertiary Sector Rest"), + MatsimTestUtils.EPSILON); + } + default -> Assertions.fail("Zone not found"); + } } } } diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/RunGenerateSmallScaleCommercialTrafficTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/RunGenerateSmallScaleCommercialTrafficTest.java index b5e92503851..c664ba46440 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/RunGenerateSmallScaleCommercialTrafficTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/RunGenerateSmallScaleCommercialTrafficTest.java @@ -19,6 +19,11 @@ * *********************************************************************** */ package org.matsim.smallScaleCommercialTrafficGeneration; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -30,13 +35,19 @@ import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.core.utils.io.IOUtils; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarriersUtils; import org.matsim.freight.carriers.FreightCarriersConfigGroup; import org.matsim.testcases.MatsimTestUtils; import org.matsim.utils.eventsfilecomparison.ComparisonResult; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; /** @@ -50,30 +61,44 @@ public class RunGenerateSmallScaleCommercialTrafficTest { @Test void testMainRunAndResults() { - String inputDataDirectory = utils.getPackageInputDirectory() + "config_demand.xml"; + String pathToConfig = utils.getPackageInputDirectory() + "config_demand.xml"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); String output = utils.getOutputDirectory(); String sample = "0.1"; String jspritIterations = "2"; String creationOption = "createNewCarrierFile"; String landuseConfiguration = "useExistingDataDistribution"; String smallScaleCommercialTrafficType = "commercialPersonTraffic"; + String regionsShapeFileName = utils.getPackageInputDirectory() + "/shp/testRegions.shp"; + String regionsShapeRegionColumn = "region"; String zoneShapeFileName = utils.getPackageInputDirectory() + "/shp/testZones.shp"; + String zoneShapeFileNameColumn = "name"; String buildingsShapeFileName = utils.getPackageInputDirectory() + "/shp/testBuildings.shp"; + String shapeFileBuildingTypeColumn = "type"; String landuseShapeFileName = utils.getPackageInputDirectory() + "/shp/testLanduse.shp"; + String shapeFileLanduseTypeColumn = "fclass"; String shapeCRS = "EPSG:4326"; String resultPopulation = "testPopulation.xml.gz"; new GenerateSmallScaleCommercialTrafficDemand().execute( - inputDataDirectory, + pathToConfig, + "--pathToInvestigationAreaData", pathToInvestigationAreaData.toString(), + "--pathToExistingDataDistributionToZones", pathToExistingDataDistributionToZones.toString(), "--sample", sample, "--jspritIterations", jspritIterations, "--creationOption", creationOption, "--landuseConfiguration", landuseConfiguration, "--smallScaleCommercialTrafficType", smallScaleCommercialTrafficType, "--includeExistingModels", + "--regionsShapeFileName", regionsShapeFileName, + "--regionsShapeRegionColumn", regionsShapeRegionColumn, "--zoneShapeFileName", zoneShapeFileName, + "--zoneShapeFileNameColumn", zoneShapeFileNameColumn, "--buildingsShapeFileName", buildingsShapeFileName, + "--shapeFileBuildingTypeColumn", shapeFileBuildingTypeColumn, "--landuseShapeFileName", landuseShapeFileName, + "--shapeFileLanduseTypeColumn", shapeFileLanduseTypeColumn, "--shapeCRS", shapeCRS, "--nameOutputPopulation", resultPopulation, "--pathOutput", output); @@ -109,17 +134,65 @@ void testMainRunAndResults() { } Assertions.assertEquals(population.getPersons().size(), countedTours, 0); - for (File caculatedFile : Objects.requireNonNull( + for (File calculatedFile : Objects.requireNonNull( Objects.requireNonNull(new File(utils.getOutputDirectory() + "calculatedData").listFiles()))) { - MatsimTestUtils.assertEqualFilesLineByLine( - utils.getPackageInputDirectory() + "calculatedData/" + caculatedFile.getName(), - caculatedFile.getAbsolutePath()); + Map> existingDataDistribution = readCSVInputAndCreateMap(calculatedFile.getAbsolutePath()); + Map> simulatedDataDistribution = readCSVInputAndCreateMap( + utils.getPackageInputDirectory() + "calculatedData/" + calculatedFile.getName()); + compareDataDistribution(calculatedFile.getName(), existingDataDistribution, simulatedDataDistribution); } // compare events - String expected = utils.getPackageInputDirectory() + "test.output_events.xml.gz" ; + String expected = utils.getPackageInputDirectory() + "test.output_events.xml.gz"; String actual = utils.getOutputDirectory() + "test.output_events.xml.gz" ; ComparisonResult result = EventsUtils.compareEventsFiles( expected, actual ); Assertions.assertEquals( ComparisonResult.FILES_ARE_EQUAL, result ); } + + /** + * Reads a CSV file and creates a map with the first column as key and the rest as a map with the header as key and the value as value + * + * @param calculatedFile the file to read + * @return + */ + private static Map> readCSVInputAndCreateMap(String calculatedFile) { + Map> dataDistribution = new HashMap<>(); + try (BufferedReader reader = IOUtils.getBufferedReader(calculatedFile)) { + CSVParser parse = CSVFormat.Builder.create(CSVFormat.DEFAULT).setDelimiter('\t').setHeader() + .setSkipHeaderRecord(true).build().parse(reader); + for (CSVRecord record : parse) { + System.out.println(record); + dataDistribution.computeIfAbsent(record.get(0), k -> new Object2DoubleOpenHashMap<>()); + for (int i = 1; i < record.size(); i++) { + if (i == 1 && (calculatedFile.contains("dataDistributionPerZone") || calculatedFile.contains("TrafficVolume_"))) + continue; + dataDistribution.get(record.get(0)).put(parse.getHeaderNames().get(i), Double.parseDouble(record.get(i))); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return dataDistribution; + } + + /** + * Compares the data distribution of two files + * + * @param calculatedFile the file to compare + * @param existingDataDistribution the existing data distribution + * @param simulatedDataDistribution the simulated data distribution + */ + private void compareDataDistribution(String calculatedFile, Map> existingDataDistribution, + Map> simulatedDataDistribution) { + Assertions.assertEquals(existingDataDistribution.size(), simulatedDataDistribution.size()); + for (String key : existingDataDistribution.keySet()) { + Object2DoubleMap existingMap = existingDataDistribution.get(key); + Object2DoubleMap simulatedMap = simulatedDataDistribution.get(key); + for (String subKey : existingMap.keySet()) { + Assertions.assertEquals(existingMap.getDouble(subKey), simulatedMap.getDouble(subKey), + "File: " + calculatedFile + "; Expected: " + existingMap.getDouble(subKey) + " but was: " + simulatedMap.getDouble( + subKey) + " for key: " + key + " and subKey: " + subKey); + } + } + } } diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SCTUtils.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SCTUtils.java index 7b16b902d08..843a690196d 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SCTUtils.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/SCTUtils.java @@ -11,7 +11,7 @@ public class SCTUtils { static ShpOptions.Index getZoneIndex(Path inputDataDirectory) { Path shapeFileZonePath = inputDataDirectory.resolve("shp/testZones.shp"); - return new ShpOptions(shapeFileZonePath, null, null).createIndex("areaID"); + return new ShpOptions(shapeFileZonePath, null, null).createIndex("name"); } static ShpOptions.Index getIndexLanduse(Path inputDataDirectory) { @@ -24,4 +24,9 @@ static ShpOptions.Index getIndexBuildings(Path inputDataDirectory) { return new ShpOptions(shapeFileBuildingsPath, null, null).createIndex("type"); } + static ShpOptions.Index getIndexRegions(Path inputDataDirectory) { + Path shapeFileRegionsPath = inputDataDirectory.resolve("shp/testRegions.shp"); + return new ShpOptions(shapeFileRegionsPath, null, null).createIndex("region"); + } + } 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 61d3f759aac..5aa06d111fc 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 @@ -59,19 +59,21 @@ void findZoneOfLinksTest() throws IOException, URISyntaxException { config.network().setInputCRS("EPSG:4326"); Scenario scenario = ScenarioUtils.loadScenario(config); Map>> buildingsPerZone = new HashMap<>(); + String shapeFileZoneNameColumn = "name"; Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand - .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem()), + .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), + shapeFileZoneNameColumn), buildingsPerZone); Assertions.assertEquals(3, regionLinksMap.size(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(60, regionLinksMap.get("testArea1_area1").size(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(41, regionLinksMap.get("testArea1_area2").size(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(28, regionLinksMap.get("testArea2_area3").size(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(60, regionLinksMap.get("area1").size(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(41, regionLinksMap.get("area2").size(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(28, regionLinksMap.get("area3").size(), MatsimTestUtils.EPSILON); Assertions.assertNull(SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(5,4)"), regionLinksMap)); - Assertions.assertEquals("testArea1_area1", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(6,5)R"), regionLinksMap)); - Assertions.assertEquals("testArea1_area2", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(2,7)R"), regionLinksMap)); - Assertions.assertEquals("testArea2_area3", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(2,2)R"), regionLinksMap)); + Assertions.assertEquals("area1", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(6,5)R"), regionLinksMap)); + Assertions.assertEquals("area2", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(2,7)R"), regionLinksMap)); + Assertions.assertEquals("area3", SmallScaleCommercialTrafficUtils.findZoneOfLink(Id.createLinkId("j(2,2)R"), regionLinksMap)); } } 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 b1646548777..b680e568ffb 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 @@ -60,11 +60,15 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { assert(new File(output.resolve("calculatedData").toString()).mkdir()); Path inputDataDirectory = Path.of(utils.getPackageInputDirectory()); String usedLanduseConfiguration = "useExistingDataDistribution"; + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); String usedTrafficType = "commercialPersonTraffic"; @@ -86,7 +90,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertTrue(trafficVolumePerTypeAndZone_start.containsKey(trafficVolumeKey)); Assertions.assertTrue(trafficVolumePerTypeAndZone_stop.containsKey(trafficVolumeKey)); } - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area1", modesORvehTypes.get(0)); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area1", modesORvehTypes.get(0)); Assertions.assertEquals(30, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(124, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(277, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -99,7 +103,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertEquals(121, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(65, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area2", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area2", modesORvehTypes.get(0)); Assertions.assertEquals(30, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(211, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(514, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -112,7 +116,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertEquals(246, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(102, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea2_area3", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area3", modesORvehTypes.get(0)); Assertions.assertEquals(6, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(34, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(79, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -136,7 +140,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertEquals(3, trafficVolumePerTypeAndZone_start.size()); Assertions.assertEquals(3, trafficVolumePerTypeAndZone_stop.size()); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area1", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area1", modesORvehTypes.get(0)); Assertions.assertEquals(7, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(31, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(69, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -149,7 +153,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertEquals(30, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(16, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area2", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area2", modesORvehTypes.get(0)); Assertions.assertEquals(7, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(53, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(129, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -162,7 +166,7 @@ void testTrafficVolumeGenerationCommercialPersonTraffic() throws IOException { Assertions.assertEquals(61, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(25, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea2_area3", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area3", modesORvehTypes.get(0)); Assertions.assertEquals(1, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(8, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); Assertions.assertEquals(20, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -186,11 +190,15 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { assert(new File(output.resolve("calculatedData").toString()).mkdir()); Path inputDataDirectory = Path.of(utils.getPackageInputDirectory()); String usedLanduseConfiguration = "useExistingDataDistribution"; + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); String usedTrafficType = "goodsTraffic"; double sample = 1.; @@ -214,7 +222,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { } } - // test for "testArea1_area1" + // test for "area1" HashMap estimatesStart = new HashMap<>(); estimatesStart.put(1, 12.); estimatesStart.put(2, 30.); @@ -234,7 +242,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area1", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area1", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); if (modeORvehType.equals("vehTyp1")) { @@ -317,7 +325,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { Assertions.assertEquals(estimatesStop.get(i), sumStop, MatsimTestUtils.EPSILON); } - // test for "testArea1_area2" + // test for "area2" estimatesStart = new HashMap<>(); estimatesStart.put(1, 12.); estimatesStart.put(2, 37.); @@ -337,7 +345,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area2", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area2", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); } @@ -345,7 +353,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { Assertions.assertEquals(estimatesStop.get(i), sumStop, MatsimTestUtils.EPSILON); } - // test for "testArea2_area3" + // test for "area3" estimatesStart = new HashMap<>(); estimatesStart.put(1, 2.); estimatesStart.put(2, 7.); @@ -365,7 +373,7 @@ void testTrafficVolumeGenerationGoodsTraffic() throws IOException { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea2_area3", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area3", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); } @@ -388,9 +396,11 @@ void testAddingExistingScenarios() throws Exception { config.setContext(inputDataDirectory.resolve("config.xml").toUri().toURL()); Scenario scenario = ScenarioUtils.loadScenario(config); Map>> buildingsPerZone = new HashMap<>(); + String shapeFileZoneNameColumn = "name"; Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand - .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem()), + .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), + shapeFileZoneNameColumn), buildingsPerZone); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); @@ -414,7 +424,7 @@ void testAddingExistingScenarios() throws Exception { Assertions.assertEquals("exampleServiceCarrier", addedCarrier1.getAttributes().getAttribute("existingModel")); Assertions.assertEquals("car", addedCarrier1.getAttributes().getAttribute("networkMode")); Assertions.assertNull(addedCarrier1.getAttributes().getAttribute("vehicleType")); - Assertions.assertEquals("testArea2_area3", addedCarrier1.getAttributes().getAttribute("tourStartArea")); + Assertions.assertEquals("area3", addedCarrier1.getAttributes().getAttribute("tourStartArea")); Carrier addedCarrier2 = CarriersUtils.getCarriers(scenario).getCarriers().get(Id.create("exampleServiceCarrier_carrier2", Carrier.class)); Assertions.assertNotNull(addedCarrier2.getSelectedPlan()); @@ -428,7 +438,7 @@ void testAddingExistingScenarios() throws Exception { Assertions.assertEquals("exampleServiceCarrier", addedCarrier2.getAttributes().getAttribute("existingModel")); Assertions.assertEquals("car", addedCarrier2.getAttributes().getAttribute("networkMode")); Assertions.assertNull(addedCarrier2.getAttributes().getAttribute("vehicleType")); - Assertions.assertEquals("testArea2_area3", addedCarrier2.getAttributes().getAttribute("tourStartArea")); + Assertions.assertEquals("area3", addedCarrier2.getAttributes().getAttribute("tourStartArea")); Carrier addedCarrier3 = CarriersUtils.getCarriers(scenario).getCarriers().get(Id.create("exampleShipmentCarrier_carrier1", Carrier.class)); Assertions.assertNull(addedCarrier3.getSelectedPlan()); @@ -447,6 +457,8 @@ void testAddingExistingScenariosWithSample() throws Exception { Path shapeFileZonePath = inputDataDirectory.resolve("shp/testZones.shp"); String networkPath = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; double sample = 0.2; + String shapeFileZoneNameColumn = "name"; + Config config = ConfigUtils.createConfig(); config.global().setCoordinateSystem("EPSG:4326"); config.network().setInputFile(networkPath); @@ -455,7 +467,8 @@ void testAddingExistingScenariosWithSample() throws Exception { Scenario scenario = ScenarioUtils.loadScenario(config); Map>> buildingsPerZone = new HashMap<>(); Map, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand - .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem()), + .filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(), + shapeFileZoneNameColumn), buildingsPerZone); SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap); @@ -478,7 +491,7 @@ void testAddingExistingScenariosWithSample() throws Exception { Assertions.assertEquals("exampleServiceCarrier", addedCarrier1.getAttributes().getAttribute("existingModel")); Assertions.assertEquals("car", addedCarrier1.getAttributes().getAttribute("networkMode")); Assertions.assertNull(addedCarrier1.getAttributes().getAttribute("vehicleType")); - Assertions.assertEquals("testArea2_area3", addedCarrier1.getAttributes().getAttribute("tourStartArea")); + Assertions.assertEquals("area3", addedCarrier1.getAttributes().getAttribute("tourStartArea")); Carrier addedCarrier3 = CarriersUtils.getCarriers(scenario).getCarriers().get(Id.create("exampleShipmentCarrier_carrier1", Carrier.class)); Assertions.assertNull(addedCarrier3.getSelectedPlan()); @@ -502,6 +515,10 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { String networkPath = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; String usedTrafficType = "goodsTraffic"; double sample = 1.; + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); + ArrayList modesORvehTypes = new ArrayList<>( Arrays.asList("vehTyp1", "vehTyp2", "vehTyp3", "vehTyp4", "vehTyp5")); Config config = ConfigUtils.createConfig(); @@ -514,8 +531,9 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); Map> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration .createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); @@ -530,7 +548,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { TrafficVolumeGeneration.reduceDemandBasedOnExistingCarriers(scenario, regionLinksMap, usedTrafficType, trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop); - // test for "testArea1_area1" + // test for "area1" HashMap estimatesStart = new HashMap<>(); estimatesStart.put(1, 12.); estimatesStart.put(2, 30.); @@ -550,7 +568,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area1", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area1", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); if (modeORvehType.equals("vehTyp3")) { @@ -573,7 +591,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { Assertions.assertEquals(estimatesStop.get(i), sumStop, MatsimTestUtils.EPSILON); } - // test for "testArea1_area2" + // test for "area2" estimatesStart = new HashMap<>(); estimatesStart.put(1, 12.); estimatesStart.put(2, 37.); @@ -593,7 +611,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area2", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area2", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); } @@ -601,7 +619,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { Assertions.assertEquals(estimatesStop.get(i), sumStop, MatsimTestUtils.EPSILON); } - // test for "testArea2_area3" + // test for "area3" estimatesStart = new HashMap<>(); estimatesStart.put(1, 2.); estimatesStart.put(2, 7.); @@ -621,7 +639,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception { double sumStart = 0; double sumStop = 0; for (String modeORvehType : modesORvehTypes) { - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea2_area3", modeORvehType); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area3", modeORvehType); sumStart += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(i); sumStop += trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(i); if (modeORvehType.equals("vehTyp3")) { @@ -657,6 +675,10 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th String networkPath = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; String usedTrafficType = "commercialPersonTraffic"; double sample = 1.; + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); + ArrayList modesORvehTypes = new ArrayList<>( List.of("total")); Config config = ConfigUtils.createConfig(); @@ -669,8 +691,9 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + SCTUtils.getIndexLanduse(inputDataDirectory), SCTUtils.getZoneIndex(inputDataDirectory), SCTUtils.getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); Map> trafficVolumePerTypeAndZone_start = TrafficVolumeGeneration .createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); @@ -688,7 +711,7 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th //because the reduction of the start volume in zone3 (purpose 2) is higher than the value, a start reduction will be distributed over other zones double sumOfStartOtherAreas = 0; - TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area1", modesORvehTypes.get(0)); + TrafficVolumeKey trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area1", modesORvehTypes.get(0)); Assertions.assertEquals(30, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); sumOfStartOtherAreas += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2); Assertions.assertEquals(277, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -701,7 +724,7 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th Assertions.assertEquals(121, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(65, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea1_area2", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area2", modesORvehTypes.get(0)); Assertions.assertEquals(30, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); sumOfStartOtherAreas += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2); Assertions.assertEquals(514, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(3), MatsimTestUtils.EPSILON); @@ -714,7 +737,7 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th Assertions.assertEquals(246, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(4), MatsimTestUtils.EPSILON); Assertions.assertEquals(102, trafficVolumePerTypeAndZone_stop.get(trafficVolumeKey).getDouble(5), MatsimTestUtils.EPSILON); - trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("testArea2_area3", modesORvehTypes.get(0)); + trafficVolumeKey = TrafficVolumeGeneration.makeTrafficVolumeKey("area3", modesORvehTypes.get(0)); Assertions.assertEquals(6, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(1), MatsimTestUtils.EPSILON); Assertions.assertEquals(0, trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2), MatsimTestUtils.EPSILON); sumOfStartOtherAreas += trafficVolumePerTypeAndZone_start.get(trafficVolumeKey).getDouble(2); diff --git a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrixTest.java b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrixTest.java index 0cf215c836c..7190ba7350d 100644 --- a/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrixTest.java +++ b/contribs/small-scale-traffic-generation/src/test/java/org/matsim/smallScaleCommercialTrafficGeneration/TripDistributionMatrixTest.java @@ -59,10 +59,15 @@ void testTripDistributionCommercialPersonTrafficTraffic() throws IOException { String usedLanduseConfiguration = "useExistingDataDistribution"; String networkLocation = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; Network network = NetworkUtils.readNetwork(networkLocation); + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); + Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - getIndexLanduse(inputDataDirectory), getZoneIndex(inputDataDirectory), getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + getIndexLanduse(inputDataDirectory), getZoneIndex(inputDataDirectory), getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); String usedTrafficType = "commercialPersonTraffic"; double sample = 1.; @@ -75,18 +80,18 @@ void testTripDistributionCommercialPersonTrafficTraffic() throws IOException { .createTrafficVolume_start(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); Map> trafficVolumePerTypeAndZone_stop = TrafficVolumeGeneration .createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType); - ArrayList listOfZones = new ArrayList<>( List.of("testArea1_area1", "testArea1_area2", "testArea2_area3")); + ArrayList listOfZones = new ArrayList<>( List.of("area1", "area2", "area3")); final TripDistributionMatrix odMatrix = TripDistributionMatrix.Builder .newInstance(getZoneIndex(inputDataDirectory), trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop, usedTrafficType, listOfZones).build(); Map, Link>> regionLinksMap = new HashMap<>(); - regionLinksMap.put("testArea1_area1", new HashMap<>()); - regionLinksMap.get("testArea1_area1").put(Id.createLinkId("i(8,6)"), network.getLinks().get(Id.createLinkId("i(8,6)"))); - regionLinksMap.put("testArea1_area2", new HashMap<>()); - regionLinksMap.get("testArea1_area2").put(Id.createLinkId("i(2,7)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); - regionLinksMap.put("testArea2_area3", new HashMap<>()); - regionLinksMap.get("testArea2_area3").put(Id.createLinkId("i(2,1)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); + regionLinksMap.put("area1", new HashMap<>()); + regionLinksMap.get("area1").put(Id.createLinkId("i(8,6)"), network.getLinks().get(Id.createLinkId("i(8,6)"))); + regionLinksMap.put("area2", new HashMap<>()); + regionLinksMap.get("area2").put(Id.createLinkId("i(2,7)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); + regionLinksMap.put("area3", new HashMap<>()); + regionLinksMap.get("area3").put(Id.createLinkId("i(2,1)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); for (String startZone : resultingDataPerZone.keySet()) { for (String stopZone : resultingDataPerZone.keySet()) { @@ -94,7 +99,7 @@ void testTripDistributionCommercialPersonTrafficTraffic() throws IOException { for (Integer purpose : trafficVolumePerTypeAndZone_start .get(TrafficVolumeGeneration.makeTrafficVolumeKey(startZone, modeORvehType)).keySet()) { odMatrix.setTripDistributionValue(startZone, stopZone, modeORvehType, purpose, usedTrafficType, - network, regionLinksMap, resistanceFactor); + network, regionLinksMap, resistanceFactor, shapeFileZoneNameColumn); } } } @@ -146,10 +151,14 @@ void testTripDistributionGoodsTraffic() throws IOException { String usedLanduseConfiguration = "useExistingDataDistribution"; String networkLocation = "https://raw.githubusercontent.com/matsim-org/matsim-libs/master/examples/scenarios/freight-chessboard-9x9/grid9x9.xml"; Network network = NetworkUtils.readNetwork(networkLocation); + String shapeFileZoneNameColumn = "name"; + Path pathToInvestigationAreaData = Path.of(utils.getPackageInputDirectory()).resolve("investigationAreaData.csv"); + Path pathToExistingDataDistributionToZones = Path.of(utils.getPackageInputDirectory()).resolve("dataDistributionPerZone.csv"); Map> resultingDataPerZone = LanduseBuildingAnalysis .createInputDataDistribution(output, landuseCategoriesAndDataConnection, - inputDataDirectory, usedLanduseConfiguration, - getIndexLanduse(inputDataDirectory), getZoneIndex(inputDataDirectory), getIndexBuildings(inputDataDirectory), buildingsPerZone); + usedLanduseConfiguration, + getIndexLanduse(inputDataDirectory), getZoneIndex(inputDataDirectory), getIndexBuildings(inputDataDirectory), + SCTUtils.getIndexRegions(inputDataDirectory), shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData, pathToExistingDataDistributionToZones); String usedTrafficType = "goodsTraffic"; double sample = 1.; @@ -157,7 +166,7 @@ void testTripDistributionGoodsTraffic() throws IOException { ArrayList modesORvehTypes = new ArrayList( Arrays.asList("vehTyp1", "vehTyp2", "vehTyp3", "vehTyp4", "vehTyp5")); - ArrayList listOfZones = new ArrayList<>( List.of("testArea1_area1", "testArea1_area2", "testArea2_area3")); + ArrayList listOfZones = new ArrayList<>( List.of("area1", "area2", "area3")); TrafficVolumeGeneration.setInputParameters(usedTrafficType); @@ -170,12 +179,12 @@ void testTripDistributionGoodsTraffic() throws IOException { listOfZones).build(); Map, Link>> regionLinksMap = new HashMap<>(); - regionLinksMap.put("testArea1_area1", new HashMap<>()); - regionLinksMap.get("testArea1_area1").put(Id.createLinkId("i(8,6)"), network.getLinks().get(Id.createLinkId("i(8,6)"))); - regionLinksMap.put("testArea1_area2", new HashMap<>()); - regionLinksMap.get("testArea1_area2").put(Id.createLinkId("i(2,7)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); - regionLinksMap.put("testArea2_area3", new HashMap<>()); - regionLinksMap.get("testArea2_area3").put(Id.createLinkId("i(2,1)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); + regionLinksMap.put("area1", new HashMap<>()); + regionLinksMap.get("area1").put(Id.createLinkId("i(8,6)"), network.getLinks().get(Id.createLinkId("i(8,6)"))); + regionLinksMap.put("area2", new HashMap<>()); + regionLinksMap.get("area2").put(Id.createLinkId("i(2,7)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); + regionLinksMap.put("area3", new HashMap<>()); + regionLinksMap.get("area3").put(Id.createLinkId("i(2,1)R"), network.getLinks().get(Id.createLinkId("i(2,7)R"))); for (String startZone : resultingDataPerZone.keySet()) { for (String stopZone : resultingDataPerZone.keySet()) { @@ -183,7 +192,7 @@ void testTripDistributionGoodsTraffic() throws IOException { for (Integer purpose : trafficVolumePerTypeAndZone_start .get(TrafficVolumeGeneration.makeTrafficVolumeKey(startZone, modeORvehType)).keySet()) { odMatrix.setTripDistributionValue(startZone, stopZone, modeORvehType, purpose, usedTrafficType, - network, regionLinksMap, resistanceFactor); + network, regionLinksMap, resistanceFactor, shapeFileZoneNameColumn); } } } diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_startPerZone_10pt.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_startPerZone_10pt.csv index bfdf8e63f8c..76905762d24 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_startPerZone_10pt.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_startPerZone_10pt.csv @@ -1,4 +1,4 @@ -areaID mode/vehType 1 2 3 4 5 -testArea2_area3 total 1 3 8 6 9 -testArea1_area2 total 3 21 51 44 63 -testArea1_area1 total 3 12 28 18 25 +zoneID mode/vehType 1 2 3 4 5 +area2 total 3 21 51 44 63 +area1 total 3 12 28 18 25 +area3 total 1 3 8 6 9 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_stopPerZone_10pt.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_stopPerZone_10pt.csv index 0c53286d73b..837a7d38659 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_stopPerZone_10pt.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/TrafficVolume_commercialPersonTraffic_stopPerZone_10pt.csv @@ -1,4 +1,4 @@ -areaID mode/vehType 1 2 3 4 5 -testArea2_area3 total 0 3 13 4 2 -testArea1_area2 total 1 20 86 25 10 -testArea1_area1 total 1 10 43 12 6 +zoneID mode/vehType 1 2 3 4 5 +area2 total 1 20 86 25 10 +area1 total 1 10 43 12 6 +area3 total 0 3 13 4 2 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/dataDistributionPerZone.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/dataDistributionPerZone.csv index 70857ece6c1..0a841cc7dd0 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/dataDistributionPerZone.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/dataDistributionPerZone.csv @@ -1,4 +1,4 @@ -areaID areaName Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest -testArea1_area2 area2 4000 6500 500 1500 500 500 1500 2000 -testArea2_area3 area3 800 1000 50 200 100 150 200 300 -testArea1_area1 area1 4000 3500 0 500 500 1000 500 1000 \ No newline at end of file +zoneID region Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest +area2 region1 4000 6500 500 1500 500 500 1500 2000 +area3 region2 800 1000 50 200 100 150 200 300 +area1 region1 4000 3500 0 500 500 1000 500 1000 \ No newline at end of file diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose1.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose1.csv index 38573c7f4c0..1bc43756980 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose1.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose1.csv @@ -1,4 +1,4 @@ - testArea2_area3 testArea1_area2 testArea1_area1 -testArea2_area3 0 0 0 -testArea1_area2 0 1 0 -testArea1_area1 0 0 1 +O/D area2 area1 area3 +area2 1 0 0 +area1 0 1 0 +area3 0 0 0 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose2.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose2.csv index 30cf57e5fc3..5b49558b3a5 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose2.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose2.csv @@ -1,4 +1,4 @@ - testArea2_area3 testArea1_area2 testArea1_area1 -testArea2_area3 0 0 0 -testArea1_area2 0 8 7 -testArea1_area1 1 5 3 +O/D area2 area1 area3 +area2 8 6 0 +area1 5 4 1 +area3 0 0 0 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose3.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose3.csv index 44108374c44..04d2d8af059 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose3.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose3.csv @@ -1,4 +1,4 @@ - testArea2_area3 testArea1_area2 testArea1_area1 -testArea2_area3 2 7 3 -testArea1_area2 7 52 25 -testArea1_area1 4 27 15 +O/D area2 area1 area3 +area2 51 24 7 +area1 27 15 4 +area3 8 4 2 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose4.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose4.csv index 6cebadd2f70..3d2f4777106 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose4.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose4.csv @@ -1,4 +1,4 @@ - testArea2_area3 testArea1_area2 testArea1_area1 -testArea2_area3 0 2 2 -testArea1_area2 2 17 7 -testArea1_area1 2 6 3 +O/D area2 area1 area3 +area2 16 7 2 +area1 7 3 1 +area3 2 2 1 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose5.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose5.csv index 5d7cb865fbf..ac996432028 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose5.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/calculatedData/odMatrix_commercialPersonTraffic_total_purpose5.csv @@ -1,4 +1,4 @@ - testArea2_area3 testArea1_area2 testArea1_area1 -testArea2_area3 0 0 0 -testArea1_area2 1 7 4 -testArea1_area1 1 3 2 +O/D area2 area1 area3 +area2 7 4 1 +area1 3 2 0 +area3 0 0 1 diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/dataDistributionPerZone.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/dataDistributionPerZone.csv index 70857ece6c1..0a841cc7dd0 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/dataDistributionPerZone.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/dataDistributionPerZone.csv @@ -1,4 +1,4 @@ -areaID areaName Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest -testArea1_area2 area2 4000 6500 500 1500 500 500 1500 2000 -testArea2_area3 area3 800 1000 50 200 100 150 200 300 -testArea1_area1 area1 4000 3500 0 500 500 1000 500 1000 \ No newline at end of file +zoneID region Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest +area2 region1 4000 6500 500 1500 500 500 1500 2000 +area3 region2 800 1000 50 200 100 150 200 300 +area1 region1 4000 3500 0 500 500 1000 500 1000 \ No newline at end of file diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/investigationAreaData.csv b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/investigationAreaData.csv index e8dd1cb57ff..97fe8fd80b7 100644 --- a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/investigationAreaData.csv +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/investigationAreaData.csv @@ -1,3 +1,3 @@ -Area Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest -testArea1 8000 10000 500 2000 1000 1500 2000 3000 -testArea2 800 1000 50 200 100 150 200 300 \ No newline at end of file +Region Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest +region1 8000 10000 500 2000 1000 1500 2000 3000 +region2 800 1000 50 200 100 150 200 300 \ No newline at end of file diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.cpg b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.cpg new file mode 100644 index 00000000000..3ad133c048f --- /dev/null +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.dbf b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.dbf new file mode 100644 index 00000000000..c97184381a4 Binary files /dev/null and b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.dbf differ diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.prj b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.prj new file mode 100644 index 00000000000..f45cbadf007 --- /dev/null +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.prj @@ -0,0 +1 @@ +GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] \ No newline at end of file diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.qmd b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.qmd new file mode 100644 index 00000000000..d8b7603dead --- /dev/null +++ b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.qmd @@ -0,0 +1,26 @@ + + + + + + dataset + + + + + + + + + + 0 + 0 + + + + + false + + + + diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shp b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shp new file mode 100644 index 00000000000..50121591ca3 Binary files /dev/null and b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shp differ diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shx b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shx new file mode 100644 index 00000000000..7bf75055f1c Binary files /dev/null and b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/shp/testRegions.shx differ diff --git a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/test.output_events.xml.gz b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/test.output_events.xml.gz index a3f7231747b..cedefa5d9a5 100644 Binary files a/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/test.output_events.xml.gz and b/contribs/small-scale-traffic-generation/test/input/org/matsim/smallScaleCommercialTrafficGeneration/test.output_events.xml.gz differ