From 91ad7a4fbaedea2895d6c831238d5eb92e257def Mon Sep 17 00:00:00 2001 From: Colin Sheppard Date: Mon, 24 Dec 2018 08:33:10 -0800 Subject: [PATCH 1/4] turns into case objects, change delay metric bins --- .../agents/vehicles/BeamVehicle.scala | 84 +++++-------------- .../beam/analysis/DelayMetricAnalysis.scala | 4 +- src/main/scala/beam/sim/common/GeoUtils.scala | 59 +++++++++++++ 3 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala b/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala index 6c7f403a015..3d419125c8e 100755 --- a/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala +++ b/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala @@ -11,6 +11,8 @@ import beam.agentsim.infrastructure.ParkingStall.ChargingType import beam.router.Modes import beam.router.model.BeamLeg import beam.sim.BeamServices +import beam.sim.common.GeoUtils +import beam.sim.common.GeoUtils.{Straight, TurningDirection} import com.typesafe.scalalogging.StrictLogging import org.matsim.api.core.v01.network.{Link, Network} import org.matsim.api.core.v01.{Coord, Id} @@ -178,68 +180,18 @@ object BeamVehicle { ) case class FuelConsumptionData( - linkId: Int, - linkCapacity: Double, - linkLength: Double, - averageSpeed: Double, - freeFlowSpeed: Double, - linkArrivalTime: Long, - vehicleId: String, - vehicleType: BeamVehicleType, - turnAtLinkEnd: String, - numberOfStops: Int + linkId: Int, + linkCapacity: Double, + linkLength: Double, + averageSpeed: Double, + freeFlowSpeed: Double, + linkArrivalTime: Long, + vehicleId: String, + vehicleType: BeamVehicleType, + turnAtLinkEnd: TurningDirection, + numberOfStops: Int ) - /** - * Get the desired direction to be taken , based on the angle between the coordinates - * @param source source coordinates - * @param destination destination coordinates - * @return Direction to be taken ( L / SL / HL / R / HR / SR / S) - */ - def getDirection(source: Coord, destination: Coord): String = { - val radians = computeAngle(source, destination) - radians match { - case _ if radians < 0.174533 || radians >= 6.10865 => "S" // Straight - case _ if radians >= 0.174533 & radians < 1.39626 => "SL" // Soft Left - case _ if radians >= 1.39626 & radians < 1.74533 => "L" // Left - case _ if radians >= 1.74533 & radians < 3.14159 => "HL" // Hard Left - case _ if radians >= 3.14159 & radians < 4.53785 => "HR" // Hard Right - case _ if radians >= 4.53785 & radians < 4.88692 => "R" // Right - case _ if radians >= 4.88692 & radians < 6.10865 => "SR" // Soft Right - case _ => "S" // default => Straight - } - } - - /** - * Generate the vector coordinates from the link nodes - * @param link link in the network - * @return vector coordinates - */ - def vectorFromLink(link: Link): Coord = { - new Coord( - link.getToNode.getCoord.getX - link.getFromNode.getCoord.getX, - link.getToNode.getCoord.getY - link.getFromNode.getCoord.getY - ) - } - - /** - * Computes the angle between two coordinates - * @param source source coordinates - * @param destination destination coordinates - * @return angle between the coordinates (in radians). - */ - def computeAngle(source: Coord, destination: Coord): Double = { - val rad = Math.atan2( - source.getX * destination.getY - source.getY * destination.getX, - source.getX * destination.getX - source.getY * destination.getY - ) - if (rad < 0) { - rad + 3.141593 * 2.0 - } else { - rad - } - } - /** * Organizes the fuel consumption data table * @param beamLeg Instance of beam leg @@ -288,9 +240,13 @@ object BeamVehicle { } val turnAtLinkEnd = currentLink match { case Some(curLink) => - getDirection(vectorFromLink(curLink), vectorFromLink(nextLink.get)) + GeoUtils.getDirection(GeoUtils.vectorFromLink(curLink), GeoUtils.vectorFromLink(nextLink.get)) case None => - "S" + Straight + } + val numStops = turnAtLinkEnd match { + case Straight => 0 + case _ => 1 } FuelConsumptionData( linkId = id, @@ -302,9 +258,7 @@ object BeamVehicle { vehicleId = id.toString, vehicleType = vehicleType, turnAtLinkEnd = turnAtLinkEnd, - numberOfStops = - if (turnAtLinkEnd.equalsIgnoreCase("NA")) 0 - else 1 + numberOfStops = numStops ) }.toList } diff --git a/src/main/scala/beam/analysis/DelayMetricAnalysis.scala b/src/main/scala/beam/analysis/DelayMetricAnalysis.scala index 5379756d9a3..0641189fb1b 100644 --- a/src/main/scala/beam/analysis/DelayMetricAnalysis.scala +++ b/src/main/scala/beam/analysis/DelayMetricAnalysis.scala @@ -35,8 +35,8 @@ class DelayMetricAnalysis @Inject()( private var linkTravelsCount: Map[String, Int] = Map() private var linkAverageDelay: Map[String, DelayInLength] = Map() - private val bins = Array(0, 100, 250, 500, 1000, 2000, 3000) - private val legends = Array("0-100", "100-250", "250-500", "500-1000", "1000-2000", "2000-3000", "3000+") + private val bins = Array(0, 500, 1000, 2000, 3000) + private val legends = Array("0-500", "500-1000", "1000-2000", "2000-3000", "3000+") private val capacitiesDelay = scala.collection.mutable.Map[Int, Double]() val dataset = new DefaultCategoryDataset diff --git a/src/main/scala/beam/sim/common/GeoUtils.scala b/src/main/scala/beam/sim/common/GeoUtils.scala index 0c47692a620..94aa3a0183c 100755 --- a/src/main/scala/beam/sim/common/GeoUtils.scala +++ b/src/main/scala/beam/sim/common/GeoUtils.scala @@ -8,6 +8,7 @@ import com.conveyal.r5.streets.{Split, StreetLayer} import com.google.inject.{ImplementedBy, Inject} import com.vividsolutions.jts.geom.Envelope import org.matsim.api.core.v01.Coord +import org.matsim.api.core.v01.network.Link import org.matsim.core.utils.geometry.transformations.GeotoolsTransformation /** @@ -137,6 +138,64 @@ object GeoUtils { dist } + + sealed trait TurningDirection + case object Straight extends TurningDirection + case object SoftLeft extends TurningDirection + case object Left extends TurningDirection + case object HardLeft extends TurningDirection + case object SoftRight extends TurningDirection + case object Right extends TurningDirection + case object HardRight extends TurningDirection + /** + * Get the desired direction to be taken , based on the angle between the coordinates + * @param source source coordinates + * @param destination destination coordinates + * @return Direction to be taken ( L / SL / HL / R / HR / SR / S) + */ + def getDirection(source: Coord, destination: Coord): TurningDirection = { + val radians = computeAngle(source, destination) + radians match { + case _ if radians < 0.174533 || radians >= 6.10865 => Straight + case _ if radians >= 0.174533 & radians < 1.39626 => SoftLeft + case _ if radians >= 1.39626 & radians < 1.74533 => Left + case _ if radians >= 1.74533 & radians < 3.14159 => HardLeft + case _ if radians >= 3.14159 & radians < 4.53785 => HardRight + case _ if radians >= 4.53785 & radians < 4.88692 => Right + case _ if radians >= 4.88692 & radians < 6.10865 => SoftRight + case _ => Straight + } + } + + /** + * Generate the vector coordinates from the link nodes + * @param link link in the network + * @return vector coordinates + */ + def vectorFromLink(link: Link): Coord = { + new Coord( + link.getToNode.getCoord.getX - link.getFromNode.getCoord.getX, + link.getToNode.getCoord.getY - link.getFromNode.getCoord.getY + ) + } + + /** + * Computes the angle between two coordinates + * @param source source coordinates + * @param destination destination coordinates + * @return angle between the coordinates (in radians). + */ + def computeAngle(source: Coord, destination: Coord): Double = { + val rad = Math.atan2( + source.getX * destination.getY - source.getY * destination.getX, + source.getX * destination.getX - source.getY * destination.getY + ) + if (rad < 0) { + rad + 3.141593 * 2.0 + } else { + rad + } + } } class GeoUtilsImpl @Inject()(override val beamServices: BeamServices) extends GeoUtils {} From 8a4fd037d848351bd526f245f1ad6403d37b7946 Mon Sep 17 00:00:00 2001 From: rajnikant Date: Wed, 2 Jan 2019 23:13:44 +0530 Subject: [PATCH 2/4] change delay metric plot (#1083) * change plot for delay metric * Scala fmt * resolved average delay graph issue * more descriptive titles * space --- .../agents/vehicles/BeamVehicle.scala | 22 +++---- .../beam/analysis/DelayMetricAnalysis.scala | 62 ++++++++++--------- src/main/scala/beam/sim/common/GeoUtils.scala | 11 ++-- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala b/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala index 3d419125c8e..b18d1b4a413 100755 --- a/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala +++ b/src/main/scala/beam/agentsim/agents/vehicles/BeamVehicle.scala @@ -180,16 +180,16 @@ object BeamVehicle { ) case class FuelConsumptionData( - linkId: Int, - linkCapacity: Double, - linkLength: Double, - averageSpeed: Double, - freeFlowSpeed: Double, - linkArrivalTime: Long, - vehicleId: String, - vehicleType: BeamVehicleType, - turnAtLinkEnd: TurningDirection, - numberOfStops: Int + linkId: Int, + linkCapacity: Double, + linkLength: Double, + averageSpeed: Double, + freeFlowSpeed: Double, + linkArrivalTime: Long, + vehicleId: String, + vehicleType: BeamVehicleType, + turnAtLinkEnd: TurningDirection, + numberOfStops: Int ) /** @@ -246,7 +246,7 @@ object BeamVehicle { } val numStops = turnAtLinkEnd match { case Straight => 0 - case _ => 1 + case _ => 1 } FuelConsumptionData( linkId = id, diff --git a/src/main/scala/beam/analysis/DelayMetricAnalysis.scala b/src/main/scala/beam/analysis/DelayMetricAnalysis.scala index 0641189fb1b..5a09936d4d2 100644 --- a/src/main/scala/beam/analysis/DelayMetricAnalysis.scala +++ b/src/main/scala/beam/analysis/DelayMetricAnalysis.scala @@ -10,12 +10,14 @@ import beam.router.Modes.BeamMode.CAR import beam.sim.BeamServices import beam.sim.config.BeamConfig import com.google.inject.Inject -import org.jfree.data.category.{CategoryDataset, DefaultCategoryDataset} +import org.jfree.chart.plot.CategoryPlot +import org.jfree.data.category.DefaultCategoryDataset import org.matsim.core.api.experimental.events.EventsManager import org.matsim.core.controler.OutputDirectoryHierarchy import org.matsim.core.controler.events.IterationEndsEvent import scala.collection.mutable.Map +import collection.JavaConverters._ case class DelayInLength(delay: Double, length: Int) @@ -38,15 +40,14 @@ class DelayMetricAnalysis @Inject()( private val bins = Array(0, 500, 1000, 2000, 3000) private val legends = Array("0-500", "500-1000", "1000-2000", "2000-3000", "3000+") private val capacitiesDelay = scala.collection.mutable.Map[Int, Double]() - val dataset = new DefaultCategoryDataset - + private val delayAveragePerKMDataset = new DefaultCategoryDataset + private val delayTotalByLinkCapacityDataset = new DefaultCategoryDataset private val fileName = "delayTotalByLinkCapacity" - private val xAxisName = "capacity bins" - private val yAxisName = "vehicle delay (hour)" - private val graphTitle = "Delay Metric Analysis" - private val xAxisAverageGraphName = "Iteration(s)" - private val yAxisAverageGraphName = " Average Delay Intensity (sec/km)" - private val averageGraphTitle = "Delay Average per kilometer Analysis" + private val xAxisName = "Iteration (s)" + private val yAxisName = "Total Delay (hour)" + private val graphTitle = "Total Delay by Binned Link Capacity" + private val yAxisAverageGraphName = "Average Delay Intensity (sec/km)" + private val averageGraphTitle = "Average Delay per Kilometer" var totalTravelTime = 0.0 /** @@ -63,7 +64,7 @@ class DelayMetricAnalysis @Inject()( val linkTravelTimes = pathTraversalEvent.getLinkTravelTimes.split(",").map(_.toInt) assert(linkIds.length == linkTravelTimes.length) - if (linkIds.length > 0) { + if (linkIds.nonEmpty) { for (index <- linkIds.indices) { val linkId = linkIds(index) val freeLength = networkLinks.get(Id.createLinkId(linkId)).getLength @@ -83,10 +84,8 @@ class DelayMetricAnalysis @Inject()( linkTravelsCount(linkId) = linkTravelsCount.getOrElse(linkId, 0) + 1 linkAverageDelay(linkId) = DelayInLength( - (linkTravelsCount.get(linkId).get * cumulativeDelay.get(linkId).get) / cumulativeLength - .get(linkId) - .get, - linkTravelsCount.get(linkId).get + (linkTravelsCount(linkId) * cumulativeDelay(linkId)) / cumulativeLength(linkId), + linkTravelsCount(linkId) ) //calculate average of link delay for further calculating weighted average } else if (freeFlowDelay >= -1) { @@ -110,22 +109,21 @@ class DelayMetricAnalysis @Inject()( totalTravelTime = 0 } - def categoryDelayCapacityDataset(): CategoryDataset = { + def categoryDelayCapacityDataset(iteration: Int): Unit = { cumulativeDelay.keySet foreach { linkId => - val delay = cumulativeDelay.get(linkId).getOrElse(0.0) + val delay = cumulativeDelay.getOrElse(linkId, 0.0) val capacity = networkLinks.get(Id.createLinkId(linkId)).getCapacity + val bin = largeset(capacity) - val capacityDelay = capacitiesDelay.get(bin).getOrElse(0.0) + val capacityDelay = capacitiesDelay.getOrElse(bin, 0.0) capacitiesDelay(bin) = delay + capacityDelay } - val dataset = new DefaultCategoryDataset for (index <- bins.indices) { val bin = bins(index) val capacityBin: Double = capacitiesDelay.getOrElse(bin, 0) - dataset.addValue(capacityBin / 3600, 0, legends(index)) + delayTotalByLinkCapacityDataset.addValue(capacityBin / 3600, legends(index), iteration) } - dataset } // getting the bin for capacity @@ -142,29 +140,33 @@ class DelayMetricAnalysis @Inject()( val avg = linkAverageDelay.values.map(delayInLength => delayInLength.delay).sum / linkAverageDelay.values .map(delayInLength => delayInLength.length) .sum - dataset.addValue(avg, 0, iteration) + delayAveragePerKMDataset.addValue(avg, 0, iteration) } def generateDelayAnalysis(event: IterationEndsEvent): Unit = { - val dataset = categoryDelayCapacityDataset() - if (dataset != null) { - createDelayCapacityGraph(dataset, event.getIteration, fileName) + categoryDelayCapacityDataset(event.getIteration) + if (delayTotalByLinkCapacityDataset != null) { + createDelayCapacityGraph(fileName) } averageDelayDataset(event) createDelayAveragePerKilometerGraph() } - def createDelayCapacityGraph(dataset: CategoryDataset, iterationNumber: Int, fileName: String): Unit = { + def createDelayCapacityGraph(fileName: String): Unit = { val chart = GraphUtils.createStackedBarChartWithDefaultSettings( - dataset, + delayTotalByLinkCapacityDataset, graphTitle, xAxisName, yAxisName, fileName + ".png", - false + true ) + + val plot: CategoryPlot = chart.getCategoryPlot + GraphUtils.plotLegendItems(plot, legends.toList.asJava, delayTotalByLinkCapacityDataset.getRowCount) + val graphImageFile = - GraphsStatsAgentSimEventsListener.CONTROLLER_IO.getIterationFilename(iterationNumber, fileName + ".png") + GraphsStatsAgentSimEventsListener.CONTROLLER_IO.getOutputFilename(fileName + ".png") GraphUtils.saveJFreeChartAsPNG( chart, graphImageFile, @@ -176,9 +178,9 @@ class DelayMetricAnalysis @Inject()( def createDelayAveragePerKilometerGraph(): Unit = { val fileName = controlerIO.getOutputFilename("delayAveragePerKilometer.png") val chart = GraphUtils.createStackedBarChartWithDefaultSettings( - dataset, + delayAveragePerKMDataset, averageGraphTitle, - xAxisAverageGraphName, + xAxisName, yAxisAverageGraphName, fileName, false diff --git a/src/main/scala/beam/sim/common/GeoUtils.scala b/src/main/scala/beam/sim/common/GeoUtils.scala index 94aa3a0183c..7685de189ab 100755 --- a/src/main/scala/beam/sim/common/GeoUtils.scala +++ b/src/main/scala/beam/sim/common/GeoUtils.scala @@ -147,12 +147,13 @@ object GeoUtils { case object SoftRight extends TurningDirection case object Right extends TurningDirection case object HardRight extends TurningDirection + /** - * Get the desired direction to be taken , based on the angle between the coordinates - * @param source source coordinates - * @param destination destination coordinates - * @return Direction to be taken ( L / SL / HL / R / HR / SR / S) - */ + * Get the desired direction to be taken , based on the angle between the coordinates + * @param source source coordinates + * @param destination destination coordinates + * @return Direction to be taken ( L / SL / HL / R / HR / SR / S) + */ def getDirection(source: Coord, destination: Coord): TurningDirection = { val radians = computeAngle(source, destination) radians match { From c64196419d2b9bc7f3f39746d65f227a2be65832 Mon Sep 17 00:00:00 2001 From: Colin Sheppard Date: Fri, 4 Jan 2019 12:44:14 -0800 Subject: [PATCH 3/4] debugging non-deterministic stuck issue --- .../agents/ridehail/RideHailManager.scala | 2 +- ...deHailModifyPassengerScheduleManager.scala | 26 ++++++++++--------- src/main/scala/beam/utils/StuckFinder.scala | 11 +++++--- .../ExponentialLoggerWrapperImpl.scala | 4 +-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala b/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala index 6f0946bb9ca..042447c9f27 100755 --- a/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala +++ b/src/main/scala/beam/agentsim/agents/ridehail/RideHailManager.scala @@ -232,6 +232,7 @@ class RideHailManager( new RideHailModifyPassengerScheduleManager( log, self, + this, scheduler, beamServices.beamConfig ) @@ -525,7 +526,6 @@ class RideHailManager( triggersToSchedule, tick ) - if (modifyPassengerScheduleManager.numberPendingModifyPassengerScheduleAcks == 0) cleanUp case Some(requestId) => // Some here means this is part of a reservation / dispatch of vehicle to a customer log.debug("modifyPassengerScheduleAck received, completing reservation {}", modifyPassengerScheduleAck) diff --git a/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala b/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala index 6c1c3e92751..e6f99210146 100755 --- a/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala +++ b/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala @@ -23,10 +23,11 @@ import org.matsim.vehicles.Vehicle import scala.collection.mutable class RideHailModifyPassengerScheduleManager( - val log: LoggingAdapter, - val rideHailManager: ActorRef, - val scheduler: ActorRef, - val beamConfig: BeamConfig + val log: LoggingAdapter, + val rideHailManagerRef: ActorRef, + val rideHailManager: RideHailManager, + val scheduler: ActorRef, + val beamConfig: BeamConfig ) extends HasTickAndTrigger { val resourcesNotCheckedIn_onlyForDebugging: mutable.Set[Id[Vehicle]] = mutable.Set() @@ -83,7 +84,7 @@ class RideHailModifyPassengerScheduleManager( we send a resume message to the agent. This puts the driver back to state driving, so that the reservation interrupt is received when the agent is in state driving. */ if (reply.isInstanceOf[InterruptedWhileDriving]) { - modifyStatus.rideHailAgent.tell(Resume(), rideHailManager) + modifyStatus.rideHailAgent.tell(Resume(), rideHailManagerRef) } case SingleReservation => // process reservation interrupt confirmation @@ -118,10 +119,10 @@ class RideHailModifyPassengerScheduleManager( modifyStatus: RideHailModifyPassengerScheduleStatus, stopDriving: Boolean ): Unit = { - if (stopDriving) modifyStatus.rideHailAgent.tell(StopDriving(modifyStatus.tick.toInt), rideHailManager) + if (stopDriving) modifyStatus.rideHailAgent.tell(StopDriving(modifyStatus.tick.toInt), rideHailManagerRef) resourcesNotCheckedIn_onlyForDebugging += modifyStatus.vehicleId - modifyStatus.rideHailAgent.tell(modifyStatus.modifyPassengerSchedule, rideHailManager) - modifyStatus.rideHailAgent.tell(Resume(), rideHailManager) + modifyStatus.rideHailAgent.tell(modifyStatus.modifyPassengerSchedule, rideHailManagerRef) + modifyStatus.rideHailAgent.tell(Resume(), rideHailManagerRef) modifyStatus.status = InterruptMessageStatus.MODIFY_PASSENGER_SCHEDULE_SENT } @@ -164,8 +165,9 @@ class RideHailModifyPassengerScheduleManager( allTriggersInWave = triggersToSchedule ++ allTriggersInWave if (numberPendingModifyPassengerScheduleAcks == 0) { - log.debug("sendCompletionAndScheduleNewTimeout 165") + log.debug("sendCompletionAndScheduleNewTimeout from line 167 @ {} with trigger {}", _currentTick, _currentTriggerId) sendCompletionAndScheduleNewTimeout(Reposition, tick) + rideHailManager.cleanUp } } @@ -207,8 +209,8 @@ class RideHailModifyPassengerScheduleManager( // ) // } scheduler.tell( - CompletionNotice(triggerId, allTriggersInWave :+ ScheduleTrigger(timerTrigger, rideHailManager)), - rideHailManager + CompletionNotice(triggerId, allTriggersInWave :+ ScheduleTrigger(timerTrigger, rideHailManagerRef)), + rideHailManagerRef ) allTriggersInWave = Vector() } @@ -330,7 +332,7 @@ class RideHailModifyPassengerScheduleManager( passengerScheduleStatus.status = InterruptMessageStatus.INTERRUPT_SENT // log.debug("sendInterruptMessage:" + passengerScheduleStatus) passengerScheduleStatus.rideHailAgent - .tell(Interrupt(passengerScheduleStatus.interruptId, passengerScheduleStatus.tick), rideHailManager) + .tell(Interrupt(passengerScheduleStatus.interruptId, passengerScheduleStatus.tick), rideHailManagerRef) } def isPendingReservationEnding( diff --git a/src/main/scala/beam/utils/StuckFinder.scala b/src/main/scala/beam/utils/StuckFinder.scala index 9a8b060c8ee..cb00181f5e9 100644 --- a/src/main/scala/beam/utils/StuckFinder.scala +++ b/src/main/scala/beam/utils/StuckFinder.scala @@ -5,6 +5,7 @@ import beam.agentsim.scheduler.BeamAgentScheduler.ScheduledTrigger import beam.agentsim.scheduler.Trigger import beam.sim.config.BeamConfig.Beam.Debug.StuckAgentDetection import beam.sim.config.BeamConfig.Beam.Debug.StuckAgentDetection.Thresholds$Elm +import beam.utils.logging.ExponentialLazyLogging import beam.utils.reflection.ReflectionUtils import com.typesafe.scalalogging.LazyLogging @@ -17,6 +18,7 @@ import scala.collection.mutable.ArrayBuffer class StuckFinder(val cfg: StuckAgentDetection) extends LazyLogging { private var tickValue: Int = -1 private var lastUpdatedTime: Long = 0 + private var numCriticalStuckMessages = 0 private val actorToTriggerMessages: mutable.Map[ActorRef, mutable.Map[Class[_], Int]] = mutable.Map[ActorRef, mutable.Map[Class[_], Int]]() @@ -65,7 +67,7 @@ class StuckFinder(val cfg: StuckAgentDetection) extends LazyLogging { if (cfg.enabled) { updateTickIfNeeded(st.triggerWithId.trigger.tick) if (isNew && cfg.checkMaxNumberOfMessagesEnabled) - checkIfExiceedMaxNumOfMsgPerActorType(st) + checkIfExceedMaxNumOfMsgPerActorType(st) class2Helper .get(toKey(st)) .foreach { helper => @@ -140,7 +142,10 @@ class StuckFinder(val cfg: StuckAgentDetection) extends LazyLogging { val diff = System.currentTimeMillis() - lastUpdatedTime val isStuck = diff > cfg.overallSimulationTimeoutMs if (isStuck) { - logger.error(s"Critical. No progress in overall simulation for last $diff ms") + numCriticalStuckMessages = numCriticalStuckMessages + 1 + if(beam.utils.logging.ExponentialLoggerWrapperImpl.isNumberPowerOfTwo(numCriticalStuckMessages)){ + logger.error(s"Critical. No progress in overall simulation for last $diff ms") + } } } } @@ -160,7 +165,7 @@ class StuckFinder(val cfg: StuckAgentDetection) extends LazyLogging { } } - private def checkIfExiceedMaxNumOfMsgPerActorType(st: ScheduledTrigger): Unit = { + private def checkIfExceedMaxNumOfMsgPerActorType(st: ScheduledTrigger): Unit = { val actor = st.agent val triggerClazz = st.triggerWithId.trigger.getClass val msgCount = updateAndGetNumOfTriggerMessagesPerActor(actor, triggerClazz) diff --git a/src/main/scala/beam/utils/logging/ExponentialLoggerWrapperImpl.scala b/src/main/scala/beam/utils/logging/ExponentialLoggerWrapperImpl.scala index 4b54ebb024f..a89aaf7e6f3 100644 --- a/src/main/scala/beam/utils/logging/ExponentialLoggerWrapperImpl.scala +++ b/src/main/scala/beam/utils/logging/ExponentialLoggerWrapperImpl.scala @@ -5,7 +5,7 @@ import java.util.concurrent.ConcurrentHashMap import beam.utils.logging.ExponentialLoggerWrapperImpl._ import org.slf4j.{Logger, LoggerFactory} -private class ExponentialLoggerWrapperImpl(name: String) extends LoggerWrapper { +class ExponentialLoggerWrapperImpl(name: String) extends LoggerWrapper { private type Func = String => Unit @@ -55,7 +55,7 @@ private class ExponentialLoggerWrapperImpl(name: String) extends LoggerWrapper { } -private object ExponentialLoggerWrapperImpl { +object ExponentialLoggerWrapperImpl { def isNumberPowerOfTwo(number: Int): Boolean = { number > 0 && ((number & (number - 1)) == 0) From befc14f1e05d70131daf9e64d9f6b03626de14b1 Mon Sep 17 00:00:00 2001 From: Colin Sheppard Date: Fri, 4 Jan 2019 13:01:36 -0800 Subject: [PATCH 4/4] fmt --- .../RideHailModifyPassengerScheduleManager.scala | 16 ++++++++++------ src/main/scala/beam/utils/StuckFinder.scala | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala b/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala index e6f99210146..359121c2d31 100755 --- a/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala +++ b/src/main/scala/beam/agentsim/agents/ridehail/RideHailModifyPassengerScheduleManager.scala @@ -23,11 +23,11 @@ import org.matsim.vehicles.Vehicle import scala.collection.mutable class RideHailModifyPassengerScheduleManager( - val log: LoggingAdapter, - val rideHailManagerRef: ActorRef, - val rideHailManager: RideHailManager, - val scheduler: ActorRef, - val beamConfig: BeamConfig + val log: LoggingAdapter, + val rideHailManagerRef: ActorRef, + val rideHailManager: RideHailManager, + val scheduler: ActorRef, + val beamConfig: BeamConfig ) extends HasTickAndTrigger { val resourcesNotCheckedIn_onlyForDebugging: mutable.Set[Id[Vehicle]] = mutable.Set() @@ -165,7 +165,11 @@ class RideHailModifyPassengerScheduleManager( allTriggersInWave = triggersToSchedule ++ allTriggersInWave if (numberPendingModifyPassengerScheduleAcks == 0) { - log.debug("sendCompletionAndScheduleNewTimeout from line 167 @ {} with trigger {}", _currentTick, _currentTriggerId) + log.debug( + "sendCompletionAndScheduleNewTimeout from line 167 @ {} with trigger {}", + _currentTick, + _currentTriggerId + ) sendCompletionAndScheduleNewTimeout(Reposition, tick) rideHailManager.cleanUp } diff --git a/src/main/scala/beam/utils/StuckFinder.scala b/src/main/scala/beam/utils/StuckFinder.scala index cb00181f5e9..0731efdb4f0 100644 --- a/src/main/scala/beam/utils/StuckFinder.scala +++ b/src/main/scala/beam/utils/StuckFinder.scala @@ -143,7 +143,7 @@ class StuckFinder(val cfg: StuckAgentDetection) extends LazyLogging { val isStuck = diff > cfg.overallSimulationTimeoutMs if (isStuck) { numCriticalStuckMessages = numCriticalStuckMessages + 1 - if(beam.utils.logging.ExponentialLoggerWrapperImpl.isNumberPowerOfTwo(numCriticalStuckMessages)){ + if (beam.utils.logging.ExponentialLoggerWrapperImpl.isNumberPowerOfTwo(numCriticalStuckMessages)) { logger.error(s"Critical. No progress in overall simulation for last $diff ms") } }