adjusting pathfinding costs, trying to figure out why walking routes are awful

This commit is contained in:
Dustin Carlino 2018-11-29 16:19:55 -08:00
parent ecc5a6efb1
commit 87a357d67c
2 changed files with 32 additions and 19 deletions

View File

@ -361,6 +361,8 @@ impl Pathfinder {
} }
fn pathfind(&self, map: &Map, start: Position, end: Position) -> Option<Vec<InternalPathStep>> { fn pathfind(&self, map: &Map, start: Position, end: Position) -> Option<Vec<InternalPathStep>> {
let debug = start.lane().0 == 1871 && end.lane().0 == 1913;
if start.lane() == end.lane() { if start.lane() == end.lane() {
if start.dist_along() > end.dist_along() { if start.dist_along() > end.dist_along() {
if !map.get_l(start.lane()).is_sidewalk() { if !map.get_l(start.lane()).is_sidewalk() {
@ -373,30 +375,34 @@ impl Pathfinder {
// This should be deterministic, since cost ties would be broken by PathStep. // This should be deterministic, since cost ties would be broken by PathStep.
let mut queue: BinaryHeap<(NotNaN<f64>, InternalPathStep)> = BinaryHeap::new(); let mut queue: BinaryHeap<(NotNaN<f64>, InternalPathStep)> = BinaryHeap::new();
let start_len = map.get_l(start.lane()).length();
if map.get_l(start.lane()).is_sidewalk() { if map.get_l(start.lane()).is_sidewalk() {
if start.dist_along() != map.get_l(start.lane()).length() { if start.dist_along() != start_len {
queue.push(( let step = InternalPathStep::Lane(start.lane());
NotNaN::new(-0.0).unwrap(), let cost = start_len - start.dist_along();
InternalPathStep::Lane(start.lane()), let heuristic = step.heuristic(self.goal_pt, map);
)); queue.push((dist_to_pri_queue(cost + heuristic), step));
} }
if start.dist_along() != 0.0 * si::M { if start.dist_along() != 0.0 * si::M {
queue.push(( let step = InternalPathStep::ContraflowLane(start.lane());
NotNaN::new(-0.0).unwrap(), let cost = start.dist_along();
InternalPathStep::ContraflowLane(start.lane()), let heuristic = step.heuristic(self.goal_pt, map);
)); queue.push((dist_to_pri_queue(cost + heuristic), step));
} }
} else { } else {
queue.push(( let step = InternalPathStep::Lane(start.lane());
NotNaN::new(-0.0).unwrap(), let cost = start_len - start.dist_along();
InternalPathStep::Lane(start.lane()), let heuristic = step.heuristic(self.goal_pt, map);
)); queue.push((dist_to_pri_queue(cost + heuristic), step));
} }
let mut backrefs: HashMap<InternalPathStep, InternalPathStep> = HashMap::new(); let mut backrefs: HashMap<InternalPathStep, InternalPathStep> = HashMap::new();
while !queue.is_empty() { while !queue.is_empty() {
let (cost_sofar, current) = queue.pop().unwrap(); let (cost_sofar, current) = queue.pop().unwrap();
if debug {
println!("considering {:?} with cost {}", current, cost_sofar);
}
// Found it, now produce the path // Found it, now produce the path
if current == InternalPathStep::Lane(end.lane()) if current == InternalPathStep::Lane(end.lane())
@ -422,12 +428,10 @@ impl Pathfinder {
backrefs.insert(next, current); backrefs.insert(next, current);
let cost = next.cost(map); let cost = next.cost(map);
let heuristic = next.heuristic(self.goal_pt, map); let heuristic = next.heuristic(self.goal_pt, map);
// Negate since BinaryHeap is a max-heap. if debug {
queue.push(( println!(" next step {:?} with cost+heuristic {}", next, cost + heuristic);
NotNaN::new(-1.0).unwrap() }
* (NotNaN::new((cost + heuristic).value_unsafe).unwrap() + cost_sofar), queue.push((dist_to_pri_queue(cost + heuristic) + cost_sofar, next));
next,
));
} }
} }
} }
@ -476,3 +480,8 @@ fn validate(map: &Map, steps: &Vec<PathStep>) {
} }
} }
} }
// Negate since BinaryHeap is a max-heap.
fn dist_to_pri_queue(dist: si::Meter<f64>) -> NotNaN<f64> {
NotNaN::new(-1.0 * dist.value_unsafe).unwrap()
}

View File

@ -554,6 +554,10 @@ impl Spawner {
let ped_id = PedestrianID(self.ped_id_counter); let ped_id = PedestrianID(self.ped_id_counter);
self.ped_id_counter += 1; self.ped_id_counter += 1;
if ped_id.0 == 31 {
println!("p31 is going from {:?} to {:?}", start, goal);
}
let first_stop = SidewalkSpot::bus_stop(stop1, map); let first_stop = SidewalkSpot::bus_stop(stop1, map);
let legs = vec![ let legs = vec![
TripLeg::Walk(first_stop.clone()), TripLeg::Walk(first_stop.clone()),