Function complete_graph

Source
pub fn complete_graph<G, T, F, H, M>(
    num_nodes: Option<usize>,
    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,
Expand description

Generate a complete graph

Arguments:

  • num_nodes - The number of nodes to create a complete graph for. Either this or weights must be specified. If both this and weights are specified, weights will take priority and this argument will be ignored
  • weights - A Vec of node weight objects.
  • 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::complete_graph;
use rustworkx_core::petgraph::visit::EdgeRef;

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