diff --git a/src/main/scala/beam/agentsim/agents/PersonAgent.scala b/src/main/scala/beam/agentsim/agents/PersonAgent.scala index 69e2072f265..5df05df283d 100755 --- a/src/main/scala/beam/agentsim/agents/PersonAgent.scala +++ b/src/main/scala/beam/agentsim/agents/PersonAgent.scala @@ -286,6 +286,8 @@ object PersonAgent { case basePersonData: BasePersonData => Some(basePersonData) case _ => None } + + def atHome(activity: Activity): Boolean = activity.getType.equalsIgnoreCase("home") } class PersonAgent( @@ -407,7 +409,7 @@ class PersonAgent( // which is used in place of our real remaining tour distance of 0.0 // which should help encourage residential end-of-day charging val tomorrowFirstLegDistance = - if (nextAct.getType.toLowerCase == "home") { + if (atHome(nextAct)) { findFirstCarLegOfTrip(personData) match { case Some(carLeg) => carLeg.beamLeg.travelPath.distanceInM @@ -497,22 +499,6 @@ class PersonAgent( val tripIndexOfElement = tour .tripIndexOfElement(nextAct) .getOrElse(throw new IllegalArgumentException(s"Element [$nextAct] not found")) - if (tripIndexOfElement == 0 && currentActivity(personData).getType != "Home") - logger.warn( - "~Activity {}, idx {}, id {}, next {}", - currentActivity(personData).getType, - tripIndexOfElement, - id, - nextAct.getType - ) - if (tripIndexOfElement == lastTripIndex && nextAct.getType != "Home") - logger.warn( - "Cur ~Activity {}, idx {}, id {}, next {}", - currentActivity(personData).getType, - tripIndexOfElement, - id, - nextAct.getType - ) (tripIndexOfElement, lastTripIndex) } @@ -1353,7 +1339,7 @@ class PersonAgent( currentTrip = None, restOfCurrentTrip = List(), currentTourPersonalVehicle = None, - currentTourMode = if (activity.getType.equals("Home")) None else data.currentTourMode, + currentTourMode = if (atHome(activity)) None else data.currentTourMode, currentTripMode = None, hasDeparted = false ) @@ -1443,7 +1429,7 @@ class PersonAgent( currentTourPersonalVehicle = currentTourPersonalVehicle match { case Some(personalVehId) => val personalVeh = beamVehicles(personalVehId).asInstanceOf[ActualVehicle].vehicle - if (activity.getType.equals("Home")) { + if (atHome(activity)) { potentiallyChargingBeamVehicles.put(personalVeh.id, beamVehicles(personalVeh.id)) beamVehicles -= personalVeh.id personalVeh.getManager.get ! ReleaseVehicle(personalVeh, triggerId) @@ -1454,7 +1440,7 @@ class PersonAgent( case None => None }, - currentTourMode = if (activity.getType.equals("Home")) None else currentTourMode, + currentTourMode = if (atHome(activity)) None else currentTourMode, currentTripMode = None, hasDeparted = false ) diff --git a/src/main/scala/beam/agentsim/agents/household/HouseholdActor.scala b/src/main/scala/beam/agentsim/agents/household/HouseholdActor.scala index 1c25958ce19..1af1da550b8 100755 --- a/src/main/scala/beam/agentsim/agents/household/HouseholdActor.scala +++ b/src/main/scala/beam/agentsim/agents/household/HouseholdActor.scala @@ -197,8 +197,8 @@ object HouseholdActor { val homeCoordFromPlans = household.members .flatMap(person => person.getSelectedPlan.getPlanElements.asScala.flatMap { - case act: Activity if act.getType == "Home" => Some(act.getCoord) - case _ => None + case act: Activity if PersonAgent.atHome(act) => Some(act.getCoord) + case _ => None } ) .headOption diff --git a/src/main/scala/beam/agentsim/agents/household/HouseholdFleetManager.scala b/src/main/scala/beam/agentsim/agents/household/HouseholdFleetManager.scala index ebd7062290b..a0caffb9bad 100644 --- a/src/main/scala/beam/agentsim/agents/household/HouseholdFleetManager.scala +++ b/src/main/scala/beam/agentsim/agents/household/HouseholdFleetManager.scala @@ -7,6 +7,7 @@ import akka.util.Timeout import beam.agentsim.Resource.NotifyVehicleIdle import beam.agentsim.agents.BeamAgent.Finish import beam.agentsim.agents.InitializeTrigger +import beam.agentsim.agents.PersonAgent.atHome import beam.agentsim.agents.household.HouseholdActor._ import beam.agentsim.agents.household.HouseholdFleetManager.ResolvedParkingResponses import beam.agentsim.agents.modalbehaviors.DrivesVehicle.ActualVehicle @@ -104,7 +105,7 @@ class HouseholdFleetManager( case GetVehicleTypes(triggerId) => sender() ! VehicleTypesResponse(vehicles.values.map(_.beamVehicleType).toSet, triggerId) - case MobilityStatusInquiry(personId, whenWhere, _, requireVehicleCategoryAvailable, triggerId) => + case MobilityStatusInquiry(personId, whenWhere, originActivity, requireVehicleCategoryAvailable, triggerId) => { for { neededVehicleCategory <- requireVehicleCategoryAvailable @@ -157,13 +158,15 @@ class HouseholdFleetManager( } }.getOrElse { availableVehicles = availableVehicles match { - case firstVehicle :: rest => + //in case of replanning because of TRANSIT failure WALK_TRANSIT is used + //but we may want to introduce maxWalkingDistance and check that the agent is close enough to the vehicle + case firstVehicle :: rest if atHome(originActivity) => logger.debug("Vehicle {} is now taken", firstVehicle.id) firstVehicle.becomeDriver(sender) sender() ! MobilityStatusResponse(Vector(ActualVehicle(firstVehicle)), triggerId) rest - case Nil => - logger.debug(s"Not returning vehicle because no default is defined") + case _ => + logger.debug(s"Not returning vehicle because no default is defined or agent is not at home") sender() ! MobilityStatusResponse(Vector(), triggerId) Nil }