/// <summary> /// Add a match to the isomorphism /// </summary> /// <remarks> /// This is only a proposed match. If it fails, the passed in BacktrackRecord /// will have all the actions taken as a consequence and they can be undone using /// that BacktrackRecord. /// </remarks> /// <param name="mtc">Proposed match</param> /// <param name="btr">BacktrackRecord to record actions into</param> /// <returns>True if match is locally consistent with a full isomorphism</returns> private bool FAddMatchToSolution(Match mtc, BacktrackRecord <TV, TE> btr) { var ivtx1 = mtc.Ivtx1; var ivtx2 = mtc.Ivtx2; // Record the match action in the backtrackRecord btr.SetMatch(mtc.Ivtx1, mtc.Ivtx2, this); // In and Out neighbors of the vertices in the match var lstIn1 = VfGraph1.InNeighbors(ivtx1); var lstIn2 = VfGraph2.InNeighbors(ivtx2); var lstOut1 = VfGraph1.OutNeighbors(ivtx1); var lstOut2 = VfGraph2.OutNeighbors(ivtx2); // Reclassify any neighbors of the added vertices that require it foreach (var ivtx in lstOut1) { if (((int)VfGraph1.GetGroup(ivtx) & (int)(Group.Disconnected | Group.ToMapping)) != 0) { btr.MoveToGroup(1, ivtx, Group.FromMapping, this); } } foreach (var ivtx in lstIn1) { if (((int)VfGraph1.GetGroup(ivtx) & (int)(Group.Disconnected | Group.FromMapping)) != 0) { btr.MoveToGroup(1, ivtx, Group.ToMapping, this); } } foreach (var ivtx in lstOut2) { if (((int)VfGraph2.GetGroup(ivtx) & (int)(Group.Disconnected | Group.ToMapping)) != 0) { btr.MoveToGroup(2, ivtx, Group.FromMapping, this); } } foreach (var ivtx in lstIn2) { if (((int)VfGraph2.GetGroup(ivtx) & (int)(Group.Disconnected | Group.FromMapping)) != 0) { btr.MoveToGroup(2, ivtx, Group.ToMapping, this); } } // If the total degrees into or out of the isomorphism don't match up properly (less for // subgraph isomorphism equal for exact isomorphism) then we can never match properly. if (!FnCompareDegrees(_outDegreeTotal1, _outDegreeTotal2) || !FnCompareDegrees(_inDegreeTotal1, _inDegreeTotal2)) { return(false); } // Also check the vertex counts which is a different check from the total degree above... return(FnCompareDegrees(lstOut1.Count, lstOut2.Count) && FnCompareDegrees(lstIn1.Count, lstIn2.Count)); }
private bool FAddMatchToSolution(Match mtc, BacktrackRecord btr) { int inod1 = mtc.Inod1; int inod2 = mtc.Inod2; btr.SetMatch(mtc.Inod1, mtc.Inod2, this); List <int> lstIn1 = _vfgr1.InNeighbors(inod1); List <int> lstIn2 = _vfgr2.InNeighbors(inod2); List <int> lstOut1 = _vfgr1.OutNeighbors(inod1); List <int> lstOut2 = _vfgr2.OutNeighbors(inod2); foreach (int inod in lstOut1) { if (((int)_vfgr1.GetGroup(inod) & (int)(Groups.Disconnected | Groups.ToMapping)) != 0) { btr.MoveToGroup(1, inod, Groups.FromMapping, this); } } foreach (int inod in lstIn1) { if (((int)_vfgr1.GetGroup(inod) & (int)(Groups.Disconnected | Groups.FromMapping)) != 0) { btr.MoveToGroup(1, inod, Groups.ToMapping, this); } } foreach (int inod in lstOut2) { if (((int)_vfgr2.GetGroup(inod) & (int)(Groups.Disconnected | Groups.ToMapping)) != 0) { btr.MoveToGroup(2, inod, Groups.FromMapping, this); } } foreach (int inod in lstIn2) { if (((int)_vfgr2.GetGroup(inod) & (int)(Groups.Disconnected | Groups.FromMapping)) != 0) { btr.MoveToGroup(2, inod, Groups.ToMapping, this); } } if (!fnCmp(_outDegreeTotal1, _outDegreeTotal2) || !fnCmp(_inDegreeTotal1, _inDegreeTotal2)) { return(false); } return(fnCmp(lstOut1.Count, lstOut2.Count) && fnCmp(lstIn1.Count, lstIn2.Count)); }
public void TestMatchBacktrack() { var vfs = VfsTest(); var btr = new BacktrackRecord(); btr.SetMatch(0, 1, vfs); var grp1 = vfs.VfGraph1.GetGroup(0); var grp2 = vfs.VfGraph2.GetGroup(1); Assert.IsTrue((((int)grp1 & (int)Group.ContainedInMapping)) != 0); Assert.IsTrue((((int)grp2 & (int)Group.ContainedInMapping)) != 0); Assert.AreEqual(Group.ContainedInMapping, vfs.VfGraph1.GetGroup(0)); Assert.AreEqual(Group.ContainedInMapping, vfs.VfGraph2.GetGroup(1)); btr.Backtrack(vfs); grp1 = vfs.VfGraph1.GetGroup(0); grp2 = vfs.VfGraph2.GetGroup(1); Assert.IsFalse((((int)grp1 & (int)Group.ContainedInMapping)) != 0); Assert.IsFalse((((int)grp2 & (int)Group.ContainedInMapping)) != 0); Assert.AreEqual(Group.Disconnected, vfs.VfGraph1.GetGroup(0)); Assert.AreEqual(Group.Disconnected, vfs.VfGraph2.GetGroup(1)); }
public void TestMatchBacktrack() { VfState vfs = VfsTest(); BacktrackRecord btr = new BacktrackRecord(); btr.SetMatch(0, 1, vfs); Groups grp1 = vfs.Vfgr1.GetGroup(0); Groups grp2 = vfs.Vfgr2.GetGroup(1); Assert.IsTrue((((int)grp1 & (int)Groups.ContainedInMapping)) != 0); Assert.IsTrue((((int)grp2 & (int)Groups.ContainedInMapping)) != 0); Assert.AreEqual(Groups.ContainedInMapping, vfs.Vfgr1.GetGroup(0)); Assert.AreEqual(Groups.ContainedInMapping, vfs.Vfgr2.GetGroup(1)); btr.Backtrack(vfs); grp1 = vfs.Vfgr1.GetGroup(0); grp2 = vfs.Vfgr2.GetGroup(1); Assert.IsFalse((((int)grp1 & (int)Groups.ContainedInMapping)) != 0); Assert.IsFalse((((int)grp2 & (int)Groups.ContainedInMapping)) != 0); Assert.AreEqual(Groups.Disconnected, vfs.Vfgr1.GetGroup(0)); Assert.AreEqual(Groups.Disconnected, vfs.Vfgr2.GetGroup(1)); }