Skip to main content

AttributeCombination

Type Alias AttributeCombination 

Source
pub type AttributeCombination = igraph_attribute_combination_t;
Expand description

How to combine attributes when vertices or edges are merged (igraph_attribute_combination_t).

It maps attribute names to an AttributeCombinationType; the entry with no name (None) is the default for every attribute not listed. An empty combination drops all the attributes of merged elements.

Pass it to Graph::simplify_with_attributes, Graph::contract_vertices_with_attributes or Graph::to_undirected_with_attributes, or to other igraph functions merging elements through the raw FFI with as_ptr.

use igraph::attributes::{AttributeCombination, AttributeCombinationType as Comb};

let comb = AttributeCombination::from_pairs(&[
    (Some("weight"), Comb::Sum),
    (Some("name"), Comb::First),
    (None, Comb::Ignore),
]).unwrap();
assert_eq!(comb.query(Some("weight")).unwrap(), Comb::Sum);
assert_eq!(comb.query(Some("color")).unwrap(), Comb::Ignore); // falls back to the default

// Merge the two parallel edges: weights are summed, other attributes dropped.
use igraph::prelude::*;
let mut g = Graph::from_edges(&[(0, 1), (0, 1)], 2, false).unwrap();
g.set_edge_attr_numeric_values("weight", &[1.5, 2.0]).unwrap();
g.set_edge_attr_str_values("color", &["red", "blue"]).unwrap();
g.simplify_with_attributes(true, true, &comb).unwrap();
assert_eq!(g.edge_attr_numeric("weight", 0).unwrap(), 3.5);
assert!(!g.has_attribute(igraph::attributes::AttributeKind::Edge, "color"));

Aliased Typeยง

pub struct AttributeCombination { /* private fields */ }