Function rs_graph::classes::grid

source ·
pub fn grid<G>(n: usize, m: usize) -> Gwhere
    G: Graph + Buildable,
Expand description

Return a grid graph with n columns and m rows.

The nodes are created from left to right and from bottom to top. The following is a grid graph with 5 columns and 4 rows.

15 - 16 - 17 - 18 - 19 | | | | | 10 - 11 - 12 - 13 - 14 | | | | | 5 – 6 – 7 – 8 – 9 | | | | | 0 – 1 – 2 – 3 – 4

use rs_graph::LinkedListGraph;
use rs_graph::traits::*;
use rs_graph::classes;

let g: LinkedListGraph = classes::grid(5, 4);
assert_eq!(g.num_nodes(), 20);
assert_eq!(g.num_edges(), 5*3 + 4*4);

assert_eq!(g.nodes().filter(|&u| g.neighs(u).count() == 2).count(), 4);
assert_eq!(g.nodes().filter(|&u| g.neighs(u).count() == 3).count(), 10);
assert_eq!(g.nodes().filter(|&u| g.neighs(u).count() == 4).count(), 6);