Skip to main content

initial_assignment_from_cache

Function initial_assignment_from_cache 

Source
pub fn initial_assignment_from_cache(
    cached: Option<&LeidenPartition>,
    node_count: usize,
) -> Vec<usize>
Expand description

Converts a cached partition into an initial assignment vector.

node_count is the number of nodes in the current graph. Nodes not present in cached fall back to singleton assignments (assignment[i] = i).

Community IDs from the cache are remapped so they stay in [0, node_count).

ยงExamples

use std::collections::BTreeMap;
use sdivi_detection::partition::LeidenPartition;
use sdivi_detection::warm_start::initial_assignment_from_cache;

let cached = LeidenPartition {
    assignments: BTreeMap::from([(0, 0), (1, 0)]),
    stability: BTreeMap::from([(0, 0.9)]),
    modularity: 0.5,
    seed: 42,
};
let init = initial_assignment_from_cache(Some(&cached), 3);
assert_eq!(init[0], init[1]); // same community
assert_ne!(init[0], init[2]); // node 2 falls back to singleton