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
40
41
42
43
44
45
46
47
48
49
use nauty_Traces_sys::{empty_graph, ADDONEARC, SETWORDSNEEDED};
use petgraph::{visit::GetAdjacencyMatrix, EdgeType, Graph};
use std::ffi::c_int;

#[derive(Debug)]
pub struct DenseGraph {
    pub g: Vec<u64>,
    pub n: usize,
    pub e: usize,
    pub m: usize,
    pub nodes: Nodes,
}
impl DenseGraph {
    pub fn from_petgraph<N, E, Ty>(graph: &Graph<N, E, Ty>) -> Self
    where
        Ty: EdgeType,
    {
        let n = graph.node_count();
        let e = graph.edge_count();
        let m = SETWORDSNEEDED(n);
        let nodes = Nodes::new(n);
        let mut g = empty_graph(m, n);
        let adj = graph.adjacency_matrix();
        for idx in 0..n {
            for jdx in 0..n {
                if adj.contains(idx * n + jdx) {
                    ADDONEARC(&mut g, idx, jdx, m)
                }
            }
        }
        Self { g, n, e, m, nodes }
    }
}

#[derive(Debug)]
pub struct Nodes {
    pub lab: Vec<c_int>,
    pub ptn: Vec<c_int>,
    pub orbits: Vec<c_int>,
}
impl Nodes {
    pub fn new(n: usize) -> Self {
        Self {
            lab: (0..n as i32).collect(),
            ptn: vec![0; n],
            orbits: vec![0; n],
        }
    }
}