From 17478be12fbce1dfdac24c50fb316469e51ad7b3 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Thu, 27 Dec 2018 03:56:52 +0530 Subject: [PATCH 01/30] add misc summary stats --- src/main/java/beam/analysis/StatsFactory.java | 2 +- .../plots/RideHailWaitingAnalysis.java | 10 ++++- .../summary/VehicleTravelTimeAnalysis.java | 42 ++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/beam/analysis/StatsFactory.java b/src/main/java/beam/analysis/StatsFactory.java index a7214270cd2..13641b7faea 100644 --- a/src/main/java/beam/analysis/StatsFactory.java +++ b/src/main/java/beam/analysis/StatsFactory.java @@ -89,7 +89,7 @@ private BeamAnalysis createStats(StatsType statsType) { case DeadHeading: return new DeadHeadingAnalysis(writeGraphs); case VehicleHoursTraveled: - return new VehicleTravelTimeAnalysis(); + return new VehicleTravelTimeAnalysis(beamServices.matsimServices().getScenario()); case MotorizedVehicleMilesTraveled: return new MotorizedVehicleMilesTraveledAnalysis(); case NumberOfVehicles: diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 9f9facde94b..1d8b11d4a2a 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -1,6 +1,7 @@ package beam.analysis.plots; import beam.agentsim.events.ModeChoiceEvent; +import beam.analysis.IterationSummaryAnalysis; import beam.analysis.plots.modality.RideHailDistanceRowModel; import beam.sim.OutputDataDescription; import beam.sim.config.BeamConfig; @@ -26,7 +27,7 @@ /** * @author abid */ -public class RideHailWaitingAnalysis implements GraphAnalysis { +public class RideHailWaitingAnalysis implements GraphAnalysis, IterationSummaryAnalysis { public RideHailWaitingAnalysis(StatsComputation, Map>>, Tuple>, double[][]>> statComputation) { this.statComputation = statComputation; @@ -216,6 +217,13 @@ public void createGraph(IterationEndsEvent event) throws IOException { writeRideHailWaitingIndividualStatCSV(event.getIteration()); } + @Override + public Map getSummaryStats(){ + Map averageRidehailWaitTime = new HashMap(); + averageRidehailWaitTime.put("averageRidehailWaitTime" , waitTimeSum / rideHailCount); + return averageRidehailWaitTime; + } + private void writeRideHailWaitingIndividualStatCSV(int iteration) { String csvFileName = GraphsStatsAgentSimEventsListener.CONTROLLER_IO.getIterationFilename(iteration, rideHailIndividualWaitingTimesFileBaseName + ".csv"); diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index aa4aa7a4f0f..d14efd8dab0 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -2,7 +2,10 @@ import beam.agentsim.events.PathTraversalEvent; import beam.analysis.IterationSummaryAnalysis; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.network.Link; import java.util.HashMap; import java.util.Map; @@ -10,6 +13,13 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private Map secondsTraveledByVehicleType = new HashMap<>(); + private Scenario scenario; + private int countOfVehicle = 0 ; + double averageVehicleDelay = 0.0; + + public VehicleTravelTimeAnalysis(Scenario scenario){ + this.scenario = scenario; + } @Override public void processStats(Event event) { @@ -20,19 +30,47 @@ public void processStats(Event event) { Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME))); secondsTraveledByVehicleType.merge(vehicleType, hoursTraveled, (d1, d2) -> d1 + d2); + + + if (vehicleType.contains("Car") || vehicleType.contains("BUS")){ + countOfVehicle ++; + int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); + + double freeFlowDuration = 0.0; + Map, ? extends Link> linkslist = scenario.getNetwork().getLinks(); + String links[] = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_LINK_IDS).split(","); + for(String link:links ){ + Id id = Id.createLinkId(link); + if(linkslist.containsKey(id)) { + double freeFlowLength = linkslist.get(id).getLength(); + double freeFlowSpeed = linkslist.get(id).getFreespeed(); + freeFlowDuration += freeFlowLength / freeFlowSpeed; + } + } + if(hoursTraveled > freeFlowDuration ) { //discarding negative values + averageVehicleDelay += numOfPassangers * (hoursTraveled - freeFlowDuration); + } + } + } } @Override public void resetStats() { + countOfVehicle = 0; + averageVehicleDelay = 0.0; secondsTraveledByVehicleType.clear(); } @Override public Map getSummaryStats() { - return secondsTraveledByVehicleType.entrySet().stream().collect(Collectors.toMap( + Map summaryStats = secondsTraveledByVehicleType.entrySet().stream().collect(Collectors.toMap( e -> "vehicleHoursTraveled_" + e.getKey(), e -> e.getValue()/3600.0 - )); + )); + + summaryStats.put("averageVehicleDelayPerTrip" , (averageVehicleDelay / countOfVehicle)); + return summaryStats; } + } From f424bf7d2ea76e5bc58e18830e7a3a8e13605870 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Thu, 27 Dec 2018 21:11:21 +0530 Subject: [PATCH 02/30] add null check and change return syntax --- .../plots/RideHailWaitingAnalysis.java | 6 +++--- .../summary/VehicleTravelTimeAnalysis.java | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 1d8b11d4a2a..e5c6bf25cd2 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -219,9 +219,9 @@ public void createGraph(IterationEndsEvent event) throws IOException { @Override public Map getSummaryStats(){ - Map averageRidehailWaitTime = new HashMap(); - averageRidehailWaitTime.put("averageRidehailWaitTime" , waitTimeSum / rideHailCount); - return averageRidehailWaitTime; + return new HashMap() {{ + put("averageRideHailWaitTime" , waitTimeSum / rideHailCount); + }}; } private void writeRideHailWaitingIndividualStatCSV(int iteration) { diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index d14efd8dab0..237ff6f6a50 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -37,14 +37,17 @@ public void processStats(Event event) { int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); double freeFlowDuration = 0.0; - Map, ? extends Link> linkslist = scenario.getNetwork().getLinks(); - String links[] = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_LINK_IDS).split(","); - for(String link:links ){ - Id id = Id.createLinkId(link); - if(linkslist.containsKey(id)) { - double freeFlowLength = linkslist.get(id).getLength(); - double freeFlowSpeed = linkslist.get(id).getFreespeed(); - freeFlowDuration += freeFlowLength / freeFlowSpeed; + Map, ? extends Link> linkslist ; + if(scenario != null){ + linkslist = scenario.getNetwork().getLinks(); + String links[] = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_LINK_IDS).split(","); + for(String link:links ){ + Id id = Id.createLinkId(link); + if(linkslist.containsKey(id)) { + double freeFlowLength = linkslist.get(id).getLength(); + double freeFlowSpeed = linkslist.get(id).getFreespeed(); + freeFlowDuration += freeFlowLength / freeFlowSpeed; + } } } if(hoursTraveled > freeFlowDuration ) { //discarding negative values From 2b592f64d6880e8548326f8a5ca604328dd1a2eb Mon Sep 17 00:00:00 2001 From: wrashid Date: Thu, 27 Dec 2018 13:07:53 -0600 Subject: [PATCH 03/30] refactoring --- .../physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java index 3727453ae44..9f678c9bc7d 100755 --- a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java +++ b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java @@ -238,6 +238,11 @@ private void writePhyssimPlans(IterationEndsEvent event) { } } + + public boolean isPhyssimMode(String mode){ + return mode.equalsIgnoreCase(CAR) || mode.equalsIgnoreCase(BUS); + } + @Override public void handleEvent(Event event) { @@ -259,7 +264,7 @@ public void handleEvent(Event event) { } - if (mode.equalsIgnoreCase(CAR) || mode.equalsIgnoreCase(BUS)) { + if (isPhyssimMode(mode)) { String links = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_LINK_IDS); double departureTime = Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME)); From 28e1ef0fc273ccd9e2125cd52d7c6018ff072423 Mon Sep 17 00:00:00 2001 From: wrashid Date: Thu, 27 Dec 2018 13:08:13 -0600 Subject: [PATCH 04/30] bug fix: wrong field used --- .../beam/analysis/summary/VehicleTravelTimeAnalysis.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 237ff6f6a50..cecb235da10 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -25,14 +25,14 @@ public VehicleTravelTimeAnalysis(Scenario scenario){ public void processStats(Event event) { if (event instanceof PathTraversalEvent || event.getEventType().equalsIgnoreCase(PathTraversalEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); - String vehicleType = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_VEHICLE_TYPE); + String mode = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_MODE); double hoursTraveled = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME))); - secondsTraveledByVehicleType.merge(vehicleType, hoursTraveled, (d1, d2) -> d1 + d2); + secondsTraveledByVehicleType.merge(mode, hoursTraveled, (d1, d2) -> d1 + d2); - if (vehicleType.contains("Car") || vehicleType.contains("BUS")){ + if (mode.contains("Car") || mode.contains("BUS")){ countOfVehicle ++; int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); From 264fd05c9c55201d4d5a3d423e560a2912a4c4cd Mon Sep 17 00:00:00 2001 From: wrashid Date: Thu, 27 Dec 2018 13:09:29 -0600 Subject: [PATCH 05/30] refactor: reuse code --- .../java/beam/analysis/summary/VehicleTravelTimeAnalysis.java | 3 ++- .../beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index cecb235da10..4c96e177ca6 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -2,6 +2,7 @@ import beam.agentsim.events.PathTraversalEvent; import beam.analysis.IterationSummaryAnalysis; +import beam.physsim.jdeqsim.AgentSimToPhysSimPlanConverter; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.events.Event; @@ -32,7 +33,7 @@ public void processStats(Event event) { secondsTraveledByVehicleType.merge(mode, hoursTraveled, (d1, d2) -> d1 + d2); - if (mode.contains("Car") || mode.contains("BUS")){ + if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)){ countOfVehicle ++; int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); diff --git a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java index 9f678c9bc7d..33f35189555 100755 --- a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java +++ b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java @@ -239,7 +239,7 @@ private void writePhyssimPlans(IterationEndsEvent event) { } - public boolean isPhyssimMode(String mode){ + public static boolean isPhyssimMode(String mode){ return mode.equalsIgnoreCase(CAR) || mode.equalsIgnoreCase(BUS); } From 89a3f33e9959d236f284036ddda2c67a5ae6d774 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Fri, 28 Dec 2018 01:14:53 +0530 Subject: [PATCH 06/30] add totalHoursOfVehicleTrafficDelay in summary stats. --- .../java/beam/analysis/summary/VehicleTravelTimeAnalysis.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 4c96e177ca6..e5e856b15ce 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -17,6 +17,7 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private Scenario scenario; private int countOfVehicle = 0 ; double averageVehicleDelay = 0.0; + double totalVehicleTrafficDelay = 0.0; public VehicleTravelTimeAnalysis(Scenario scenario){ this.scenario = scenario; @@ -53,6 +54,7 @@ public void processStats(Event event) { } if(hoursTraveled > freeFlowDuration ) { //discarding negative values averageVehicleDelay += numOfPassangers * (hoursTraveled - freeFlowDuration); + totalVehicleTrafficDelay += (hoursTraveled - freeFlowDuration); } } @@ -63,6 +65,7 @@ public void processStats(Event event) { public void resetStats() { countOfVehicle = 0; averageVehicleDelay = 0.0; + totalVehicleTrafficDelay = 0.0; secondsTraveledByVehicleType.clear(); } @@ -74,6 +77,7 @@ public Map getSummaryStats() { )); summaryStats.put("averageVehicleDelayPerTrip" , (averageVehicleDelay / countOfVehicle)); + summaryStats.put("totalHoursOfVehicleTrafficDelay" , totalVehicleTrafficDelay / 3600); return summaryStats; } From 9512003d7c0f1ae0317b81ef1f3ee715d51ac4bd Mon Sep 17 00:00:00 2001 From: rajnikant Date: Fri, 28 Dec 2018 02:24:05 +0530 Subject: [PATCH 07/30] add summary stats for averagePTWaitingTime --- .../analysis/plots/RideHailWaitingAnalysis.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index e5c6bf25cd2..beacf8f7c86 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -125,9 +125,11 @@ private double[][] buildModesFrequencyDataset(Map> private boolean writeGraph; private List rideHailWaitingIndividualStatList = new ArrayList<>(); private Map rideHailWaiting = new HashMap<>(); + private Map ptWaiting = new HashMap<>(); private Map> hoursTimesMap = new HashMap<>(); private double waitTimeSum = 0; //sum of all wait times experienced by customers private int rideHailCount = 0; //later used to calculate average wait time experienced by customers + private double averagePTWaitingTime = 0.0; private final StatsComputation, Map>>, Tuple>, double[][]>> statComputation; private static int numberOfTimeBins = 30; @@ -149,6 +151,7 @@ public RideHailWaitingAnalysis(StatsComputation, Map personId = modeChoiceEvent.getPersonId(); rideHailWaiting.put(personId.toString(), event); } + if (mode.equalsIgnoreCase("walk_transit")) { + + ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) event; + Id personId = modeChoiceEvent.getPersonId(); + ptWaiting.put(personId.toString(), event.getTime()); + } + } else if (event instanceof PersonEntersVehicleEvent) { PersonEntersVehicleEvent personEntersVehicleEvent = (PersonEntersVehicleEvent) event; @@ -195,6 +205,10 @@ public void processStats(Event event) { // Remove the personId from the list of ModeChoiceEvent rideHailWaiting.remove(_personId); } + // added summary stats for averagePTWaitingTime + if(ptWaiting.containsKey(personId.toString()) && eventAttributes.get("vehicle").contains("body")) { + averagePTWaitingTime += event.getTime() - ptWaiting.get(personId.toString()); + } } } @@ -221,6 +235,7 @@ public void createGraph(IterationEndsEvent event) throws IOException { public Map getSummaryStats(){ return new HashMap() {{ put("averageRideHailWaitTime" , waitTimeSum / rideHailCount); + put("averagePTWaitingTime" , averagePTWaitingTime / 3600); }}; } From 1e47ea02ce6c7282c91c38d430e54db8342172f1 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Fri, 28 Dec 2018 03:12:59 +0530 Subject: [PATCH 08/30] add bus crowding in summary stats --- .../analysis/summary/VehicleTravelTimeAnalysis.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index e5e856b15ce..6f74d0be8e0 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -18,6 +18,7 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private int countOfVehicle = 0 ; double averageVehicleDelay = 0.0; double totalVehicleTrafficDelay = 0.0; + double busCrowding = 0.0; public VehicleTravelTimeAnalysis(Scenario scenario){ this.scenario = scenario; @@ -30,13 +31,13 @@ public void processStats(Event event) { String mode = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_MODE); double hoursTraveled = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME))); + int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); + int seatingCapacity = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_SEATING_CAPACITY)); secondsTraveledByVehicleType.merge(mode, hoursTraveled, (d1, d2) -> d1 + d2); - if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)){ countOfVehicle ++; - int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); double freeFlowDuration = 0.0; Map, ? extends Link> linkslist ; @@ -58,6 +59,10 @@ public void processStats(Event event) { } } + if(numOfPassangers > seatingCapacity){ + int numOfStandingPeople = numOfPassangers - seatingCapacity; + busCrowding += hoursTraveled * numOfStandingPeople ; + } } } @@ -78,6 +83,7 @@ public Map getSummaryStats() { summaryStats.put("averageVehicleDelayPerTrip" , (averageVehicleDelay / countOfVehicle)); summaryStats.put("totalHoursOfVehicleTrafficDelay" , totalVehicleTrafficDelay / 3600); + summaryStats.put("busCrowding" , busCrowding/3600); return summaryStats; } From a6a41e00d745726498972e4444a6b0d7a843d03e Mon Sep 17 00:00:00 2001 From: rajnikant Date: Fri, 28 Dec 2018 03:25:32 +0530 Subject: [PATCH 09/30] reset bus crowding --- .../java/beam/analysis/summary/VehicleTravelTimeAnalysis.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 6f74d0be8e0..3580cb934e3 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -71,6 +71,7 @@ public void resetStats() { countOfVehicle = 0; averageVehicleDelay = 0.0; totalVehicleTrafficDelay = 0.0; + busCrowding = 0.0; secondsTraveledByVehicleType.clear(); } From 868fca18a698ee80473b6b0a5956aa8a51a11397 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Fri, 28 Dec 2018 04:51:42 +0530 Subject: [PATCH 10/30] add averageTripExpenditure in summary stats --- .../java/beam/analysis/summary/PersonCostAnalysis.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java index 6681f1adc2e..9f52abab843 100644 --- a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java +++ b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java @@ -3,6 +3,7 @@ import beam.agentsim.events.PersonCostEvent; import beam.analysis.IterationSummaryAnalysis; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.events.PersonDepartureEvent; import java.util.HashMap; import java.util.Map; @@ -10,6 +11,8 @@ public class PersonCostAnalysis implements IterationSummaryAnalysis { private Map personCostByCostType = new HashMap<>(); private String[] costTypes = {"Cost","Subsidy","Toll"}; + int numberOfTrips = 0; + double totalCost = 0.0; @Override public void processStats(Event event) { @@ -27,18 +30,25 @@ public void processStats(Event event) { } String statType = String.format("total%s_%s", costType, mode); personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); + totalCost += cost; } } + if (event instanceof PersonDepartureEvent || event.getEventType().equalsIgnoreCase(PersonDepartureEvent.EVENT_TYPE)){ + numberOfTrips++; + } } @Override public void resetStats() { personCostByCostType.clear(); + numberOfTrips = 0; + totalCost = 0; } @Override public Map getSummaryStats() { + personCostByCostType.put("averageTripExpenditure", totalCost/numberOfTrips); return personCostByCostType; } } From 1be997bea98a83d9fcdfdf6ede2e639fb25c620e Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 05:12:45 +0500 Subject: [PATCH 11/30] fixed cost aggregation --- src/main/java/beam/analysis/summary/PersonCostAnalysis.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java index 9f52abab843..fdcfdf23c1c 100644 --- a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java +++ b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java @@ -23,14 +23,14 @@ public void processStats(Event event) { for(String costType : costTypes){ if(costType.equals("Cost")){ cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_NET_COST)); + totalCost += cost; }else if(costType.equals("Subsidy")){ cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_SUBSIDY)); }else if(costType.equals("Toll")) { cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_TOLL_COST)); } String statType = String.format("total%s_%s", costType, mode); - personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); - totalCost += cost; + personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); } } if (event instanceof PersonDepartureEvent || event.getEventType().equalsIgnoreCase(PersonDepartureEvent.EVENT_TYPE)){ From f50c8efabfdbed5d71ea7b2b9afb88db54a49299 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 05:55:22 +0500 Subject: [PATCH 12/30] fixed PTCrowding (bus) --- .../summary/VehicleTravelTimeAnalysis.java | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 3580cb934e3..3219d313ac3 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -15,12 +15,13 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private Map secondsTraveledByVehicleType = new HashMap<>(); private Scenario scenario; - private int countOfVehicle = 0 ; - double averageVehicleDelay = 0.0; - double totalVehicleTrafficDelay = 0.0; - double busCrowding = 0.0; + private int countOfVehicle = 0; + private double averageVehicleDelay = 0.0; + private double totalVehicleTrafficDelay = 0.0; + private double busCrowding = 0.0; + private long numOfPathTraversalsWithBusMode = 0; - public VehicleTravelTimeAnalysis(Scenario scenario){ + public VehicleTravelTimeAnalysis(Scenario scenario) { this.scenario = scenario; } @@ -31,43 +32,47 @@ public void processStats(Event event) { String mode = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_MODE); double hoursTraveled = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME))); - int numOfPassangers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); + int numOfPassengers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); int seatingCapacity = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_SEATING_CAPACITY)); secondsTraveledByVehicleType.merge(mode, hoursTraveled, (d1, d2) -> d1 + d2); - if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)){ - countOfVehicle ++; + if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)) { + countOfVehicle++; double freeFlowDuration = 0.0; - Map, ? extends Link> linkslist ; - if(scenario != null){ - linkslist = scenario.getNetwork().getLinks(); + Map, ? extends Link> linksMap; + if (scenario != null) { + linksMap = scenario.getNetwork().getLinks(); String links[] = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_LINK_IDS).split(","); - for(String link:links ){ - Id id = Id.createLinkId(link); - if(linkslist.containsKey(id)) { - double freeFlowLength = linkslist.get(id).getLength(); - double freeFlowSpeed = linkslist.get(id).getFreespeed(); + for (String linkId : links) { + Link link = linksMap.get(Id.createLinkId(linkId)); + if (link != null) { + double freeFlowLength = link.getLength(); + double freeFlowSpeed = link.getFreespeed(); freeFlowDuration += freeFlowLength / freeFlowSpeed; } } } - if(hoursTraveled > freeFlowDuration ) { //discarding negative values - averageVehicleDelay += numOfPassangers * (hoursTraveled - freeFlowDuration); + if (hoursTraveled > freeFlowDuration) { //discarding negative values + averageVehicleDelay += numOfPassengers * (hoursTraveled - freeFlowDuration); totalVehicleTrafficDelay += (hoursTraveled - freeFlowDuration); } } - if(numOfPassangers > seatingCapacity){ - int numOfStandingPeople = numOfPassangers - seatingCapacity; - busCrowding += hoursTraveled * numOfStandingPeople ; + if(AgentSimToPhysSimPlanConverter.BUS.equalsIgnoreCase(mode)) { + numOfPathTraversalsWithBusMode++; + if (numOfPassengers > seatingCapacity) { + int numOfStandingPeople = numOfPassengers - seatingCapacity; + busCrowding += hoursTraveled * numOfStandingPeople; + } } } } @Override public void resetStats() { + numOfPathTraversalsWithBusMode = 0; countOfVehicle = 0; averageVehicleDelay = 0.0; totalVehicleTrafficDelay = 0.0; @@ -77,15 +82,15 @@ public void resetStats() { @Override public Map getSummaryStats() { - Map summaryStats = secondsTraveledByVehicleType.entrySet().stream().collect(Collectors.toMap( + Map summaryStats = secondsTraveledByVehicleType.entrySet().stream().collect(Collectors.toMap( e -> "vehicleHoursTraveled_" + e.getKey(), - e -> e.getValue()/3600.0 + e -> e.getValue() / 3600.0 )); - summaryStats.put("averageVehicleDelayPerTrip" , (averageVehicleDelay / countOfVehicle)); - summaryStats.put("totalHoursOfVehicleTrafficDelay" , totalVehicleTrafficDelay / 3600); - summaryStats.put("busCrowding" , busCrowding/3600); - return summaryStats; + summaryStats.put("averageVehicleDelayPerTrip", (averageVehicleDelay / countOfVehicle)); + summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); + summaryStats.put("busCrowding", busCrowding / 3600 / numOfPathTraversalsWithBusMode); + return summaryStats; } } From 25b3fd92c56e7012e823c52d0d76e531c206eb80 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:03:19 +0500 Subject: [PATCH 13/30] renamed to totalNetCost --- .../beam/analysis/summary/PersonCostAnalysis.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java index fdcfdf23c1c..8b1688aef25 100644 --- a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java +++ b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java @@ -11,8 +11,8 @@ public class PersonCostAnalysis implements IterationSummaryAnalysis { private Map personCostByCostType = new HashMap<>(); private String[] costTypes = {"Cost","Subsidy","Toll"}; - int numberOfTrips = 0; - double totalCost = 0.0; + private int numberOfTrips = 0; + double totalNetCost = 0.0; @Override public void processStats(Event event) { @@ -23,14 +23,14 @@ public void processStats(Event event) { for(String costType : costTypes){ if(costType.equals("Cost")){ cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_NET_COST)); - totalCost += cost; + totalNetCost += cost; }else if(costType.equals("Subsidy")){ cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_SUBSIDY)); }else if(costType.equals("Toll")) { cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_TOLL_COST)); } String statType = String.format("total%s_%s", costType, mode); - personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); + personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); } } if (event instanceof PersonDepartureEvent || event.getEventType().equalsIgnoreCase(PersonDepartureEvent.EVENT_TYPE)){ @@ -43,12 +43,12 @@ public void processStats(Event event) { public void resetStats() { personCostByCostType.clear(); numberOfTrips = 0; - totalCost = 0; + totalNetCost = 0; } @Override public Map getSummaryStats() { - personCostByCostType.put("averageTripExpenditure", totalCost/numberOfTrips); + personCostByCostType.put("averageTripExpenditure", totalNetCost /numberOfTrips); return personCostByCostType; } } From 624d95c622dc43092e3cd997dd5fc8e30f550a09 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:03:53 +0500 Subject: [PATCH 14/30] fixed warnings --- .../analysis/summary/PersonCostAnalysis.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java index 8b1688aef25..beb98a4e9a6 100644 --- a/src/main/java/beam/analysis/summary/PersonCostAnalysis.java +++ b/src/main/java/beam/analysis/summary/PersonCostAnalysis.java @@ -9,31 +9,35 @@ import java.util.Map; public class PersonCostAnalysis implements IterationSummaryAnalysis { - private Map personCostByCostType = new HashMap<>(); - private String[] costTypes = {"Cost","Subsidy","Toll"}; + private Map personCostByCostType = new HashMap<>(); + private String[] costTypes = {"Cost", "Subsidy", "Toll"}; private int numberOfTrips = 0; - double totalNetCost = 0.0; + private double totalNetCost = 0.0; @Override public void processStats(Event event) { - if (event instanceof PersonCostEvent || event.getEventType().equalsIgnoreCase(PersonCostEvent.EVENT_TYPE)){ + if (event instanceof PersonCostEvent || event.getEventType().equalsIgnoreCase(PersonCostEvent.EVENT_TYPE)) { Map attributes = event.getAttributes(); String mode = attributes.get(PersonCostEvent.ATTRIBUTE_MODE); Double cost = 0.0; - for(String costType : costTypes){ - if(costType.equals("Cost")){ - cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_NET_COST)); - totalNetCost += cost; - }else if(costType.equals("Subsidy")){ - cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_SUBSIDY)); - }else if(costType.equals("Toll")) { - cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_TOLL_COST)); + for (String costType : costTypes) { + switch (costType) { + case "Cost": + cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_NET_COST)); + totalNetCost += cost; + break; + case "Subsidy": + cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_SUBSIDY)); + break; + case "Toll": + cost = Double.parseDouble(attributes.get(PersonCostEvent.ATTRIBUTE_TOLL_COST)); + break; } String statType = String.format("total%s_%s", costType, mode); personCostByCostType.merge(statType, cost, (d1, d2) -> d1 + d2); } } - if (event instanceof PersonDepartureEvent || event.getEventType().equalsIgnoreCase(PersonDepartureEvent.EVENT_TYPE)){ + if (event instanceof PersonDepartureEvent || event.getEventType().equalsIgnoreCase(PersonDepartureEvent.EVENT_TYPE)) { numberOfTrips++; } @@ -48,7 +52,7 @@ public void resetStats() { @Override public Map getSummaryStats() { - personCostByCostType.put("averageTripExpenditure", totalNetCost /numberOfTrips); + personCostByCostType.put("averageTripExpenditure", totalNetCost / numberOfTrips); return personCostByCostType; } } From 73d33928c56bc81b58ed42d48494d837b9f816a4 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:10:58 +0500 Subject: [PATCH 15/30] reset ptWaiting against personId --- .../java/beam/analysis/plots/RideHailWaitingAnalysis.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index beacf8f7c86..0428f1ccd4c 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -206,8 +206,9 @@ public void processStats(Event event) { rideHailWaiting.remove(_personId); } // added summary stats for averagePTWaitingTime - if(ptWaiting.containsKey(personId.toString()) && eventAttributes.get("vehicle").contains("body")) { - averagePTWaitingTime += event.getTime() - ptWaiting.get(personId.toString()); + if(ptWaiting.containsKey(_personId) && eventAttributes.get("vehicle").contains("body")) { + averagePTWaitingTime += event.getTime() - ptWaiting.get(_personId); + ptWaiting.remove(_personId); } } } From 360b39eb6f268b687728b800ebf0ccf51fc625b1 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:34:44 +0500 Subject: [PATCH 16/30] fixed average and update labels --- .../analysis/plots/RideHailWaitingAnalysis.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 0428f1ccd4c..06c8c376f28 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -3,9 +3,7 @@ import beam.agentsim.events.ModeChoiceEvent; import beam.analysis.IterationSummaryAnalysis; import beam.analysis.plots.modality.RideHailDistanceRowModel; -import beam.sim.OutputDataDescription; import beam.sim.config.BeamConfig; -import beam.utils.OutputDataDescriptor; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.data.category.CategoryDataset; @@ -129,7 +127,8 @@ private double[][] buildModesFrequencyDataset(Map> private Map> hoursTimesMap = new HashMap<>(); private double waitTimeSum = 0; //sum of all wait times experienced by customers private int rideHailCount = 0; //later used to calculate average wait time experienced by customers - private double averagePTWaitingTime = 0.0; + private double totalPTWaitingTime = 0.0; + private int numOfTrips = 0; private final StatsComputation, Map>>, Tuple>, double[][]>> statComputation; private static int numberOfTimeBins = 30; @@ -150,8 +149,9 @@ public RideHailWaitingAnalysis(StatsComputation, Map getSummaryStats(){ return new HashMap() {{ - put("averageRideHailWaitTime" , waitTimeSum / rideHailCount); - put("averagePTWaitingTime" , averagePTWaitingTime / 3600); + put("averageRideHailWaitTimeInSec" , waitTimeSum / rideHailCount); + put("averagePTWaitingTimeInSec" , totalPTWaitingTime / numOfTrips); }}; } From 1ae9793d837628822425807c7198bc55e5ddbafc Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:40:38 +0500 Subject: [PATCH 17/30] hoursTraveled should be renamed to travelDurationInSec, as this is not in hours --- .../analysis/summary/VehicleTravelTimeAnalysis.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 3219d313ac3..c67c1b2e267 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -30,12 +30,12 @@ public void processStats(Event event) { if (event instanceof PathTraversalEvent || event.getEventType().equalsIgnoreCase(PathTraversalEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); String mode = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_MODE); - double hoursTraveled = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - + double travelDurationInSec = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_DEPARTURE_TIME))); int numOfPassengers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); int seatingCapacity = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_SEATING_CAPACITY)); - secondsTraveledByVehicleType.merge(mode, hoursTraveled, (d1, d2) -> d1 + d2); + secondsTraveledByVehicleType.merge(mode, travelDurationInSec, (d1, d2) -> d1 + d2); if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)) { countOfVehicle++; @@ -54,9 +54,9 @@ public void processStats(Event event) { } } } - if (hoursTraveled > freeFlowDuration) { //discarding negative values - averageVehicleDelay += numOfPassengers * (hoursTraveled - freeFlowDuration); - totalVehicleTrafficDelay += (hoursTraveled - freeFlowDuration); + if (travelDurationInSec > freeFlowDuration) { //discarding negative values + averageVehicleDelay += numOfPassengers * (travelDurationInSec - freeFlowDuration); + totalVehicleTrafficDelay += (travelDurationInSec - freeFlowDuration); } } @@ -64,7 +64,7 @@ public void processStats(Event event) { numOfPathTraversalsWithBusMode++; if (numOfPassengers > seatingCapacity) { int numOfStandingPeople = numOfPassengers - seatingCapacity; - busCrowding += hoursTraveled * numOfStandingPeople; + busCrowding += travelDurationInSec * numOfStandingPeople; } } } From 272523128ad1753fb1a468662141c6a921165e06 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:41:38 +0500 Subject: [PATCH 18/30] remove / 3600 for busCrowding --- .../java/beam/analysis/summary/VehicleTravelTimeAnalysis.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index c67c1b2e267..e4706b01c13 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -89,7 +89,7 @@ public Map getSummaryStats() { summaryStats.put("averageVehicleDelayPerTrip", (averageVehicleDelay / countOfVehicle)); summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); - summaryStats.put("busCrowding", busCrowding / 3600 / numOfPathTraversalsWithBusMode); + summaryStats.put("busCrowding", busCrowding / numOfPathTraversalsWithBusMode); return summaryStats; } From 7a160a33f81dc6b60231c90d875143a7ebab55ee Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 06:46:12 +0500 Subject: [PATCH 19/30] fixed hard coding of modes --- .../java/beam/analysis/plots/RideHailWaitingAnalysis.java | 6 ++++-- .../physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 06c8c376f28..996f31a0d0f 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -3,6 +3,7 @@ import beam.agentsim.events.ModeChoiceEvent; import beam.analysis.IterationSummaryAnalysis; import beam.analysis.plots.modality.RideHailDistanceRowModel; +import beam.router.Modes; import beam.sim.config.BeamConfig; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; @@ -163,13 +164,14 @@ public void processStats(Event event) { Map eventAttributes = event.getAttributes(); if (event instanceof ModeChoiceEvent) { String mode = eventAttributes.get("mode"); - if (mode.equalsIgnoreCase("ride_hail")) { + + if (Modes.BeamMode.RIDE_HAIL.value().equalsIgnoreCase(mode)) { ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) event; Id personId = modeChoiceEvent.getPersonId(); rideHailWaiting.put(personId.toString(), event); } - if (mode.equalsIgnoreCase("walk_transit")) { + if (Modes.BeamMode.WALK_TRANSIT.value().equalsIgnoreCase(mode)) { ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) event; Id personId = modeChoiceEvent.getPersonId(); diff --git a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java index 33f35189555..863b21af09b 100755 --- a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java +++ b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java @@ -9,6 +9,7 @@ import beam.analysis.via.EventWriterXML_viaCompatible; import beam.calibration.impl.example.CountsObjectiveFunction; import beam.router.BeamRouter; +import beam.router.Modes; import beam.sim.BeamServices; import beam.sim.config.BeamConfig; import beam.sim.metrics.MetricsSupport; @@ -53,8 +54,8 @@ */ public class AgentSimToPhysSimPlanConverter implements BasicEventHandler, MetricsSupport, IterationStatsProvider { - public static final String CAR = "car"; - public static final String BUS = "bus"; + public static final String CAR = Modes.BeamMode.CAR.value(); + public static final String BUS = Modes.BeamMode.BUS.value(); private static final String DUMMY_ACTIVITY = "DummyActivity"; private static PhyssimCalcLinkStats linkStatsGraph; private static PhyssimCalcLinkSpeedStats linkSpeedStatsGraph; From 476eb7596e8c3bf4f80e100aa024681bd7eae4c6 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 07:02:32 +0500 Subject: [PATCH 20/30] fixed hard coding of modes --- .../java/beam/analysis/plots/RideHailWaitingAnalysis.java | 7 +++++-- .../physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 996f31a0d0f..12c82cb3c99 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -28,6 +28,9 @@ */ public class RideHailWaitingAnalysis implements GraphAnalysis, IterationSummaryAnalysis { + public static final String RIDE_HAIL = "ride_hail"; + public static final String WALK_TRANSIT = "walk_transit"; + public RideHailWaitingAnalysis(StatsComputation, Map>>, Tuple>, double[][]>> statComputation) { this.statComputation = statComputation; } @@ -165,13 +168,13 @@ public void processStats(Event event) { if (event instanceof ModeChoiceEvent) { String mode = eventAttributes.get("mode"); - if (Modes.BeamMode.RIDE_HAIL.value().equalsIgnoreCase(mode)) { + if (mode.equalsIgnoreCase(RIDE_HAIL)) { ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) event; Id personId = modeChoiceEvent.getPersonId(); rideHailWaiting.put(personId.toString(), event); } - if (Modes.BeamMode.WALK_TRANSIT.value().equalsIgnoreCase(mode)) { + if (mode.equalsIgnoreCase(WALK_TRANSIT)) { ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) event; Id personId = modeChoiceEvent.getPersonId(); diff --git a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java index 863b21af09b..33f35189555 100755 --- a/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java +++ b/src/main/java/beam/physsim/jdeqsim/AgentSimToPhysSimPlanConverter.java @@ -9,7 +9,6 @@ import beam.analysis.via.EventWriterXML_viaCompatible; import beam.calibration.impl.example.CountsObjectiveFunction; import beam.router.BeamRouter; -import beam.router.Modes; import beam.sim.BeamServices; import beam.sim.config.BeamConfig; import beam.sim.metrics.MetricsSupport; @@ -54,8 +53,8 @@ */ public class AgentSimToPhysSimPlanConverter implements BasicEventHandler, MetricsSupport, IterationStatsProvider { - public static final String CAR = Modes.BeamMode.CAR.value(); - public static final String BUS = Modes.BeamMode.BUS.value(); + public static final String CAR = "car"; + public static final String BUS = "bus"; private static final String DUMMY_ACTIVITY = "DummyActivity"; private static PhyssimCalcLinkStats linkStatsGraph; private static PhyssimCalcLinkSpeedStats linkSpeedStatsGraph; From 65e326d9618afe8a968e98a6b5d600672446d86c Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 07:05:47 +0500 Subject: [PATCH 21/30] rename _person --- .../plots/RideHailWaitingAnalysis.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 12c82cb3c99..a9255601afb 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -185,36 +185,33 @@ public void processStats(Event event) { PersonEntersVehicleEvent personEntersVehicleEvent = (PersonEntersVehicleEvent) event; Id personId = personEntersVehicleEvent.getPersonId(); - String _personId = personId.toString(); + String pId = personId.toString(); // This rideHailVehicle check is put here again to remove the non rideHail vehicleId which were coming due the // another occurrence of modeChoice event because of replanning event. if (rideHailWaiting.containsKey(personId.toString()) && eventAttributes.get("vehicle").contains("rideHailVehicle")) { - ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) rideHailWaiting.get(_personId); + ModeChoiceEvent modeChoiceEvent = (ModeChoiceEvent) rideHailWaiting.get(pId); double difference = personEntersVehicleEvent.getTime() - modeChoiceEvent.getTime(); processRideHailWaitingTimes(modeChoiceEvent, difference); // Building the RideHailWaitingIndividualStat List - String __vehicleId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_VEHICLE); - String __personId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_PERSON); - RideHailWaitingIndividualStat rideHailWaitingIndividualStat = new RideHailWaitingIndividualStat(); rideHailWaitingIndividualStat.time = modeChoiceEvent.getTime(); - rideHailWaitingIndividualStat.personId = __personId; - rideHailWaitingIndividualStat.vehicleId = __vehicleId; + rideHailWaitingIndividualStat.personId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_PERSON); + rideHailWaitingIndividualStat.vehicleId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_VEHICLE);; rideHailWaitingIndividualStat.waitingTime = difference; rideHailWaitingIndividualStatList.add(rideHailWaitingIndividualStat); // Remove the personId from the list of ModeChoiceEvent - rideHailWaiting.remove(_personId); + rideHailWaiting.remove(pId); } // added summary stats for totalPTWaitingTime - if(ptWaiting.containsKey(_personId) && eventAttributes.get("vehicle").contains("body")) { - totalPTWaitingTime += event.getTime() - ptWaiting.get(_personId); + if(ptWaiting.containsKey(pId) && eventAttributes.get("vehicle").contains("body")) { + totalPTWaitingTime += event.getTime() - ptWaiting.get(pId); numOfTrips++; - ptWaiting.remove(_personId); + ptWaiting.remove(pId); } } } From 9cc03016259b583ccf9c19018710bc4e7f13435d Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Fri, 28 Dec 2018 07:07:54 +0500 Subject: [PATCH 22/30] fixed warnings and format --- .../plots/RideHailWaitingAnalysis.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index a9255601afb..002019ff57f 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -3,7 +3,6 @@ import beam.agentsim.events.ModeChoiceEvent; import beam.analysis.IterationSummaryAnalysis; import beam.analysis.plots.modality.RideHailDistanceRowModel; -import beam.router.Modes; import beam.sim.config.BeamConfig; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; @@ -35,7 +34,7 @@ public RideHailWaitingAnalysis(StatsComputation, Map, Map>>, Tuple>, double[][]>> { + public static class WaitingStatsComputation implements StatsComputation, Map>>, Tuple>, double[][]>> { @Override public Tuple>, double[][]> compute(Tuple, Map>> stat) { @@ -138,7 +137,7 @@ private double[][] buildModesFrequencyDataset(Map> private static int numberOfTimeBins = 30; public RideHailWaitingAnalysis(StatsComputation, Map>>, Tuple>, double[][]>> statComputation, - BeamConfig beamConfig){ + BeamConfig beamConfig) { this.statComputation = statComputation; this.writeGraph = beamConfig.beam().outputs().writeGraphs(); final int timeBinSize = beamConfig.beam().outputs().stats().binSize(); @@ -199,7 +198,7 @@ public void processStats(Event event) { RideHailWaitingIndividualStat rideHailWaitingIndividualStat = new RideHailWaitingIndividualStat(); rideHailWaitingIndividualStat.time = modeChoiceEvent.getTime(); rideHailWaitingIndividualStat.personId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_PERSON); - rideHailWaitingIndividualStat.vehicleId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_VEHICLE);; + rideHailWaitingIndividualStat.vehicleId = eventAttributes.get(PersonEntersVehicleEvent.ATTRIBUTE_VEHICLE); rideHailWaitingIndividualStat.waitingTime = difference; rideHailWaitingIndividualStatList.add(rideHailWaitingIndividualStat); @@ -208,7 +207,7 @@ public void processStats(Event event) { rideHailWaiting.remove(pId); } // added summary stats for totalPTWaitingTime - if(ptWaiting.containsKey(pId) && eventAttributes.get("vehicle").contains("body")) { + if (ptWaiting.containsKey(pId) && eventAttributes.get("vehicle").contains("body")) { totalPTWaitingTime += event.getTime() - ptWaiting.get(pId); numOfTrips++; ptWaiting.remove(pId); @@ -236,10 +235,10 @@ public void createGraph(IterationEndsEvent event) throws IOException { } @Override - public Map getSummaryStats(){ + public Map getSummaryStats() { return new HashMap() {{ - put("averageRideHailWaitTimeInSec" , waitTimeSum / rideHailCount); - put("averagePTWaitingTimeInSec" , totalPTWaitingTime / numOfTrips); + put("averageRideHailWaitTimeInSec", waitTimeSum / rideHailCount); + put("averagePTWaitingTimeInSec", totalPTWaitingTime / numOfTrips); }}; } @@ -272,7 +271,7 @@ private void writeRideHailWaitingIndividualStatCSV(int iteration) { private void processRideHailWaitingTimes(Event event, double waitingTime) { int hour = GraphsStatsAgentSimEventsListener.getEventHour(event.getTime()); - waitingTime = waitingTime/60; + waitingTime = waitingTime / 60; List timeList = hoursTimesMap.get(hour); if (timeList == null) { @@ -356,9 +355,9 @@ private List getLegends(List categories) { for (Double category : categories) { double legend = getRoundedCategoryUpperBound(category); - if(legend > 60 ) + if (legend > 60) legends.add("60+"); - else{ + else { legends.add(category.intValue() + "min"); } From 28c7be61d66ee46fae9ba92308ef2cd12b60035b Mon Sep 17 00:00:00 2001 From: rajnikant Date: Sat, 29 Dec 2018 04:48:53 +0530 Subject: [PATCH 23/30] create summary stats for average vehicle delay for motorized leg. (#1095) --- .../summary/VehicleTravelTimeAnalysis.java | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index e4706b01c13..d67d3567da0 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -5,7 +5,9 @@ import beam.physsim.jdeqsim.AgentSimToPhysSimPlanConverter; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.events.ActivityStartEvent; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; import org.matsim.api.core.v01.network.Link; import java.util.HashMap; @@ -15,11 +17,19 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private Map secondsTraveledByVehicleType = new HashMap<>(); private Scenario scenario; - private int countOfVehicle = 0; - private double averageVehicleDelay = 0.0; + private int countOfHomeVehicle = 0; + private int countOfWorkVehicle = 0; + private int countOfSecondaryVehicle = 0; private double totalVehicleTrafficDelay = 0.0; private double busCrowding = 0.0; + private double averageVehicleDelayWork = 0.0; + private double averageVehicleDelayHome = 0.0; + private double averageVehicleDelaySecondary = 0.0; private long numOfPathTraversalsWithBusMode = 0; + private Map vehicleIdDelay = new HashMap<>(); + private Map personIdDelay = new HashMap<>(); + private static final String work = "Work"; + private static final String home = "Home"; public VehicleTravelTimeAnalysis(Scenario scenario) { this.scenario = scenario; @@ -38,7 +48,6 @@ public void processStats(Event event) { secondsTraveledByVehicleType.merge(mode, travelDurationInSec, (d1, d2) -> d1 + d2); if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)) { - countOfVehicle++; double freeFlowDuration = 0.0; Map, ? extends Link> linksMap; @@ -55,12 +64,16 @@ public void processStats(Event event) { } } if (travelDurationInSec > freeFlowDuration) { //discarding negative values - averageVehicleDelay += numOfPassengers * (travelDurationInSec - freeFlowDuration); + if(AgentSimToPhysSimPlanConverter.CAR.equalsIgnoreCase(mode)){ + String vehicleID = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_VEHICLE_ID); + double averageVehicleDelay = numOfPassengers * (travelDurationInSec - freeFlowDuration); + vehicleIdDelay.put(vehicleID, averageVehicleDelay); + } totalVehicleTrafficDelay += (travelDurationInSec - freeFlowDuration); } } - if(AgentSimToPhysSimPlanConverter.BUS.equalsIgnoreCase(mode)) { + if (AgentSimToPhysSimPlanConverter.BUS.equalsIgnoreCase(mode)) { numOfPathTraversalsWithBusMode++; if (numOfPassengers > seatingCapacity) { int numOfStandingPeople = numOfPassengers - seatingCapacity; @@ -68,16 +81,53 @@ public void processStats(Event event) { } } } + + if (event instanceof PersonLeavesVehicleEvent || event.getEventType().equalsIgnoreCase(PersonLeavesVehicleEvent.EVENT_TYPE)) { + Map eventAttributes = event.getAttributes(); + String vehicleID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_VEHICLE); + if (vehicleIdDelay.containsKey(vehicleID)) { + String personID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_PERSON); + personIdDelay.put(personID, vehicleIdDelay.get(vehicleID)); + vehicleIdDelay.remove(vehicleID); + } + } + + if (event instanceof ActivityStartEvent || event.getEventType().equalsIgnoreCase(ActivityStartEvent.EVENT_TYPE)) { + Map eventAttributes = event.getAttributes(); + String personId = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_PERSON); + if(personIdDelay.containsKey(personId)){ + String actType = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_ACTTYPE); + if(actType.equals(work)){ + averageVehicleDelayWork += personIdDelay.get(personId); + countOfWorkVehicle++; + } + if(actType.equals(home)){ + averageVehicleDelayHome += personIdDelay.get(personId); + countOfHomeVehicle++; + } + else{ + averageVehicleDelaySecondary += personIdDelay.get(personId); + countOfSecondaryVehicle++; + } + personIdDelay.remove(personId); + } + } } @Override public void resetStats() { numOfPathTraversalsWithBusMode = 0; - countOfVehicle = 0; - averageVehicleDelay = 0.0; + countOfHomeVehicle = 0; + countOfWorkVehicle = 0; + countOfSecondaryVehicle = 0; totalVehicleTrafficDelay = 0.0; busCrowding = 0.0; + averageVehicleDelayWork = 0.0; + averageVehicleDelayHome = 0.0; + averageVehicleDelaySecondary = 0.0; secondsTraveledByVehicleType.clear(); + vehicleIdDelay.clear(); + personIdDelay.clear(); } @Override @@ -87,10 +137,11 @@ public Map getSummaryStats() { e -> e.getValue() / 3600.0 )); - summaryStats.put("averageVehicleDelayPerTrip", (averageVehicleDelay / countOfVehicle)); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_work", countOfWorkVehicle !=0 ? averageVehicleDelayWork/countOfWorkVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", countOfHomeVehicle !=0 ? averageVehicleDelayHome/countOfHomeVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", countOfSecondaryVehicle !=0 ? averageVehicleDelaySecondary/countOfSecondaryVehicle : 0); summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); summaryStats.put("busCrowding", busCrowding / numOfPathTraversalsWithBusMode); return summaryStats; } - } From 1050166e71641d16cdbf26714deeba0f1dce0a9d Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Sat, 29 Dec 2018 05:10:45 +0500 Subject: [PATCH 24/30] fixed numOfTimesBusTaken in busCrowding --- .../summary/VehicleTravelTimeAnalysis.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index d67d3567da0..7753af34021 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -10,7 +10,9 @@ import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; import org.matsim.api.core.v01.network.Link; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -25,11 +27,12 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private double averageVehicleDelayWork = 0.0; private double averageVehicleDelayHome = 0.0; private double averageVehicleDelaySecondary = 0.0; - private long numOfPathTraversalsWithBusMode = 0; private Map vehicleIdDelay = new HashMap<>(); private Map personIdDelay = new HashMap<>(); private static final String work = "Work"; private static final String home = "Home"; + private long numOfTimesBusTaken = 0; + private List buses = new ArrayList<>(); public VehicleTravelTimeAnalysis(Scenario scenario) { this.scenario = scenario; @@ -73,26 +76,26 @@ public void processStats(Event event) { } } - if (AgentSimToPhysSimPlanConverter.BUS.equalsIgnoreCase(mode)) { - numOfPathTraversalsWithBusMode++; + if(AgentSimToPhysSimPlanConverter.BUS.equalsIgnoreCase(mode)) { + buses.add(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_VEHICLE_ID)); if (numOfPassengers > seatingCapacity) { int numOfStandingPeople = numOfPassengers - seatingCapacity; busCrowding += travelDurationInSec * numOfStandingPeople; } } - } - - if (event instanceof PersonLeavesVehicleEvent || event.getEventType().equalsIgnoreCase(PersonLeavesVehicleEvent.EVENT_TYPE)) { + } else if (event instanceof PersonLeavesVehicleEvent || event.getEventType().equalsIgnoreCase(PersonLeavesVehicleEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); - String vehicleID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_VEHICLE); - if (vehicleIdDelay.containsKey(vehicleID)) { - String personID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_PERSON); - personIdDelay.put(personID, vehicleIdDelay.get(vehicleID)); - vehicleIdDelay.remove(vehicleID); + String vehicleId = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_VEHICLE); + if(buses.contains(vehicleId)) { + numOfTimesBusTaken++; } - } - if (event instanceof ActivityStartEvent || event.getEventType().equalsIgnoreCase(ActivityStartEvent.EVENT_TYPE)) { + if (vehicleIdDelay.containsKey(vehicleId)) { + String personID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_PERSON); + personIdDelay.put(personID, vehicleIdDelay.get(vehicleId)); + vehicleIdDelay.remove(vehicleId); + } + } else if (event instanceof ActivityStartEvent || event.getEventType().equalsIgnoreCase(ActivityStartEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); String personId = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_PERSON); if(personIdDelay.containsKey(personId)){ @@ -116,7 +119,7 @@ public void processStats(Event event) { @Override public void resetStats() { - numOfPathTraversalsWithBusMode = 0; + numOfTimesBusTaken = 0; countOfHomeVehicle = 0; countOfWorkVehicle = 0; countOfSecondaryVehicle = 0; @@ -128,6 +131,7 @@ public void resetStats() { secondsTraveledByVehicleType.clear(); vehicleIdDelay.clear(); personIdDelay.clear(); + buses.clear(); } @Override @@ -141,7 +145,7 @@ public Map getSummaryStats() { summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", countOfHomeVehicle !=0 ? averageVehicleDelayHome/countOfHomeVehicle : 0); summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", countOfSecondaryVehicle !=0 ? averageVehicleDelaySecondary/countOfSecondaryVehicle : 0); summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); - summaryStats.put("busCrowding", busCrowding / numOfPathTraversalsWithBusMode); + summaryStats.put("busCrowding", busCrowding / numOfTimesBusTaken); return summaryStats; } } From 76e0ef44618a2a91e3a223b57472f31bf83142a7 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Sat, 29 Dec 2018 05:31:08 +0500 Subject: [PATCH 25/30] changed buses list to set --- .../beam/analysis/summary/VehicleTravelTimeAnalysis.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 7753af34021..1089f9b5fd6 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -10,10 +10,7 @@ import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; import org.matsim.api.core.v01.network.Link; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { @@ -32,7 +29,7 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private static final String work = "Work"; private static final String home = "Home"; private long numOfTimesBusTaken = 0; - private List buses = new ArrayList<>(); + private Set buses = new HashSet<>(); public VehicleTravelTimeAnalysis(Scenario scenario) { this.scenario = scenario; From c16754570de966a096db80306f19e45603cf2a53 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Sun, 30 Dec 2018 16:59:12 +0500 Subject: [PATCH 26/30] fixed averageVehicleDelay --- .../summary/VehicleTravelTimeAnalysis.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 1089f9b5fd6..6370c7c2741 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -3,10 +3,13 @@ import beam.agentsim.events.PathTraversalEvent; import beam.analysis.IterationSummaryAnalysis; import beam.physsim.jdeqsim.AgentSimToPhysSimPlanConverter; +import com.google.common.collect.Lists; +import org.apache.commons.collections4.ListUtils; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.events.ActivityStartEvent; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; import org.matsim.api.core.v01.network.Link; @@ -24,20 +27,27 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private double averageVehicleDelayWork = 0.0; private double averageVehicleDelayHome = 0.0; private double averageVehicleDelaySecondary = 0.0; - private Map vehicleIdDelay = new HashMap<>(); private Map personIdDelay = new HashMap<>(); + private Map> personsByVehicleIds = new HashMap<>(); private static final String work = "Work"; private static final String home = "Home"; private long numOfTimesBusTaken = 0; private Set buses = new HashSet<>(); + public VehicleTravelTimeAnalysis(Scenario scenario) { this.scenario = scenario; } @Override public void processStats(Event event) { - if (event instanceof PathTraversalEvent || event.getEventType().equalsIgnoreCase(PathTraversalEvent.EVENT_TYPE)) { + if (event instanceof PersonEntersVehicleEvent || event.getEventType().equalsIgnoreCase(PersonEntersVehicleEvent.EVENT_TYPE)) { + Map eventAttributes = event.getAttributes(); + String vehicleId = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_VEHICLE); + String personId = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_PERSON); + + personsByVehicleIds.merge(vehicleId, Lists.newArrayList(personId), ListUtils::union); + } else if (event instanceof PathTraversalEvent || event.getEventType().equalsIgnoreCase(PathTraversalEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); String mode = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_MODE); double travelDurationInSec = (Double.parseDouble(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_ARRIVAL_TIME)) - @@ -45,7 +55,7 @@ public void processStats(Event event) { int numOfPassengers = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_NUM_PASS)); int seatingCapacity = Integer.parseInt(eventAttributes.get(PathTraversalEvent.ATTRIBUTE_SEATING_CAPACITY)); - secondsTraveledByVehicleType.merge(mode, travelDurationInSec, (d1, d2) -> d1 + d2); + secondsTraveledByVehicleType.merge(mode, travelDurationInSec, Double::sum); if (AgentSimToPhysSimPlanConverter.isPhyssimMode(mode)) { @@ -64,11 +74,14 @@ public void processStats(Event event) { } } if (travelDurationInSec > freeFlowDuration) { //discarding negative values - if(AgentSimToPhysSimPlanConverter.CAR.equalsIgnoreCase(mode)){ - String vehicleID = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_VEHICLE_ID); - double averageVehicleDelay = numOfPassengers * (travelDurationInSec - freeFlowDuration); - vehicleIdDelay.put(vehicleID, averageVehicleDelay); + + String vehicleID = eventAttributes.get(PathTraversalEvent.ATTRIBUTE_VEHICLE_ID); + double averageVehicleDelay = travelDurationInSec - freeFlowDuration; + + if(personsByVehicleIds.containsKey(vehicleID)) { + personsByVehicleIds.get(vehicleID).forEach(personId -> personIdDelay.merge(personId, averageVehicleDelay, Double::sum)); } + totalVehicleTrafficDelay += (travelDurationInSec - freeFlowDuration); } } @@ -86,12 +99,7 @@ public void processStats(Event event) { if(buses.contains(vehicleId)) { numOfTimesBusTaken++; } - - if (vehicleIdDelay.containsKey(vehicleId)) { - String personID = eventAttributes.get(PersonLeavesVehicleEvent.ATTRIBUTE_PERSON); - personIdDelay.put(personID, vehicleIdDelay.get(vehicleId)); - vehicleIdDelay.remove(vehicleId); - } + personsByVehicleIds.remove(vehicleId); } else if (event instanceof ActivityStartEvent || event.getEventType().equalsIgnoreCase(ActivityStartEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); String personId = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_PERSON); @@ -126,7 +134,7 @@ public void resetStats() { averageVehicleDelayHome = 0.0; averageVehicleDelaySecondary = 0.0; secondsTraveledByVehicleType.clear(); - vehicleIdDelay.clear(); + personsByVehicleIds.clear(); personIdDelay.clear(); buses.clear(); } @@ -134,7 +142,7 @@ public void resetStats() { @Override public Map getSummaryStats() { Map summaryStats = secondsTraveledByVehicleType.entrySet().stream().collect(Collectors.toMap( - e -> "vehicleHoursTraveled_" + e.getKey(), + e -> "vehicleHoursTraveled_" + e.getKey(), e -> e.getValue() / 3600.0 )); From 7306232fb2ac5a3f7b5176feb8112d9d475bbc1c Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Sun, 30 Dec 2018 23:39:53 +0500 Subject: [PATCH 27/30] fixed delay stat variable name --- .../summary/VehicleTravelTimeAnalysis.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 6370c7c2741..e7856bf26f5 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -24,9 +24,9 @@ public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private int countOfSecondaryVehicle = 0; private double totalVehicleTrafficDelay = 0.0; private double busCrowding = 0.0; - private double averageVehicleDelayWork = 0.0; - private double averageVehicleDelayHome = 0.0; - private double averageVehicleDelaySecondary = 0.0; + private double totalVehicleDelayWork = 0.0; + private double totalVehicleDelayHome = 0.0; + private double totalVehicleDelaySecondary = 0.0; private Map personIdDelay = new HashMap<>(); private Map> personsByVehicleIds = new HashMap<>(); private static final String work = "Work"; @@ -106,15 +106,15 @@ public void processStats(Event event) { if(personIdDelay.containsKey(personId)){ String actType = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_ACTTYPE); if(actType.equals(work)){ - averageVehicleDelayWork += personIdDelay.get(personId); + totalVehicleDelayWork += personIdDelay.get(personId); countOfWorkVehicle++; } if(actType.equals(home)){ - averageVehicleDelayHome += personIdDelay.get(personId); + totalVehicleDelayHome += personIdDelay.get(personId); countOfHomeVehicle++; } else{ - averageVehicleDelaySecondary += personIdDelay.get(personId); + totalVehicleDelaySecondary += personIdDelay.get(personId); countOfSecondaryVehicle++; } personIdDelay.remove(personId); @@ -130,9 +130,9 @@ public void resetStats() { countOfSecondaryVehicle = 0; totalVehicleTrafficDelay = 0.0; busCrowding = 0.0; - averageVehicleDelayWork = 0.0; - averageVehicleDelayHome = 0.0; - averageVehicleDelaySecondary = 0.0; + totalVehicleDelayWork = 0.0; + totalVehicleDelayHome = 0.0; + totalVehicleDelaySecondary = 0.0; secondsTraveledByVehicleType.clear(); personsByVehicleIds.clear(); personIdDelay.clear(); @@ -146,9 +146,9 @@ public Map getSummaryStats() { e -> e.getValue() / 3600.0 )); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_work", countOfWorkVehicle !=0 ? averageVehicleDelayWork/countOfWorkVehicle : 0); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", countOfHomeVehicle !=0 ? averageVehicleDelayHome/countOfHomeVehicle : 0); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", countOfSecondaryVehicle !=0 ? averageVehicleDelaySecondary/countOfSecondaryVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_work", countOfWorkVehicle !=0 ? totalVehicleDelayWork /countOfWorkVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", countOfHomeVehicle !=0 ? totalVehicleDelayHome /countOfHomeVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", countOfSecondaryVehicle !=0 ? totalVehicleDelaySecondary /countOfSecondaryVehicle : 0); summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); summaryStats.put("busCrowding", busCrowding / numOfTimesBusTaken); return summaryStats; From 67b966950ed5502df437804aace225c711fb3e4a Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Mon, 31 Dec 2018 00:21:44 +0500 Subject: [PATCH 28/30] fixed delay stats calculation --- .../analysis/summary/VehicleTravelTimeAnalysis.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 041b13b4183..4ddd197a817 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -17,6 +17,8 @@ import java.util.*; import java.util.stream.Collectors; +import static java.lang.Math.max; + public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { private Map secondsTraveledByVehicleType = new HashMap<>(); private scala.collection.Set> vehicleTypes; @@ -151,11 +153,11 @@ public Map getSummaryStats() { vehicleTypes.foreach(vt -> summaryStats.merge("vehicleHoursTraveled_" + vt.toString(),0D, Double::sum)); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_work", countOfWorkVehicle !=0 ? totalVehicleDelayWork /countOfWorkVehicle : 0); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", countOfHomeVehicle !=0 ? totalVehicleDelayHome /countOfHomeVehicle : 0); - summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", countOfSecondaryVehicle !=0 ? totalVehicleDelaySecondary /countOfSecondaryVehicle : 0); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_work", totalVehicleDelayWork / max(countOfWorkVehicle, 1)); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_home", totalVehicleDelayHome / max(countOfHomeVehicle, 1)); + summaryStats.put("averageVehicleDelayPerMotorizedLeg_secondary", totalVehicleDelaySecondary / max(countOfSecondaryVehicle, 1)); summaryStats.put("totalHoursOfVehicleTrafficDelay", totalVehicleTrafficDelay / 3600); - summaryStats.put("busCrowding", busCrowding / numOfTimesBusTaken); + summaryStats.put("busCrowding", busCrowding / max(numOfTimesBusTaken, 1)); return summaryStats; } } From e8512854a5779807bf3d4722bae6ea071017cb86 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Mon, 31 Dec 2018 00:26:55 +0500 Subject: [PATCH 29/30] fix n/0 issue --- .../java/beam/analysis/plots/RideHailWaitingAnalysis.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java index 002019ff57f..13154d1f5ff 100644 --- a/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java +++ b/src/main/java/beam/analysis/plots/RideHailWaitingAnalysis.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.util.*; +import static java.lang.Integer.max; + /** * @author abid */ @@ -237,8 +239,8 @@ public void createGraph(IterationEndsEvent event) throws IOException { @Override public Map getSummaryStats() { return new HashMap() {{ - put("averageRideHailWaitTimeInSec", waitTimeSum / rideHailCount); - put("averagePTWaitingTimeInSec", totalPTWaitingTime / numOfTrips); + put("averageRideHailWaitTimeInSec", waitTimeSum / max(rideHailCount, 1)); + put("averagePTWaitingTimeInSec", totalPTWaitingTime / max(numOfTrips, 1)); }}; } From b0bc67efc873c17b0c968a9d2e928224173f9dd5 Mon Sep 17 00:00:00 2001 From: Zeeshan Bilal Date: Mon, 31 Dec 2018 22:51:28 +0500 Subject: [PATCH 30/30] fix totalVehicles for averageDelays --- .../summary/VehicleTravelTimeAnalysis.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java index 4ddd197a817..2b2e23f6a76 100644 --- a/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java +++ b/src/main/java/beam/analysis/summary/VehicleTravelTimeAnalysis.java @@ -20,24 +20,27 @@ import static java.lang.Math.max; public class VehicleTravelTimeAnalysis implements IterationSummaryAnalysis { + + private static final String work = "Work"; + private static final String home = "Home"; + private Map secondsTraveledByVehicleType = new HashMap<>(); private scala.collection.Set> vehicleTypes; private Scenario scenario; + + private double totalVehicleTrafficDelay = 0.0; + private Set buses = new HashSet<>(); + private double busCrowding = 0.0; + private long numOfTimesBusTaken = 0; + private int countOfHomeVehicle = 0; private int countOfWorkVehicle = 0; private int countOfSecondaryVehicle = 0; - private double totalVehicleTrafficDelay = 0.0; - private double busCrowding = 0.0; private double totalVehicleDelayWork = 0.0; private double totalVehicleDelayHome = 0.0; private double totalVehicleDelaySecondary = 0.0; - private Map personIdDelay = new HashMap<>(); + private Map> personIdDelays = new HashMap<>(); private Map> personsByVehicleIds = new HashMap<>(); - private static final String work = "Work"; - private static final String home = "Home"; - private long numOfTimesBusTaken = 0; - private Set buses = new HashSet<>(); - public VehicleTravelTimeAnalysis(Scenario scenario, scala.collection.Set> vehicleTypes) { this.scenario = scenario; @@ -84,7 +87,7 @@ public void processStats(Event event) { double averageVehicleDelay = travelDurationInSec - freeFlowDuration; if(personsByVehicleIds.containsKey(vehicleID)) { - personsByVehicleIds.get(vehicleID).forEach(personId -> personIdDelay.merge(personId, averageVehicleDelay, Double::sum)); + personsByVehicleIds.get(vehicleID).forEach(personId -> personIdDelays.merge(personId, Lists.newArrayList(averageVehicleDelay), ListUtils::union)); } totalVehicleTrafficDelay += (travelDurationInSec - freeFlowDuration); @@ -108,21 +111,23 @@ public void processStats(Event event) { } else if (event instanceof ActivityStartEvent || event.getEventType().equalsIgnoreCase(ActivityStartEvent.EVENT_TYPE)) { Map eventAttributes = event.getAttributes(); String personId = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_PERSON); - if(personIdDelay.containsKey(personId)){ + if(personIdDelays.containsKey(personId)){ + double totalDelay = personIdDelays.get(personId).stream().reduce(Double::sum).orElse(0D); + int totalVehicles = personIdDelays.get(personId).size(); String actType = eventAttributes.get(ActivityStartEvent.ATTRIBUTE_ACTTYPE); if(actType.equals(work)){ - totalVehicleDelayWork += personIdDelay.get(personId); - countOfWorkVehicle++; + totalVehicleDelayWork += totalDelay; + countOfWorkVehicle += totalVehicles; } if(actType.equals(home)){ - totalVehicleDelayHome += personIdDelay.get(personId); - countOfHomeVehicle++; + totalVehicleDelayHome += totalDelay; + countOfHomeVehicle += totalVehicles; } else{ - totalVehicleDelaySecondary += personIdDelay.get(personId); - countOfSecondaryVehicle++; + totalVehicleDelaySecondary += totalDelay; + countOfSecondaryVehicle += totalVehicles; } - personIdDelay.remove(personId); + personIdDelays.remove(personId); } } } @@ -140,7 +145,6 @@ public void resetStats() { totalVehicleDelaySecondary = 0.0; secondsTraveledByVehicleType.clear(); personsByVehicleIds.clear(); - personIdDelay.clear(); buses.clear(); }