pub struct Lexicographic<P, S> {
pub primary: P,
pub secondary: S,
}Expand description
A path cost ordered by primary first, with ties broken by
secondary. Both components add up along a path.
Use it to break ties between equally cheap paths by a second criterion, such as the
fewest steps and then the fewest turns, or the cheapest route and then the fewest
conflicts with other agents. Any search generic over Cost accepts it unchanged.
§Heuristics
A heuristic (h, S::ZERO), where h is admissible or consistent for the primary cost,
keeps that property for the pair: (h(u), 0) <= (c + h(v), s) whenever
h(u) <= c + h(v). A* then returns a path of minimal primary cost and, among those, of
minimal secondary cost.
§Overflow
+ adds component-wise and overflows like its components. Cost::saturating_add and
Cost::saturating_times saturate each component separately.
§Examples
use search_core::{Cost, Lexicographic};
let fast = Lexicographic::new(10_u32, 3_u32);
let calm = Lexicographic::new(10_u32, 1_u32);
let slow = Lexicographic::new(11_u32, 0_u32);
assert!(calm < fast); // Same primary cost: fewer conflicts win.
assert!(fast < slow); // The primary cost always decides first.
assert_eq!(fast + calm, Lexicographic::new(20, 4));
assert_eq!(Lexicographic::<u32, u32>::ZERO, Lexicographic::new(0, 0));Fields§
§primary: PThe cost that is minimized first.
secondary: SThe tie-breaker, compared only between equal primary costs.
Implementations§
Source§impl<P, S> Lexicographic<P, S>
impl<P, S> Lexicographic<P, S>
Trait Implementations§
impl<P: Copy, S: Copy> Copy for Lexicographic<P, S>
Source§impl<P: Cost, S: Cost> Cost for Lexicographic<P, S>
impl<P: Cost, S: Cost> Cost for Lexicographic<P, S>
Source§fn saturating_add(self, other: Self) -> Self
fn saturating_add(self, other: Self) -> Self
Adds component-wise, each component saturating on its own.
Source§fn saturating_times(self, factor: u32) -> Self
fn saturating_times(self, factor: u32) -> Self
Scales component-wise, each component saturating on its own.