Skip to content

Commit

Permalink
Avoid emission calculation for 0 vehicles (#307)
Browse files Browse the repository at this point in the history
Not much point in doing interpolation if the result will just be multiplied with 0 anyway.
  • Loading branch information
BertScholten authored Dec 13, 2024
1 parent e841660 commit dace42d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ protected Map<Substance, BigDecimal> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dace42d

Please sign in to comment.