Skip to content

Commit

Permalink
account for group bookings in customer stats (#3135)
Browse files Browse the repository at this point in the history
account for group bookings in customer stats
  • Loading branch information
nkuehnel authored Mar 6, 2024
1 parent be4ad19 commit 6c6ce52
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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<String> collect;
Expand All @@ -119,8 +121,12 @@ private int getTotalNumberOfDrtRides() {
List<String> keys = List.of(collect.get(0).split(";"));
List<String> 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};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -569,18 +571,23 @@ private static String summarizeLegs(List<DrtLeg> legs, Map<Id<Request>, Double>
format.setMaximumFractionDigits(2);
format.setGroupingUsed(false);

Multiset<Id<Request>> 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));
directDistanceStats.addValue(leg.unsharedDistanceEstimate_m);
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)) + "",//
Expand Down

0 comments on commit 6c6ce52

Please sign in to comment.