Skip to content

Commit

Permalink
use configurable parameter for zone name column (#3192)
Browse files Browse the repository at this point in the history
* use configurable parameter for zone name column

* make methods static again
  • Loading branch information
rewertvsp authored Mar 28, 2024
1 parent e8580db commit b243edc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
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

0 comments on commit b243edc

Please sign in to comment.