diff --git a/src/router/astar.rs b/src/router/astar.rs index 167a130..3064357 100644 --- a/src/router/astar.rs +++ b/src/router/astar.rs @@ -10,7 +10,7 @@ use std::collections::{BinaryHeap, HashMap}; use std::hash::Hash; use petgraph::algo::Measure; -use petgraph::visit::{EdgeRef, GraphBase, IntoEdges}; +use petgraph::visit::{EdgeRef, GraphBase, IntoEdgeReferences, IntoEdges}; use thiserror::Error; use std::cmp::Ordering; @@ -97,19 +97,25 @@ where pub trait AstarStrategy where - G: IntoEdges, - K: Measure + Copy, + G: GraphBase, G::NodeId: Eq + Hash, + for<'a> &'a G: IntoEdges, + K: Measure + Copy, { fn is_goal(&mut self, graph: &G, node: G::NodeId, tracker: &PathTracker) -> Option; - fn edge_cost(&mut self, graph: &G, edge: G::EdgeRef) -> Option; + fn edge_cost<'a>( + &mut self, + graph: &'a G, + edge: <&'a G as IntoEdgeReferences>::EdgeRef, + ) -> Option; fn estimate_cost(&mut self, graph: &G, node: G::NodeId) -> K; } pub struct Astar where - G: IntoEdges, + G: GraphBase, G::NodeId: Eq + Hash, + for<'a> &'a G: IntoEdges, K: Measure + Copy, { pub graph: G, @@ -127,8 +133,9 @@ pub enum AstarError { pub enum AstarStatus where - G: IntoEdges, + G: GraphBase, G::NodeId: Eq + Hash, + for<'a> &'a G: IntoEdges, K: Measure + Copy, { Running, @@ -137,8 +144,9 @@ where impl Astar where - G: IntoEdges, + G: GraphBase, G::NodeId: Eq + Hash, + for<'a> &'a G: IntoEdges, K: Measure + Copy, { pub fn new(graph: G, start: G::NodeId, strategy: &mut impl AstarStrategy) -> Self { @@ -152,8 +160,10 @@ where let zero_score = K::default(); this.scores.insert(start, zero_score); - this.visit_next - .push(MinScored(strategy.estimate_cost(&&graph, start), start)); + this.visit_next.push(MinScored( + strategy.estimate_cost(&&this.graph, start), + start, + )); this } @@ -224,8 +234,9 @@ pub fn astar( strategy: &mut impl AstarStrategy, ) -> Result<(K, Vec, R), AstarError> where - G: IntoEdges, + G: GraphBase, G::NodeId: Eq + Hash, + for<'a> &'a G: IntoEdges, K: Measure + Copy, { let mut astar = Astar::new(graph, start, strategy);