diff --git a/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala b/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala index dad1bcf79d3..52d14a42123 100755 --- a/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala +++ b/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala @@ -70,7 +70,7 @@ import scala.collection.mutable import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.duration._ -import scala.util.Random +import scala.util.{Random, Try} object RideHailManager { val INITIAL_RIDE_HAIL_LOCATION_HOME = "HOME" @@ -416,34 +416,44 @@ class RideHailManager( writeMetric("beam-run-RH-non-ev-cav", cntnEVCAV) writeMetric("beam-run-RH-non-ev-non-cav", cntnEVnCAV) + private val rideHailResourceAllocationManager = RideHailResourceAllocationManager( + managerConfig.allocationManager.name, + this + ) + + private val rideHailBeamVehicleIdToShiftsOpt = mutable.Map.empty[Id[BeamVehicle], Option[List[Shift]]] + + val numRideHailAgents: Int = initializeRideHailFleet() + if ( beamServices.matsimServices != null && new File( beamServices.matsimServices.getControlerIO.getIterationPath(beamServices.matsimServices.getIterationNumber) ).exists() ) { - rideHailinitialLocationSpatialPlot.writeCSV( - beamServices.matsimServices.getControlerIO - .getIterationFilename(beamServices.matsimServices.getIterationNumber, fileBaseName + ".csv") - ) - - if (beamServices.beamConfig.beam.outputs.writeGraphs) { - rideHailinitialLocationSpatialPlot.writeImage( + Try( + rideHailinitialLocationSpatialPlot.writeCSV( beamServices.matsimServices.getControlerIO - .getIterationFilename(beamServices.matsimServices.getIterationNumber, fileBaseName + ".png") + .getIterationFilename( + beamServices.matsimServices.getIterationNumber, + s"$fileBaseName-${managerConfig.name}.csv" + ) ) + ).recover { case exception => log.error(exception, s"Cannot write $fileBaseName-${managerConfig.name}.csv") } + + if (beamServices.beamConfig.beam.outputs.writeGraphs) { + Try( + rideHailinitialLocationSpatialPlot.writeImage( + beamServices.matsimServices.getControlerIO + .getIterationFilename( + beamServices.matsimServices.getIterationNumber, + s"$fileBaseName-${managerConfig.name}.png" + ) + ) + ).recover { case exception => log.error(exception, s"Cannot write $fileBaseName-${managerConfig.name}.png") } } } - private val rideHailResourceAllocationManager = RideHailResourceAllocationManager( - managerConfig.allocationManager.name, - this - ) - - private val rideHailBeamVehicleIdToShiftsOpt = mutable.Map.empty[Id[BeamVehicle], Option[List[Shift]]] - - val numRideHailAgents: Int = initializeRideHailFleet() - var requestedRideHail: Int = 0 var servedRideHail: Int = 0