/// The graph distance between two vertices is the minimum count of edges to connect them. For a fully-connected graph, it means how many steps to take for traversing from vertice 1 to vertice 2
The graph distance between two vertices is the minimum count of edges to connect them. For a fully-connected graph, it means how many steps to take for traversing from vertice 1 to vertice 2
The graph distance between two vertices is the minimum count of edges to connect them . For a fully - connected graph it means how many steps to take for traversing from vertice 1 to vertice 2
pub fn graph_distance<T: graph::Vertex>(
    vertex_1: usize,
    vertex_2: usize,
    vv: &graph::VertexVec<T>
) -> usize {
    if vertex_1 == vertex_2 {
        return 0
    } else {
        let mut vertices_visited: Vec<usize> = vec![];
        let mut vertices_boundary: Vec<usize> = vec![vertex_1];
        let mut distance: usize = 0;
        while vertices_visited.len() <  vv.len() {
            distance += 1;
            let mut neighbours: Vec<usize> = vertices_boundary.iter()
                .map(|&idx| vv[idx].neighbour_indexes())
                .flatten()
                .collect(); 
            neighbours.sort_unstable();
            neighbours.dedup();
            if neighbours.contains(&vertex_2) {
                break;
            } else {
                vertices_boundary.clear();
                for &idx in neighbours.iter() {
                    if !vertices_visited.contains(&idx) {
                        vertices_visited.push(idx);
                        vertices_boundary.push(idx);
                    }
                }
            }
        }
        distance
    }
}
pub fn graph_distance < T : graph :: Vertex > ( vertex_1 : usize , vertex_2 : usize , vv : & graph :: VertexVec < T > ) -> usize { if vertex_1 == vertex_2 { return 0 } else { let mut vertices_visited : Vec < usize > = vec ! [ ] ; let mut vertices_boundary : Vec < usize > = vec ! [ vertex_1 ] ; let mut distance : usize = 0 ; while vertices_visited . len ( ) < vv . len ( ) { distance += 1 ; let mut neighbours : Vec < usize > = vertices_boundary . iter ( ) . map ( | & idx | vv [ idx ] . neighbour_indexes ( ) ) . flatten ( ) . collect ( ) ; neighbours . sort_unstable ( ) ; neighbours . dedup ( ) ; if neighbours . contains ( & vertex_2 ) { break ; } else { vertices_boundary . clear ( ) ; for & idx in neighbours . iter ( ) { if ! vertices_visited . contains ( & idx ) { vertices_visited . push ( idx ) ; vertices_boundary . push ( idx ) ; } } } } distance } }
The graph distance between two vertices is the minimum count of edges to connect them.
The graph distance between two vertices is the minimum count of edges to connect them .
vertex_1
usize
vertex_2
usize
vv
&graph::VertexVec<T>