Skip to content

Commit

Permalink
allow non-dominating transit paths
Browse files Browse the repository at this point in the history
  • Loading branch information
zneedell committed Mar 29, 2022
1 parent 5c4bbc9 commit 9bb0b46
Show file tree
Hide file tree
Showing 3 changed files with 1,972 additions and 3,550 deletions.
2 changes: 2 additions & 0 deletions src/main/resources/beam-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ beam.routing {
bikeLaneScaleFactor = "double | 1.0"
bikeLaneLinkIdsFilePath = ""
linkRadiusMeters = "double | 10000.0"
transitAlternativeList = "OPTIMAL"
suboptimalMinutes = "int | 0"
}
gh {
useAlternativeRoutes = "boolean | false"
Expand Down
33 changes: 25 additions & 8 deletions src/main/scala/beam/router/r5/R5Wrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import beam.sim.metrics.{Metrics, MetricsSupport}
import com.conveyal.r5.analyst.fare.SimpleInRoutingFareCalculator
import com.conveyal.r5.api.ProfileResponse
import com.conveyal.r5.api.util._
import com.conveyal.r5.profile.{McRaptorSuboptimalPathProfileRouter, ProfileRequest, StreetMode, StreetPath}
import com.conveyal.r5.profile.{
DominatingList,
McRaptorSuboptimalPathProfileRouter,
ProfileRequest,
StreetMode,
StreetPath,
SuboptimalDominatingList
}
import com.conveyal.r5.streets._
import com.conveyal.r5.transit.TransitLayer
import com.typesafe.scalalogging.StrictLogging
Expand All @@ -28,6 +35,7 @@ import org.matsim.vehicles.Vehicle
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
import java.util
import java.util.function.IntFunction
import java.util.{Collections, Optional}
import scala.collection.JavaConverters._
import scala.collection.mutable
Expand Down Expand Up @@ -222,7 +230,7 @@ class R5Wrapper(workerParams: R5Parameters, travelTime: TravelTime, travelTimeNo
profileRequest.date = dates.localBaseDate
// Doesn't calculate any fares, is just a no-op placeholder
profileRequest.inRoutingFareCalculator = new SimpleInRoutingFareCalculator
profileRequest.suboptimalMinutes = 0
profileRequest.suboptimalMinutes = beamConfig.beam.routing.r5.suboptimalMinutes
profileRequest
}

Expand Down Expand Up @@ -618,6 +626,20 @@ class R5Wrapper(workerParams: R5Parameters, travelTime: TravelTime, travelTimeNo
}
}

val departureTimeToDominatingList: IntFunction[DominatingList] = (departureTime: Int) =>
beamConfig.beam.routing.r5.transitAlternativeList.toLowerCase match {
case "suboptimal" =>
new SuboptimalDominatingList(
profileRequest.suboptimalMinutes
)
case _ =>
new BeamDominatingList(
profileRequest.inRoutingFareCalculator,
Integer.MAX_VALUE,
departureTime + profileRequest.maxTripDurationMinutes * 60
)
}

val transitPaths = latency("getpath-transit-time", Metrics.VerboseLevel) {
profileRequest.fromTime = request.departureTime
profileRequest.toTime =
Expand All @@ -627,12 +649,7 @@ class R5Wrapper(workerParams: R5Parameters, travelTime: TravelTime, travelTimeNo
profileRequest,
accessStopsByMode.mapValues(_.stops).asJava,
egressStopsByMode.mapValues(_.stops).asJava,
(departureTime: Int) =>
new BeamDominatingList(
profileRequest.inRoutingFareCalculator,
Integer.MAX_VALUE,
departureTime + profileRequest.maxTripDurationMinutes * 60
),
departureTimeToDominatingList,
null
)
Try(router.getPaths.asScala).getOrElse(Nil) // Catch IllegalStateException in R5.StatsCalculator
Expand Down
Loading

0 comments on commit 9bb0b46

Please sign in to comment.