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

This operation computes the shortest distance from the initial state 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::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 = shortest_distance(&fst).unwrap();

assert_eq!(dists, vec![
    IntegerWeight::one(),
    IntegerWeight::new(18),
    IntegerWeight::new(21 + 18*55),
]);