From dace42d723b2842464f69474f68d94d8868ec5b8 Mon Sep 17 00:00:00 2001 From: Bert Scholten Date: Fri, 13 Dec 2024 15:20:50 +0100 Subject: [PATCH] Avoid emission calculation for 0 vehicles (#307) Not much point in doing interpolation if the result will just be multiplied with 0 anyway. --- .../aerius/shared/emissions/ADMSRoadEmissionsCalculator.java | 4 +++- .../shared/emissions/ADMSRoadEmissionsCalculatorTest.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculator.java b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculator.java index fe25c2bc..90b5f068 100644 --- a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculator.java +++ b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculator.java @@ -84,7 +84,9 @@ protected Map calculateEmissions(final StandardVehicles s final TrafficDirection direction = roadEmissionSource.getTrafficDirection(); // ADMSRoad does not use stagnation (this is incorporated into the speed used). // However, the gradient depends on the direction - if (direction == TrafficDirection.A_TO_B) { + if (BigDecimal.ZERO.compareTo(numberOfVehiclesPerDay) == 0) { + results = new EnumMap<>(Substance.class); + } else if (direction == TrafficDirection.A_TO_B) { // If A to B, all vehicles go that way, calculate appropriately results = calculateAtoBEmissions(standardVehicles, standardVehicleCode, numberOfVehiclesPerDay, roadEmissionSource); } else if (direction == TrafficDirection.B_TO_A) { diff --git a/source/imaer-shared/src/test/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculatorTest.java b/source/imaer-shared/src/test/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculatorTest.java index 91d33912..26072461 100644 --- a/source/imaer-shared/src/test/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculatorTest.java +++ b/source/imaer-shared/src/test/java/nl/overheid/aerius/shared/emissions/ADMSRoadEmissionsCalculatorTest.java @@ -300,6 +300,10 @@ private StandardVehicles createMultipleStandard(final double gradient) { valuesPerVehicleType.setVehiclesPerTimeUnit(2000); final String vehicleType = "HEAVY_FREIGHT"; vehicles.getValuesPerVehicleTypes().put(vehicleType, valuesPerVehicleType); + final ValuesPerVehicleType valuesPerVehicleTypeZeroVehicles = new ValuesPerVehicleType(); + valuesPerVehicleTypeZeroVehicles.setVehiclesPerTimeUnit(0); + final String vehicleTypeZeroVehicles = "TAXI"; + vehicles.getValuesPerVehicleTypes().put(vehicleTypeZeroVehicles, valuesPerVehicleTypeZeroVehicles); final boolean strictEnforcement = vehicles.getStrictEnforcement(); final int maximumSpeed = vehicles.getMaximumSpeed(); final int gradientMatch = (int) gradient;