pub fn single_source_shortest_distance<F: ExpandedFst>(
    fst: &F,
    state_id: StateId
) -> Result<Vec<<F as CoreFst>::W>, Error>
Expand description

This operation computes the shortest distance from the state state_id to every state. The shortest distance from p to q is the ⊕-sum of the weights of all the paths between p and q.

Example

use rustfst::semirings::{Semiring, IntegerWeight};
use rustfst::fst_impls::VectorFst;
use rustfst::fst_traits::MutableFst;
use rustfst::algorithms::single_source_shortest_distance;
use rustfst::arc::Arc;

let mut fst = VectorFst::new();
let s0 = fst.add_state();
let s1 = fst.add_state();
let s2 = fst.add_state();

fst.set_start(&s0).unwrap();
fst.add_arc(&s0, Arc::new(32, 23, IntegerWeight::new(18), s1));
fst.add_arc(&s0, Arc::new(32, 23, IntegerWeight::new(21), s2));
fst.add_arc(&s1, Arc::new(32, 23, IntegerWeight::new(55), s2));

let dists = single_source_shortest_distance(&fst, s1).unwrap();

assert_eq!(dists, vec![
    IntegerWeight::zero(),
    IntegerWeight::one(),
    IntegerWeight::new(55),
]);