1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Constant Potts Model (CPM) quality function helpers.
//!
//! `Q_CPM = Σ_C [e_C − γ · n_C · (n_C − 1) / 2]`
//!
//! where `e_C` is internal edges in community `C`, `n_C` is the number of
//! nodes, and `γ` is the resolution parameter.
//!
//! The gain computation is used in the local move phase for `QualityFunction::Cpm`.
/// CPM gain of moving `node` into community `to`.
///
/// `k_in_to` = edges from `node` to community `to`.
/// `n_to` = current size of community `to` (after `node` was removed from its
/// previous community).
/// `gamma` = resolution parameter.
///
/// Positive return value means the move improves CPM quality.