Function cnetworks::bfs [−][src]
pub fn bfs(
net: &Network,
root: usize,
target: usize
) -> Result<Option<usize>, Err>
Expand description
Perform a breadth-first search over the network, starting with root and looking for target.
Returns distance (ie. number of edges) from root to target in the resulting BFS tree or None
if no path is found. Returns Err
if the root or target nodes do not exist.
Panics
This function pancis when the queue operations fail.
Examples
let net = Network::new(100, Model::ER { p: 0.05, whole: false }, Weight::None);
match bfs(&net, 1, 3)? {
Some(d) => println!("Edges between 1 and 3: {}", d),
None => println!("No path from 1 to 3 found!"),
}