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

use correct events manager #3896

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/main/scala/beam/agentsim/agents/PersonAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1100,14 +1100,14 @@ class PersonAgent(
stay using updatedData
case Event(UnpluggingVehicle(tick, _, vehicle, _, energyCharged), data: BasePersonData) =>
log.debug(s"Vehicle ${vehicle.id} ended charging and it is not handled by the CNM at tick $tick")
handleReleasingParkingSpot(tick, vehicle, Some(energyCharged), id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, vehicle, Some(energyCharged), id, parkingManager, beamServices, eventsManager)
goto(ProcessingNextLegOrStartActivity) using data
case Event(UnhandledVehicle(tick, _, vehicle, _), data: BasePersonData) =>
log.error(
s"Vehicle ${vehicle.id} is not handled by the CNM at tick $tick. Something is broken." +
s"the agent will now disconnect the vehicle ${currentBeamVehicle.id} to let the simulation continue!"
)
handleReleasingParkingSpot(tick, vehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, vehicle, None, id, parkingManager, beamServices, eventsManager)
goto(ProcessingNextLegOrStartActivity) using data
}

Expand Down
24 changes: 16 additions & 8 deletions src/main/scala/beam/agentsim/agents/parking/ChoosesParking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,20 @@ trait ChoosesParking extends {
s"Vehicle ${vehicle.id} is not handled by the CNM at tick $tick. Something is broken." +
s"the agent will now disconnect the vehicle ${currentBeamVehicle.id} to let the simulation continue!"
)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices, eventsManager)
goto(WaitingToDrive) using data

case Event(UnpluggingVehicle(tick, _, vehicle, _, energy), data: BasePersonData)
if data.enrouteData.isInEnrouteState =>
log.debug(
s"Vehicle ${vehicle.id} [chosen for enroute] ended charging and it is not handled by the CNM at tick $tick"
)
handleReleasingParkingSpot(tick, vehicle, Some(energy), id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, vehicle, Some(energy), id, parkingManager, beamServices, eventsManager)
goto(ReadyToChooseParking) using data

case Event(UnpluggingVehicle(tick, _, vehicle, _, energy), data) =>
log.debug(s"Vehicle ${vehicle.id} ended charging and it is not handled by the CNM at tick $tick")
handleReleasingParkingSpot(tick, vehicle, Some(energy), id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, vehicle, Some(energy), id, parkingManager, beamServices, eventsManager)
releaseTickAndTriggerId()
goto(WaitingToDrive) using data
}
Expand Down Expand Up @@ -326,7 +326,7 @@ trait ChoosesParking extends {
if (data.enrouteData.isInEnrouteState)
ReadyToChooseParking
else {
handleReleasingParkingSpot(tick, vehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, vehicle, None, id, parkingManager, beamServices, eventsManager)
releaseTickAndTriggerId()
WaitingToDrive
}
Expand All @@ -335,7 +335,15 @@ trait ChoosesParking extends {
}

case Event(StateTimeout, data) =>
handleReleasingParkingSpot(getCurrentTick.get, currentBeamVehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(
getCurrentTick.get,
currentBeamVehicle,
None,
id,
parkingManager,
beamServices,
eventsManager
)
releaseTickAndTriggerId()
goto(WaitingToDrive) using data
}
Expand Down Expand Up @@ -380,7 +388,7 @@ trait ChoosesParking extends {
triggerId,
Vector(ScheduleTrigger(StartLegTrigger(nextLeg.startTime, nextLeg), self))
)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices, eventsManager)
goto(WaitingToDrive) using data.copy(enrouteData = EnrouteData())
case _ =>
// Else the stall requires a diversion in travel, calc the new routes (in-vehicle to the stall and walking to the destination)
Expand Down Expand Up @@ -504,7 +512,7 @@ trait ChoosesParking extends {
)
)

handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices, eventsManager)

goto(WaitingToDrive) using data.copy(
currentTrip = Some(EmbodiedBeamTrip(newCurrentTripLegs)),
Expand Down Expand Up @@ -583,7 +591,7 @@ trait ChoosesParking extends {
)
)

handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices)
handleReleasingParkingSpot(tick, currentBeamVehicle, None, id, parkingManager, beamServices, eventsManager)

goto(WaitingToDrive) using data.copy(
currentTrip = Some(EmbodiedBeamTrip(newCurrentTripLegs)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,15 @@ class RideHailAgent(
vehicle.getState
)
}
handleReleasingParkingSpot(tick, currentBeamVehicle, Some(energyCharged), id, parkingManager, beamServices)
handleReleasingParkingSpot(
tick,
currentBeamVehicle,
Some(energyCharged),
id,
parkingManager,
beamServices,
eventsManager
)
}

private def parkAndStartRefueling(stall: ParkingStall, data: RideHailAgentData): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ trait RideHailDepotManager extends {
*/
private def releaseStall(parkingStall: ParkingStall, tick: Int, beamVehicle: BeamVehicle, triggerId: Long): Unit = {
if (parkingStall.chargingPointType.isEmpty) {
ParkingNetworkManager.handleReleasingParkingSpot(tick, beamVehicle, None, this.id, parkingManager, beamServices)
ParkingNetworkManager.handleReleasingParkingSpot(
tick,
beamVehicle,
None,
this.id,
parkingManager,
beamServices,
eventsManager
)
} else {
(chargingNetworkManager ? ChargingUnplugRequest(tick, this.id, beamVehicle, triggerId))
.pipeTo(beamVehicle.getDriver.get)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package beam.agentsim.agents.vehicles

import beam.agentsim.agents.vehicles.FuelType._
import beam.agentsim.agents.vehicles.VehicleCategory.{Class78Tractor, _}
import beam.agentsim.agents.vehicles.VehicleCategory._
import beam.agentsim.infrastructure.charging.ChargingPointType
import org.matsim.api.core.v01.Id

Expand Down Expand Up @@ -85,7 +85,11 @@ object VehicleCategory {
case object Class78Vocational extends VehicleCategory // CLass 7&8 (GVWR 26001-33,000 lbs.)
case object Class78Tractor extends VehicleCategory // Class 7&8 Tractor (GVWR >33,000 lbs.)

def fromString(value: String): VehicleCategory = fromStringOptional(value).get
def fromString(value: String): VehicleCategory =
try { fromStringOptional(value).get }
catch {
case exception: Exception => throw new RuntimeException(f"Can not parse vehicle category: '$value'.", exception)
}

private def fromStringOptional(value: String): Option[VehicleCategory] = {
Vector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import beam.utils.logging.LoggingMessageActor
import beam.utils.metrics.SimpleCounter
import com.typesafe.scalalogging.LazyLogging
import org.matsim.api.core.v01.Id
import org.matsim.core.api.experimental.events.EventsManager
import org.matsim.core.network.NetworkUtils

import scala.concurrent.duration._
Expand Down Expand Up @@ -67,7 +68,8 @@ object ParkingNetworkManager extends LazyLogging {
energyChargedMaybe: Option[Double],
driver: Id[_],
parkingManager: ActorRef,
beamServices: BeamServices
beamServices: BeamServices,
eventsManager: EventsManager
): Unit = {
val stallForLeavingParkingEventMaybe = currentBeamVehicle.stall match {
case Some(stall) =>
Expand All @@ -93,7 +95,7 @@ object ParkingNetworkManager extends LazyLogging {
currentBeamVehicle.emitEmissions(vehicleActivityData, classOf[LeavingParkingEvent], beamServices)
val energyCharge: Double = energyChargedMaybe.getOrElse(0.0)
val score = calculateScore(stall.costInDollars, energyCharge)
beamServices.matsimServices.getEvents.processEvent(
eventsManager.processEvent(
LeavingParkingEvent(
tick,
stall,
Expand Down
20 changes: 18 additions & 2 deletions src/main/scala/beam/agentsim/infrastructure/ScaleUpCharging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,26 @@ trait ScaleUpCharging extends {
log.debug(s"Received EndingRefuelSession: $reply")
case reply @ UnhandledVehicle(tick, personId, vehicle, _) =>
log.error(s"Received UnhandledVehicle: $reply")
handleReleasingParkingSpot(tick, vehicle, None, personId, getParkingManager, getBeamServices)
handleReleasingParkingSpot(
tick,
vehicle,
None,
personId,
getParkingManager,
getBeamServices,
getBeamServices.matsimServices.getEvents
)
case reply @ UnpluggingVehicle(tick, personId, vehicle, _, energyCharged) =>
log.debug(s"Received UnpluggingVehicle: $reply")
handleReleasingParkingSpot(tick, vehicle, Some(energyCharged), personId, getParkingManager, getBeamServices)
handleReleasingParkingSpot(
tick,
vehicle,
Some(energyCharged),
personId,
getParkingManager,
getBeamServices,
getBeamServices.matsimServices.getEvents
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ODVehicleTypeSkimmerSpec extends AnyWordSpecLike with Matchers with BeamHe
.parseString("""
beam.agentsim.lastIteration = 1
beam.agentsim.agents.freight.replanning.disableAfterIteration = 0
beam.router.skim.origin-destination-vehicle-type-skimmer.vehicleCategories = "LightDutyTruck, HeavyDutyTruck"
beam.router.skim.origin-destination-vehicle-type-skimmer.vehicleCategories = "Class456Vocational, Class78Vocational"
""")
.withFallback(testConfig("test/input/beamville/beam-freight.conf"))
.resolve()
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/beam/sim/BeamWarmStartRunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BeamWarmStartRunSpec
"ITERS/it.2/2.skimsFreight_Aggregated.csv.gz",
"ITERS/it.2/2.skimsParking_Aggregated.csv.gz",
"ITERS/it.2/2.skimsTransitCrowding_Aggregated.csv.gz",
"ITERS/it.2/2.skimsEmissions_Aggregated.csv.gz",
"ITERS/it.2/2.linkstats.csv.gz",
"ITERS/it.2/2.plans.csv.gz",
"ITERS/it.2/2.plans.xml.gz",
Expand Down