diff --git a/src/expand_n_contract.rs b/src/expand_n_contract.rs index f16949b784d03f419e6976427381a778c206f8a4..e75599674f5824825ccf59b759bcb5bc1ba80593 100644 --- a/src/expand_n_contract.rs +++ b/src/expand_n_contract.rs @@ -17,7 +17,7 @@ pub fn expand_n_contract( // NOTE: Start with the normal form of the wheel graph. let mut wheel_graph: UndirectedGraph = UndirectedGraph::wheel_graph(num_spokes); - let (wheel_graph_sign, wheel_graph_vertex_orbits, _) = wheel_graph.normal_form(false); + let (wheel_graph_sign, wheel_graph_vertex_orbits) = wheel_graph.normal_form(false); assert!(wheel_graph_sign != 0); cocycle_graphs.push(wheel_graph.clone()); cocycle_graph_index.insert(wheel_graph, 0); @@ -51,8 +51,7 @@ pub fn expand_n_contract( writeln!(sparse_matrix_file, "{} {} {}", dg_idx + 1, g_idx + 1, c)?; num_nonzeros += 1; - let cg_data: HashMap<UndirectedGraph, Vec<usize>> = - dg.contractions(&dg_edge_orbits); + let cg_data: HashMap<UndirectedGraph, Vec<usize>> = dg.contractions(&dg_edge_orbits); for (cg, cg_vertex_orbits) in cg_data { // eprintln!("{:?}", cg); if !cocycle_graph_index.contains_key(&cg) { diff --git a/src/undirected_graph.rs b/src/undirected_graph.rs index b297db669ed36f51cf891ffee3451a031ef4d81b..fc6a0a72ccef738a45d01a2e0c94e78b7f316a59 100644 --- a/src/undirected_graph.rs +++ b/src/undirected_graph.rs @@ -241,7 +241,7 @@ impl UndirectedGraph { } } - pub fn normal_form(&mut self, compute_edge_orbits: bool) -> (i32, Vec<usize>, Vec<usize>) { + pub fn normal_form(&mut self, compute_edge_orbits: bool) -> (i32, Vec<usize>) { let mut options: nauty_Traces_sys::optionblk = nauty_Traces_sys::optionblk { getcanon: nauty_Traces_sys::TRUE, userautomproc: Some(Self::process_nauty_automorphism), @@ -292,11 +292,6 @@ impl UndirectedGraph { lab_inv[lab[i] as usize] = i as i32; } - let normal_self_orbits: Vec<usize> = orbits - .iter() - .map(|&v| lab_inv[v as usize] as usize) - .collect(); - let mut sign: i32 = 1; let mut normal_self_edge_orbits: Vec<usize> = vec![]; Self::EDGE_ORBIT_DATA.with_borrow_mut(|edge_orbit_data: &mut EdgeOrbitData| { @@ -321,7 +316,15 @@ impl UndirectedGraph { self.nauty_graph = normal_self.nauty_graph; - (sign, normal_self_orbits, normal_self_edge_orbits) + if compute_edge_orbits { + (sign, normal_self_edge_orbits) + } else { + let normal_self_orbits: Vec<usize> = orbits + .iter() + .map(|&v| lab_inv[v as usize] as usize) + .collect(); + (sign, normal_self_orbits) + } } fn expand_vertex(&self, &position: &usize) -> Vec<(i64, UndirectedGraph)> { @@ -474,9 +477,7 @@ impl UndirectedGraph { for (orbit_rep, orbit_size) in orbit_reps { for (c, mut dg) in self.expand_vertex(&orbit_rep) { - // TODO: Avoid computing orbits when not used. - let (normal_dg_sign, _normal_dg_orbits, normal_dg_edge_orbits) = - dg.normal_form(true); + let (normal_dg_sign, normal_dg_edge_orbits) = dg.normal_form(true); if normal_dg_sign == 0 { continue; } @@ -568,7 +569,7 @@ impl UndirectedGraph { nauty_graph: contracted_graph, }; - let (normal_cg_sign, normal_cg_orbits, _) = cg.normal_form(false); + let (normal_cg_sign, normal_cg_orbits) = cg.normal_form(false); if normal_cg_sign == 0 { continue; }