diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java index 6815899be8a..48eb2951430 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/Grid.java @@ -268,19 +268,32 @@ private void setActivityCoord2NearestReceiverPointId () { counter.printCounter(); counter = new Counter("compute nearest receiver-points #"); + Counter otherCounter = new Counter("activities outside grid #"); for (Coord coord : consideredActivityCoordsForSpatialFunctionality) { // TODO maybe add a check here so we consider only the rp in the 9 surrounding cells? - ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); - if(rp != null) { - if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ - log.warn("this must not happen"); + // ts, nov' 24: ---> might be done by the following filtering (by grid) ?? + + // Filter activity coords that are within the quadTree. + // I do not know, why whe put a buffer around the grid when instantiating the QuadTree, above, but I'll keep it for now + // tschlenther, nov '24 + if (coord.getX() >= xCoordMin && coord.getX() <= xCoordMax && + coord.getY() >= yCoordMin && coord.getY() <= yCoordMax){ + + ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); + if(rp != null) { + if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ + log.warn("this must not happen"); + } } - } - counter.incCounter(); + counter.incCounter(); + } else { + otherCounter.incCounter(); + } } counter.printCounter(); + otherCounter.printCounter(); } private void readReceiverPoints(String file, CoordinateTransformation ct) throws IOException { diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java index d941615320a..bad61d3696c 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseContextImpl.java @@ -201,9 +201,9 @@ private void checkConsistency() { || this.grid.getGridParams().getReceiverPointsGridMinX() != 0. || this.grid.getGridParams().getReceiverPointsGridMaxY() != 0. || this.grid.getGridParams().getReceiverPointsGridMinY() != 0.) { - log.warn("In order to keep track of the agent activities, the grid of receiver points should not be limited to a set of predefined coordinates." + log.warn("In order to keep track of ALL the agent activities, the grid of receiver points should not be limited to a set of predefined coordinates." + "For a grid covering all activity locations, set the minimum and maximum x/y parameters to 0.0. " - + "There will be more agents mapped to the receiver points at the edges. Only the inner receiver points should be used for analysis."); + + "Damages will be computed only for activities that are performed within the receiver point grid."); } if (this.grid.getGridParams().getReceiverPointsGridMinX() == 0. && this.grid.getGridParams().getReceiverPointsGridMinY() == 0. && this.grid.getGridParams().getReceiverPointsGridMaxX() == 0. && this.grid.getGridParams().getReceiverPointsGridMaxY() == 0.) { diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java index a4ce705e001..178bfa9109f 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/NoiseDashboardTests.java @@ -1,5 +1,6 @@ package org.matsim.simwrapper.dashboard; +import com.opencsv.CSVReader; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -15,6 +16,7 @@ import org.matsim.testcases.MatsimTestUtils; +import java.io.FileReader; import java.net.URL; import java.nio.file.Path; @@ -51,6 +53,19 @@ void generate() { .isDirectoryContaining("glob:**damages_receiverPoint_per_day.avro") .isDirectoryContaining("glob:**noise_stats.csv"); - //TODO check content / values of the files + double totalDamages; + double totalImmissions; + try { + CSVReader reader = new CSVReader(new FileReader(utils.getOutputDirectory() + "analysis/noise/noise_stats.csv")); + reader.skip(1); + totalDamages = Double.parseDouble(reader.readNext()[1]); + totalImmissions = Double.parseDouble(reader.readNext()[1]); + } catch (Exception e) { + throw new RuntimeException(e); + } + + Assertions.assertThat(totalDamages == 3573114.25); + Assertions.assertThat( totalImmissions == 2.688); + } }