Skip to main content

weighted_cliques

Function weighted_cliques 

Source
pub fn weighted_cliques(
    graph: &Graph,
    vertex_weights: &[f64],
    maximal: bool,
    min_weight: f64,
    max_weight: f64,
    max_results: Option<usize>,
) -> IgraphResult<Vec<Vec<VertexId>>>
Expand description

Finds all cliques whose total weight lies in a given range.

The weight of a clique is the sum of its vertex weights (positive integer weights, truncated to their integer parts). When maximal is true, only maximal cliques are considered; otherwise every clique is. A clique is kept when its weight is >= min_weight (unless min_weight <= 0, meaning no lower bound) and <= max_weight (unless max_weight <= 0, meaning no upper bound). If max_results is Some(n), at most n cliques are returned. Results are sorted for determinism.

This is the counterpart of igraph’s igraph_weighted_cliques.

Edge directions are ignored for directed graphs.

§Errors

Returns IgraphError::InvalidArgument if vertex_weights has the wrong length or any (truncated) weight is not a positive integer.

§Examples

use rust_igraph::{Graph, weighted_cliques};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
// All maximal cliques, unbounded weight range.
let cs = weighted_cliques(&g, &[1.0, 1.0, 1.0, 1.0], true, 0.0, 0.0, None).unwrap();
assert_eq!(cs, vec![vec![0, 1, 2], vec![2, 3]]);