pub fn mcmf(&self) -> (i32, Vec<Path<T>>) {
        let mut next_id = 0;
        let source = Vertex::Source.clone();
        let sink = Vertex::Sink.clone();
        let mut index_mapper = BTreeMap::new();
        for vertex in self.edge_list.iter()
                .flat_map(move |&(ref a, ref b, _, _)| iter::once(a).chain(iter::once(b)))
                .chain(iter::once(&source))
                .chain(iter::once(&sink)) {
            if !index_mapper.contains_key(&vertex) {
                index_mapper.insert(vertex, next_id);
                next_id += 1;
            }
        }
        let num_vertices = next_id;
        let mut g = Graph::new_default(num_vertices);
        for &(ref a, ref b, cap, cost) in &self.edge_list {
            let node_a = Node(*index_mapper.get(&a).unwrap());
            let node_b = Node(*index_mapper.get(&b).unwrap());
            if *a == Vertex::Source || *b == Vertex::Sink {
                // The + supply and - supply must be equal because of how LEMON interprets
                // its input.
                // http://lemon.cs.elte.hu/pub/doc/latest/a00005.html
                g.increase_supply(Node(*index_mapper.get(&Vertex::Source).unwrap()), cap.0 as i64);
                g.decrease_supply(Node(*index_mapper.get(&Vertex::Sink).unwrap()), cap.0 as i64);
            }
            g.add_edge(node_a, node_b, EdgeData::new(cost, cap));
        }
        let total_amount = g.mcmf() as i32;
        let (_, edges) = g.extract();
        let inverse_mapping: BTreeMap<_, _> =
            index_mapper.into_iter().map(|(a, b)| (b, a)).collect();
        let flows = edges.into_iter().map(|x| {
            let a = (**inverse_mapping.get(&x.a.0).unwrap()).clone();
            let b = (**inverse_mapping.get(&x.b.0).unwrap()).clone();
            let amount = x.data.flow as u32;
            let cost = x.data.cost as i32;
            Flow {a, b, amount, cost}
        })
            .filter(|x| x.amount != 0)
            .collect();
        let mut paths = GraphBuilder::path_decomposition(flows);
        paths.sort_by_key(|path| path.len());
        (total_amount, paths)
    }
/// Computes the minimum cost maximum flow.
/// 
/// Returns a tuple (total cost, list of paths). The paths are sorted in ascending order by length.
///
/// This gives incorrect results when the total cost or the total flow exceeds 2^(31)-1.
/// It is the responsibility of the caller to ensure that the total cost doesn't exceed 2^(31)-1.
Computes the minimum cost maximum flow.
Returns a tuple (total cost, list of paths). The paths are sorted in ascending order by length.

This gives incorrect results when the total cost or the total flow exceeds 2^(31)-1.
It is the responsibility of the caller to ensure that the total cost doesn't exceed 2^(31)-1.
Computes the minimum cost maximum flow . Returns a tuple ( total cost list of paths ) . The paths are sorted in ascending order by length . This gives incorrect results when the total cost or the total flow exceeds 2^ ( 31 ) - 1 . It is the responsibility of the caller to ensure that the total cost doesn ' t exceed 2^ ( 31 ) - 1 .
pub fn mcmf(&self) -> (i32, Vec<Path<T>>) {
        let mut next_id = 0;
        let source = Vertex::Source.clone();
        let sink = Vertex::Sink.clone();
        let mut index_mapper = BTreeMap::new();
        for vertex in self.edge_list.iter()
                .flat_map(move |&(ref a, ref b, _, _)| iter::once(a).chain(iter::once(b)))
                .chain(iter::once(&source))
                .chain(iter::once(&sink)) {
            if !index_mapper.contains_key(&vertex) {
                index_mapper.insert(vertex, next_id);
                next_id += 1;
            }
        }
        let num_vertices = next_id;
        let mut g = Graph::new_default(num_vertices);
        for &(ref a, ref b, cap, cost) in &self.edge_list {
            let node_a = Node(*index_mapper.get(&a).unwrap());
            let node_b = Node(*index_mapper.get(&b).unwrap());
            if *a == Vertex::Source || *b == Vertex::Sink {
                // The + supply and - supply must be equal because of how LEMON interprets
                // its input.
                // http://lemon.cs.elte.hu/pub/doc/latest/a00005.html
                g.increase_supply(Node(*index_mapper.get(&Vertex::Source).unwrap()), cap.0 as i64);
                g.decrease_supply(Node(*index_mapper.get(&Vertex::Sink).unwrap()), cap.0 as i64);
            }
            g.add_edge(node_a, node_b, EdgeData::new(cost, cap));
        }
        let total_amount = g.mcmf() as i32;
        let (_, edges) = g.extract();
        let inverse_mapping: BTreeMap<_, _> =
            index_mapper.into_iter().map(|(a, b)| (b, a)).collect();
        let flows = edges.into_iter().map(|x| {
            let a = (**inverse_mapping.get(&x.a.0).unwrap()).clone();
            let b = (**inverse_mapping.get(&x.b.0).unwrap()).clone();
            let amount = x.data.flow as u32;
            let cost = x.data.cost as i32;
            Flow {a, b, amount, cost}
        })
            .filter(|x| x.amount != 0)
            .collect();
        let mut paths = GraphBuilder::path_decomposition(flows);
        paths.sort_by_key(|path| path.len());
        (total_amount, paths)
    }
pub fn mcmf ( & self ) -> ( i32 , Vec < Path < T > > ) { let mut next_id = 0 ; let source = Vertex :: Source . clone ( ) ; let sink = Vertex :: Sink . clone ( ) ; let mut index_mapper = BTreeMap :: new ( ) ; for vertex in self . edge_list . iter ( ) . flat_map ( move | & ( ref a , ref b , _ , _ ) | iter :: once ( a ) . chain ( iter :: once ( b ) ) ) . chain ( iter :: once ( & source ) ) . chain ( iter :: once ( & sink ) ) { if ! index_mapper . contains_key ( & vertex ) { index_mapper . insert ( vertex , next_id ) ; next_id += 1 ; } } let num_vertices = next_id ; let mut g = Graph :: new_default ( num_vertices ) ; for & ( ref a , ref b , cap , cost ) in & self . edge_list { let node_a = Node ( * index_mapper . get ( & a ) . unwrap ( ) ) ; let node_b = Node ( * index_mapper . get ( & b ) . unwrap ( ) ) ; if * a == Vertex :: Source || * b == Vertex :: Sink { // The + supply and - supply must be equal because of how LEMON interprets // its input. // http://lemon.cs.elte.hu/pub/doc/latest/a00005.html g . increase_supply ( Node ( * index_mapper . get ( & Vertex :: Source ) . unwrap ( ) ) , cap . 0 as i64 ) ; g . decrease_supply ( Node ( * index_mapper . get ( & Vertex :: Sink ) . unwrap ( ) ) , cap . 0 as i64 ) ; } g . add_edge ( node_a , node_b , EdgeData :: new ( cost , cap ) ) ; } let total_amount = g . mcmf ( ) as i32 ; let ( _ , edges ) = g . extract ( ) ; let inverse_mapping : BTreeMap < _ , _ > = index_mapper . into_iter ( ) . map ( | ( a , b ) | ( b , a ) ) . collect ( ) ; let flows = edges . into_iter ( ) . map ( | x | { let a = ( * * inverse_mapping . get ( & x . a . 0 ) . unwrap ( ) ) . clone ( ) ; let b = ( * * inverse_mapping . get ( & x . b . 0 ) . unwrap ( ) ) . clone ( ) ; let amount = x . data . flow as u32 ; let cost = x . data . cost as i32 ; Flow { a , b , amount , cost } } ) . filter ( | x | x . amount != 0 ) . collect ( ) ; let mut paths = GraphBuilder :: path_decomposition ( flows ) ; paths . sort_by_key ( | path | path . len ( ) ) ; ( total_amount , paths ) }
Computes the minimum cost maximum flow.
Computes the minimum cost maximum flow .
&self
&self