Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hl/#2063 pooling metrics (a fix) #2095

Merged
merged 7 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 58 additions & 47 deletions src/main/java/beam/analysis/summary/RideHailSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,84 @@

public class RideHailSummary implements IterationSummaryAnalysis {

private int countOfPoolTrips = 0;
private int countOfSoloPoolTrips = 0;
private int countOfMultiPassengerPoolTrips = 0;
private int countOfOnePassengerPoolTrips = 0;
private int countOfSoloTrips = 0;
private int countOfUnmatchedPoolRequests = 0;
private int countOfUnmatchedSoloRequests = 0;
private double sumDeadheadingDistanceTraveled = 0.0;
private double sumRideHailDistanceTraveled = 0.0;

private Map<Id<Person>, String> latestModeChoiceAttempt = new HashMap<Id<Person>, String>();
private Map<Id<Person>, Boolean> personSharedTrip = new HashMap<Id<Person>, Boolean>();
private Map<Id<Vehicle>, Integer> withinPooledTrip = new HashMap<Id<Vehicle>, Integer>();
private Map<Id<Person>, String> modeChoiceAttempt = new HashMap<Id<Person>, String>();
private Map<Id<Person>, Boolean> personHasSharedATrip = new HashMap<Id<Person>, Boolean>();
private Map<Id<Vehicle>, Integer> passengersPerVeh = new HashMap<Id<Vehicle>, Integer>();
private Map<Id<Person>, Id<Vehicle>> personInVeh = new HashMap<Id<Person>, Id<Vehicle>>();

@Override
public void processStats(Event event) {
switch(event.getEventType()) {
case "ModeChoice":
ModeChoiceEvent modeChoice = (ModeChoiceEvent)event;
if(modeChoice.mode.contains("ride_hail")) {
latestModeChoiceAttempt.put(modeChoice.personId, modeChoice.mode);
} else if(latestModeChoiceAttempt.containsKey(modeChoice.personId) &&
!latestModeChoiceAttempt.get(modeChoice.personId).contains("unmatched")) {
String previousMode = latestModeChoiceAttempt.get(modeChoice.personId);
latestModeChoiceAttempt.put(modeChoice.personId, previousMode + "_unmatched");
if(modeChoice.getPersonId().toString().startsWith("rideHailAgent")) {
// do nothing, agent is driving (this test might be unnecessary)
} else if(modeChoice.mode.startsWith("ride_hail")) {
modeChoiceAttempt.put(modeChoice.personId, modeChoice.mode);
} else if(modeChoiceAttempt.containsKey(modeChoice.personId) &&
!modeChoiceAttempt.get(modeChoice.personId).endsWith("unmatched")) {
String previousMode = modeChoiceAttempt.get(modeChoice.personId);
modeChoiceAttempt.put(modeChoice.personId, previousMode + "_unmatched");
}
break;
case "PersonEntersVehicle":
PersonEntersVehicleEvent personEntersVehicle = (PersonEntersVehicleEvent)event;
Id<Vehicle> idVehE = personEntersVehicle.getVehicleId();
Id<Person> idPerE = personEntersVehicle.getPersonId();
if(!latestModeChoiceAttempt.containsKey(idPerE)) return;
String modeChosenL = latestModeChoiceAttempt.get(idPerE);
if(modeChosenL.contains("unmatched")) {
if(modeChosenL.contains("ride_hail_pooled")) countOfUnmatchedPoolRequests++;
else countOfUnmatchedSoloRequests++;
if(!modeChoiceAttempt.containsKey(personEntersVehicle.getPersonId())) return;
String modeChosenL = modeChoiceAttempt.get(personEntersVehicle.getPersonId());
if(modeChosenL.endsWith("unmatched")) {
if(modeChosenL.startsWith("ride_hail_pooled"))
countOfUnmatchedPoolRequests++;
else
countOfUnmatchedSoloRequests++;
} else if(!personEntersVehicle.getVehicleId().toString().startsWith("rideHailVehicle")) {
// do nothing, agent is walking
} else if(modeChosenL.equals("ride_hail_pooled")){
personSharedTrip.put(idPerE, false);
withinPooledTrip.putIfAbsent(idVehE, 0);
withinPooledTrip.put(idVehE, withinPooledTrip.get(idVehE) + 1);
if(withinPooledTrip.get(idVehE) > 1) personSharedTrip.put(idPerE, true);
personInVeh.put(personEntersVehicle.getPersonId(), personEntersVehicle.getVehicleId());
int prev_pool = passengersPerVeh.getOrDefault(personEntersVehicle.getVehicleId(), 0);
passengersPerVeh.put(personEntersVehicle.getVehicleId(), prev_pool + 1);
for (Map.Entry<Id<Person>, Id<Vehicle>> entry : personInVeh.entrySet()) {
if(entry.getValue() != personEntersVehicle.getVehicleId())
continue;
if(!personHasSharedATrip.getOrDefault(entry.getKey(), false)){
personHasSharedATrip.put(entry.getKey(), passengersPerVeh.get(personEntersVehicle.getVehicleId()) > 1);
}
}
} else {
countOfSoloTrips++;
}
break;
case "PersonLeavesVehicle":
PersonLeavesVehicleEvent personLeavesVehicle = (PersonLeavesVehicleEvent)event;
Id<Vehicle> idVehL = personLeavesVehicle.getVehicleId();
Id<Person> idPerL = personLeavesVehicle.getPersonId();
if(!idVehL.toString().contains("rideHailVehicle") || idPerL.toString().contains("rideHailAgent")) return;
String chosenModeL = latestModeChoiceAttempt.get(personLeavesVehicle.getPersonId());
if(! (chosenModeL==null ) && chosenModeL.equals("ride_hail_pooled")) {
if(withinPooledTrip.get(idVehL) > 1) personSharedTrip.put(idPerL, true);
if(personSharedTrip.get(idPerL)) {
countOfPoolTrips++;
if(!modeChoiceAttempt.containsKey(personLeavesVehicle.getPersonId())) return;
String chosenModeL = modeChoiceAttempt.get(personLeavesVehicle.getPersonId());
if(!personLeavesVehicle.getVehicleId().toString().startsWith("rideHailVehicle")) {
// do nothing, agent probably walking, although it shouldn't happen here
} else if(chosenModeL.equals("ride_hail_pooled")) {
if(passengersPerVeh.get(personLeavesVehicle.getVehicleId()) > 1)
personHasSharedATrip.put(personLeavesVehicle.getPersonId(), true);
if(personHasSharedATrip.get(personLeavesVehicle.getPersonId())) {
countOfMultiPassengerPoolTrips++;
} else {
countOfSoloPoolTrips++;
countOfOnePassengerPoolTrips++;
}
personHasSharedATrip.remove(personLeavesVehicle.getPersonId());
personInVeh.remove(personLeavesVehicle.getPersonId());
passengersPerVeh.put(personLeavesVehicle.getVehicleId(), passengersPerVeh.get(personLeavesVehicle.getVehicleId()) - 1);
}
latestModeChoiceAttempt.remove(personLeavesVehicle.getPersonId());
personSharedTrip.remove(personLeavesVehicle.getPersonId());
if (idVehL != null && withinPooledTrip.get(idVehL) != null) {
withinPooledTrip.put(idVehL, withinPooledTrip.get(idVehL) - 1);
}
modeChoiceAttempt.remove(personLeavesVehicle.getPersonId());
break;
case "PathTraversal":
PathTraversalEvent pathTraversal = (PathTraversalEvent)event;
if(!pathTraversal.vehicleId().toString().contains("rideHailVehicle")) return;
if(pathTraversal.numberOfPassengers() < 1) sumDeadheadingDistanceTraveled += pathTraversal.legLength();
if(!pathTraversal.vehicleId().toString().startsWith("rideHailVehicle")) return;
if(pathTraversal.numberOfPassengers() < 1)
sumDeadheadingDistanceTraveled += pathTraversal.legLength();
sumRideHailDistanceTraveled += pathTraversal.legLength();
break;
default:
Expand All @@ -90,16 +101,16 @@ public void processStats(Event event) {

@Override
public void resetStats() {
countOfPoolTrips = 0;
countOfSoloPoolTrips = 0;
countOfMultiPassengerPoolTrips = 0;
countOfOnePassengerPoolTrips = 0;
countOfSoloTrips = 0;
countOfUnmatchedPoolRequests = 0;
countOfUnmatchedSoloRequests = 0;
sumDeadheadingDistanceTraveled = 0.0;
sumRideHailDistanceTraveled = 0.0;
latestModeChoiceAttempt.clear();
personSharedTrip.clear();
withinPooledTrip.clear();
modeChoiceAttempt.clear();
personHasSharedATrip.clear();
passengersPerVeh.clear();
}

@Override
Expand All @@ -110,12 +121,12 @@ public Map<String, Double> getSummaryStats() {
double unmatchedPerRideHailRequests = 0.0;
double deadheadingPerRideHailTrips = 0.0;

double totPoolTrips = countOfPoolTrips+countOfSoloPoolTrips;
double totPoolTrips = countOfMultiPassengerPoolTrips + countOfOnePassengerPoolTrips;
double totRHTrips = totPoolTrips+countOfSoloTrips;
double totRHUnmatched = countOfUnmatchedPoolRequests+countOfUnmatchedSoloRequests;
double totRHRequests = totRHTrips+totRHUnmatched;
if(totPoolTrips > 0) multiPassengersTripsPerPoolTrips = countOfPoolTrips/totPoolTrips;
if(totRHTrips > 0) multiPassengersTripsPerRideHailTrips = countOfPoolTrips/totRHTrips;
if(totPoolTrips > 0) multiPassengersTripsPerPoolTrips = countOfMultiPassengerPoolTrips /totPoolTrips;
if(totRHTrips > 0) multiPassengersTripsPerRideHailTrips = countOfMultiPassengerPoolTrips /totRHTrips;
if(totRHRequests > 0) unmatchedPerRideHailRequests = totRHUnmatched/totRHRequests;
if(sumRideHailDistanceTraveled > 0) deadheadingPerRideHailTrips = sumDeadheadingDistanceTraveled/sumRideHailDistanceTraveled;
summaryStats.put("RHSummary_multiPassengerTripsPerPoolTrips", multiPassengersTripsPerPoolTrips);
Expand Down
6 changes: 3 additions & 3 deletions test/input/sf-light/urbansim-10k.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include "../common/matsim.conf"
beam.agentsim.simulationName = "urbansim-10k-xml"
beam.agentsim.agentSampleSizeAsFractionOfPopulation = 1.0
beam.agentsim.firstIteration = 0
beam.agentsim.lastIteration = 0
beam.agentsim.lastIteration = 2
beam.agentsim.thresholdForWalkingInMeters = 100
beam.agentsim.timeBinSize = 3600
beam.agentsim.startTime = "00:00:00"
Expand All @@ -27,8 +27,8 @@ beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.car_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.walk_transit_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.drive_transit_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.ride_hail_transit_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.ride_hail_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.ride_hail_pooled_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.ride_hail_intercept = 5.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.ride_hail_pooled_intercept = 20.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.walk_intercept = 0.0
beam.agentsim.agents.modalBehaviors.mulitnomialLogit.params.bike_intercept = 0.0
beam.agentsim.agents.modalBehaviors.lccm.filePath = ${beam.inputDirectory}"/lccm-long.csv"
Expand Down