From 43a6b2799da76a9d97f738272af4e16efe101c2f Mon Sep 17 00:00:00 2001 From: schlenther Date: Wed, 2 Oct 2024 12:10:50 +0200 Subject: [PATCH] update MATSim: use DashboardUtils and new pt fare implementation (with old values and logic) --- pom.xml | 6 ++-- .../AverageKelheimEmissionsDashboard.java | 16 ++------- .../AverageKelheimNoiseDashboard.java | 31 ++++------------- .../dashboard/KelheimEmissionsDashboard.java | 14 +++----- .../dashboard/KelheimSimWrapperRunner.java | 2 +- .../org/matsim/run/KelheimPtFareModule.java | 34 ------------------- .../org/matsim/run/RunKelheimScenario.java | 30 +++++++++------- 7 files changed, 36 insertions(+), 97 deletions(-) delete mode 100644 src/main/java/org/matsim/run/KelheimPtFareModule.java diff --git a/pom.xml b/pom.xml index ac713775..28b6112f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ matsim-all - 2025.0-PR3402 + 2025.0-PR3501 @@ -15,7 +15,7 @@ 4.0.0 com.github.matsim-scenarios matsim-kelheim - 3.x-SNAPSHOT + 2024.2-SNAPSHOT MATSim Kelheim Model A transport model of the district of Kelheim and it's surroundings @@ -212,7 +212,7 @@ org.apache.avro avro - 1.11.3 + 1.12.0 diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java index fa369af5..b5263be8 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimEmissionsDashboard.java @@ -21,17 +21,12 @@ package org.matsim.dashboard; import org.matsim.analysis.postAnalysis.emissions.EmissionsPostProcessingAverageAnalysis; -import org.matsim.simwrapper.Dashboard; -import org.matsim.simwrapper.Data; -import org.matsim.simwrapper.Header; -import org.matsim.simwrapper.Layout; +import org.matsim.simwrapper.*; import org.matsim.simwrapper.viz.*; import java.util.ArrayList; import java.util.List; -import static org.matsim.dashboard.AverageKelheimNoiseDashboard.*; - /** * Average emissions dashboard for several runs with the same config but a different random seed. */ @@ -130,21 +125,16 @@ public void configure(Header header, Layout layout) { layout.row("second").el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per day. Be aware that CO2 values are provided in the simulation sample size!"; - setGridMapStandards(viz); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_emissions_grid_per_day.xyt.csv"); }); layout.row("third") .el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per hour. Be aware that CO2 values are provided in the simulation sample size!"; - setGridMapStandards(viz); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_emissions_grid_per_hour.csv"); }); } - private static void setGridMapStandards(GridMap viz) { - viz.projection = "EPSG:25832"; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); - viz.height = 12.0; - } } diff --git a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java index b4715dd9..34aa0e57 100644 --- a/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java +++ b/src/main/java/org/matsim/dashboard/AverageKelheimNoiseDashboard.java @@ -1,10 +1,8 @@ package org.matsim.dashboard; import org.matsim.analysis.postAnalysis.NoiseAverageAnalysis; -import org.matsim.simwrapper.Dashboard; -import org.matsim.simwrapper.Data; -import org.matsim.simwrapper.Header; -import org.matsim.simwrapper.Layout; +import org.matsim.run.RunKelheimScenario; +import org.matsim.simwrapper.*; import org.matsim.simwrapper.viz.ColorScheme; import org.matsim.simwrapper.viz.GridMap; import org.matsim.simwrapper.viz.MapPlot; @@ -23,12 +21,7 @@ public class AverageKelheimNoiseDashboard implements Dashboard { private final List dirs; private final Integer noRuns; private static final String NOISE = "noise"; - static final String DARK_BLUE = "#1175b3"; - static final String LIGHT_BLUE = "#95c7df"; - static final String ORANGE = "#f4a986"; - static final String RED = "#cc0c27"; - static final String SAND = "#dfb095"; - static final String YELLOW = "#dfdb95"; + public AverageKelheimNoiseDashboard(List dirs, Integer noRuns) { this.dirs = dirs; @@ -78,38 +71,28 @@ public void configure(Header header, Layout layout) { .el(GridMap.class, (viz, data) -> { viz.title = "Noise Immissions (Grid)"; viz.description = "Total Noise Immissions per day"; - setGridMapStandards(viz, data); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_immission_per_day.avro"); }) .el(GridMap.class, (viz, data) -> { viz.title = "Hourly Noise Immissions (Grid)"; viz.description = "Noise Immissions per hour"; - setGridMapStandards(viz, data); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_immission_per_hour.avro"); }); layout.row("damages") .el(GridMap.class, (viz, data) -> { viz.title = "Daily Noise Damages (Grid)"; viz.description = "Total Noise Damages per day [€]"; - setGridMapStandards(viz, data); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_damages_receiverPoint_per_day.avro"); }) .el(GridMap.class, (viz, data) -> { viz.title = "Hourly Noise Damages (Grid)"; viz.description = "Noise Damages per hour [€]"; - setGridMapStandards(viz, data); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); viz.file = postProcess(data, "mean_damages_receiverPoint_per_hour.avro"); }); } - private static void setGridMapStandards(GridMap viz, Data data) { - viz.height = 12.0; - viz.cellSize = 250; - viz.opacity = 0.1; - viz.maxHeight = 40; - viz.projection = "EPSG:25832"; - viz.center = data.context().getCenter(); - viz.zoom = data.context().mapZoomLevel; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); - } } diff --git a/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java index 80141b08..f59d55e0 100644 --- a/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java +++ b/src/main/java/org/matsim/dashboard/KelheimEmissionsDashboard.java @@ -23,6 +23,7 @@ import org.matsim.analysis.postAnalysis.emissions.KelheimOfflineAirPollutionAnalysisByEngineInformation; import org.matsim.application.prepare.network.CreateGeoJsonNetwork; import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.DashboardUtils; import org.matsim.simwrapper.Header; import org.matsim.simwrapper.Layout; import org.matsim.simwrapper.viz.GridMap; @@ -94,21 +95,16 @@ public void configure(Header header, Layout layout) { layout.row("second").el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per day. Be aware that CO2 values are provided in the simulation sample size!"; - setGridMapStandards(viz, 12.0, data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_day.xyt.csv", new String[0])); - + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); + viz.file = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_day.xyt.csv", new String[0]); }); layout.row("third") .el(GridMap.class, (viz, data) -> { viz.title = "CO₂ Emissions"; viz.description = "per hour. Be aware that CO2 values are provided in the simulation sample size!"; - setGridMapStandards(viz, 12., data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_hour.csv")); + DashboardUtils.setGridMapStandards(viz, data, "EPSG:25832"); + viz.file = data.compute(KelheimOfflineAirPollutionAnalysisByEngineInformation.class, "emissions_grid_per_hour.csv"); }); } - private static void setGridMapStandards(GridMap viz, double height, String data) { - viz.height = height; - viz.projection = "EPSG:25832"; - viz.file = data; - viz.setColorRamp(new double[]{30, 40, 50, 60, 70}, new String[]{DARK_BLUE, LIGHT_BLUE, YELLOW, SAND, ORANGE, RED}); - } } diff --git a/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java b/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java index 01b3c3a6..7baec11c 100644 --- a/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java +++ b/src/main/java/org/matsim/dashboard/KelheimSimWrapperRunner.java @@ -106,7 +106,7 @@ public Integer call() throws Exception { new DrtDashboardProvider().getDashboards(config, sw).forEach(sw::addDashboard); } if (noise){ - sw.addDashboard(new NoiseDashboard()); + sw.addDashboard(new NoiseDashboard(config.global().getCoordinateSystem())); } try { diff --git a/src/main/java/org/matsim/run/KelheimPtFareModule.java b/src/main/java/org/matsim/run/KelheimPtFareModule.java deleted file mode 100644 index 2f823747..00000000 --- a/src/main/java/org/matsim/run/KelheimPtFareModule.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.matsim.run; - -import org.matsim.api.core.v01.TransportMode; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.AbstractModule; -import playground.vsp.pt.fare.DistanceBasedPtFareHandler; -import playground.vsp.pt.fare.DistanceBasedPtFareParams; -import playground.vsp.pt.fare.PtFareConfigGroup; -import playground.vsp.pt.fare.PtFareUpperBoundHandler; - -/** - * Module to install classes for pt fare. - */ -public class KelheimPtFareModule extends AbstractModule { - @Override - public void install() { - // Set the money related thing in the config (planCalcScore) file to 0. - getConfig().scoring().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0); - getConfig().scoring().getModes().get(TransportMode.pt).setMarginalUtilityOfDistance(0); - - // Initialize config group (and also write in the output config) - PtFareConfigGroup ptFareConfigGroup = ConfigUtils.addOrGetModule(this.getConfig(), PtFareConfigGroup.class); - DistanceBasedPtFareParams distanceBasedPtFareParams = ConfigUtils.addOrGetModule(this.getConfig(), DistanceBasedPtFareParams.class); - - - // Add bindings - addEventHandlerBinding().toInstance(new DistanceBasedPtFareHandler(distanceBasedPtFareParams)); - if (ptFareConfigGroup.getApplyUpperBound()) { - PtFareUpperBoundHandler ptFareUpperBoundHandler = new PtFareUpperBoundHandler(ptFareConfigGroup.getUpperBoundFactor()); - addEventHandlerBinding().toInstance(ptFareUpperBoundHandler); - addControlerListenerBinding().toInstance(ptFareUpperBoundHandler); - } - } -} diff --git a/src/main/java/org/matsim/run/RunKelheimScenario.java b/src/main/java/org/matsim/run/RunKelheimScenario.java index d146f381..d3d1bab8 100644 --- a/src/main/java/org/matsim/run/RunKelheimScenario.java +++ b/src/main/java/org/matsim/run/RunKelheimScenario.java @@ -43,6 +43,7 @@ import org.matsim.contrib.dvrp.run.DvrpModule; import org.matsim.contrib.dvrp.run.DvrpQSimComponents; import org.matsim.contrib.dvrp.trafficmonitoring.DvrpModeLimitedMaxSpeedTravelTimeModule; +import org.matsim.contrib.vsp.pt.fare.PtFareModule; import org.matsim.contrib.vsp.scenario.SnzActivities; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; @@ -62,8 +63,8 @@ import org.matsim.simwrapper.SimWrapperModule; import org.matsim.vehicles.VehicleType; import picocli.CommandLine; -import playground.vsp.pt.fare.DistanceBasedPtFareParams; -import playground.vsp.pt.fare.PtFareConfigGroup; +import org.matsim.contrib.vsp.pt.fare.DistanceBasedPtFareParams; +import org.matsim.contrib.vsp.pt.fare.PtFareConfigGroup; import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; import javax.annotation.Nullable; @@ -221,16 +222,18 @@ protected Config prepareConfig(Config config) { // Minimum fare (e.g. short trip or 1 zone ticket) distanceBasedPtFareParams.setMinFare(2.0); - // Division between long trip and short trip (unit: m) - distanceBasedPtFareParams.setLongDistanceTripThreshold(50000); - // y = ax + b --> a value, for short trips - distanceBasedPtFareParams.setNormalTripSlope(0.00017); - // y = ax + b --> b value, for short trips - distanceBasedPtFareParams.setNormalTripIntercept(1.6); - // y = ax + b --> a value, for long trips - distanceBasedPtFareParams.setLongDistanceTripSlope(0.00025); - // y = ax + b --> b value, for long trips - distanceBasedPtFareParams.setLongDistanceTripIntercept(30); + + distanceBasedPtFareParams.setTransactionPartner("pt-operator"); + DistanceBasedPtFareParams.DistanceClassLinearFareFunctionParams shortDistance = distanceBasedPtFareParams.getOrCreateDistanceClassFareParams(50000); + shortDistance.setFareIntercept(1.6); + shortDistance.setFareSlope(0.00017); + + DistanceBasedPtFareParams.DistanceClassLinearFareFunctionParams longDistance = distanceBasedPtFareParams.getOrCreateDistanceClassFareParams(Double.POSITIVE_INFINITY); + longDistance.setFareIntercept(30); + longDistance.setFareSlope(0.00025); + distanceBasedPtFareParams.setOrder(1); + + ptFareConfigGroup.addParameterSet(distanceBasedPtFareParams); //enable plan inheritance analysis config.planInheritance().setEnabled(true); @@ -291,7 +294,8 @@ protected void prepareControler(Controler controler) { controler.addOverridingModule(new AbstractModule() { @Override public void install() { - install(new KelheimPtFareModule()); +// install(new KelheimPtFareModule()); + install(new PtFareModule()); install(new SwissRailRaptorModule()); install(new PersonMoneyEventsAnalysisModule()); install(new SimWrapperModule());