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

Inm/#2067 adding param to adjust in demand following repositioning manager how many closest clusters to consider #2068

2 changes: 2 additions & 0 deletions src/main/resources/beam-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ beam.agentsim.agents.rideHail.repositioningManager.timeout = "int | 0"
# Larger value increase probability of the ride-hail vehicle to reposition
beam.agentsim.agents.rideHail.repositioningManager.demandFollowingRepositioningManager.sensitivityOfRepositioningToDemand = "double | 1"
beam.agentsim.agents.rideHail.repositioningManager.demandFollowingRepositioningManager.numberOfClustersForDemand = "int | 30"
beam.agentsim.agents.rideHail.repositioningManager.demandFollowingRepositioningManager.fractionOfClosestClustersToConsider = "double | 0.2"

beam.agentsim.agents.rideHail.allocationManager.repositionLowWaitingTimes.repositionCircleRadiusInMeters = "double | 3000"
beam.agentsim.agents.rideHail.allocationManager.repositionLowWaitingTimes.minimumNumberOfIdlingVehiclesThresholdForRepositioning = "int | 1"
beam.agentsim.agents.rideHail.allocationManager.repositionLowWaitingTimes.percentageOfVehiclesToReposition = "double | 0.01"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,23 @@ class DemandFollowingRepositioningManager(val beamServices: BeamServices, val ri
private def findWhereToReposition(tick: Int, vehicleLocation: Coord, vehicleId: Id[Vehicle]): Option[Coord] = {
val currentHour = tick / 3600
val nextHour = currentHour + 1
val fractionOfClosestClusters =
beamServices.beamConfig.beam.agentsim.agents.rideHail.repositioningManager.demandFollowingRepositioningManager.fractionOfClosestClustersToConsider

hourToClusters.lift(nextHour).map { clusters =>
// We get top 5 closest clusters and randomly pick one of them.
val N: Int = Math.max(1, Math.round(clusters.length * fractionOfClosestClusters).toInt)

// We get top N closest clusters and randomly pick one of them.
// The probability is proportional to the cluster size - meaning it is proportional to the demand, as higher demands as higher probability
val top5Closest = clusters.sortBy(x => beamServices.geo.distUTMInMeters(x.coord, vehicleLocation)).take(5)
val pmf = top5Closest.map { x =>
val topNClosest = clusters.sortBy(x => beamServices.geo.distUTMInMeters(x.coord, vehicleLocation)).take(N)
val pmf = topNClosest.map { x =>
new CPair[ClusterInfo, java.lang.Double](x, x.size.toDouble)
}.toList

val distr = new EnumeratedDistribution[ClusterInfo](rng, pmf.asJava)
val sampled = distr.sample()
logger.debug(
s"tick $tick, currentHour: $currentHour, nextHour: $nextHour, vehicleId: $vehicleId, vehicleLocation: $vehicleLocation. Top 5 closest: ${top5Closest.toVector}, sampled: $sampled"
s"tick $tick, currentHour: $currentHour, nextHour: $nextHour, vehicleId: $vehicleId, vehicleLocation: $vehicleLocation. Top $N closest: ${topNClosest.toVector}, sampled: $sampled"
)
sampled.coord
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/beam/sim/config/BeamConfig.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// generated by tscfg 0.9.4 on Thu Aug 15 19:31:00 MSK 2019
// source: src/main/resources/beam-template.conf

package beam.sim.config
Expand Down Expand Up @@ -998,6 +999,7 @@ object BeamConfig {

object RepositioningManager {
case class DemandFollowingRepositioningManager(
fractionOfClosestClustersToConsider: scala.Double,
numberOfClustersForDemand: scala.Int,
sensitivityOfRepositioningToDemand: scala.Double
)
Expand All @@ -1008,6 +1010,10 @@ object BeamConfig {
c: com.typesafe.config.Config
): BeamConfig.Beam.Agentsim.Agents.RideHail.RepositioningManager.DemandFollowingRepositioningManager = {
BeamConfig.Beam.Agentsim.Agents.RideHail.RepositioningManager.DemandFollowingRepositioningManager(
fractionOfClosestClustersToConsider =
if (c.hasPathOrNull("fractionOfClosestClustersToConsider"))
c.getDouble("fractionOfClosestClustersToConsider")
else 0.2,
numberOfClustersForDemand =
if (c.hasPathOrNull("numberOfClustersForDemand")) c.getInt("numberOfClustersForDemand") else 30,
sensitivityOfRepositioningToDemand =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VehicleMilesTraveledAnalysisSpec extends GenericAnalysisSpec with Matchers
override def beforeAll(): Unit = {
super.beforeAll()

vehicleTypes = beamServices.vehicleTypes.keySet
vehicleTypes = beamServices.beamScenario.vehicleTypes.keySet
runAnalysis(new VehicleMilesTraveledAnalysis(vehicleTypes))
}

Expand All @@ -25,11 +25,13 @@ class VehicleMilesTraveledAnalysisSpec extends GenericAnalysisSpec with Matchers

"calculate total vehicle traveled " in {

val defaultHumanBodyBeamVehicleTypeId = Id.create("BODY-TYPE-DEFAULT", classOf[BeamVehicleType])

import scala.collection.JavaConverters._
summaryStats.asScala
.filterNot(_._1.equalsIgnoreCase("motorizedVehicleMilesTraveled_total"))
.filterNot(
_._1.equalsIgnoreCase(s"motorizedVehicleMilesTraveled_${BeamVehicleType.defaultHumanBodyBeamVehicleType.id}")
_._1.equalsIgnoreCase(s"motorizedVehicleMilesTraveled_$defaultHumanBodyBeamVehicleTypeId")
)
.filterNot(_._1.startsWith("vehicleMilesTraveled_"))
.values
Expand Down