Skip to content

Commit

Permalink
fix road pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
Janekdererste committed Jun 2, 2023
1 parent 1bbf080 commit a8b5b6f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/matsim/run/MosaikRunnerWithRoadPricing.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ public static void main(String[] args) throws IOException {
var tollLinks = getTollLinks(rpConfigGroup, scenario.getNetwork());
var emissionPerMeter = createEmissionPerMeter();

var path = Paths.get(config.controler().getOutputDirectory()).resolve("tolls.csv");
var path = Paths.get("./tolls.csv");
log.info("writing tolls to: " + path);
try (var writer = Files.newBufferedWriter(path); var p = CSVFormat.DEFAULT.withFirstRecordAsHeader().withHeader("time", "toll [€/m]").print(writer)) {
for (var bin : timeFactors.getTimeBins()) {

var time = bin.getStartTime();
var tollPerMeter = bin.getValue().entrySet().stream()
.mapToDouble(entry -> costFactors.get(entry.getKey()) * emissionPerMeter.get(entry.getKey()) * entry.getValue())
.mapToDouble(entry -> {
var costFactor = costFactors.get(entry.getKey());
var epm = emissionPerMeter.get(entry.getKey());
var timeFactor = entry.getValue();
var tollResult = costFactor * epm * timeFactor;
return tollResult;
})
.sum();
p.printRecord(time, tollPerMeter);

Expand Down Expand Up @@ -187,7 +193,6 @@ private static Map<Pollutant, Double> createEmissionPerMeter() {
log.info("Creating emission per meter");
return Map.of(
Pollutant.PM, 0.002 / 1000,
Pollutant.PM_non_exhaust, 0.002 / 1000,
Pollutant.NOx, 0.338 / 1000
);
}
Expand All @@ -201,7 +206,6 @@ private static Map<Pollutant, Double> createCostFactors() {
log.info("Creating cost factors.");
return Map.of(
Pollutant.PM, 39.6 / 1000,
Pollutant.PM_non_exhaust, 39.6 / 1000,
Pollutant.NOx, 36.8 / 1000
);
}
Expand Down Expand Up @@ -230,7 +234,6 @@ private static TimeBinMap<Map<Pollutant, Double>> createTimeFactors() {
bin.setValue(new HashMap<>());
}
bin.getValue().put(Pollutant.PM, factor);
bin.getValue().put(Pollutant.PM_non_exhaust, factor);
});

return result;
Expand Down Expand Up @@ -303,4 +306,4 @@ public Mosaik2ConfigGroup() {
super(GROUP_NAME);
}
}
}
}

0 comments on commit a8b5b6f

Please sign in to comment.