Skip to content

Commit

Permalink
Fixed not using current tour personal vehicle. Fixed trip/tour field.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaopen committed Mar 25, 2022
1 parent 6d063a9 commit de1684a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,24 @@ trait ChoosesMode {
def bodyVehiclePersonId: PersonIdWithActorRef = PersonIdWithActorRef(id, self)

onTransition { case _ -> ChoosingMode =>
val correctedCurrentTripMode = nextStateData match {
case choosesModeData: ChoosesModeData =>
val availableModes: Seq[BeamMode] = availableModesForPerson(matsimPlan.getPerson, choosesModeData.excludeModes)
val nextAct = nextActivity(choosesModeData.personData).get
correctCurrentTripModeAccordingToRules(
choosesModeData.personData.currentTripMode,
choosesModeData.personData,
nextAct,
availableModes
)
case _ => None
}
val choosesModeData: ChoosesModeData = nextStateData.asInstanceOf[ChoosesModeData]
val availableModes: Seq[BeamMode] = availableModesForPerson(matsimPlan.getPerson, choosesModeData.excludeModes)
val nextAct = nextActivity(choosesModeData.personData).get
val correctedCurrentTripMode = correctCurrentTripModeAccordingToRules(
choosesModeData.personData.currentTripMode,
choosesModeData.personData,
nextAct,
availableModes
)
nextStateData match {
// If I am already on a tour in a vehicle, only that vehicle is available to me
case data: ChoosesModeData
if data.personData.currentTourPersonalVehicle.isDefined && (
data.personData.currentTourMode.exists(mode => Modes.isPersonalVehicleMode(mode))
&& isLastTripWithinTour(data.personData, nextActivity(data.personData).get)
) =>
if data.personData.currentTourPersonalVehicle.isDefined &&
(
data.personData.currentTourMode.exists(mode => mode == CAR || mode == BIKE) ||
data.personData.currentTourMode.exists(mode => mode == DRIVE_TRANSIT || mode == BIKE_TRANSIT)
&& isLastTripWithinTour(data.personData, nextAct)
) =>
self ! MobilityStatusResponse(
Vector(beamVehicles(data.personData.currentTourPersonalVehicle.get)),
getCurrentTriggerIdOrGenerate
Expand All @@ -165,21 +164,21 @@ trait ChoosesMode {
requestAvailableVehicles(
vehicleFleets,
data.currentLocation,
_experiencedBeamPlan.activities(data.personData.currentActivityIndex),
currentActivity(data.personData),
Some(VehicleCategory.Car)
) pipeTo self
case Some(BIKE | BIKE_TRANSIT) =>
requestAvailableVehicles(
vehicleFleets,
data.currentLocation,
_experiencedBeamPlan.activities(data.personData.currentActivityIndex),
currentActivity(data.personData),
Some(VehicleCategory.Bike)
) pipeTo self
case _ =>
requestAvailableVehicles(
vehicleFleets,
data.currentLocation,
_experiencedBeamPlan.activities(data.personData.currentActivityIndex)
currentActivity(data.personData)
) pipeTo self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ trait DrivesVehicle[T <: DrivingData] extends BeamAgent[T] with Stash with Expon
case Event(
TriggerWithId(EndLegTrigger(tick), triggerId),
LiterallyDrivingData(data: BasePersonData, _, _)
) if data.currentTripMode.contains(HOV2_TELEPORTATION) || data.currentTourMode.contains(HOV3_TELEPORTATION) =>
) if data.currentTripMode.contains(HOV2_TELEPORTATION) || data.currentTripMode.contains(HOV3_TELEPORTATION) =>
updateLatestObservedTick(tick)

val dataForNextLegOrActivity: BasePersonData = data.copy(
Expand Down
8 changes: 5 additions & 3 deletions src/test/scala/beam/integration/SingleModeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import beam.router.RouteHistory
import beam.sflight.RouterForTest
import beam.sim.common.GeoUtilsImpl
import beam.sim.{BeamHelper, BeamMobsim, RideHailFleetInitializerProvider}
import beam.utils.SimRunnerForTest
import beam.utils.{MathUtils, SimRunnerForTest}
import beam.utils.TestConfigUtils.testConfig
import com.typesafe.config.ConfigFactory
import org.matsim.api.core.v01.events.{ActivityEndEvent, Event, PersonDepartureEvent, PersonEntersVehicleEvent}
Expand Down Expand Up @@ -269,8 +269,10 @@ class SingleModeSpec
val personDepartureEvents = events.collect { case event: PersonDepartureEvent => event }
personDepartureEvents should not be empty
val regularPersonEvents = filterOutProfessionalDriversAndCavs(personDepartureEvents)
val (drive, others) = regularPersonEvents.map(_.getLegMode).partition(_ == "car")
others.size should be < (0.02 * drive.size).toInt
val othersCount = regularPersonEvents.count(_.getLegMode != "car")
withClue("Majority of agents should use cars. Other modes take place when no car available.") {
othersCount should be < MathUtils.doubleToInt(0.02 * regularPersonEvents.size)
}
}
}

Expand Down

0 comments on commit de1684a

Please sign in to comment.