From 6c6ce5298f46028130eb9f372a732d469572bcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20K=C3=BChnel?= Date: Wed, 6 Mar 2024 11:16:00 +0100 Subject: [PATCH] account for group bookings in customer stats (#3135) account for group bookings in customer stats --- .../RunDrtWithCompanionExampleIT.java | 36 +++++++++++-------- .../DrtAnalysisControlerListener.java | 11 ++++-- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java index 4a7cb879f50..8a6b6e4098c 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java @@ -20,13 +20,6 @@ package org.matsim.contrib.drt.extension.companions; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; -import java.util.stream.Collectors; - import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -44,6 +37,13 @@ import org.matsim.testcases.MatsimTestUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; + /** * @author Steffen Axer */ @@ -74,8 +74,9 @@ void testRunDrtWithCompanions() { Controler controler = DrtCompanionControlerCreator.createControler(config); controler.run(); - int actualRides = getTotalNumberOfDrtRides(); - Assertions.assertThat(actualRides).isEqualTo(706); + int[] actualRides = getTotalNumberOfDrtRides(); + Assertions.assertThat(actualRides[0]).isEqualTo(378); + Assertions.assertThat(actualRides[1]).isEqualTo(706); } @Test @@ -101,11 +102,12 @@ void testRunDrtWithCompanionsMultiThreaded() { Controler controler = DrtCompanionControlerCreator.createControler(config); controler.run(); - int actualRides = getTotalNumberOfDrtRides(); - Assertions.assertThat(actualRides).isEqualTo(699); + int[] actualRides = getTotalNumberOfDrtRides(); + Assertions.assertThat(actualRides[0]).isEqualTo(375); + Assertions.assertThat(actualRides[1]).isEqualTo(699); } - private int getTotalNumberOfDrtRides() { + private int[] getTotalNumberOfDrtRides() { String filename = utils.getOutputDirectory() + "/drt_customer_stats_drt.csv"; final List collect; @@ -119,8 +121,12 @@ private int getTotalNumberOfDrtRides() { List keys = List.of(collect.get(0).split(";")); List lastIterationValues = List.of(collect.get(size - 1).split(";")); - int index = keys.indexOf("rides"); - String value = lastIterationValues.get(index); - return Integer.parseInt(value); + int ridesRequestIndex = keys.indexOf("rides"); + int ridesRequest = Integer.parseInt(lastIterationValues.get(ridesRequestIndex)); + + int ridesPaxIndex = keys.indexOf("rides_pax"); + int ridesPax = Integer.parseInt(lastIterationValues.get(ridesPaxIndex)); + + return new int[]{ridesRequest, ridesPax}; } } diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java index 399804f9aee..edc20fb87b7 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/DrtAnalysisControlerListener.java @@ -20,6 +20,8 @@ package org.matsim.contrib.drt.analysis; import com.google.common.base.Preconditions; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.apache.logging.log4j.LogManager; @@ -332,7 +334,7 @@ private void writeIterationPassengerStats(String summarizeLegs, int it) { try (var bw = getAppendingBufferedWriter("drt_customer_stats", ".csv")) { if (!headerWritten) { headerWritten = true; - bw.write(line("runId", "iteration", "rides", "wait_average", "wait_max", "wait_p95", "wait_p75", "wait_median", + bw.write(line("runId", "iteration", "rides", "rides_pax", "groupSize_mean", "wait_average", "wait_max", "wait_p95", "wait_p75", "wait_median", "percentage_WT_below_10", "percentage_WT_below_15", "inVehicleTravelTime_mean", "distance_m_mean", "directDistance_m_mean", "totalTravelTime_mean", "fareAllReferences_mean", "rejections", "rejectionRate")); } @@ -569,10 +571,13 @@ private static String summarizeLegs(List legs, Map, Double> format.setMaximumFractionDigits(2); format.setGroupingUsed(false); + Multiset> servedRides = HashMultiset.create(); + for (DrtLeg leg : legs) { if (leg.toLinkId == null) { continue; } + servedRides.add(leg.request); waitStats.addValue(leg.waitTime); rideStats.addValue(leg.arrivalTime - leg.departureTime - leg.waitTime); distanceStats.addValue(travelDistances.get(leg.request)); @@ -580,7 +585,9 @@ private static String summarizeLegs(List legs, Map, Double> traveltimes.addValue(leg.arrivalTime - leg.departureTime); } - return String.join(delimiter, format.format(waitStats.getValues().length) + "",// + return String.join(delimiter, format.format(servedRides.entrySet().size()) + "",// + format.format(servedRides.size()) + "",// + format.format(((double) servedRides.size()) / servedRides.entrySet().size()) + "",// format.format(waitStats.getMean()) + "",// format.format(waitStats.getMax()) + "",// format.format(waitStats.getPercentile(95)) + "",//