public void Mark() { CompatibilityMatrix m = new CompatibilityMatrix(5, 5); m.Set1(0, 1); m.Set1(0, 2); m.Set1(0, 4); m.Set1(1, 0); m.Set1(1, 3); Assert.IsTrue(m.Get1(0, 1)); Assert.IsTrue(m.Get1(0, 4)); m.Mark(0, 1, -1); m.Mark(0, 4, -4); m.Mark(1, 3, -6); Assert.IsFalse(m.Get1(0, 1)); Assert.IsFalse(m.Get1(0, 4)); Assert.IsFalse(m.Get1(1, 3)); m.ResetRows(0, -1); Assert.IsTrue(m.Get1(0, 1)); Assert.IsFalse(m.Get1(0, 4)); Assert.IsFalse(m.Get1(1, 3)); m.ResetRows(0, -4); Assert.IsTrue(m.Get1(0, 1)); Assert.IsTrue(m.Get1(0, 4)); Assert.IsFalse(m.Get1(1, 3)); m.ResetRows(0, -6); Assert.IsTrue(m.Get1(0, 1)); Assert.IsTrue(m.Get1(0, 4)); Assert.IsTrue(m.Get1(1, 3)); }
public void MarkRow() { CompatibilityMatrix m = new CompatibilityMatrix(5, 5); m.Set1(0, 1); m.Set1(0, 2); m.Set1(0, 4); Assert.IsTrue(Compares.AreEqual(new int[] { 0, 1, 1, 0, 1 }, m.Fix()[0])); m.MarkRow(0, -1); Assert.IsTrue(Compares.AreEqual(new int[] { 0, -1, -1, 0, -1 }, m.Fix()[0])); }
/// <summary> /// Create a state for matching subgraphs using the Ullmann refinement /// procedure. /// </summary> /// <param name="container1">query container</param> /// <param name="container2">target container</param> /// <param name="g1">query container adjacency list</param> /// <param name="g2">target container adjacency list</param> /// <param name="bonds1">query container bond map</param> /// <param name="bonds2">target container bond map</param> /// <param name="atomMatcher">method of matching atom semantics</param> /// <param name="bondMatcher">method of matching bond semantics</param> public UllmannState(IAtomContainer container1, IAtomContainer container2, int[][] g1, int[][] g2, EdgeToBondMap bonds1, EdgeToBondMap bonds2, AtomMatcher atomMatcher, BondMatcher bondMatcher) { this.bondMatcher = bondMatcher; this.g1 = g1; this.g2 = g2; this.bond1 = bonds1; this.bonds2 = bonds2; this.m1 = new int[g1.Length]; this.m2 = new int[g2.Length]; Arrays.Fill(m1, UNMAPPED); Arrays.Fill(m2, UNMAPPED); // build up compatibility matrix matrix = new CompatibilityMatrix(g1.Length, g2.Length); for (int i = 0; i < g1.Length; i++) { for (int j = 0; j < g2.Length; j++) { if (g1[i].Length <= g2[j].Length && atomMatcher.Matches(container1.Atoms[i], container2.Atoms[j])) { matrix.Set1(i, j); } } } }
/// <inheritdoc/> public override bool Add(int n, int m) { if (!matrix.Get1(n, m)) { return(false); } // fix the mapping matrix.MarkRow(n, -(n + 1)); matrix.Set1(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); } }
public void AccessAndModify() { CompatibilityMatrix m = new CompatibilityMatrix(5, 5); Assert.IsFalse(m.Get1(0, 1)); Assert.IsFalse(m.Get1(0, 4)); Assert.IsFalse(m.Get1(1, 0)); Assert.IsFalse(m.Get1(1, 3)); m.Set1(0, 1); m.Set1(0, 4); m.Set1(1, 0); m.Set1(1, 3); Assert.IsTrue(m.Get1(0, 1)); Assert.IsTrue(m.Get1(0, 4)); Assert.IsTrue(m.Get1(1, 0)); Assert.IsTrue(m.Get1(1, 3)); }
public void Fix() { CompatibilityMatrix m = new CompatibilityMatrix(5, 5); m.Set1(0, 1); m.Set1(0, 2); m.Set1(0, 4); m.Set1(1, 0); m.Set1(1, 3); m.Set1(2, 4); Assert.IsTrue(Compares.AreDeepEqual(new int[][] { new[] { 0, 1, 1, 0, 1 }, new[] { 1, 0, 0, 1, 0 }, new[] { 0, 0, 0, 0, 1 }, new[] { 0, 0, 0, 0, 0 }, new[] { 0, 0, 0, 0, 0 }, }, m.Fix())); }