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

switch from walk to EMERGENCY(faster walk) as last resort mode #3488 #3512

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion production/sfbay
Submodule sfbay updated 568 files
42 changes: 19 additions & 23 deletions src/main/scala/beam/agentsim/agents/PersonAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import beam.agentsim.agents.modalbehaviors.ChoosesMode.ChoosesModeData
import beam.agentsim.agents.modalbehaviors.DrivesVehicle._
import beam.agentsim.agents.modalbehaviors.{ChoosesMode, DrivesVehicle, ModeChoiceCalculator}
import beam.agentsim.agents.parking.ChoosesParking
import beam.agentsim.agents.parking.ChoosesParking.{
handleReleasingParkingSpot,
ChoosingParkingSpot,
ReleasingParkingSpot
}
import beam.agentsim.agents.parking.ChoosesParking.{ChoosingParkingSpot, ReleasingParkingSpot, handleReleasingParkingSpot}
import beam.agentsim.agents.planning.{BeamPlan, Tour}
import beam.agentsim.agents.ridehail.RideHailManager.TravelProposal
import beam.agentsim.agents.ridehail._
Expand All @@ -34,27 +30,12 @@ import beam.agentsim.scheduler.BeamAgentScheduler.{CompletionNotice, IllegalTrig
import beam.agentsim.scheduler.Trigger.TriggerWithId
import beam.agentsim.scheduler.{BeamAgentSchedulerTimer, Trigger}
import beam.router.Modes.BeamMode
import beam.router.Modes.BeamMode.{
CAR,
CAV,
HOV2_TELEPORTATION,
HOV3_TELEPORTATION,
RIDE_HAIL,
RIDE_HAIL_POOLED,
RIDE_HAIL_TRANSIT,
WALK,
WALK_TRANSIT
}
import beam.router.Modes.BeamMode.{CAR, CAV, EMERGENCY, HOV2_TELEPORTATION, HOV3_TELEPORTATION, RIDE_HAIL, RIDE_HAIL_POOLED, RIDE_HAIL_TRANSIT, WALK, WALK_TRANSIT}
import beam.router.RouteHistory
import beam.router.model.{EmbodiedBeamLeg, EmbodiedBeamTrip}
import beam.router.osm.TollCalculator
import beam.router.skim.ActivitySimSkimmerEvent
import beam.router.skim.event.{
DriveTimeSkimmerEvent,
ODSkimmerEvent,
RideHailSkimmerEvent,
UnmatchedRideHailRequestSkimmerEvent
}
import beam.router.skim.event.{DriveTimeSkimmerEvent, ODSkimmerEvent, RideHailSkimmerEvent, UnmatchedRideHailRequestSkimmerEvent}
import beam.sim.common.GeoUtils
import beam.sim.config.BeamConfig.Beam.Debug
import beam.sim.population.AttributesOfIndividual
Expand Down Expand Up @@ -261,7 +242,22 @@ object PersonAgent {
bodyVehicleId: Id[BeamVehicle],
bodyVehicleTypeId: Id[BeamVehicleType]
): EmbodiedBeamTrip = {
if (trip.tripClassifier != WALK && trip.tripClassifier != WALK_TRANSIT) {
if (trip.tripClassifier != EMERGENCY && trip.tripClassifier != EMERGENCY) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a copy/paste error or something to that extent - as the condition is the same

trip.copy(
legs = trip.legs
.dropRight(1) :+ EmbodiedBeamLeg
.dummyLegAt(
endTime - trip.legs.last.beamLeg.duration,
bodyVehicleId,
isLastLeg = true,
trip.legs.dropRight(1).last.beamLeg.travelPath.endPoint.loc,
EMERGENCY,
bodyVehicleTypeId,
asDriver = true,
trip.legs.last.beamLeg.duration
)
)
} else if (trip.tripClassifier != WALK && trip.tripClassifier != WALK_TRANSIT) {
trip.copy(
legs = trip.legs
.dropRight(1) :+ EmbodiedBeamLeg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import beam.agentsim.infrastructure.{ParkingInquiry, ParkingInquiryResponse, Zon
import beam.agentsim.scheduler.BeamAgentScheduler.{CompletionNotice, ScheduleTrigger}
import beam.router.BeamRouter._
import beam.router.Modes.BeamMode
import beam.router.Modes.BeamMode.{WALK, _}
import beam.router.Modes.BeamMode.{WALK, EMERGENCY, _}
import beam.router.model.{BeamLeg, EmbodiedBeamLeg, EmbodiedBeamTrip}
import beam.router.skim.core.ODSkimmer
import beam.router.skim.event.ODSkimmerFailedTripEvent
Expand Down Expand Up @@ -343,8 +343,8 @@ trait ChoosesMode {
if availableModes.contains(CAR) && replanningIsAvailable =>
Some(mode)
case Some(mode) if availableModes.contains(mode) && replanningIsAvailable => Some(mode)
case Some(mode) if availableModes.contains(mode) => Some(WALK)
case None if !replanningIsAvailable => Some(WALK)
case Some(mode) if availableModes.contains(mode) => Some(EMERGENCY)
case None if !replanningIsAvailable => Some(EMERGENCY)
case _ => None
}

Expand Down Expand Up @@ -469,10 +469,7 @@ trait ChoosesMode {
newlyAvailableBeamVehicles.map(_.streetVehicle) :+ bodyStreetVehicle,
possibleEgressVehicles = dummySharedVehicles
)
case Some(WALK) =>
responsePlaceholders = makeResponsePlaceholders(withRouting = true)
makeRequestWith(withTransit = true, Vector(bodyStreetVehicle))
case Some(WALK_TRANSIT) =>
case Some(WALK | WALK_TRANSIT | EMERGENCY | EMERGENCY_TRANSIT) =>
responsePlaceholders = makeResponsePlaceholders(withRouting = true)
makeRequestWith(withTransit = true, Vector(bodyStreetVehicle))
Xuan-1998 marked this conversation as resolved.
Show resolved Hide resolved
case Some(CAV) =>
Expand Down Expand Up @@ -1355,10 +1352,10 @@ trait ChoosesMode {
)
case _ =>
// Bad things happen but we want them to continue their day, so we signal to downstream that trip should be made to be expensive
val originalWalkTripLeg =
routingResponse.itineraries.find(_.tripClassifier == WALK) match {
case Some(originalWalkTrip) =>
originalWalkTrip.legs.head
val originalEmergencyTripLeg =
routingResponse.itineraries.find(_.tripClassifier == EMERGENCY) match {
case Some(originalEmergencyTrip) =>
originalEmergencyTrip.legs.head
case None =>
RoutingWorker
.createBushwackingTrip(
Expand All @@ -1371,12 +1368,12 @@ trait ChoosesMode {
.legs
.head
}
val expensiveWalkTrip = EmbodiedBeamTrip(
Vector(originalWalkTripLeg.copy(replanningPenalty = 10.0))
val emergencyTrip = EmbodiedBeamTrip(
Vector(originalEmergencyTripLeg.copy(replanningPenalty = 10.0))
)

goto(FinishingModeChoice) using choosesModeData.copy(
pendingChosenTrip = Some(expensiveWalkTrip),
pendingChosenTrip = Some(emergencyTrip),
availableAlternatives = availableAlts
)
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/beam/router/Modes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ object Modes {

case object HOV3_TELEPORTATION extends BeamMode(value = "hov3_teleportation", None, "")

case object EMERGENCY extends BeamMode(value = "emergency", None, "")

// Driving / Automobile-like (hailed rides are a bit of a hybrid)

case object CAR extends BeamMode(value = "car", Some(Left(LegMode.CAR)), TransportMode.car)
Expand Down Expand Up @@ -101,6 +103,13 @@ object Modes {
TransportMode.transit_walk
)

case object EMERGENCY_TRANSIT
extends BeamMode(
value = "emergency_transit",
Some(Right(TransitModes.TRANSIT)),
TransportMode.other
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this EMERGENCY_TRANSIT mode? Why we cannot use just EMERGENCY even if there is a TRANSIT leg in it?

case object DRIVE_TRANSIT
extends BeamMode(
value = "drive_transit",
Expand Down Expand Up @@ -135,13 +144,15 @@ object Modes {
CAV,
WALK,
BIKE,
EMERGENCY,
TRANSIT,
RIDE_HAIL,
RIDE_HAIL_POOLED,
RIDE_HAIL_TRANSIT,
DRIVE_TRANSIT,
WALK_TRANSIT,
BIKE_TRANSIT,
EMERGENCY_TRANSIT,
HOV2_TELEPORTATION,
HOV3_TELEPORTATION
)
Expand Down Expand Up @@ -234,6 +245,7 @@ object Modes {
case BeamMode.TRANSIT => throw new IllegalArgumentException("access vehicle is unknown")
case BeamMode.WALK_TRANSIT => BeamMode.WALK
case BeamMode.DRIVE_TRANSIT => BeamMode.CAR
case BeamMode.EMERGENCY_TRANSIT => BeamMode.EMERGENCY
case BeamMode.RIDE_HAIL_TRANSIT => BeamMode.CAR
case BeamMode.BIKE_TRANSIT => BeamMode.BIKE
case _ => throw new IllegalArgumentException("not a transit mode: " + mode.value)
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/beam/router/model/EmbodiedBeamTrip.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import beam.router.Modes.BeamMode.{
CAR_HOV3,
CAV,
DRIVE_TRANSIT,
EMERGENCY,
EMERGENCY_TRANSIT,
HOV2_TELEPORTATION,
HOV3_TELEPORTATION,
RIDE_HAIL,
Expand Down Expand Up @@ -91,6 +93,7 @@ object EmbodiedBeamTrip {
var hasUsedCar: Boolean = false
var hasUsedBike: Boolean = false
var hasUsedRideHail: Boolean = false
var hasUsedEmergency: Boolean = false
legs.foreach { leg =>
// Any presence of transit makes it transit
if (leg.beamLeg.mode.isTransit) {
Expand All @@ -115,7 +118,10 @@ object EmbodiedBeamTrip {
theMode = leg.beamLeg.mode
} else if (theMode == WALK && leg.beamLeg.mode == BIKE) {
theMode = leg.beamLeg.mode
} else if (theMode == WALK && leg.beamLeg.mode == EMERGENCY) {
theMode = EMERGENCY
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Because we introduce a new possible return value for EmbodiedBeamTrip#tripClassifier then we need to carefully check all the pattern matching on this field to validate that there wouldn't be a MatchError.
  2. Also because EMERGENCY trip is actually a WALK trip. Then we need to check all the places where tripClassifer is compared with WALK (i.e.
    if (trip.tripClassifier != WALK && trip.tripClassifier != WALK_TRANSIT) {
    ) and add these EMERGENCY there.

}
if (leg.beamLeg.mode == EMERGENCY) hasUsedEmergency = true
if (leg.beamLeg.mode == BIKE) hasUsedBike = true
if (leg.beamLeg.mode == CAR) hasUsedCar = true
if (leg.isRideHail) hasUsedRideHail = true
Expand All @@ -126,6 +132,8 @@ object EmbodiedBeamTrip {
DRIVE_TRANSIT
} else if (theMode == TRANSIT && hasUsedBike) {
BIKE_TRANSIT
} else if (theMode == TRANSIT && hasUsedEmergency) {
EMERGENCY_TRANSIT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's safier not to change these method at all. But in this case we wouldn't have EMERGENCY in PathTraversalEvent.

} else if (theMode == TRANSIT && !hasUsedCar) {
WALK_TRANSIT
} else {
Expand Down