Skip to main content

DynamicSearch

Struct DynamicSearch 

Source
pub struct DynamicSearch<C, P, const N: usize> { /* private fields */ }
Expand description

An incremental multi-objective search on a DynamicGraph: every state keeps the Pareto set of path costs from the start (label correcting), and edge changes repair only what they touch.

After DynamicSearch::set_cost, DynamicSearch::remove_edge or DynamicSearch::add_edge, the labels whose paths use the changed edge, and everything built on them, are dropped; every state that lost a label is re-seeded from the live labels of its predecessors, and label correcting runs from there, as LPA* re-expands only the inconsistent part of its search tree. Labels elsewhere stay. DynamicSearch::front then equals a fresh search’s front.

Goal states end paths. Edge costs must be non-negative.

§Examples

use multiobjective_search::{DynamicGraph, DynamicSearch};

let mut graph = DynamicGraph::new(3);
let direct = graph.add_edge(0, 2, [10_u32, 1]);
graph.add_edge(0, 1, [1, 5]);
graph.add_edge(1, 2, [1, 5]);

let mut search = DynamicSearch::new(graph, 0, |s: &u32| *s == 2);
let costs = |s: &DynamicSearch<_, _, 2>| s.front().solutions.iter().map(|x| x.cost).collect::<Vec<_>>();
assert_eq!(costs(&search), [[2, 10], [10, 1]]);

search.set_cost(direct, [1, 1]); // the direct road got better
assert_eq!(costs(&search), [[1, 1]]);

Implementations§

Source§

impl<C: Cost, P: Fn(&u32) -> bool, const N: usize> DynamicSearch<C, P, N>

Source

pub fn new(graph: DynamicGraph<C, N>, start: u32, is_goal: P) -> Self

Searches graph from start.

§Panics

Panics if start is not a state of graph.

Source

pub const fn graph(&self) -> &DynamicGraph<C, N>

The current graph.

Source

pub const fn stats(&self) -> Stats

Effort counters over the initial search and every repair.

Source

pub fn set_cost(&mut self, id: usize, cost: [C; N])

Changes the cost of edge id and repairs.

§Panics

Panics if the edge does not exist.

Source

pub fn remove_edge(&mut self, id: usize)

Removes edge id and repairs.

§Panics

Panics if the edge does not exist.

Source

pub fn add_edge(&mut self, from: u32, to: u32, cost: [C; N]) -> usize

Adds an edge, repairs, and returns its identity.

Source

pub fn front(&self) -> Output<u32, [C; N]>

The current Pareto-optimal goal paths, one per cost, sorted.

§Panics

Never: states are indexed by u32.

Auto Trait Implementations§

§

impl<C, P, const N: usize> Forget for DynamicSearch<C, P, N>

§

impl<C, P, const N: usize> Freeze for DynamicSearch<C, P, N>
where DynamicGraph<C, N>: Freeze, P: Freeze, Vec<Label<C, N>>: Freeze,

§

impl<C, P, const N: usize> Move for DynamicSearch<C, P, N>

§

impl<C, P, const N: usize> RefUnwindSafe for DynamicSearch<C, P, N>
where DynamicGraph<C, N>: RefUnwindSafe, P: RefUnwindSafe, Vec<Label<C, N>>: RefUnwindSafe,

§

impl<C, P, const N: usize> Send for DynamicSearch<C, P, N>
where P: Send, DynamicGraph<C, N>: Send, Vec<Label<C, N>>: Send,

§

impl<C, P, const N: usize> Sync for DynamicSearch<C, P, N>
where P: Sync, DynamicGraph<C, N>: Sync, Vec<Label<C, N>>: Sync,

§

impl<C, P, const N: usize> Unpin for DynamicSearch<C, P, N>
where P: Unpin, DynamicGraph<C, N>: Unpin, Vec<Label<C, N>>: Unpin,

§

impl<C, P, const N: usize> UnsafeUnpin for DynamicSearch<C, P, N>
where DynamicGraph<C, N>: UnsafeUnpin, P: UnsafeUnpin, Vec<Label<C, N>>: UnsafeUnpin,

§

impl<C, P, const N: usize> UnwindSafe for DynamicSearch<C, P, N>
where DynamicGraph<C, N>: UnwindSafe, P: UnwindSafe, Vec<Label<C, N>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.