From d117a41d09ba588ab58c49dc4b259b8c1f91468a Mon Sep 17 00:00:00 2001 From: sime94 Date: Wed, 16 Oct 2024 14:04:35 +0200 Subject: [PATCH 1/3] update to PR3515 --- pom.xml | 2 +- .../java/org/matsim/dashboards/LausitzDashboardProvider.java | 2 +- .../java/org/matsim/dashboards/LausitzSimWrapperRunner.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e7ad193..320a4c4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ - 2025.0-PR3496 + 2025.0-PR3515 diff --git a/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java index 10ed8d8..e4bd385 100644 --- a/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java +++ b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java @@ -25,7 +25,7 @@ public List getDashboards(Config config, SimWrapper simWrapper) { .setAnalysisArgs("--person-filter", "subpopulation=person"); return List.of(trips, - new EmissionsDashboard() + new EmissionsDashboard(config.global().getCoordinateSystem()) // the NoiseAnalysis is not run here because it needs more RAM than the entire simulation, // which leads to VM crashes and prevents other analysis to run. We have to run it separately (e.g. with LausitzSimWrapperRunner) ); diff --git a/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java index d0794b5..bbc186e 100644 --- a/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java +++ b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java @@ -87,7 +87,7 @@ public Integer call() throws Exception { //add dashboards according to command line parameters // if more dashboards are to be added here, we need to check if noise==true before adding noise dashboard here if (noise) { - sw.addDashboard(Dashboard.customize(new NoiseDashboard()).context("noise")); + sw.addDashboard(Dashboard.customize(new NoiseDashboard(config.global().getCoordinateSystem())).context("noise")); } if (trips) { From 9367897e5c6ab9afd22c954de39d1d63950dceb0 Mon Sep 17 00:00:00 2001 From: sime94 Date: Wed, 16 Oct 2024 14:49:43 +0200 Subject: [PATCH 2/3] set ride params via matsim-libs method --- .../java/org/matsim/run/scenarios/LausitzScenario.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/run/scenarios/LausitzScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java index 53f1ba9..6ed0ddb 100644 --- a/src/main/java/org/matsim/run/scenarios/LausitzScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java @@ -22,6 +22,7 @@ import org.matsim.contrib.vsp.pt.fare.PtFareConfigGroup; import org.matsim.contrib.vsp.pt.fare.PtFareModule; import org.matsim.contrib.vsp.scenario.SnzActivities; +import org.matsim.contrib.vsp.scoring.RideScoringParamsFromCarParams; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ReplanningConfigGroup; @@ -135,15 +136,11 @@ public Config prepareConfig(Config config) { scoringConfigGroup.setPathSizeLogitBeta(0.); // set ride scoring params dependent from car params - ScoringConfigGroup.ModeParams rideParams = scoringConfigGroup.getOrCreateModeParams(TransportMode.ride); - ScoringConfigGroup.ModeParams carParams = scoringConfigGroup.getModes().get(TransportMode.car); // 2.0 + 1.0 = alpha + 1 // ride cost = alpha * car cost // ride marg utility of traveling = (alpha + 1) * marg utility travelling car + alpha * beta perf double alpha = 2; - rideParams.setMarginalUtilityOfTraveling((alpha + 1) * carParams.getMarginalUtilityOfTraveling() - alpha * config.scoring().getPerforming_utils_hr()); - rideParams.setDailyMonetaryConstant(0.); - rideParams.setMonetaryDistanceRate(carParams.getMonetaryDistanceRate() * 2); + RideScoringParamsFromCarParams.setRideScoringParamsBasedOnCarParams(scoringConfigGroup, alpha); config.qsim().setUsingTravelTimeCheckInTeleportation(true); config.qsim().setUsePersonIdForMissingVehicleId(false); From 5b46dba9ba5f140031303b7c1364a95376953063 Mon Sep 17 00:00:00 2001 From: sime94 Date: Wed, 16 Oct 2024 16:37:33 +0200 Subject: [PATCH 3/3] add emissions dashboard as option for post procession creation of dashboards --- .../dashboards/LausitzSimWrapperRunner.java | 43 +++++++++++++++++-- .../matsim/run/scenarios/LausitzScenario.java | 23 ++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java index bbc186e..4c0df2b 100644 --- a/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java +++ b/src/main/java/org/matsim/dashboards/LausitzSimWrapperRunner.java @@ -22,16 +22,23 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.matsim.api.core.v01.Scenario; import org.matsim.application.ApplicationUtils; import org.matsim.application.MATSimAppCommand; import org.matsim.application.options.ShpOptions; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.run.prepare.PrepareNetwork; +import org.matsim.run.scenarios.LausitzScenario; import org.matsim.simwrapper.Dashboard; import org.matsim.simwrapper.SimWrapper; import org.matsim.simwrapper.SimWrapperConfigGroup; +import org.matsim.simwrapper.dashboard.EmissionsDashboard; import org.matsim.simwrapper.dashboard.NoiseDashboard; import org.matsim.simwrapper.dashboard.TripDashboard; +import org.matsim.vehicles.MatsimVehicleWriter; import picocli.CommandLine; import java.io.IOException; @@ -57,6 +64,8 @@ public final class LausitzSimWrapperRunner implements MATSimAppCommand { private boolean noise; @CommandLine.Option(names = "--trips", defaultValue = "false", description = "create trips dashboard") private boolean trips; + @CommandLine.Option(names = "--emissions", defaultValue = "false", description = "create emission dashboard") + private boolean emissions; public LausitzSimWrapperRunner(){ @@ -66,15 +75,15 @@ public LausitzSimWrapperRunner(){ @Override public Integer call() throws Exception { - if (!noise && !trips){ + if (!noise && !trips && !emissions){ throw new IllegalArgumentException("you have not configured any dashboard to be created! Please use command line parameters!"); } for (Path runDirectory : inputPaths) { log.info("Running on {}", runDirectory); - Path configPath = ApplicationUtils.matchInput("config.xml", runDirectory); - Config config = ConfigUtils.loadConfig(configPath.toString()); + String configPath = ApplicationUtils.matchInput("config.xml", runDirectory).toString(); + Config config = ConfigUtils.loadConfig(configPath); SimWrapper sw = SimWrapper.create(config); SimWrapperConfigGroup simwrapperCfg = ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class); @@ -99,6 +108,34 @@ public Integer call() throws Exception { .withDistanceDistribution("lausitz_mode_share_distance_distribution.csv")); } + if (emissions) { + sw.addDashboard(Dashboard.customize(new EmissionsDashboard(config.global().getCoordinateSystem())).context("emissions")); + + LausitzScenario.setEmissionsConfigs(config); + ConfigUtils.writeConfig(config, configPath); + + Config dummyConfig = new Config(); + + String networkPath = ApplicationUtils.matchInput("output_network.xml.gz", runDirectory).toString(); + String vehiclesPath = ApplicationUtils.matchInput("output_vehicles.xml.gz", runDirectory).toString(); + String transitVehiclesPath = ApplicationUtils.matchInput("output_transitVehicles.xml.gz", runDirectory).toString(); + + dummyConfig.network().setInputFile(networkPath); + dummyConfig.vehicles().setVehiclesFile(vehiclesPath); + dummyConfig.transit().setVehiclesFile(transitVehiclesPath); + + Scenario scenario = ScenarioUtils.loadScenario(dummyConfig); + +// adapt network and veh types for emissions analysis like in LausitzScenario base run class + PrepareNetwork.prepareEmissionsAttributes(scenario.getNetwork()); + LausitzScenario.prepareVehicleTypesForEmissionAnalysis(scenario); + +// overwrite outputs with adapted files + NetworkUtils.writeNetwork(scenario.getNetwork(), networkPath); + new MatsimVehicleWriter(scenario.getVehicles()).writeFile(vehiclesPath); + new MatsimVehicleWriter(scenario.getTransitVehicles()).writeFile(transitVehiclesPath); + } + try { sw.generate(runDirectory, true); diff --git a/src/main/java/org/matsim/run/scenarios/LausitzScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java index 6ed0ddb..69a1853 100644 --- a/src/main/java/org/matsim/run/scenarios/LausitzScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java @@ -169,13 +169,7 @@ public Config prepareConfig(Config config) { if (emissions == EmissionAnalysisHandling.PERFORM_EMISSIONS_ANALYSIS) { // set hbefa input files for emission analysis - EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class); - eConfig.setDetailedColdEmissionFactorsFile(HBEFA_FILE_COLD_DETAILED); - eConfig.setDetailedWarmEmissionFactorsFile(HBEFA_FILE_WARM_DETAILED); - eConfig.setAverageColdEmissionFactorsFile(HBEFA_FILE_COLD_AVERAGE); - eConfig.setAverageWarmEmissionFactorsFile(HBEFA_FILE_WARM_AVERAGE); - eConfig.setHbefaTableConsistencyCheckingLevel(EmissionsConfigGroup.HbefaTableConsistencyCheckingLevel.consistent); - eConfig.setDetailedVsAverageLookupBehavior(EmissionsConfigGroup.DetailedVsAverageLookupBehavior.tryDetailedThenTechnologyAverageThenAverageTable); + setEmissionsConfigs(config); } return config; } @@ -259,7 +253,20 @@ public static void prepareCommercialTrafficConfig(Config config) { } } - private static void prepareVehicleTypesForEmissionAnalysis(Scenario scenario) { + public static void setEmissionsConfigs(Config config) { + EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class); + eConfig.setDetailedColdEmissionFactorsFile(HBEFA_FILE_COLD_DETAILED); + eConfig.setDetailedWarmEmissionFactorsFile(HBEFA_FILE_WARM_DETAILED); + eConfig.setAverageColdEmissionFactorsFile(HBEFA_FILE_COLD_AVERAGE); + eConfig.setAverageWarmEmissionFactorsFile(HBEFA_FILE_WARM_AVERAGE); + eConfig.setHbefaTableConsistencyCheckingLevel(EmissionsConfigGroup.HbefaTableConsistencyCheckingLevel.consistent); + eConfig.setDetailedVsAverageLookupBehavior(EmissionsConfigGroup.DetailedVsAverageLookupBehavior.tryDetailedThenTechnologyAverageThenAverageTable); + } + + /** + * Prepare vehicle types with necessary HBEFA information for emission analysis. + */ + public static void prepareVehicleTypesForEmissionAnalysis(Scenario scenario) { for (VehicleType type : scenario.getVehicles().getVehicleTypes().values()) { EngineInformation engineInformation = type.getEngineInformation();