Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into do/#3441-mode-choi…
Browse files Browse the repository at this point in the history
…ce-strategy

# Conflicts:
#	docs/inputs.rst
  • Loading branch information
zneedell committed May 31, 2022
2 parents be4bd40 + c1e64b1 commit f25a4be
Show file tree
Hide file tree
Showing 87 changed files with 1,270 additions and 1,540 deletions.
13 changes: 9 additions & 4 deletions aws/src/main/python/updateDependencies/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@
- echo "-------------------checkout $bn----------------------"
- sudo GIT_LFS_SKIP_SMUDGE=1 git checkout $bn
- sudo git reset --hard origin/$bn
- sudo git pull
- sudo git lfs pull
- for submodule in $SUBMODULES
- do
- sudo git submodule update --init --remote $submodule
- sudo git pull
- sudo git lfs pull
- done
- done
- sudo chown -R ubuntu:ubuntu /home/ubuntu/git/beam
- echo "gradlew assemble ..."
- ./gradlew assemble
- ./gradlew clean
- echo "preparing for python analysis"
- 'echo resetting git to base: "$(date)"'
- sudo git reset --hard
- sudo git reset --hard
- 'echo fetching the latest: "$(date)"'
- sudo git fetch
- 'echo current git status: "$(date)"'
Expand Down Expand Up @@ -134,8 +138,9 @@ def lambda_handler(event, context):
shutdown_wait = "10"
runName = 'update-beam-dependencies'
branches = os.environ['BRANCHES']
submodules = os.environ['SUBMODULES']

script = initscript.replace('$BRANCH', branches).replace('$SHUTDOWN_WAIT', shutdown_wait)
script = initscript.replace('$BRANCH', branches).replace('$SHUTDOWN_WAIT', shutdown_wait).replace('$SUBMODULES', submodules)

init_ec2(region)
instance_id = deploy(script, instance_type, region.replace("-", "_")+'_', shutdown_behaviour, runName, en_vars)
Expand Down
24 changes: 24 additions & 0 deletions aws/src/main/python/updateDependencies/updateDependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
updateDependencies:
Type: 'AWS::Serverless::Function'
Properties:
Handler: lambda_function.lambda_handler
Runtime: python2.7
CodeUri: .
Description: ''
MemorySize: 128
Timeout: 300
Role: 'arn:aws:iam::340032650202:role/BeamLambdaExecution'
Events:
Schedule1:
Type: Schedule
Properties:
Schedule: rate(4 days)
Environment:
Variables:
BRANCHES: master develop freight-develop hl/gemini-develop gemini-develop
INSTANCE_TYPE: t2.small
SUBMODULES: production/newyork production/sfbay production/austin
49 changes: 25 additions & 24 deletions docs/inputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,19 @@ Routing Configuration
^^^^^^^^^^^^^^^^^^^^^
::

# values: R5, staticGH, quasiDynamicGH, nativeCCH (Linux Only)
beam.routing.carRouter="R5"
beam.routing {
#Base local date in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM
baseDate = "2016-10-17T00:00:00-07:00"
transitOnStreetNetwork = true # PathTraversalEvents for transit vehicles
r5 {
directory = ${beam.inputDirectory}"/r5"
# Departure window in min
departureWindow = "double | 15.0"
numberOfSamples = "int | 1"
osmMapdbFile = ${beam.routing.r5.directory}"/osm.mapdb"
# values: R5, staticGH, quasiDynamicGH, nativeCCH (Linux Only)
beam.routing.carRouter="R5"
beam.routing {
#Base local date in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM
baseDate = "2016-10-17T00:00:00-07:00"
transitOnStreetNetwork = true # PathTraversalEvents for transit vehicles
r5 {
directory = ${beam.inputDirectory}"/r5"
directory2 = "String? |"
# Departure window in min
departureWindow = "double | 15.0"
numberOfSamples = "int | 1"
osmMapdbFile = ${beam.routing.r5.directory}"/osm.mapdb"
mNetBuilder.fromCRS = "EPSG:4326" # WGS84
mNetBuilder.toCRS = "EPSG:26910" # UTM10N
travelTimeNoiseFraction = 0.0
Expand All @@ -249,29 +250,29 @@ beam.routing {
startingIterationForTravelTimesMSA = 0
overrideNetworkTravelTimesUsingSkims = false

# Set a lower bound on travel times that can possibly be used to override the network-based
# travel time in the route.This is used to prevent unrealistically fast trips or negative
# duration trips.
minimumPossibleSkimBasedTravelTimeInS= 60
skimTravelTimesScalingFactor = 0.0
writeRoutingStatistic = false
}
# Set a lower bound on travel times that can possibly be used to override the network-based
# travel time in the route.This is used to prevent unrealistically fast trips or negative
# duration trips.
minimumPossibleSkimBasedTravelTimeInS= 60
skimTravelTimesScalingFactor = 0.0
writeRoutingStatistic = false
}

Parameters within beam.routing namespace
* carRouter: type of car router. The values are R5, staticGH, quasiDynamicGH, nativeCCH (Linux Only) where staticGH is GraphHopper router (when link travel times don't depend on time of the day), quasiDynamicGH is GraphHopper router (link
travel times depend on time of the day), nativeCCH is router that uses native CCH library.

* carRouter: type of car router. The values are R5, staticGH, quasiDynamicGH, nativeCCH (Linux Only) where staticGH is GraphHopper router (when link travel times don't depend on time of the day), quasiDynamicGH is GraphHopper router (link travel times depend on time of the day), nativeCCH is router that uses native CCH library.
* baseDate: the date which routes are requested on (transit depends on it)
* transitOnStreetNetwork: if set to true transit PathTraversalEvents includes the route links
* r5.directory: the directory that contains R5 data which includes pbf file, GTFS files.
* r5.directory: the directory that contains R5 data which includes pbf file, GTFS files. If the directory contains multiple pbf files then a random file is loaded.
* r5.directory2: An optional directory that contains R5 data for the second router. It must contain the same pbf file and a subset of the GTFS files that are in the r5.directory (the first r5 directory). I.e. one can leave only the train GTFS file in the directory2. In this case train routes will be provided twice as much. But the first r5 directory must also contains the same train file or the second router will provide routes based on a different network which may lead to errors.
* r5.departureWindow: the departure window for transit requests
* r5.numberOfSamples: Number of Monte Carlo draws to take for frequency searches when doing routing
* r5.osmMapdbFile: osm map db file that is stored to this location
* r5.mNetBuilder.fromCRS: convert network coordinates from this CRS
* r5.mNetBuilder.toCRS: convert network coordinates to this CRS
* r5.travelTimeNoiseFraction: if it's greater than zero some noise to link travel times will be added
* r5.maxDistanceLimitByModeInMeters: one can limit max distance to be used for a particular mode
* r5.bikeLaneScaleFactor: this parameter is intended to make the links with bike lanes to be more preferable when the
router calculates a route for bikes. The less this scaleFactor the more preferable these links get
* r5.bikeLaneScaleFactor: this parameter is intended to make the links with bike lanes to be more preferable when the router calculates a route for bikes. The less this scaleFactor the more preferable these links get
* r5.bikeLaneLinkIdsFilePath: the ids of links that have bike lanes
* startingIterationForTravelTimesMSA: ???
* overrideNetworkTravelTimesUsingSkims: travel time is got from skims
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object GeometryPerformance {
val baseConfigUnresolved = ConfigFactory.parseString("config=" + configLocation)
val baseConfig = baseConfigUnresolved.resolve()
val beamConfig = BeamConfig(baseConfig)
val stalls = InfrastructureUtils.loadStalls[TAZ](
val stalls = InfrastructureUtils.loadStalls(
s"$beamHome/test/input/sf-bay/parking/taz-parking-unlimited-fast-limited-l2-150-baseline.csv",
IndexedSeq(),
tazMap.tazQuadTree, //it is required only in case of failures
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/beam-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ beam.input.lastBaseOutputDir = ${beam.outputs.baseOutputDirectory}
beam.input.simulationPrefix = ${beam.agentsim.simulationName}

beam.agentsim.simulationName = "beamville"
beam.agentsim.randomSeedForPopulationSampling = "int?"
beam.agentsim.agentSampleSizeAsFractionOfPopulation = "double | 1.0"
beam.agentsim.fractionOfPlansWithSingleActivity = "double | 0.0"
beam.agentsim.thresholdForWalkingInMeters = 100
Expand Down Expand Up @@ -168,16 +169,16 @@ beam.agentsim.agents.parking.rangeAnxietyBuffer = "double | 20000.0" # if our re
beam.agentsim.agents.parking.minSearchRadius = "double | 250.00" # something small enough that, on average, we see 2 orders of magnitude of samples at most
beam.agentsim.agents.parking.maxSearchRadius = "double | 8046.72" # something large enough that we do not strand our drivers in an oasis
beam.agentsim.agents.parking.searchMaxDistanceRelativeToEllipseFoci = "double | 4.0" # something large enough that we do not travel longer than the actual distance to destination
beam.agentsim.agents.parking.fractionOfSameTypeZones = "double | 0.5"
beam.agentsim.agents.parking.minNumberOfSameTypeZones = "int | 10"

#TAZ params
beam.agentsim.taz.filePath = ${beam.inputDirectory}"/taz-centers.csv"
beam.agentsim.taz.parkingFilePath = ""
beam.agentsim.taz.parkingStallCountScalingFactor = "double | 1.0"
beam.agentsim.taz.parkingCostScalingFactor = "double | 1.0"
# options: DEFAULT, HIERARCHICAL, PARALLEL, HIERARCHICAL requires link parking file
# options: DEFAULT, HIERARCHICAL, PARALLEL
beam.agentsim.taz.parkingManager.method = "String | DEFAULT"
# options: TAZ, Link (Link level can work only with DEFAULT parking manager)
beam.agentsim.taz.parkingManager.level = "TAZ"
beam.agentsim.taz.parkingManager.displayPerformanceTimings = false
beam.agentsim.taz.parkingManager.parallel.numberOfClusters = "int | 8"
#Toll params
Expand Down
14 changes: 12 additions & 2 deletions src/main/scala/beam/agentsim/agents/household/HouseholdActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.matsim.households
import org.matsim.households.Household

import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
import scala.collection.mutable
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters.collectionAsScalaIterableConverter
Expand Down Expand Up @@ -529,7 +530,13 @@ object HouseholdActor {
veh.setManager(Some(self))
for {
ParkingInquiryResponse(stall, _, _) <- parkingManager ? ParkingInquiry
.init(veh.spaceTime, "init", triggerId = triggerId)
.init(
veh.spaceTime,
"init",
VehicleManager.getReservedFor(veh.vehicleManagerId.get()).get,
Some(veh),
triggerId = triggerId
)
} {
veh.useParkingStall(stall)
veh.spaceTime = SpaceTime(stall.locationUTM.getX, stall.locationUTM.getY, 0)
Expand Down Expand Up @@ -612,10 +619,13 @@ object HouseholdActor {
whenWhere: SpaceTime,
manager: ActorRef
): BeamVehicle = {
val vehicleManagerId =
VehicleManager.createOrGetReservedFor(household.getId.toString, VehicleManager.TypeEnum.Household).managerId
val vehicle = new BeamVehicle(
Id.createVehicleId(personId.toString + "-emergency-" + vehicleIndex),
new Powertrain(vehicleType.primaryFuelConsumptionInJoulePerMeter),
vehicleType
vehicleType,
new AtomicReference[Id[VehicleManager]](vehicleManagerId)
)
vehicle.initializeFuelLevelsFromUniformDistribution(
beamScenario.beamConfig.beam.agentsim.agents.vehicles.meanPrivateVehicleStartingSOC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import beam.agentsim.agents.InitializeTrigger
import beam.agentsim.agents.household.HouseholdActor._
import beam.agentsim.agents.household.HouseholdFleetManager.ResolvedParkingResponses
import beam.agentsim.agents.modalbehaviors.DrivesVehicle.ActualVehicle
import beam.agentsim.agents.vehicles.BeamVehicle
import beam.agentsim.agents.vehicles.{BeamVehicle, VehicleManager}
import beam.agentsim.events.SpaceTime
import beam.agentsim.infrastructure.{ParkingInquiry, ParkingInquiryResponse}
import beam.agentsim.scheduler.BeamAgentScheduler.CompletionNotice
Expand Down Expand Up @@ -59,16 +59,19 @@ class HouseholdFleetManager(

case TriggerWithId(InitializeTrigger(_), triggerId) =>
triggerSender = Some(sender())
val listOfFutures: List[Future[(Id[BeamVehicle], ParkingInquiryResponse)]] = vehicles.toList.map { case (id, _) =>
(parkingManager ? ParkingInquiry.init(
SpaceTime(homeCoord, 0),
"init",
triggerId = triggerId
))
.mapTo[ParkingInquiryResponse]
.map { r =>
(id, r)
}
val listOfFutures: List[Future[(Id[BeamVehicle], ParkingInquiryResponse)]] = vehicles.toList.map {
case (id, veh) =>
(parkingManager ? ParkingInquiry.init(
SpaceTime(homeCoord, 0),
"init",
VehicleManager.getReservedFor(veh.vehicleManagerId.get()).get,
Some(veh),
triggerId = triggerId
))
.mapTo[ParkingInquiryResponse]
.map { r =>
(id, r)
}
}
val futureOfList = Future.sequence(listOfFutures)
val response = futureOfList.map(ResolvedParkingResponses(triggerId, _))
Expand Down Expand Up @@ -171,6 +174,8 @@ class HouseholdFleetManager(
val responseFuture = parkingManager ? ParkingInquiry.init(
inquiry.whereWhen,
"wherever",
VehicleManager.getReservedFor(vehicle.vehicleManagerId.get()).get,
Some(vehicle),
triggerId = inquiry.triggerId
)
logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ import beam.sim.{BeamServices, Geofence}
import beam.utils.logging.pattern.ask
import beam.utils.plan.sampling.AvailableModeUtils._
import org.matsim.api.core.v01.Id
import org.matsim.api.core.v01.network.Link
import org.matsim.api.core.v01.population.{Activity, Leg}
import org.matsim.core.population.routes.NetworkRoute
import org.matsim.core.population.routes.{NetworkRoute, RouteUtils}
import org.matsim.core.utils.misc.Time

import java.util.concurrent.atomic.AtomicReference
import scala.collection.JavaConverters
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters.asJavaIterableConverter

/**
* BEAM
Expand Down Expand Up @@ -618,6 +621,29 @@ trait ChoosesMode {
routingFinished = true
)
}

// If person plan doesn't have a route for an activity create and save it
for {
activity <- nextActivity(choosesModeData.personData)
leg <- _experiencedBeamPlan.getTripContaining(activity).leg if leg.getRoute == null
} {
val links =
response.itineraries
.flatMap(_.beamLegs)
.find(_.mode == BeamMode.CAR)
.map { beamLeg =>
beamLeg.travelPath.linkIds
.map(id => Id.create(id, classOf[Link]))
.toList
}
.getOrElse(List.empty)

if (links.nonEmpty) {
val route = RouteUtils.createNetworkRoute(JavaConverters.seqAsJavaList(links), beamScenario.network)
leg.setRoute(route)
}
}

stay() using newData

case Event(theRideHailResult: RideHailResponse, choosesModeData: ChoosesModeData) =>
Expand Down
Loading

0 comments on commit f25a4be

Please sign in to comment.