Skip to content

Commit

Permalink
editoast: pathfinding: initial upperbound is based on begin/end track…
Browse files Browse the repository at this point in the history
…’s bboxes
  • Loading branch information
Tristramg committed Dec 1, 2023
1 parent 149b9ea commit bd5d68e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions editoast/src/map/bounding_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ impl BoundingBox {
pub fn from_geometry(value: Geometry) -> Result<Self> {
Self::from_geojson(value.value)
}

/// Computes the length (in meters) of the diagonal
/// It represents the longest distance as the crow flies between two points in the box
pub fn diagonal_length(&self) -> f64 {
let a = osm4routing::Coord {
lon: self.0 .0,
lat: self.0 .1,
};
let b = osm4routing::Coord {
lon: self.1 .0,
lat: self.1 .1,
};
a.distance_to(b)
}
}

#[derive(Debug, Error, EditoastError)]
Expand Down
14 changes: 13 additions & 1 deletion editoast/src/views/infra/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,19 @@ fn compute_path(
let into_cost = |length: f64| (length * 100.).round() as u64;
let get_length = |track: &String| track_sections[track].unwrap_track_section().length;
let success = |step: &PathfindingStep| step.found;
let mut best_distance = u64::MAX;

let starting_track = track_sections[&input.starting.track.0].unwrap_track_section();
let ending_track = track_sections[&input.ending.track.0].unwrap_track_section();
let best_distance = starting_track
.bbox_geo
.clone()
.union(&ending_track.bbox_geo)
.diagonal_length();
// We build an upper bound that is the diagonal of the bounding box covering start and end
// During the path search, we prune any route that is twice that distance
// We set an upper bound of at least 10 km to avoid problems on very short distances
let mut best_distance = into_cost(best_distance.max(10_000.0));

let successors = |step: &PathfindingStep| {
// We initially don’t know in which direction start searching the path
// So the first step as two successors, at the same track-position, but in opposite directions
Expand Down

0 comments on commit bd5d68e

Please sign in to comment.