pub fn execute<G, W: Copy + Zero + Any + Ord, E: Edge<W>>(
        self,
        graph: &G,
    ) -> Result<HashMap<(usize, usize), Magnitude<W>>>
    where
        G: provide::Edges<W, E> + provide::Vertices,
    {
        let vertices = graph.vertices();
        let vertex_count = vertices.len();

        let id_map = graph.continuos_id_map();

        let mut dist = vec![vec![Magnitude::PosInfinite; vertex_count]; vertex_count];

        for &u_real_id in &vertices {
            let u_virt_id = id_map.virt_id_of(u_real_id);
            dist[u_virt_id][u_virt_id] = W::zero().into();
        }

        for &u_real_id in &vertices {
            let u_virt_id = id_map.virt_id_of(u_real_id);

            for (v_real_id, edge) in graph.edges_from(u_real_id).unwrap() {
                let v_virt_id = id_map.virt_id_of(v_real_id);
                dist[u_virt_id][v_virt_id] = edge.get_weight().clone();
            }
        }

        for k in 0..vertex_count {
            for &i in &vertices {
                let i_virt_id = id_map.virt_id_of(i);
                for &j in &vertices {
                    let j_virt_id = id_map.virt_id_of(j);

                    if (dist[i_virt_id][k] + dist[k][j_virt_id]).is_finite()
                        && dist[i_virt_id][j_virt_id] > dist[i_virt_id][k] + dist[k][j_virt_id]
                    {
                        dist[i_virt_id][j_virt_id] = dist[i_virt_id][k] + dist[k][j_virt_id]
                    }
                }

                // check for negative cycle
                for v_id in &vertices {
                    let v_virt_id = id_map.virt_id_of(*v_id);
                    if dist[v_virt_id][v_virt_id] < W::zero().into() {
                        Err(Error::new_ncd())?
                    }
                }
            }
        }

        let mut distance_map = HashMap::new();
        for i in 0..vertex_count {
            let i_real_id = id_map.real_id_of(i);
            for j in 0..vertex_count {
                let j_real_id = id_map.real_id_of(j);

                distance_map.insert((i_real_id, j_real_id), dist[i][j].clone());
            }
        }

        Ok(distance_map)
    }
/// Finds shortest path from all vertices to all the other ones.
///
/// # Arguments
/// * `graph`: Graph to search for the shortest paths in.
/// * `src_id`: Id of the source vertex(Shortest path will be calculated from this vertex to all other vertices)
///
/// # Returns
/// * `Ok`: Containing shortest path information in the form of: (src_id, dst_id) -> distance.
/// * `Err`: If graph contains negative cycle.
Finds shortest path from all vertices to all the other ones.
Finds shortest path from all vertices to all the other ones .
pub fn execute<G, W: Copy + Zero + Any + Ord, E: Edge<W>>(
        self,
        graph: &G,
    ) -> Result<HashMap<(usize, usize), Magnitude<W>>>
    where
        G: provide::Edges<W, E> + provide::Vertices,
    {
        let vertices = graph.vertices();
        let vertex_count = vertices.len();
        let id_map = graph.continuos_id_map();
        let mut dist = vec![vec![Magnitude::PosInfinite; vertex_count]; vertex_count];
        for &u_real_id in &vertices {
            let u_virt_id = id_map.virt_id_of(u_real_id);
            dist[u_virt_id][u_virt_id] = W::zero().into();
        }
        for &u_real_id in &vertices {
            let u_virt_id = id_map.virt_id_of(u_real_id);
            for (v_real_id, edge) in graph.edges_from(u_real_id).unwrap() {
                let v_virt_id = id_map.virt_id_of(v_real_id);
                dist[u_virt_id][v_virt_id] = edge.get_weight().clone();
            }
        }
        for k in 0..vertex_count {
            for &i in &vertices {
                let i_virt_id = id_map.virt_id_of(i);
                for &j in &vertices {
                    let j_virt_id = id_map.virt_id_of(j);
                    if (dist[i_virt_id][k] + dist[k][j_virt_id]).is_finite()
                        && dist[i_virt_id][j_virt_id] > dist[i_virt_id][k] + dist[k][j_virt_id]
                    {
                        dist[i_virt_id][j_virt_id] = dist[i_virt_id][k] + dist[k][j_virt_id]
                    }
                }
                // check for negative cycle
                for v_id in &vertices {
                    let v_virt_id = id_map.virt_id_of(*v_id);
                    if dist[v_virt_id][v_virt_id] < W::zero().into() {
                        Err(Error::new_ncd())?
                    }
                }
            }
        }
        let mut distance_map = HashMap::new();
        for i in 0..vertex_count {
            let i_real_id = id_map.real_id_of(i);
            for j in 0..vertex_count {
                let j_real_id = id_map.real_id_of(j);
                distance_map.insert((i_real_id, j_real_id), dist[i][j].clone());
            }
        }
        Ok(distance_map)
    }
pub fn execute < G , W : Copy + Zero + Any + Ord , E : Edge < W > > ( self , graph : & G , ) -> Result < HashMap < ( usize , usize ) , Magnitude < W > > > where G : provide :: Edges < W , E > + provide :: Vertices , { let vertices = graph . vertices ( ) ; let vertex_count = vertices . len ( ) ; let id_map = graph . continuos_id_map ( ) ; let mut dist = vec ! [ vec [ Magnitude PosInfinite vertex_count ] vertex_count ] ; for & u_real_id in & vertices { let u_virt_id = id_map . virt_id_of ( u_real_id ) ; dist [ u_virt_id ] [ u_virt_id ] = W :: zero ( ) . into ( ) ; } for & u_real_id in & vertices { let u_virt_id = id_map . virt_id_of ( u_real_id ) ; for ( v_real_id , edge ) in graph . edges_from ( u_real_id ) . unwrap ( ) { let v_virt_id = id_map . virt_id_of ( v_real_id ) ; dist [ u_virt_id ] [ v_virt_id ] = edge . get_weight ( ) . clone ( ) ; } } for k in 0 .. vertex_count { for & i in & vertices { let i_virt_id = id_map . virt_id_of ( i ) ; for & j in & vertices { let j_virt_id = id_map . virt_id_of ( j ) ; if ( dist [ i_virt_id ] [ k ] + dist [ k ] [ j_virt_id ] ) . is_finite ( ) && dist [ i_virt_id ] [ j_virt_id ] > dist [ i_virt_id ] [ k ] + dist [ k ] [ j_virt_id ] { dist [ i_virt_id ] [ j_virt_id ] = dist [ i_virt_id ] [ k ] + dist [ k ] [ j_virt_id ] } } // check for negative cycle for v_id in & vertices { let v_virt_id = id_map . virt_id_of ( * v_id ) ; if dist [ v_virt_id ] [ v_virt_id ] < W :: zero ( ) . into ( ) { Err ( Error :: new_ncd ( ) ) ? } } } } let mut distance_map = HashMap :: new ( ) ; for i in 0 .. vertex_count { let i_real_id = id_map . real_id_of ( i ) ; for j in 0 .. vertex_count { let j_real_id = id_map . real_id_of ( j ) ; distance_map . insert ( ( i_real_id , j_real_id ) , dist [ i ] [ j ] . clone ( ) ) ; } } Ok ( distance_map ) }
Finds shortest path from all vertices to all the other ones.
Finds shortest path from all vertices to all the other ones .
self
graph
&G
`Ok`: Containing shortest path information in the form of: (src_id, dst_id) -> distance.
`Err`: If graph contains negative cycle.
` Ok ` : Containing shortest path information in the form of : ( src_id dst_id ) - > distance . ` Err ` : If graph contains negative cycle .
self
graph
&G