/**{@inheritDoc} */ @Override public Iterator<int[]> iterator() { return new StateStream(new UllmannState(container1, container2, g1, g2, bonds1, bonds2, atomMatcher, bondMatcher)); } }
for (int m = 0; m < matrix.mCols; m++) { if (matrix.get(n, m) && !verify(n, m)) { if (!hasCandidate(n)) return false;
@Test public void testNextM() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.nextM(0, -1), is(0)); assertThat(state.nextM(0, 0), is(1)); assertThat(state.nextM(0, 1), is(2)); state.m2[1] = 0; // 1 has been mapped and should be skipped over assertThat(state.nextM(0, 0), is(2)); }
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}})); assertTrue(state.add(0, 0)); assertTrue(state.add(1, 9)); assertTrue(state.add(2, 8)); assertTrue(state.add(3, 7)); assertTrue(state.add(4, 2)); assertTrue(state.add(5, 1)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, -4}, {-4, -1, 1, -1, -1, -1, -1, -1, -5, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, -5}})); state.remove(5, 1); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, -4}, {-4, -1, 1, -1, -1, -1, -1, -1, -5, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, -5}})); state.remove(4, 2); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, -4}, {-4, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); state.remove(3, 7); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, 1}, {1, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); state.remove(2, 8); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
/**{@inheritDoc} */ @Override boolean add(int n, int m) { if (!matrix.get(n, m)) return false; // fix the mapping matrix.markRow(n, -(n + 1)); matrix.set(n, m); // attempt to refine the mapping if (refine(n)) { size = size + 1; m1[n] = m; m2[m] = n; return true; } else { // mapping became invalid - unfix mapping matrix.resetRows(n, -(n + 1)); return false; } }
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}})); assertTrue(state.add(0, 0)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}, {1, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, 1, -1, -1, -1, 1, -1, 1}, {1, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); assertTrue(state.add(1, 9)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {1, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -2, -1, -1, -1, 1, -1, 1}, {1, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); assertTrue(state.add(2, 8)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, 1}, {1, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); assertTrue(state.add(3, 7)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, -4}, {-4, -1, 1, -1, -1, -1, -1, -1, 1, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, 1}})); assertTrue(state.add(4, 2)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -2, -1, -1, -1, -1, -1, -1, -1, 1}, {-3, -1, -2, -1, -1, -1, -1, -1, 1, -1}, {-1, -3, -1, -2, -1, -1, -1, 1, -1, -4}, {-4, -1, 1, -1, -1, -1, -1, -1, -5, -1}, {-1, 1, -1, -1, -1, -1, -1, -1, -1, -5}})); assertTrue(state.add(5, 1)); assertThat(state.matrix.fix(), is(new int[][]{{1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
/** * Create a state for matching benzene to naphthalene Benzene: * InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H Naphthalene: InChI=1/C10H8/c1-2-6-10-8-4-3-7-9(10)5-1/h1-8H */ UllmannState createBenzeneToNaphthalene(AtomMatcher atomMatcher, BondMatcher bondMatcher) throws Exception { IAtomContainer container1 = TestMoleculeFactory.makeBenzene(); IAtomContainer container2 = TestMoleculeFactory.makeNaphthalene(); GraphUtil.EdgeToBondMap bonds1 = GraphUtil.EdgeToBondMap.withSpaceFor(container1); GraphUtil.EdgeToBondMap bonds2 = GraphUtil.EdgeToBondMap.withSpaceFor(container2); int[][] g1 = GraphUtil.toAdjList(container1, bonds1); int[][] g2 = GraphUtil.toAdjList(container2, bonds2); return new UllmannState(container1, container2, g1, g2, bonds1, bonds2, atomMatcher, bondMatcher); } }