From dfcee21fc4481eba3d5f61b23c6022cf281c1336 Mon Sep 17 00:00:00 2001 From: schlenther Date: Mon, 11 Nov 2024 16:26:35 +0100 Subject: [PATCH] defaults for networkModesToIgnore + consistency checks/warnings --- .../analysis/noise/NoiseAnalysis.java | 21 +++++------ .../contrib/noise/NoiseConfigGroup.java | 36 +++++++++++++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/noise/NoiseAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/noise/NoiseAnalysis.java index a3f321c7f38..bac5eaadd7c 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/noise/NoiseAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/noise/NoiseAnalysis.java @@ -66,7 +66,7 @@ public class NoiseAnalysis implements MATSimAppCommand { @CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation." + " Use asterisk ('*') for acttype prefixes, if all such acts shall be considered.", defaultValue = "home*,work*,educ*,leisure*") - private Set considerActivities; + private Set consideredActivities; @CommandLine.Option(names = "--noise-barrier", description = "Path to the noise barrier File", defaultValue = "") private String noiseBarrierFile; @@ -86,19 +86,20 @@ public Integer call() throws Exception { boolean overrideParameters = ! ConfigUtils.hasModule(config, NoiseConfigGroup.class); NoiseConfigGroup noiseParameters = ConfigUtils.addOrGetModule(config, NoiseConfigGroup.class); - if(overrideParameters){ + if (overrideParameters){ log.warn("no NoiseConfigGroup was configured before. Will set some standards. You should check the next lines in the log file and the output_config.xml!"); - noiseParameters.setConsideredActivitiesForReceiverPointGridArray(considerActivities.toArray(String[]::new)); - noiseParameters.setConsideredActivitiesForDamageCalculationArray(considerActivities.toArray(String[]::new)); + noiseParameters.setConsideredActivitiesForReceiverPointGridArray(consideredActivities.toArray(String[]::new)); + noiseParameters.setConsideredActivitiesForDamageCalculationArray(consideredActivities.toArray(String[]::new)); { - Set set = CollectionUtils.stringArrayToSet( new String[]{TransportMode.bike, TransportMode.walk, TransportMode.transit_walk, TransportMode.non_network_walk} ); - noiseParameters.setNetworkModesToIgnoreSet( set ); - } - { - String[] set = new String[]{"freight"}; - noiseParameters.setHgvIdPrefixesArray( set ); + //the default settings are now actually the same as what we 'override' here, but let's leave it here for clarity. + Set ignoredNetworkModes = CollectionUtils.stringArrayToSet( new String[]{TransportMode.bike, TransportMode.walk, TransportMode.transit_walk, TransportMode.non_network_walk} ); + noiseParameters.setNetworkModesToIgnoreSet( ignoredNetworkModes ); + + String[] hgvIdPrefixes = {"lkw", "truck", "freight"}; + noiseParameters.setHgvIdPrefixesArray( hgvIdPrefixes ); } + //use actual speed and not freespeed noiseParameters.setUseActualSpeedLevel(true); //use the valid speed range (recommended by IK) diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java index 06e793c85d9..c2c9bc8d039 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java @@ -26,6 +26,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigGroup; @@ -134,9 +135,9 @@ public enum NoiseAllocationApproach { private NoiseAllocationApproach noiseAllocationApproach = NoiseAllocationApproach.AverageCost; private String[] hgvIdPrefixes = {"lkw", "truck", "freight"}; + private Set networkModesToIgnore = CollectionUtils.stringArrayToSet( new String[]{TransportMode.bike, TransportMode.walk, TransportMode.transit_walk, TransportMode.non_network_walk} ); private Set busIdIdentifier = new HashSet<>(); private Set> tunnelLinkIDs = new HashSet<>(); - private Set networkModesToIgnore = new HashSet<>(); private double noiseTollFactor = 1.0; @@ -209,7 +210,7 @@ public Map getComments() { comments.put(USE_DEM, "Set to 'true' if a DEM (digital elevation model) should be used for road gradients. Otherwise set to 'false'."); comments.put(DEM_FILE, "Path to the geoTiff file of the DEM."); - comments.put(NETWORK_MODES_TO_IGNORE, "Specifies the network modes to be excluded from the noise computation, e.g. 'bike'."); + comments.put(NETWORK_MODES_TO_IGNORE, "Specifies the network modes to be excluded from the noise computation. By default, the following modes are excluded: [bike, walk, transit_walk, non_network_walk]."); comments.put(NOISE_COMPUTATION_METHOD, "Specifies the computation method of different guidelines: " + Arrays.toString(NoiseComputationMethod.values())); @@ -313,6 +314,37 @@ private void checkNoiseParametersForConsistency(Config config) { this.considerNoiseBarriers = false; } } + + List walkAndBikeModes = List.of(TransportMode.bike, TransportMode.walk, TransportMode.transit_walk, TransportMode.non_network_walk); + String exclude = "["; + for (String mode : walkAndBikeModes){ + exclude += mode + ","; + } + exclude = exclude.substring(0, exclude.lastIndexOf(',')) + "]"; + String warning = "You should set networkModesToIgnore such that all of the standard walk and bike modes are included!" + + " These are " + exclude + "."; + if (this.networkModesToIgnore.isEmpty() || + ! this.networkModesToIgnore.containsAll(walkAndBikeModes)){ + boolean bikeOrWalkIsNetworkMode = config.routing().getNetworkModes().stream() + .filter(networkMode -> networkModesToIgnore.contains(networkMode)) + .findAny() + .isPresent(); + if (bikeOrWalkIsNetworkMode){ + //TODO: use enum for consistencyCheckLevel and replace all RunTimeExceptions thrown within this class. + throw new RuntimeException(warning + " You configured one of these modes as networkMode in config().routing.getNetworkModes()! This will lead to wrong results!" + + "Make sure ignore all network modes that do not model a car, a heavy-goods-vehicle (HGV) or a transit vehicle to be considered by the noise analysis!!! Will abort now..."); + } else { + log.warn( warning + + " Otherwise, your results will turn wrong as soon as you are routing these modes on the network (which luckily appears not to be the case in your current setup)."); + } + } + + Set defaultHGVIdPrefixes = Set.of("lkw", "truck", "freight"); + + if (! defaultHGVIdPrefixes.stream().allMatch(defaultPrefix -> + Arrays.stream(this.hgvIdPrefixes).anyMatch(prefix -> defaultPrefix.equals(prefix)))){ + log.warn("You are not considering all of [lkw, truck, freight] as HGV prefixes, which you should! Especially when you use scenarios created by VSP!!"); + } } // ########################################################################################################