Skip to content

Commit

Permalink
Update mat sim (#90)
Browse files Browse the repository at this point in the history
* update MATSim: use DashboardUtils and new pt fare implementation (with old values and logic)

* clean code

* set version number to 2024.2 in java code

* Revert "set version number to 2024.2 in java code"

This reverts commit 9ea16e0.

* change array types

---------

Co-authored-by: sime94 <[email protected]>
Co-authored-by: simei94 <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent b17048c commit 27a106d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 117 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>matsim-all</artifactId>

<!-- PR-labelled release -->
<version>2025.0-PR3402</version> <!-- PR3402 is from August 09, '24, when TS fixed bugs and included damages in NoiseAnalysis -->
<version>2025.0-PR3501</version> <!-- PR3501 is from October 01, 2024 -->

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>16.0-SNAPSHOT</matsim.version>-->
Expand All @@ -15,7 +15,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.matsim-scenarios</groupId>
<artifactId>matsim-kelheim</artifactId>
<version>3.x-SNAPSHOT</version>
<version>2024.2-SNAPSHOT</version>

<name>MATSim Kelheim Model</name>
<description>A transport model of the district of Kelheim and it's surroundings</description>
Expand Down Expand Up @@ -212,7 +212,7 @@
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.11.3</version>
<version>1.12.0</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.file.FileReader;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.PrimitivesArrays;
import org.apache.avro.io.DatumWriter;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.util.Utf8;
Expand Down Expand Up @@ -215,10 +215,8 @@ private XYTData calcAvroMeans(List<GenericRecord> recordList, String dataFieldNa
getCoordData(object1, xCoords);
getCoordData(object2, yCoords);


// TODO: for the example data even for the hourly data there was only one time stamp. This might be different with real data. this needs to be checked
if (object3 instanceof GenericData.Array<?>) {
List<Integer> ints = new ArrayList<>((GenericData.Array<Integer>) object3);
if (object3 instanceof PrimitivesArrays.IntArray intArray) {
List<Integer> ints = new ArrayList<>(intArray);

if (!timeStamps.equals(ints)) {
if (timeStamps.isEmpty()) {
Expand All @@ -235,8 +233,8 @@ private XYTData calcAvroMeans(List<GenericRecord> recordList, String dataFieldNa
List<Float> values = new ArrayList<>();

for (Map.Entry<?, ?> entry : ((HashMap<?, ?>) object4).entrySet()) {
if (entry.getKey() instanceof Utf8 && entry.getKey().toString().equals(dataFieldName) && entry.getValue() instanceof GenericData.Array<?>) {
values.addAll((GenericData.Array<Float>) entry.getValue());
if (entry.getKey() instanceof Utf8 && entry.getKey().toString().equals(dataFieldName) && entry.getValue() instanceof PrimitivesArrays.FloatArray floatArray) {
values.addAll(floatArray);

String entryString = ((Utf8) entry.getKey()).toString();

Expand Down Expand Up @@ -265,8 +263,8 @@ private XYTData calcAvroMeans(List<GenericRecord> recordList, String dataFieldNa
}

private void getCoordData(Object object, List<Float> target) {
if (object instanceof GenericData.Array<?>) {
List<Float> floats = new ArrayList<>((GenericData.Array<Float>) object);
if (object instanceof PrimitivesArrays.FloatArray floatArray) {
List<Float> floats = new ArrayList<>(floatArray);

if (!target.equals(floats)) {
if (target.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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.simwrapper.*;
import org.matsim.simwrapper.viz.ColorScheme;
import org.matsim.simwrapper.viz.GridMap;
import org.matsim.simwrapper.viz.MapPlot;
Expand All @@ -23,12 +20,7 @@ public class AverageKelheimNoiseDashboard implements Dashboard {
private final List<String> 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<String> dirs, Integer noRuns) {
this.dirs = dirs;
Expand Down Expand Up @@ -78,38 +70,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});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/org/matsim/run/KelheimPtFareModule.java

This file was deleted.

40 changes: 16 additions & 24 deletions src/main/java/org/matsim/run/RunKelheimScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -291,7 +294,7 @@ protected void prepareControler(Controler controler) {
controler.addOverridingModule(new AbstractModule() {
@Override
public void install() {
install(new KelheimPtFareModule());
install(new PtFareModule());
install(new SwissRailRaptorModule());
install(new PersonMoneyEventsAnalysisModule());
install(new SimWrapperModule());
Expand Down Expand Up @@ -377,17 +380,6 @@ public void install() {
// TODO: when to include AV?
//estimatorConfig.addParameterSet(new DrtEstimatorConfigGroup("av"));


// if (intermodal){
// controler.addOverridingModule(new IntermodalTripFareCompensatorsModule());
// controler.addOverridingModule(new PtIntermodalRoutingModesModule());
// controler.addOverridingModule(new AbstractModule() {
// @Override
// public void install() {
// bind(RaptorIntermodalAccessEgress.class).to(EnhancedRaptorIntermodalAccessEgress.class);
// }
// });
// }
}
}
}

0 comments on commit 27a106d

Please sign in to comment.