Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use configurable parameter for zone name column #3192

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public Integer call() throws Exception {
usedLanduseConfiguration.toString(), indexLanduse, indexZones,
indexBuildings, indexInvestigationAreaRegions, shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData,
pathToExistingDataDistributionToZones);
Map<String, Map<Id<Link>, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone);
Map<String, Map<Id<Link>, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone, shapeFileZoneNameColumn);

switch (usedSmallScaleCommercialTrafficType) {
case commercialPersonTraffic, goodsTraffic ->
Expand Down Expand Up @@ -909,7 +909,8 @@ private Id<Link> findPossibleLink(String zone, String selectedCategory, List<Str
* Filters links by used mode "car" and creates Map with all links in each zone
*/
static Map<String, Map<Id<Link>, Link>> filterLinksForZones(Scenario scenario, Index indexZones,
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone) throws URISyntaxException {
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone,
String shapeFileZoneNameColumn) throws URISyntaxException {
Map<String, Map<Id<Link>, Link>> regionLinksMap = new HashMap<>();
List<Link> links;
log.info("Filtering and assign links to zones. This take some time...");
Expand All @@ -936,7 +937,7 @@ static Map<String, Map<Id<Link>, Link>> filterLinksForZones(Scenario scenario, I
.computeIfAbsent((String) l.getAttributes().getAttribute("zone"), (k) -> new HashMap<>())
.put(l.getId(), l));
if (regionLinksMap.size() != indexZones.size())
findNearestLinkForZonesWithoutLinks(networkToChange, regionLinksMap, indexZones, buildingsPerZone);
findNearestLinkForZonesWithoutLinks(networkToChange, regionLinksMap, indexZones, buildingsPerZone, shapeFileZoneNameColumn);

return regionLinksMap;
}
Expand All @@ -946,9 +947,10 @@ static Map<String, Map<Id<Link>, Link>> filterLinksForZones(Scenario scenario, I
*/
private static void findNearestLinkForZonesWithoutLinks(Network networkToChange, Map<String, Map<Id<Link>, Link>> regionLinksMap,
Index shpZones,
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone) {
Map<String, Map<String, List<SimpleFeature>>> buildingsPerZone,
String shapeFileZoneNameColumn) {
for (SimpleFeature singleArea : shpZones.getAllFeatures()) {
String zoneID = (String) singleArea.getAttribute("areaID");
String zoneID = (String) singleArea.getAttribute(shapeFileZoneNameColumn);
if (!regionLinksMap.containsKey(zoneID) && buildingsPerZone.get(zoneID) != null) {
for (List<SimpleFeature> buildingList : buildingsPerZone.get(zoneID).values()) {
for (SimpleFeature building : buildingList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void findZoneOfLinksTest() throws IOException, URISyntaxException {
Map<String, Map<Id<Link>, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand
.filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(),
shapeFileZoneNameColumn),
buildingsPerZone);
buildingsPerZone, shapeFileZoneNameColumn);

Assertions.assertEquals(3, regionLinksMap.size(), MatsimTestUtils.EPSILON);
Assertions.assertEquals(60, regionLinksMap.get("area1").size(), MatsimTestUtils.EPSILON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void testAddingExistingScenarios() throws Exception {
Map<String, Map<Id<Link>, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand
.filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(),
shapeFileZoneNameColumn),
buildingsPerZone);
buildingsPerZone, shapeFileZoneNameColumn);

SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);

Expand Down Expand Up @@ -469,7 +469,7 @@ void testAddingExistingScenariosWithSample() throws Exception {
Map<String, Map<Id<Link>, Link>> regionLinksMap = GenerateSmallScaleCommercialTrafficDemand
.filterLinksForZones(scenario, SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, config.global().getCoordinateSystem(),
shapeFileZoneNameColumn),
buildingsPerZone);
buildingsPerZone, shapeFileZoneNameColumn);

SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);

Expand Down Expand Up @@ -541,7 +541,7 @@ void testReducingDemandAfterAddingExistingScenarios_goods() throws Exception {
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);

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

SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);

Expand Down Expand Up @@ -701,7 +701,7 @@ void testReducingDemandAfterAddingExistingScenarios_commercialPersonTraffic() th
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, usedTrafficType);

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

SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);

Expand Down
Loading