Function rustfst::algorithms::shortest_distance_with_config [−][src]
pub fn shortest_distance_with_config<W: Semiring, F: ExpandedFst<W>>(
fst: &F,
reverse: bool,
config: ShortestDistanceConfig
) -> Result<Vec<W>>
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
fn main() -> Result<()> { let mut fst = VectorFst::<IntegerWeight>::new(); let s0 = fst.add_state(); let s1 = fst.add_state(); let s2 = fst.add_state(); fst.set_start(s0).unwrap(); fst.add_tr(s0, Tr::new(32, 23, 18, s1)); fst.add_tr(s0, Tr::new(32, 23, 21, s2)); fst.add_tr(s1, Tr::new(32, 23, 55, s2)); let dists = shortest_distance(&fst, false)?; assert_eq!(dists, vec![ IntegerWeight::one(), IntegerWeight::new(18), IntegerWeight::new(21 + 18*55), ]);