diff --git a/src/main.rs b/src/main.rs index 3d3e8ef1738cb6a74f12e18620a82e532bd076b6..eb3ac1678a4af91bc0c62cf5fca22ff8f1e5002f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,8 @@ fn main() { println!("normal_g.expanding_differential(&orbits) = {:?}", normal_g.expanding_differential(&orbits)); println!("normal_g.contractions() = {:?}", normal_g.contractions(&vec![0_usize])); let h: UndirectedGraph = UndirectedGraph::new(7,vec![(0, 1), (0, 2), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6), (4, 5)]); - let edge_orbit_reps_h: Vec<usize> = vec![0, 2, 3, 4, 7, 9, 10]; - println!("normal_h.contractions(&edge_orbits_h) = {:?}", h.contractions(&edge_orbit_reps_h)); + let edge_orbits_h: Vec<usize> = vec![0, 0, 2, 3, 4, 3, 4, 10, 7, 7, 9]; + println!("normal_h.contractions(&edge_orbits_h) = {:?}", h.contractions(&edge_orbits_h)); let triangle: UndirectedGraph = UndirectedGraph::new(3, vec![(0,1), (1,2), (0,2)]); println!("triangle.normal_form() = {:?}", triangle.normal_form(true)); println!("triangle.contractions() = {:?}", triangle.contractions(&vec![0_usize])); diff --git a/src/undirected_graph.rs b/src/undirected_graph.rs index 0aef71cc458c1e9fc0a7c70606ce4412e485001c..6d8aa8abc5a73270036dc6765b1710af1471e866 100644 --- a/src/undirected_graph.rs +++ b/src/undirected_graph.rs @@ -324,11 +324,16 @@ impl UndirectedGraph { pub fn contractions( &self, - edge_orbit_reps: &Vec<usize>, + edge_orbits: &Vec<usize>, ) -> HashMap<UndirectedGraph, HashMap<usize, usize>> { // TODO: Check that passing around hashmaps is not too expensive. let mut contractions: HashMap<UndirectedGraph, HashMap<usize, usize>> = HashMap::new(); - for &edge_orbit_rep in edge_orbit_reps { + let mut edge_orbit_reps: HashSet<usize> = HashSet::new(); + for &edge_orbit_rep in edge_orbits { + // Skip orbits already seen. + if !edge_orbit_reps.insert(edge_orbit_rep) { + continue; + } let edge: (usize, usize) = self.edges[edge_orbit_rep]; // TODO: Optimize the computation of new_edges. let mut new_edges: Vec<(usize, usize)> = self.edges.clone();