fn enumerate_neighbour_mappings(
    neighbours: &NeighbourIndexes, 
    numbering: &Vec<usize>,
) -> Vec<Vec<usize>> {
    let mut neighbour_indexes = neighbours.to_vec();
    neighbour_indexes.sort_by_key(|&ni| numbering[ni]);

    let mut neighbour_indexes_by_group: Vec<Vec<usize>> = vec![vec![neighbour_indexes[0]]];
    let mut current_numbering: usize = numbering[neighbour_indexes[0]];
    for i in 1..neighbour_indexes.len() {
        let size: usize = neighbour_indexes_by_group.len();
        if numbering[neighbour_indexes[i]] == current_numbering {
            neighbour_indexes_by_group[size - 1].push(neighbour_indexes[i]);
        } else {
            current_numbering = numbering[neighbour_indexes[i]];
            neighbour_indexes_by_group.push(vec![neighbour_indexes[i]]);
        }
    }

    let mut permutations: Vec<Vec<usize>> = vec![vec![]];
    for i in 0..neighbour_indexes_by_group.len() {
        if neighbour_indexes_by_group[i].len() == 1 {
            for j in 0..permutations.len() {
                permutations[j].push(neighbour_indexes_by_group[i][0]);
            }
        } else {
            let permutated_neighbours = core::cnap::factorial_vec(&neighbour_indexes_by_group[i]);
            let mut permutations_tmp = permutations.clone();
            permutations.clear();
            while let Some(p) = permutations_tmp.pop() {
                let mut pn_tmp = permutated_neighbours.clone();
                while let Some(mut pn) = pn_tmp.pop() {
                    let mut p_cloned: Vec<usize> = p.clone();
                    p_cloned.append(&mut pn);
                    permutations.push(p_cloned);
                }
            }
        }
    }

    permutations
}
/// Enumerate all possible mappings of the neighbours according to a numbering
Enumerate all possible mappings of the neighbours according to a numbering
Enumerate all possible mappings of the neighbours according to a numbering
fn enumerate_neighbour_mappings(
    neighbours: &NeighbourIndexes, 
    numbering: &Vec<usize>,
) -> Vec<Vec<usize>> {
    let mut neighbour_indexes = neighbours.to_vec();
    neighbour_indexes.sort_by_key(|&ni| numbering[ni]);
    let mut neighbour_indexes_by_group: Vec<Vec<usize>> = vec![vec![neighbour_indexes[0]]];
    let mut current_numbering: usize = numbering[neighbour_indexes[0]];
    for i in 1..neighbour_indexes.len() {
        let size: usize = neighbour_indexes_by_group.len();
        if numbering[neighbour_indexes[i]] == current_numbering {
            neighbour_indexes_by_group[size - 1].push(neighbour_indexes[i]);
        } else {
            current_numbering = numbering[neighbour_indexes[i]];
            neighbour_indexes_by_group.push(vec![neighbour_indexes[i]]);
        }
    }
    let mut permutations: Vec<Vec<usize>> = vec![vec![]];
    for i in 0..neighbour_indexes_by_group.len() {
        if neighbour_indexes_by_group[i].len() == 1 {
            for j in 0..permutations.len() {
                permutations[j].push(neighbour_indexes_by_group[i][0]);
            }
        } else {
            let permutated_neighbours = core::cnap::factorial_vec(&neighbour_indexes_by_group[i]);
            let mut permutations_tmp = permutations.clone();
            permutations.clear();
            while let Some(p) = permutations_tmp.pop() {
                let mut pn_tmp = permutated_neighbours.clone();
                while let Some(mut pn) = pn_tmp.pop() {
                    let mut p_cloned: Vec<usize> = p.clone();
                    p_cloned.append(&mut pn);
                    permutations.push(p_cloned);
                }
            }
        }
    }
    permutations
}
fn enumerate_neighbour_mappings ( neighbours : & NeighbourIndexes , numbering : & Vec < usize > , ) -> Vec < Vec < usize > > { let mut neighbour_indexes = neighbours . to_vec ( ) ; neighbour_indexes . sort_by_key ( | & ni | numbering [ ni ] ) ; let mut neighbour_indexes_by_group : Vec < Vec < usize > > = vec ! [ vec [ neighbour_indexes [ 0 ] ] ] ; let mut current_numbering : usize = numbering [ neighbour_indexes [ 0 ] ] ; for i in 1 .. neighbour_indexes . len ( ) { let size : usize = neighbour_indexes_by_group . len ( ) ; if numbering [ neighbour_indexes [ i ] ] == current_numbering { neighbour_indexes_by_group [ size - 1 ] . push ( neighbour_indexes [ i ] ) ; } else { current_numbering = numbering [ neighbour_indexes [ i ] ] ; neighbour_indexes_by_group . push ( vec ! [ neighbour_indexes [ i ] ] ) ; } } let mut permutations : Vec < Vec < usize > > = vec ! [ vec [ ] ] ; for i in 0 .. neighbour_indexes_by_group . len ( ) { if neighbour_indexes_by_group [ i ] . len ( ) == 1 { for j in 0 .. permutations . len ( ) { permutations [ j ] . push ( neighbour_indexes_by_group [ i ] [ 0 ] ) ; } } else { let permutated_neighbours = core :: cnap :: factorial_vec ( & neighbour_indexes_by_group [ i ] ) ; let mut permutations_tmp = permutations . clone ( ) ; permutations . clear ( ) ; while let Some ( p ) = permutations_tmp . pop ( ) { let mut pn_tmp = permutated_neighbours . clone ( ) ; while let Some ( mut pn ) = pn_tmp . pop ( ) { let mut p_cloned : Vec < usize > = p . clone ( ) ; p_cloned . append ( & mut pn ) ; permutations . push ( p_cloned ) ; } } } } permutations }
Enumerate all possible mappings of the neighbours according to a numbering
Enumerate all possible mappings of the neighbours according to a numbering
neighbours
&NeighbourIndexes
numbering
&Vec<usize>
neighbours
&NeighbourIndexes
numbering
&Vec<usize>