From 77c2647c37a057aeb6c356f3eeb0132c5cee08ce Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Mon, 25 Nov 2024 13:43:51 +0100 Subject: [PATCH] add zonal rejection (rates) to output --- .../zonal/DrtZonalWaitTimesAnalyzer.java | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java index ce140ce1772..610511c61e2 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtZonalWaitTimesAnalyzer.java @@ -37,6 +37,7 @@ import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector; import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector.EventSequence; import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.contrib.dvrp.optimizer.Request; import org.matsim.core.controler.events.IterationEndsEvent; import org.matsim.core.controler.events.ShutdownEvent; import org.matsim.core.controler.listener.IterationEndsListener; @@ -79,7 +80,7 @@ public void notifyIterationEnds(IterationEndsEvent event) { } public void write(String fileName) { - Map, DescriptiveStatistics> zoneStats = createZonalStats(); + Map, ZonalStatistics> zoneStats = createZonalStats(); BufferedWriter bw = IOUtils.getBufferedWriter(fileName); try { DecimalFormat format = new DecimalFormat(); @@ -90,7 +91,8 @@ public void write(String fileName) { String header = new StringJoiner(delimiter) .add("zone").add("centerX").add("centerY").add("nRequests") .add("sumWaitTime").add("meanWaitTime").add("min").add("max") - .add("p95").add("p90").add("p80").add("p75").add("p50").toString(); + .add("p95").add("p90").add("p80").add("p75").add("p50") + .add("rejections").add("rejectionRate").toString(); bw.append(header); // sorted output SortedSet> zoneIdsAndOutside = new TreeSet<>(zones.getZones().keySet()); @@ -100,7 +102,8 @@ public void write(String fileName) { Zone drtZone = zones.getZones().get(zoneId); String centerX = drtZone != null ? String.valueOf(drtZone.getCentroid().getX()) : notAvailableString; String centerY = drtZone != null ? String.valueOf(drtZone.getCentroid().getY()) : notAvailableString; - DescriptiveStatistics stats = zoneStats.get(zoneId); + DescriptiveStatistics stats = zoneStats.get(zoneId).waitStats; + Set> rejections = zoneStats.get(zoneId).rejections; bw.newLine(); bw.append( new StringJoiner(delimiter) @@ -116,7 +119,10 @@ public void write(String fileName) { .add(String.valueOf(stats.getPercentile(90))) .add(String.valueOf(stats.getPercentile(80))) .add(String.valueOf(stats.getPercentile(75))) - .add(String.valueOf(stats.getPercentile(50))).toString() + .add(String.valueOf(stats.getPercentile(50))) + .add(String.valueOf(rejections.size())) + .add(String.valueOf(rejections.size() / (double) (rejections.size() + stats.getN()))) + .toString() ); } bw.flush(); @@ -126,13 +132,15 @@ public void write(String fileName) { } } - private Map, DescriptiveStatistics> createZonalStats() { - Map, DescriptiveStatistics> zoneStats = new IdMap<>(Zone.class); + record ZonalStatistics(DescriptiveStatistics waitStats, Set> rejections){} + + private Map, ZonalStatistics> createZonalStats() { + Map, ZonalStatistics> zoneStats = new IdMap<>(Zone.class); // prepare stats for all zones for (Id zoneId : zones.getZones().keySet()) { - zoneStats.put(zoneId, new DescriptiveStatistics()); + zoneStats.put(zoneId, new ZonalStatistics(new DescriptiveStatistics(), new HashSet<>())); } - zoneStats.put(zoneIdForOutsideOfZonalSystem, new DescriptiveStatistics()); + zoneStats.put(zoneIdForOutsideOfZonalSystem, new ZonalStatistics(new DescriptiveStatistics(), new HashSet<>())); for (EventSequence seq : requestAnalyzer.getPerformedRequestSequences().values()) { for (Map.Entry, EventSequence.PersonEvents> entry : seq.getPersonEvents().entrySet()) { @@ -140,10 +148,17 @@ private Map, DescriptiveStatistics> createZonalStats() { Id zone = zones.getZoneForLinkId(seq.getSubmitted().getFromLinkId()) .map(Identifiable::getId).orElse(zoneIdForOutsideOfZonalSystem); double waitTime = entry.getValue().getPickedUp().get() .getTime() - seq.getSubmitted().getTime(); - zoneStats.get(zone).addValue(waitTime); + zoneStats.get(zone).waitStats.addValue(waitTime); } } } + + for (EventSequence seq : requestAnalyzer.getRejectedRequestSequences().values()) { + Id zone = zones.getZoneForLinkId(seq.getSubmitted().getFromLinkId()) + .map(Identifiable::getId).orElse(zoneIdForOutsideOfZonalSystem); + zoneStats.get(zone).rejections.add(seq.getSubmitted().getRequestId()); + } + return zoneStats; } @@ -191,16 +206,19 @@ private Collection convertGeometriesToSimpleFeatures(String targe simpleFeatureBuilder.add("p80", Double.class); simpleFeatureBuilder.add("p75", Double.class); simpleFeatureBuilder.add("p50", Double.class); + simpleFeatureBuilder.add("rejections", Double.class); + simpleFeatureBuilder.add("rejectRate", Double.class); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureBuilder.buildFeatureType()); Collection features = new ArrayList<>(); - Map, DescriptiveStatistics> zoneStats = createZonalStats(); + Map, ZonalStatistics> zoneStats = createZonalStats(); for (Zone zone : zones.getZones().values()) { - Object[] routeFeatureAttributes = new Object[14]; + Object[] routeFeatureAttributes = new Object[16]; Geometry geometry = zone.getPreparedGeometry() != null ? zone.getPreparedGeometry().getGeometry() : null; - DescriptiveStatistics stats = zoneStats.get(zone.getId()); + DescriptiveStatistics stats = zoneStats.get(zone.getId()).waitStats; + Set> rejections = zoneStats.get(zone.getId()).rejections; routeFeatureAttributes[0] = geometry; routeFeatureAttributes[1] = zone.getId(); routeFeatureAttributes[2] = zone.getCentroid().getX(); @@ -215,6 +233,8 @@ private Collection convertGeometriesToSimpleFeatures(String targe routeFeatureAttributes[11] = stats.getPercentile(80); routeFeatureAttributes[12] = stats.getPercentile(75); routeFeatureAttributes[13] = stats.getPercentile(50); + routeFeatureAttributes[14] = rejections.size(); + routeFeatureAttributes[15] = rejections.size() / (double) (rejections.size() + stats.getN()); try { features.add(builder.buildFeature(zone.getId().toString(), routeFeatureAttributes));