pathfinding using bus stops, unused, and not the right interface yet

This commit is contained in:
Dustin Carlino 2018-09-09 13:44:38 -07:00
parent ad55fd2924
commit 013b3e11c5
6 changed files with 40 additions and 4 deletions

View File

@ -736,6 +736,10 @@ have to parse the same GTFS? well, it's like RoadEdits -- we can pass it into
the map constructor and physically just load it once.
routing: https://stackoverflow.com/questions/483488/strategy-to-find-your-best-route-via-public-transportation-only
- how do we indicate that the trip uses a bus stop? how will this actually get used?
- in helpers, start trip from/to bldg maybe using transit. pathfind first using transit, then figure out the sequence of bus stops from the route, and turn that into the trip.
- so ideally it's easy to know (stop1, route, stop2) almost as a step of the path. can translate that into trip legs pretty easily.
- feels like a different interface, especially because the point is to just generate the stuff for the trip manager. throwing away the rest of the pathfinding stuff! hmm. same algorithm doesn't fit well at all.
## Everything as FSMs

View File

@ -32,7 +32,7 @@ pub enum LaneType {
Biking,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct BusStop {
pub sidewalk: LaneID,
pub idx: usize,

View File

@ -7,7 +7,7 @@ use geom::{Bounds, HashablePt2D, PolyLine, Pt2D};
use geometry;
use make;
use raw_data;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::io::Error;
use std::path;
use {
@ -378,4 +378,16 @@ impl Map {
pub fn get_bus_route(&self, name: &str) -> Option<&BusRoute> {
self.bus_routes.iter().find(|r| r.name == name)
}
// Not including transfers
pub fn get_connected_bus_stops(&self, start: BusStop) -> BTreeSet<BusStop> {
let mut stops: BTreeSet<BusStop> = BTreeSet::new();
for r in &self.bus_routes {
if r.stops.contains(&start) {
stops.extend(r.stops.clone());
}
}
stops.remove(&start);
stops
}
}

View File

@ -5,6 +5,9 @@ use {LaneID, Map};
pub enum Pathfinder {
ShortestDistance { goal_pt: Pt2D },
// TODO result isn't really lanes, we also want to know bus stops... post-process? remember
// more stuff? hmm.
UsingTransit,
}
impl Pathfinder {
@ -28,6 +31,23 @@ impl Pathfinder {
})
.collect()
}
Pathfinder::UsingTransit => {
// No heuristic, because it's hard to make admissible.
// Cost is distance spent walking, so any jumps made using a bus are FREE. This is
// unrealistic, but a good way to start exercising peds using transit.
let current_lane = map.get_l(current);
let current_length = NotNaN::new(current_lane.length().value_unsafe).unwrap();
let mut results: Vec<(LaneID, NotNaN<f64>)> = Vec::new();
for next in &map.get_next_lanes(current) {
results.push((next.id, current_length));
}
for stop1 in &current_lane.bus_stops {
for stop2 in &map.get_connected_bus_stops(stop1.id) {
results.push((stop2.sidewalk, current_length));
}
}
results
}
}
}

View File

@ -258,7 +258,7 @@ impl Sim {
}
pub fn spawn_specific_pedestrian(&mut self, map: &Map, from: BuildingID, to: BuildingID) {
self.spawner.spawn_specific_pedestrian(
self.spawner.start_trip_just_walking(
self.time.next(),
map,
from,

View File

@ -296,7 +296,7 @@ impl Spawner {
));
}
pub fn spawn_specific_pedestrian(
pub fn start_trip_just_walking(
&mut self,
at: Tick,
map: &Map,