Skip to content

Commit

Permalink
Merge pull request #2131 from LBNL-UCB-STI/HL/#2115-spatial-constrain…
Browse files Browse the repository at this point in the history
…ts-on-pool-dropoffs

spatial constraints on pool dropoffs
  • Loading branch information
wrashid authored Aug 29, 2019
2 parents 8932db1 + 4700863 commit c4774d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import beam.router.BeamRouter.Location
import beam.router.BeamSkimmer
import beam.router.BeamSkimmer.Skim
import beam.router.Modes.BeamMode
import beam.sim.common.GeoUtils
import beam.sim.{BeamServices, Geofence}
import org.jgrapht.graph.{DefaultEdge, DefaultUndirectedWeightedGraph}
import org.matsim.api.core.v01.Id
import org.matsim.api.core.v01.population.Activity
import org.matsim.core.population.PopulationUtils
import org.matsim.core.utils.collections.QuadTree

import scala.collection.JavaConverters._
import scala.collection.immutable.List
import scala.collection.mutable.ListBuffer

import beam.sim.config.BeamConfig.Beam.Agentsim.Agents.RideHail.AllocationManager

class AlonsoMoraPoolingAlgForRideHail(
Expand Down Expand Up @@ -161,6 +162,14 @@ class AlonsoMoraPoolingAlgForRideHail(

object AlonsoMoraPoolingAlgForRideHail {

def checkDistance(r: MobilityRequest, schedule: List[MobilityRequest], searchRadius: Double): Boolean = {
schedule.foreach { s =>
if (GeoUtils.distFormula(r.activity.getCoord, s.activity.getCoord) <= searchRadius)
return true
}
false
}

// a greedy assignment using a cost function
def greedyAssignment(
rTvG: RTVGraph,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package beam.agentsim.agents.ridehail

import beam.agentsim.agents.{Dropoff, EnRoute, MobilityRequest, Pickup}
import beam.agentsim.agents.ridehail.AlonsoMoraPoolingAlgForRideHail._
import beam.router.BeamSkimmer
import beam.router.Modes.BeamMode
Expand Down Expand Up @@ -32,10 +33,10 @@ class AsyncAlonsoMoraAlgForRideHail(
val vertices = MListBuffer.empty[RTVGraphNode]
val edges = MListBuffer.empty[(RTVGraphNode, RTVGraphNode)]
val finalRequestsList = MListBuffer.empty[RideHailTrip]
val center = v.getRequestWithCurrentVehiclePosition.activity.getCoord

val requestWithCurrentVehiclePosition = v.getRequestWithCurrentVehiclePosition
val center = requestWithCurrentVehiclePosition.activity.getCoord
val searchRadius = waitingTimeInSec * BeamSkimmer.speedMeterPerSec(BeamMode.CAV)
val requests = v.geofence match {
var requests = v.geofence match {
case Some(gf) =>
val gfCenter = new Coord(gf.geofenceX, gf.geofenceY)
spatialDemand
Expand All @@ -50,8 +51,13 @@ class AsyncAlonsoMoraAlgForRideHail(
case _ =>
spatialDemand.getDisk(center.getX, center.getY, searchRadius).asScala.toList
}
requests = requests.sortBy(r => GeoUtils.minkowskiDistFormula(center, r.pickup.activity.getCoord))
if (requestWithCurrentVehiclePosition.tag == EnRoute) {
val i = v.schedule.indexWhere(_.tag == EnRoute)
val nextTasks = v.schedule.slice(0, i)
requests = requests.filter(r => AlonsoMoraPoolingAlgForRideHail.checkDistance(r.dropoff, nextTasks, searchRadius))
}
requests
.sortBy(x => GeoUtils.minkowskiDistFormula(center, x.pickup.activity.getCoord))
.take(solutionSpaceSizePerVehicle) foreach (
r =>
AlonsoMoraPoolingAlgForRideHail.getRidehailSchedule(
Expand Down

0 comments on commit c4774d1

Please sign in to comment.