Function lollipop_graph

Source
pub fn lollipop_graph<G, T, F, H, M>(
    num_mesh_nodes: Option<usize>,
    num_path_nodes: Option<usize>,
    mesh_weights: Option<Vec<T>>,
    path_weights: Option<Vec<T>>,
    default_node_weight: F,
    default_edge_weight: H,
) -> Result<G, InvalidInputError>
where G: Build + Create + Data<NodeWeight = T, EdgeWeight = M> + NodeIndexable + GraphProp, F: FnMut() -> T, H: FnMut() -> M, G::NodeId: Eq + Hash,
Expand description

Generate a lollipop graph where a complete graph is connected to a path.

If neither num_path_nodes nor path_weights (described below) are specified, then this is equivalent to a complete graph.

Arguments:

  • num_mesh_nodes - The number of nodes to generate the mesh graph with. Node weights will be None if this is specified. If both num_mesh_nodes and mesh_weights are set this will be ignored and mesh_weights will be used.
  • num_path_nodes - The number of nodes to generate the path with. Node weights will be None if this is specified. If both num_path_nodes and path_weights are set this will be ignored and path_weights will be used.
  • mesh_weights - A list of node weights for the mesh graph. If both num_mesh_nodes and mesh_weights are set num_mesh_nodes will be ignored and mesh_weights will be used.
  • path_weights - A list of node weights for the path. If both num_path_nodes and path_weights are set num_path_nodes will be ignored and path_weights will be used.
  • default_node_weight - A callable that will return the weight to use for newly created nodes. This is ignored if weights is specified.
  • default_edge_weight - A callable that will return the weight object to use for newly created edges.

ยงExample

use rustworkx_core::petgraph;
use rustworkx_core::generators::lollipop_graph;
use rustworkx_core::petgraph::visit::EdgeRef;

let expected_edge_list = vec![
    (0, 1),
    (0, 2),
    (0, 3),
    (1, 2),
    (1, 3),
    (2, 3),
    (3, 4),
    (4, 5),
    (5, 6),
];
let g: petgraph::graph::UnGraph<(), ()> = lollipop_graph(
    Some(4),
    Some(3),
    None,
    None,
    || {()},
    || {()},
).unwrap();
assert_eq!(
    expected_edge_list,
    g.edge_references()
        .map(|edge| (edge.source().index(), edge.target().index()))
        .collect::<Vec<(usize, usize)>>(),
)