MinimumEquivalentCyclicSet extends EquivalentSetFinder { @Override Set<Integer> find(long[] invariants, IAtomContainer container, int[][] graph) { int n = invariants.length; RingSearch ringSearch = new RingSearch(container, graph); Map<Long, Set<Integer>> equivalent = new TreeMap<Long, Set<Integer>>(); for (int i = 0; i < invariants.length; i++) { Long invariant = invariants[i]; Set<Integer> set = equivalent.get(invariant); if (set == null) { if (ringSearch.cyclic(i)) { set = new HashSet<Integer>(n / 2); set.add(i); equivalent.put(invariant, set); } } else { set.add(i); } } int minSize = Integer.MAX_VALUE; Set<Integer> min = Collections.emptySet(); for (Map.Entry<Long, Set<Integer>> e : equivalent.entrySet()) { Set<Integer> vertices = e.getValue(); if (vertices.size() < minSize && vertices.size() > 1) { min = vertices; minSize = vertices.size(); } } return min; }    }
@Test public void testFind_OneChoice() throws Exception { IAtomContainer dummy = mock(IAtomContainer.class); int[][] g = new int[][]{{1, 5, 6}, {0, 2}, {1, 3}, {2, 4, 7}, {3, 5}, {0, 4}, {0}, {3}}; long[] values = new long[]{1, 0, 0, 1, 0, 0, 2, 2}; EquivalentSetFinder finder = new MinimumEquivalentCyclicSet(); Set<Integer> set = finder.find(values, dummy, g); assertThat(set.size(), is(2)); assertTrue(set.contains(0)); assertTrue(set.contains(3)); }
@Test public void testFind_TwoChoices() throws Exception { IAtomContainer dummy = mock(IAtomContainer.class); int[][] g = new int[][]{{1, 5, 6}, {0, 2, 8}, {1, 3, 9}, {2, 4, 7}, {3, 5, 10}, {0, 4, 11}, {0, 14, 15}, {3, 20, 21}, {1, 12, 13}, {2, 22, 23}, {4, 18, 19}, {5, 16, 17}, {8, 13}, {8, 12}, {6, 15}, {14, 6}, {11, 17}, {16, 11}, {10, 19}, {10, 18}, {7, 21}, {7, 20}, {9, 23}, {22, 9}}; long[] values = new long[]{0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; EquivalentSetFinder finder = new MinimumEquivalentCyclicSet(); Set<Integer> set = finder.find(values, dummy, g); assertThat(set.size(), is(6)); assertTrue(set.contains(0)); assertTrue(set.contains(1)); assertTrue(set.contains(2)); assertTrue(set.contains(3)); assertTrue(set.contains(4)); assertTrue(set.contains(5)); values = new long[]{1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; set = finder.find(values, dummy, g); assertThat(set.size(), is(6)); assertTrue(set.contains(6)); assertTrue(set.contains(7)); assertTrue(set.contains(8)); assertTrue(set.contains(9)); assertTrue(set.contains(10)); assertTrue(set.contains(11)); }
@Test public void testFind_NoChoice() throws Exception { IAtomContainer dummy = mock(IAtomContainer.class); int[][] g = new int[][]{{1, 2, 3}, {0, 4, 9}, {0, 5, 6}, {0, 7, 8}, {1}, {2}, {2}, {3}, {3}, {1}}; long[] values = new long[]{1, 2, 2, 2, 3, 3, 3, 3, 3, 3}; EquivalentSetFinder finder = new MinimumEquivalentCyclicSet(); Set<Integer> set = finder.find(values, dummy, g); assertThat(set.size(), is(0)); }