-
Notifications
You must be signed in to change notification settings - Fork 57
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
Jl/update ridehail surge #3740
base: develop
Are you sure you want to change the base?
Jl/update ridehail surge #3740
Changes from 10 commits
d3ae9d1
1514a44
d594baf
d3f8088
b86524f
bd6de34
aa813f7
e9ed9e2
f0d5c5f
3474fa5
fda022a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package beam.agentsim.agents.ridehail | ||
|
||
import beam.router.BeamRouter.Location | ||
import beam.sim.BeamServices | ||
import beam.sim.{BeamScenario, BeamServices} | ||
import beam.sim.config.BeamConfig | ||
import beam.sim.config.BeamConfig.Beam.Agentsim.Agents | ||
import com.google.inject.Inject | ||
import org.matsim.core.utils.misc.Time | ||
|
@@ -10,10 +11,16 @@ import scala.collection.JavaConverters._ | |
import scala.collection.mutable.ArrayBuffer | ||
import scala.util.Random | ||
|
||
class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | ||
class RideHailSurgePricingManager @Inject() ( | ||
val beamConfig: BeamConfig, | ||
val beamScenario: BeamScenario, | ||
val managerName: String | ||
) { | ||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using constant link to beamConfig will prevent automatic updates of config in case it was changed during a simulation, instead it is better to get the latest version of config from the beamServices object each time or manually subscribe to changes of beamConfig and updating it each time. There is the same issue for the any config values that are stored in variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. The issue here is that beamServices is initialized after RideHailSurgePricingManager. And since I am initializing a map of multiple RideHailSurgePricingManager objects, I needed to actually initialize each one, which would error without access to beamServices. @nikolayilyin do you have any suggestions for alternative approaches? |
||
import RideHailSurgePricingManager._ | ||
|
||
val rideHailConfig: Agents.RideHail = beamServices.beamConfig.beam.agentsim.agents.rideHail | ||
val rideHailConfig: Option[Agents.RideHail.Managers$Elm] = | ||
beamConfig.beam.agentsim.agents.rideHail.managers.find(_.name == managerName) | ||
val surgePricing = rideHailConfig.map(_.surgePricing).getOrElse(throw new Exception("Ride hail config not found")) | ||
|
||
// TODO: | ||
|
||
|
@@ -26,14 +33,13 @@ class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | |
|
||
// TODO: can we allow any other class to inject taz as well, without loading multiple times? (Done) | ||
val timeBinSize: Int = | ||
beamServices.beamConfig.beam.agentsim.timeBinSize // TODO: does throw exception for 60min, if +1 missing below | ||
val numberOfCategories: Int = | ||
rideHailConfig.surgePricing.numberOfCategories // TODO: does throw exception for 0 and negative values | ||
beamConfig.beam.agentsim.timeBinSize // TODO: does throw exception for 60min, if +1 missing below | ||
val numberOfCategories: Int = surgePricing.numberOfCategories // TODO: does throw exception for 0 and negative values | ||
val numberOfTimeBins: Int = Math | ||
.floor(Time.parseTime(beamServices.beamConfig.matsim.modules.qsim.endTime) / timeBinSize) | ||
.floor(Time.parseTime(beamConfig.matsim.modules.qsim.endTime) / timeBinSize) | ||
.toInt + 1 | ||
val surgeLevelAdaptionStep: Double = rideHailConfig.surgePricing.surgeLevelAdaptionStep | ||
val minimumSurgeLevel: Double = rideHailConfig.surgePricing.minimumSurgeLevel | ||
val surgeLevelAdaptionStep: Double = surgePricing.surgeLevelAdaptionStep | ||
val minimumSurgeLevel: Double = surgePricing.minimumSurgeLevel | ||
// TODO: implement all cases for these surge prices properly | ||
val CONTINUES_DEMAND_SUPPLY_MATCHING = "CONTINUES_DEMAND_SUPPLY_MATCHING" | ||
val KEEP_PRICE_LEVEL_FIXED_AT_ONE = "KEEP_PRICE_LEVEL_FIXED_AT_ONE" | ||
|
@@ -42,14 +48,14 @@ class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | |
|
||
//Scala like code | ||
val surgePriceBins: Map[String, ArrayBuffer[SurgePriceBin]] = | ||
beamServices.beamScenario.tazTreeMap.tazQuadTree.values.asScala.map { v => | ||
beamScenario.tazTreeMap.tazQuadTree.values.asScala.map { v => | ||
val array = (0 until numberOfTimeBins).foldLeft(new ArrayBuffer[SurgePriceBin]) { (arrayBuffer, _) => | ||
arrayBuffer.append(defaultBinContent) | ||
arrayBuffer | ||
} | ||
(v.tazId.toString, array) | ||
}.toMap | ||
val rand = new Random(beamServices.beamConfig.matsim.modules.global.randomSeed) | ||
val rand = new Random(beamConfig.matsim.modules.global.randomSeed) | ||
var iteration = 0 | ||
var isFirstIteration = true | ||
|
||
|
@@ -61,7 +67,7 @@ class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | |
|
||
// TODO: initialize all bins (price levels and iteration revenues)! | ||
var totalSurgePricingLevel: Double = 0 | ||
var priceAdjustmentStrategy: String = rideHailConfig.surgePricing.priceAdjustmentStrategy | ||
var priceAdjustmentStrategy: String = surgePricing.priceAdjustmentStrategy | ||
|
||
// this should be invoked after each iteration | ||
// TODO: initialize in BEAMSim and also reset there after each iteration? | ||
|
@@ -118,7 +124,7 @@ class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | |
} | ||
|
||
def getSurgeLevel(location: Location, time: Double): Double = { | ||
val taz = beamServices.beamScenario.tazTreeMap.getTAZ(location.getX, location.getY) | ||
val taz = beamScenario.tazTreeMap.getTAZ(location.getX, location.getY) | ||
val timeBinIndex = getTimeBinIndex(time) | ||
surgePriceBins | ||
.get(taz.tazId.toString) | ||
|
@@ -138,7 +144,7 @@ class RideHailSurgePricingManager @Inject() (val beamServices: BeamServices) { | |
|
||
def addRideCost(time: Double, cost: Double, pickupLocation: Location): Unit = { | ||
|
||
val taz = beamServices.beamScenario.tazTreeMap.getTAZ(pickupLocation.getX, pickupLocation.getY) | ||
val taz = beamScenario.tazTreeMap.getTAZ(pickupLocation.getX, pickupLocation.getY) | ||
val timeBinIndex = getTimeBinIndex(time) | ||
|
||
surgePriceBins.get(taz.tazId.toString).foreach { i => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid putting formatting into the variable, instead let's use it in the string.format method directly, this will improve readability