Skip to main content

leiden_rs/graph/
move_components.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4/// Parameters for computing the quality delta of moving a node between communities.
5///
6/// Unified for directed and undirected graphs:
7/// - Undirected: `_in` fields are all `0.0`, `directed` is `false`. Quality
8///   functions use the `_out` fields with the classic undirected formula.
9/// - Directed: `_in` fields contain in-edge statistics, `directed` is `true`.
10///   Quality functions use both `_out` and `_in` fields.
11#[derive(Debug, Clone)]
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13pub struct MoveComponents {
14    // ── Global statistics ──
15    /// Twice the total edge weight of the graph (`2m`).
16    pub two_m: f64,
17    /// Weight of the node being moved.
18    pub node_weight: f64,
19    /// Total node weight across all communities.
20    pub total_node_weight: f64,
21
22    // ── Out-edge statistics ──
23    /// Weighted out-degree of the node being moved.
24    pub k_v_out: f64,
25    /// Out-edge weight from the node to the target community.
26    pub k_v_to_target_out: f64,
27    /// Out-edge weight from the node to its current community.
28    pub k_v_to_current_out: f64,
29    /// Total weighted out-degree of the target community.
30    pub sigma_tot_target_out: f64,
31    /// Total weighted out-degree of the current community.
32    pub sigma_tot_current_out: f64,
33
34    // ── In-edge statistics (0.0 for undirected graphs) ──
35    /// Weighted in-degree of the node being moved.
36    pub k_v_in: f64,
37    /// In-edge weight from the node to the target community.
38    pub k_v_to_target_in: f64,
39    /// In-edge weight from the node to its current community.
40    pub k_v_to_current_in: f64,
41    /// Total weighted in-degree of the target community.
42    pub sigma_tot_target_in: f64,
43    /// Total weighted in-degree of the current community.
44    pub sigma_tot_current_in: f64,
45
46    // ── Community size (used by CPM/RBER) ──
47    /// Total node weight in the target community.
48    pub n_target: f64,
49    /// Total node weight in the current community.
50    pub n_current: f64,
51
52    /// Whether the graph is directed.
53    pub directed: bool,
54}