Skip to content

Commit 93b4961

Browse files
nkuehnelrakowfrievoe97jfbischoffdependabot[bot]
authored
Update MATSim CW33 (#109)
* make drt shifts multi mode drt comatible * adjust shift efficiency tracker as well * Extended Trip analysis and dashboard (matsim-org#3332) * trip analysis for subgroups * refactor categories * write trip analysis * write out correct table * use static method * prepare for facets, add TODOs * start working on plotly facet integration * Added Test Trip Dashboard for Facets * update API * add trip choice analysis * adding test case and some todos * calculating some trip choice metrics * add choice metrics to trip dashboard * hide tab if not needed * add text box and round metrics * normalize shares per reference group correctly, added some facet dashboards (WIP) * fix pivot usage * rename entries * add plots for distance distributions * add todo * use dropdown for plots * add cohen kappa to evaluation * output euclidean distance for trip choices * add ref_id attribute * added heatmap to TripDashboard * update description * allow arbitrary object for ref ids * show heatmap labels * comment out trip dashboard wip part * use correct logger * improve wording --------- Co-authored-by: frievoe97 <[email protected]> * Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.5 to 3.3.0 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.3.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.2.5...surefire-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump org.apache.maven.plugins:maven-surefire-report-plugin Bumps [org.apache.maven.plugins:maven-surefire-report-plugin](https://github.com/apache/maven-surefire) from 3.2.5 to 3.3.0. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.2.5...surefire-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-report-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump org.apache.maven.plugins:maven-jar-plugin from 3.4.1 to 3.4.2 Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.4.1 to 3.4.2. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](apache/maven-jar-plugin@maven-jar-plugin-3.4.1...maven-jar-plugin-3.4.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jar-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Bump com.fasterxml.woodstox:woodstox-core from 6.6.2 to 7.0.0 Bumps [com.fasterxml.woodstox:woodstox-core](https://github.com/FasterXML/woodstox) from 6.6.2 to 7.0.0. - [Commits](FasterXML/woodstox@woodstox-core-6.6.2...woodstox-core-7.0.0) --- updated-dependencies: - dependency-name: com.fasterxml.woodstox:woodstox-core dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump org.jfree:jfreechart from 1.5.4 to 1.5.5 Bumps [org.jfree:jfreechart](https://github.com/jfree/jfreechart) from 1.5.4 to 1.5.5. - [Release notes](https://github.com/jfree/jfreechart/releases) - [Commits](jfree/jfreechart@v1.5.4...v1.5.5) --- updated-dependencies: - dependency-name: org.jfree:jfreechart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * make drt work with only custom constraints sets * add some logging to NetworkChangeEventsWriter * correct logging statement * add router binding for complex request unscheduling * use time as disutility * Bump junit.version from 5.10.2 to 5.10.3 Bumps `junit.version` from 5.10.2 to 5.10.3. Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](junit-team/junit5@r5.10.2...r5.10.3) Updates `org.junit.jupiter:junit-jupiter` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](junit-team/junit5@r5.10.2...r5.10.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.junit.jupiter:junit-jupiter dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * * repair wrong positioning of vehicles if linkSpeedCalculator returns speed larger than free speed * replace some (but not all) link.getAttributes()... by BicycleUtils.set/getXyz( link, ...) * bind BicycleConfigGroup explicitly in BicycleModule so that not materializing it before does not lead to a non-interpretable error message (stating that Scenario is not bound about 20 times although that is not the root of the problem) * possibly one or the other additional things * norm subgroups to 1 (matsim-org#3346) * add tests for mode restriction * add test integration test case for complex unscheduler * Bump io.grpc:grpc-all from 1.64.0 to 1.65.0 Bumps [io.grpc:grpc-all](https://github.com/grpc/grpc-java) from 1.64.0 to 1.65.0. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](grpc/grpc-java@v1.64.0...v1.65.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-all dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * add tests that depict the current behaviour * Bump com.google.protobuf:protobuf-java from 4.27.1 to 4.27.2 Bumps [com.google.protobuf:protobuf-java](https://github.com/protocolbuffers/protobuf) from 4.27.1 to 4.27.2. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl) - [Commits](https://github.com/protocolbuffers/protobuf/commits) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * implement multiple mode test * Split CalculateSkimMatrices.prepareAndCalculateNetworkMatrices() to allow for custom travel times objects * implement option for network inconsistency check; no test adaptation so far * Bump org.checkerframework:checker-qual from 3.44.0 to 3.45.0 Bumps [org.checkerframework:checker-qual](https://github.com/typetools/checker-framework) from 3.44.0 to 3.45.0. - [Release notes](https://github.com/typetools/checker-framework/releases) - [Changelog](https://github.com/typetools/checker-framework/blob/master/docs/CHANGELOG.md) - [Commits](typetools/checker-framework@checker-framework-3.44.0...checker-framework-3.45.0) --- updated-dependencies: - dependency-name: org.checkerframework:checker-qual dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * implemented network changer * implement functionality in Util classes and moved config * implement test using the new functionality for mode restriction * revert changing the default access egress type * Switch to DrtWithExtensionsConfigGroup * Bump org.apache.poi:poi-ooxml from 5.2.5 to 5.3.0 Bumps org.apache.poi:poi-ooxml from 5.2.5 to 5.3.0. --- updated-dependencies: - dependency-name: org.apache.poi:poi-ooxml dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * explicitly set access egress type * fix test failures in contribs * fix test failures in contribs and add config parameter so relevant functions * reworked CreatePseudoNetwork with loop-links to avoid duplicating stops * repair test failures * Trip facet dashboard (matsim-org#3350) * implement dropdown facets on the trip dashboard * implement dropdown facets on the trip dashboard * added backgroundColor attribute and restyled text seperators * set backgroundcolor on all plots --------- Co-authored-by: rakow <[email protected]> * adjust rounding * exclude case * Drt dashboard typo fix (matsim-org#3360) * added tooltip for gridmap/emissionsDashboard * fix typo in drt dashboard --------- Co-authored-by: rakow <[email protected]> * Bump com.fasterxml.jackson:jackson-bom from 2.17.1 to 2.17.2 Bumps [com.fasterxml.jackson:jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.17.1 to 2.17.2. - [Commits](FasterXML/jackson-bom@jackson-bom-2.17.1...jackson-bom-2.17.2) --- updated-dependencies: - dependency-name: com.fasterxml.jackson:jackson-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Bump net.bytebuddy:byte-buddy from 1.14.17 to 1.14.18 Bumps [net.bytebuddy:byte-buddy](https://github.com/raphw/byte-buddy) from 1.14.17 to 1.14.18. - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](raphw/byte-buddy@byte-buddy-1.14.17...byte-buddy-1.14.18) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * set networkMode based on vehicleTypes * pass lambda function as parameter * Bump org.assertj:assertj-core from 3.26.0 to 3.26.3 Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.26.0 to 3.26.3. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](assertj/assertj@assertj-build-3.26.0...assertj-build-3.26.3) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * chore: clean up MinimalTransferTimes (matsim-org#3365) * chore: cleanup adaptive transfers (matsim-org#3366) * chore: cleanup adaptvie transfers * make final * Bump org.apache.maven.plugins:maven-failsafe-plugin from 3.3.0 to 3.3.1 Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.3.0...surefire-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * add missing case of enum * add functionality to split jobs * use new methods * update activity creation * set activity time correctly * remove unneeded exception * change to parameterized log message * delete empty test methods * remove unused import * fix unchecked assignment * remove redundant local variables * minor code style update * remove not needed throw information * make things final * remove redundant final declaration * remove unnecessary 'throws' declarations * simplify assertions * cleanup Strings * remove redundant casts * code style update * cleanup imports * Java language: Replace explicit type with <> * Java language: use computeIfAbsent * Java language: use Double.hashCode(...) * Java language: replace if by switch * Java language: avoid raw use * Java language: use text block * Java language: use pattern variable * Java language: use add/getFirst() * Access to TestUtils.EPSILION * add not null assertion * remove one layer of "LSPs" * add prebooking support for drt shifts some minor shift cleanups possibility to assign requests to shifts that are assigned bot not started yet * cancel assigned shifts * Bump com.google.errorprone:error_prone_annotations from 2.28.0 to 2.29.2 Bumps [com.google.errorprone:error_prone_annotations](https://github.com/google/error-prone) from 2.28.0 to 2.29.2. - [Release notes](https://github.com/google/error-prone/releases) - [Commits](google/error-prone@v2.28.0...v2.29.2) --- updated-dependencies: - dependency-name: com.google.errorprone:error_prone_annotations dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * add some documentation * shift drt maintenance * some more drt shift maintenance * consider break corridors for (pre)bookings * consider break corridors for (pre)bookings * clean up obsolete method * update FISS test, reduce iterations to reduce runtime * avoid abandoning prebooked requests twice in the same time step * fix tests by disabling net consistency check * adapt error messages * remove redundant suppression * remove unused field * internal renaming * remove unnecessary toString() calls * remove unnecessary semicolon * inline and remove method * cleanup imports * simplification * make final, internal renaming * replace 'if' by 'switch' * simplification * use enhanced 'switch' * simplification * use 'getFirst()' * javadoc: replace blank lines with '<p>' * javadoc: set link as a link * logging: use parameterized logging * add casting * simplification * use 'append()' calls * simplification by removing inaccessibly parts of if statements. * remove duplicated setting of variable * Simplify assertions * Simplify stream * avoid casting * suppress warning * fix some (language) grammar * fix some typos * more simplifications * cleanup: remove commented out code * small cleanups * fix test failures by disable net consistency check * optimize h3 zone system initialization; move h3 test to common module * shift drt maintenance; fix bug for prebooked e-drt scenarios that need shifts to be assignable to requests in advance; change priority queues in shift dispatcher to sorted sets to ensure correct iteration order * make FISS integration test less sensible to smaller changes in link events * set level of some logging's back from WARN to DEBUG * SimWrapper Dashboard features (matsim-org#3381) * add explanations to the traffic dashboard, add pt viewer dashboard * add additional description * add avg beeline speed to trip dashboard * added mode share distance distribution * added plot for detailed distance distribution * upscale emission dashboard with sample size * Update GenerateFreightPlans.java (matsim-org#3387) Fixing one typo in "GenerateFreightPlans.java" and some minor updates in the input sample size interpretation and output naming. No changes in the functionality. * add events files comparison * more (javadoc) comments * add test which includes tolling. One test is failing, because it is not possible to create different schemes for the different types. * WIP: Prepare test for tolling with factor. Not implemented to the end now -> Disabled. * replace self-build RoadPricingCalculator with official RoadPricingScheme * adapt test: use tollFactor * add option if person==null * more tests * more steps forward * fix one test: Use MATSim's vehicles * fix the last test: Building the netbased costs without MATSim's vehicle types * some cleanup and javadoc * fix typos, internal renaming * Bump org.apache.maven.plugins:maven-surefire-report-plugin Bumps [org.apache.maven.plugins:maven-surefire-report-plugin](https://github.com/apache/maven-surefire) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.3.0...surefire-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-report-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Bump io.grpc:grpc-all from 1.65.0 to 1.65.1 Bumps [io.grpc:grpc-all](https://github.com/grpc/grpc-java) from 1.65.0 to 1.65.1. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](grpc/grpc-java@v1.65.0...v1.65.1) --- updated-dependencies: - dependency-name: io.grpc:grpc-all dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Bump org.apache.maven.plugins:maven-surefire-plugin from 3.3.0 to 3.3.1 Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.3.0...surefire-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Bump commons-codec:commons-codec from 1.17.0 to 1.17.1 Bumps [commons-codec:commons-codec](https://github.com/apache/commons-codec) from 1.17.0 to 1.17.1. - [Changelog](https://github.com/apache/commons-codec/blob/master/RELEASE-NOTES.txt) - [Commits](apache/commons-codec@rel/commons-codec-1.17.0...rel/commons-codec-1.17.1) --- updated-dependencies: - dependency-name: commons-codec:commons-codec dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Preserve the working directory when gui is run from cli (matsim-org#3391) * use asterisk for act type default * NoiseAnalysis: set the scale factor for according to sample size * add fare zone based pt pricing (matsim-org#3382) * first try to implement fare zone based pt pricing, deutschlandtarif numbers still missing * put deutschlandtarif price linear functions into code * unit test for FareZoneBasedPtFareHandler * better defaults for NoiseDashboard * remove the static * NoiseAnalysis: more explicit parameter settings + bug fix in MergeNoiseOutput * Update DRT estimate and teleport module (matsim-org#3333) Re-organizing the DRT estimation scripts. For more details, please see detailed description above. * NoiseAnalysis: merge damages files * NoiseDashboard: include stats and damage plots * only perform net consistency check once * CreateSingleSimWrapperDashboard * fix noise tests: explicitly set activity types for rp grid, when setting act type for damage calculation * fix nasty insertion scheduler bug --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: rakow <[email protected]> Co-authored-by: frievoe97 <[email protected]> Co-authored-by: Joschka Bischoff <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: kainagel <[email protected]> Co-authored-by: Kai Nagel <[email protected]> Co-authored-by: Paul Heinrich <[email protected]> Co-authored-by: Michal Maciejewski <[email protected]> Co-authored-by: marecabo <[email protected]> Co-authored-by: steffenaxer <[email protected]> Co-authored-by: u229351 <[email protected]> Co-authored-by: frievoe97 <[email protected]> Co-authored-by: Ricardo Ewert <[email protected]> Co-authored-by: Ricardo Ewert <[email protected]> Co-authored-by: Paul Heinrich <[email protected]> Co-authored-by: Sebastian Hörl <[email protected]> Co-authored-by: Kai Martins-Turner <[email protected]> Co-authored-by: Kai Martins-Turner <[email protected]> Co-authored-by: tschlenther <[email protected]> Co-authored-by: Chengqi Lu <[email protected]> Co-authored-by: simei94 <[email protected]>
1 parent edb9f45 commit 93b4961

File tree

164 files changed

+3326
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+3326
-604
lines changed

contribs/application/src/main/java/org/matsim/application/MATSimApplication.java

+43-12
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ public Integer call() throws Exception {
153153

154154
// load config if not present yet.
155155
if (config == null) {
156-
config = loadConfig(Objects.requireNonNull( configPath, "No default scenario location given" ).getAbsoluteFile().toString() );
156+
String path = Objects.requireNonNull( configPath, "No default scenario location given" ).getAbsoluteFile().toString();
157+
List<ConfigGroup> customModules = getCustomModules();
158+
159+
final Config config1 = ConfigUtils.loadConfig(path, customModules.toArray(new ConfigGroup[0] ) );
160+
Config prepared = prepareConfig( config1 );
161+
162+
config = prepared != null ? prepared : config1;
163+
// (The above lines of code come from inlining so maybe it happened there: I cannot see how prepared could be null but config1 not except if user code returns null which I would consider a bug. kai, aug'24)
157164
} else {
158165
Config tmp = prepareConfig(config);
159166
config = tmp != null ? tmp : config;
@@ -306,15 +313,6 @@ protected final void addRunOption(Config config, String option) {
306313
addRunOption(config, option, "");
307314
}
308315

309-
private Config loadConfig(String path) {
310-
List<ConfigGroup> customModules = getCustomModules();
311-
312-
final Config config = ConfigUtils.loadConfig(path, customModules.toArray(new ConfigGroup[0]));
313-
Config prepared = prepareConfig(config);
314-
315-
return prepared != null ? prepared : config;
316-
}
317-
318316
@Override
319317
public String defaultValue(CommandLine.Model.ArgSpec argSpec) throws Exception {
320318
Object obj = argSpec.userObject();
@@ -374,8 +372,39 @@ public static void run(Class<? extends MATSimApplication> clazz, String... args)
374372
}
375373

376374
/**
377-
* Convenience method to run a scenario from code or automatically with gui when desktop application is detected.
378-
* This method may also be used to predefine some default arguments.
375+
* <p>Convenience method to run a scenario from code or automatically with gui when desktop application is detected.
376+
* This method may also be used to predefine some default arguments.</p>
377+
*
378+
* <p>With respect to args it looks like arguments are treated in the following sequence (programmed in the run method):
379+
* <ul>
380+
* <li>ConfigUtils.loadConfig without args</li>
381+
* <li>prepareConfig which is usually overwritten</li>
382+
* <li>config options from some yaml file which can be provided as a command line option</li>
383+
* <li>config options on command line </li>
384+
* </ul></p>
385+
*
386+
* <p>defaultArgs could be used to provide defaults when calling this method here; they would go in addition to what is coming in from "upstream" which is typically the command line.</p>
387+
*
388+
* <p>There are many execution paths that can be reached from this class, but a typical one for matsim-scenarios seems to be:<ul>
389+
* <li> This method runs MATSimApplication.run( TheScenarioClass.class , args ).</li>
390+
* <li> That run class will instantiate an instance of TheScenarioClass (*), then do some args consistenty checking, then call the piccoli execute method. </li>
391+
* <li> The piccoli execute method will essentially call the "call" method of MATSimApplication. </li>
392+
* <li> I think that in the described execution path, this.config in that call method will initially be null. (The ctor of MATSimApplication was called via reflection at (*); I think that it was called there without a config argument.) </li>
393+
* <li> This call method then will do: <ul>
394+
* <li> getCustomModules() (which is empty by default but can be overriden) </li>
395+
* <li>ConfigUtils.loadConfig(...) _without_ passing on the args</li>
396+
* <li>prepareConfig(...) (which is empty by default but is typically overridden, in this case in OpenBerlinScenario). In our case, this sets the typical scoring params and the typical replanning strategies.
397+
* <li>next one can override the config from some yaml file provided as a commandline option
398+
* <li> next args is parsed and set
399+
* <li>then some standard CL options are detected and set
400+
* <li>then createScenario(config) is called (which can be overwritten but is not)
401+
* <li>then prepareScenario(scenario) is called (which can be overwritten but is not)
402+
* <li>then a standard controler is created from scenario
403+
* <li>then prepareControler is called which can be overwritten
404+
* </ul>
405+
* </ul>
406+
* </p>
407+
*
379408
* @param clazz class of the scenario to run
380409
* @param args pass arguments from the main method
381410
* @param defaultArgs predefined default arguments that will always be present
@@ -384,6 +413,8 @@ public static void runWithDefaults(Class<? extends MATSimApplication> clazz, Str
384413

385414
if (ApplicationUtils.isRunFromDesktop() && args.length == 0) {
386415

416+
System.setProperty("MATSIM_GUI_DESKTOP", "true");
417+
387418
if (defaultArgs.length > 0) {
388419
String value = String.join(ARGS_DELIMITER, defaultArgs);
389420
System.setProperty("MATSIM_GUI_ARGS", value);

contribs/application/src/main/java/org/matsim/application/ShowGUI.java

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public Integer call() throws Exception {
4040

4141
Gui gui = f.get();
4242

43+
// Set the current working directory to be used in the gui, when run from the command line
44+
// If the gui is run from desktop, the working directory is not overwritten
45+
46+
// Assumption is that starting something from command line, the user expects that the working directory remains the same
47+
if (!System.getProperty("MATSIM_GUI_DESKTOP", "false").equals("true"))
48+
gui.setWorkingDirectory(new File(""));
49+
4350
while (gui.isShowing())
4451
Thread.sleep(250);
4552

contribs/application/src/main/java/org/matsim/application/analysis/noise/MergeNoiseOutput.java

+52-45
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
import org.apache.avro.file.DataFileWriter;
1414
import org.apache.avro.io.DatumWriter;
1515
import org.apache.avro.specific.SpecificDatumWriter;
16+
import org.apache.commons.lang.StringUtils;
1617
import org.apache.logging.log4j.LogManager;
1718
import org.apache.logging.log4j.Logger;
1819
import org.matsim.api.core.v01.Coord;
1920
import org.matsim.application.avro.XYTData;
21+
import org.matsim.core.config.Config;
2022
import org.matsim.core.utils.io.IOUtils;
23+
import org.matsim.core.utils.misc.Time;
2124
import tech.tablesaw.api.*;
2225
import tech.tablesaw.io.csv.CsvReadOptions;
2326

@@ -29,7 +32,8 @@
2932
import java.nio.file.Files;
3033
import java.nio.file.Path;
3134
import java.util.*;
32-
import java.util.stream.Collectors;
35+
36+
import static org.geotools.gml3.v3_2.GML.coordinateSystem;
3337

3438
/**
3539
* Merges noise data from multiple files into one file.
@@ -44,17 +48,16 @@ final class MergeNoiseOutput {
4448
*/
4549
private static final boolean CREATE_CSV_FILES = false;
4650

47-
private final String[] inputPath;
4851
private final Path outputDirectory;
4952
private final String crs;
50-
private final String[] labels = {"immission", "emission"};
5153
private final int minTime = 3600;
5254
private int maxTime = 24 * 3600;
5355

54-
MergeNoiseOutput(String[] inputPath, Path outputDirectory, String crs) {
55-
this.inputPath = inputPath;
56-
this.outputDirectory = outputDirectory;
57-
this.crs = crs;
56+
private final Map<String,Float> totalReceiverPointValues = new HashMap<>();
57+
58+
MergeNoiseOutput(Path path, String coordinateSystem ) {
59+
this.outputDirectory = path;
60+
this.crs = coordinateSystem;
5861
}
5962

6063
/**
@@ -90,25 +93,9 @@ public void setMaxTime(int maxTime) {
9093
* Merges noise data from multiple files into one file.
9194
*/
9295
public void run() {
93-
94-
// Loop over all paths
95-
for (int i = 0; i < labels.length; i++) {
96-
97-
// Select the correct method based on the label
98-
switch (labels[i]) {
99-
case "immission" -> {
100-
if (CREATE_CSV_FILES) {
101-
mergeImmissionsCSV(inputPath[i], labels[i]);
102-
} else {
103-
mergeImissions(inputPath[i], labels[i]);
104-
}
105-
106-
}
107-
case "emission" -> mergeEmissions(inputPath[i], labels[i]);
108-
default -> log.warn("Unknown path: " + inputPath[i]);
109-
}
110-
111-
}
96+
mergeReceiverPointData(outputDirectory + "/immissions/", "immission");
97+
mergeReceiverPointData(outputDirectory + "/damages_receiverPoint/", "damages_receiverPoint");
98+
mergeLinkData(outputDirectory.toString() + "/emissions/", "emission");
11299
}
113100

114101
/**
@@ -118,6 +105,7 @@ public void run() {
118105
* @param output
119106
*/
120107
private void writeAvro(XYTData xytData, File output) {
108+
log.info(String.format("Start writing avro file to %s", output.toString() ));
121109
DatumWriter<XYTData> datumWriter = new SpecificDatumWriter<>(XYTData.class);
122110
try (DataFileWriter<XYTData> dataFileWriter = new DataFileWriter<>(datumWriter)) {
123111
dataFileWriter.setCodec(CodecFactory.deflateCodec(9));
@@ -128,7 +116,7 @@ private void writeAvro(XYTData xytData, File output) {
128116
}
129117
}
130118

131-
private void mergeEmissions(String pathParameter, String label) {
119+
private void mergeLinkData(String pathParameter, String label) {
132120
log.info("Merging emissions data for label {}", label);
133121
Object2DoubleMap<String> mergedData = new Object2DoubleOpenHashMap<>();
134122
Table csvOutputMerged = Table.create(TextColumn.create("Link Id"), DoubleColumn.create("value"));
@@ -143,9 +131,8 @@ private void mergeEmissions(String pathParameter, String label) {
143131
.separator(';').build());
144132

145133
for (Row row : table) {
146-
// index for Noise Emission xx:xx:xx -> 7
147134
String linkId = row.getString("Link Id");
148-
double value = row.getDouble(7);
135+
double value = row.getDouble(row.columnCount() - 1);
149136
mergedData.mergeDouble(linkId, value, Double::max);
150137

151138
}
@@ -165,38 +152,49 @@ private void mergeEmissions(String pathParameter, String label) {
165152
}
166153

167154
/**
168-
* Merges the immissions data
155+
* Merges receiverPoint data (written by {@link org.matsim.contrib.noise.NoiseWriter}
169156
*
170-
* @param pathParameter path to the immissions data
171-
* @param label label for the immissions data
157+
* @param outputDir path to the receiverPoint data
158+
* @param label label for the receiverPoint data (which kind of data)
172159
*/
173-
private void mergeImissions(String pathParameter, String label) {
160+
private void mergeReceiverPointData(String outputDir, String label) {
174161

175162
// data per time step, maps coord to value
176163
Int2ObjectMap<Object2FloatMap<FloatFloatPair>> data = new Int2ObjectOpenHashMap<>();
177164

178165
// Loop over all files
166+
//TODO could be adjusted to time bin size from noise config group
167+
String substrToCapitalize = null;
179168
for (int time = minTime; time <= maxTime; time += 3600) {
180169

181-
String path = pathParameter + label + "_" + round(time, 1) + ".csv";
170+
String timeDataFile = outputDir + label + "_" + round(time, 1) + ".csv";
171+
182172
Object2FloatOpenHashMap<FloatFloatPair> values = new Object2FloatOpenHashMap<>();
183173

184-
if (!Files.exists(Path.of(path))) {
185-
log.warn("File {} does not exist", path);
174+
if (!Files.exists(Path.of(timeDataFile))) {
175+
log.warn("File {} does not exist", timeDataFile);
186176
continue;
187177
}
188178

189-
// Read the file
190-
Table table = Table.read().csv(CsvReadOptions.builder(IOUtils.getBufferedReader(path))
191-
.columnTypesPartial(Map.of("x", ColumnType.FLOAT, "y", ColumnType.FLOAT, "Receiver Point Id", ColumnType.INTEGER, "t", ColumnType.DOUBLE))
179+
//we need "damages_receiverPoint" -> "Damages 01:00:00" and "immission" -> "Immision 01:00:00"
180+
substrToCapitalize = label.contains("_") ? label.substring(0, label.lastIndexOf("_")) : label;
181+
String valueHeader = StringUtils.capitalize(substrToCapitalize) + " " + Time.writeTime(time, Time.TIMEFORMAT_HHMMSS);
182+
183+
// Read the data file
184+
Table dataTable = Table.read().csv(CsvReadOptions.builder(IOUtils.getBufferedReader(timeDataFile))
185+
.columnTypesPartial(Map.of("x", ColumnType.FLOAT,
186+
"y", ColumnType.FLOAT,
187+
"Receiver Point Id", ColumnType.INTEGER,
188+
"t", ColumnType.DOUBLE,
189+
valueHeader, ColumnType.DOUBLE))
192190
.sample(false)
193191
.separator(';').build());
194192

195-
// Loop over all rows in the file
196-
for (Row row : table) {
193+
// Loop over all rows in the data file
194+
for (Row row : dataTable) {
197195
float x = row.getFloat("x");
198196
float y = row.getFloat("y");
199-
float value = (float) row.getDouble(1); // 1
197+
float value = (float) row.getDouble(valueHeader);
200198
FloatFloatPair coord = FloatFloatPair.of(x, y);
201199
values.put(coord, value);
202200
}
@@ -232,7 +230,7 @@ private void mergeImissions(String pathParameter, String label) {
232230
}
233231
}
234232

235-
xytHourData.setData(Map.of("imissions", raw));
233+
xytHourData.setData(Map.of(label, raw));
236234
xytHourData.setCrs(crs);
237235

238236
File out = outputDirectory.getParent().resolve(label + "_per_hour.avro").toFile();
@@ -254,15 +252,18 @@ private void mergeImissions(String pathParameter, String label) {
254252
xytDayData.setTimestamps(List.of(0));
255253
xytDayData.setXCoords(xCoords);
256254
xytDayData.setYCoords(yCoords);
257-
xytDayData.setData(Map.of("imissions", raw));
255+
xytDayData.setData(Map.of(label, raw));
258256
xytDayData.setCrs(crs);
259257

260258
File outDay = outputDirectory.getParent().resolve(label + "_per_day.avro").toFile();
261259

262260
writeAvro(xytDayData, outDay);
261+
//cache the overall sum
262+
this.totalReceiverPointValues.put(substrToCapitalize, raw.stream().reduce(0f, Float::sum));
263263
}
264264

265265
// Merges the immissions data
266+
266267
@Deprecated
267268
private void mergeImmissionsCSV(String pathParameter, String label) {
268269
log.info("Merging immissions data for label {}", label);
@@ -278,7 +279,10 @@ private void mergeImmissionsCSV(String pathParameter, String label) {
278279

279280
// Read the file
280281
Table table = Table.read().csv(CsvReadOptions.builder(IOUtils.getBufferedReader(path))
281-
.columnTypesPartial(Map.of("x", ColumnType.DOUBLE, "y", ColumnType.DOUBLE, "Receiver Point Id", ColumnType.INTEGER, "t", ColumnType.DOUBLE))
282+
.columnTypesPartial(Map.of("x", ColumnType.DOUBLE,
283+
"y", ColumnType.DOUBLE,
284+
"Receiver Point Id", ColumnType.INTEGER,
285+
"t", ColumnType.DOUBLE))
282286
.sample(false)
283287
.separator(';').build());
284288

@@ -319,4 +323,7 @@ private void mergeImmissionsCSV(String pathParameter, String label) {
319323
log.info("Merged noise data written to {} ", outPerDay);
320324

321325
}
326+
public Map<String, Float> getTotalReceiverPointValues() {
327+
return totalReceiverPointValues;
328+
}
322329
}

0 commit comments

Comments
 (0)