making sure we only consider appropriate lane types for parking searches

This commit is contained in:
Dustin Carlino 2019-09-15 10:11:13 -07:00
parent fa898a9c70
commit 8d8237a40e
3 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,4 @@
use crate::{LaneID, Map};
use crate::{LaneID, LaneType, Map};
use abstutil::Timer;
use petgraph::graphmap::DiGraphMap;
use std::collections::{HashSet, VecDeque};
@ -68,11 +68,9 @@ fn bidi_flood(map: &Map, start: LaneID, largest_group: &HashSet<LaneID>) -> Opti
queue.push_back(turn.id.src);
}
}
for turn in map.get_turns_from_lane(current) {
if map.is_turn_allowed(turn.id) {
for turn in map.get_legal_turns(current, vec![LaneType::Driving]) {
queue.push_back(turn.id.dst);
}
}
}
None
}

View File

@ -369,6 +369,15 @@ impl Map {
.collect()
}
pub fn get_legal_turns(&self, from: LaneID, lane_types: Vec<LaneType>) -> Vec<&Turn> {
let valid_types: HashSet<LaneType> = lane_types.into_iter().collect();
self.get_next_turns_and_lanes(from, self.get_l(from).dst_i)
.into_iter()
.filter(|(t, l)| self.is_turn_allowed(t.id) && valid_types.contains(&l.lane_type))
.map(|(t, _)| t)
.collect()
}
// These come back sorted
pub fn get_next_roads(&self, from: RoadID) -> Vec<RoadID> {
let mut roads: BTreeSet<RoadID> = BTreeSet::new();

View File

@ -263,8 +263,8 @@ fn path_to_free_parking_spot(
current = turn.src;
}
}
for turn in map.get_turns_from_lane(current) {
if map.is_turn_allowed(turn.id) && !backrefs.contains_key(&turn.id.dst) {
for turn in map.get_legal_turns(current, vec![LaneType::Driving]) {
if !backrefs.contains_key(&turn.id.dst) {
backrefs.insert(turn.id.dst, turn.id);
queue.push_back(turn.id.dst);
}