Struct pi_path_finding::AStar
source · pub struct AStar<N: PartialOrd + Zero + Copy + Debug, E: NodeEntry<N> + Default> { /* private fields */ }Expand description
Implementations§
source§impl<N: PartialOrd + Zero + Copy + Debug, E: NodeEntry<N> + Default> AStar<N, E>
impl<N: PartialOrd + Zero + Copy + Debug, E: NodeEntry<N> + Default> AStar<N, E>
sourcepub fn with_capacity(map_capacity: usize, node_number: usize) -> Self
pub fn with_capacity(map_capacity: usize, node_number: usize) -> Self
实例化A寻路算法的结构体 必须传入最大可能的全图节点容量,可选传入调用A算法时可能搜索的节点数量以提前初始化节约性能,但也可为0
sourcepub fn find<Arg>(
&mut self,
start: NodeIndex,
end: NodeIndex,
max_number: usize,
arg: &mut Arg,
make_neighbors: fn(_: &mut Arg, _: NodeIndex, _: NodeIndex, _: &mut Finder<N, E>) -> NodeNeighbors<N>
) -> AStarResult
pub fn find<Arg>( &mut self, start: NodeIndex, end: NodeIndex, max_number: usize, arg: &mut Arg, make_neighbors: fn(_: &mut Arg, _: NodeIndex, _: NodeIndex, _: &mut Finder<N, E>) -> NodeNeighbors<N> ) -> AStarResult
从起点向终点的A寻路算法
给定一组代表全图的通用节点nodes,以及寻路的起始节点在nodes的索引start 和目的节点在nodes索引end进行A 寻路;
如果 寻路到终点 或 寻路的结果节点数目超过max_number,则终止寻路并返回结果;
返回结果:是否成功寻路至目标点
大概流程:
-
- 创建起点的节点邻居nn。
-
2、弹出nn中的最优邻居节点node,判断是否到达,如果没有到达,则获取该node的节点邻居nn1,如果open表不为空,从表头取最优的节点邻居nn2,比较nn2、nn1和nn,选择放入nn1或nn, 获得最优的新的nn。 重复该步骤2。
-
3、如果open表为空,则返回NotFound。
sourcepub fn result_iter<'a>(&'a self, node: NodeIndex) -> ResultIterator<'a, N, E> ⓘ
pub fn result_iter<'a>(&'a self, node: NodeIndex) -> ResultIterator<'a, N, E> ⓘ
返回结果的迭代器
Auto Trait Implementations§
impl<N, E> RefUnwindSafe for AStar<N, E>where E: RefUnwindSafe, N: RefUnwindSafe,
impl<N, E> Send for AStar<N, E>where E: Send, N: Send,
impl<N, E> Sync for AStar<N, E>where E: Sync, N: Sync,
impl<N, E> Unpin for AStar<N, E>where E: Unpin, N: Unpin,
impl<N, E> UnwindSafe for AStar<N, E>where E: UnwindSafe, N: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.