예제 #1
0
        /// <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));
        }
예제 #2
0
        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));
        }