Example #1
0
            public void TestAutomorphic()
            {
                int   cRows = 10, cCols = 10;
                Graph graph1 = new Graph();

                graph1.InsertNodes(cRows * cCols);
                for (int iRow = 0; iRow < cRows - 1; iRow++)
                {
                    for (int iCol = 0; iCol < cCols - 1; iCol++)
                    {
                        int iNode      = iCol * cRows + iRow;
                        int iNodeToCol = iNode + 1;
                        int iNodeToRow = iNode + cRows;

                        graph1.InsertEdge(iNode, iNodeToCol);
                        graph1.InsertEdge(iNode, iNodeToRow);
                        graph1.InsertEdge(iNodeToCol, iNode);
                        graph1.InsertEdge(iNodeToRow, iNode);
                    }
                }
                Graph graph2 = graph1.IsomorphicShuffling(new Random(102));
                // Insert this and you'll wait a LONG time for this test to finish...
                // Note - the above is no longer true now that we have Degree compatibility check
                // graph1.InsertEdge(0, cRows * cCols - 1);

                VfState vfs = new VfState(graph1, graph2, true);

                Assert.IsTrue(vfs.FMatch());
            }
            public void TestRandomly()
            {
                var     rg = new RandomGraph(0.3, 4000 /* seed */);
                Graph   graph1, graph2;
                VfState vfs;

                FullMapping[] matches;

                for (var i = 0; i < 10; i++)
                {
                    rg.IsomorphicPair(100, out graph1, out graph2);
                    vfs     = new VfState(graph1, graph2);
                    matches = vfs.Matches().ToArray();
                    Assert.AreNotEqual(0, matches.Length);
                }

                graph1  = rg.GetGraph(100);
                graph2  = rg.GetGraph(100);
                vfs     = new VfState(graph1, graph2);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(0, matches.Length);

                rg      = new RandomGraph(0.3, 5000 /* seed */);
                graph1  = rg.GetGraph(100);
                rg      = new RandomGraph(0.3, 5000 /* seed */);
                graph2  = rg.GetGraph(100);
                vfs     = new VfState(graph1, graph2);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(1, matches.Length);
            }
            public void TestAutomorphic()
            {
                const int cRows  = 10;
                const int cCols  = 10;
                var       graph1 = new Graph();

                graph1.InsertVertices(cRows * cCols);
                for (var iRow = 0; iRow < cRows - 1; iRow++)
                {
                    for (var iCol = 0; iCol < cCols - 1; iCol++)
                    {
                        var ivtx         = iCol * cRows + iRow;
                        var iVertexToCol = ivtx + 1;
                        var iVertexToRow = ivtx + cRows;

                        graph1.AddEdge(ivtx, iVertexToCol);
                        graph1.AddEdge(ivtx, iVertexToRow);
                        graph1.AddEdge(iVertexToCol, ivtx);
                        graph1.AddEdge(iVertexToRow, ivtx);
                    }
                }
                var graph2 = graph1.IsomorphicShuffling(new Random(102));
                // Insert this and you'll wait a LONG time for this test to finish...
                // Note - the above is no longer true now that we have Degree compatibility check
                // graph1.AddEdge(0, cRows * cCols - 1);

                var vfs     = new VfState(graph1, graph2, true);
                var matches = vfs.Matches().ToArray();

                Assert.AreNotEqual(0, matches.Length);
            }
            public void TestMatch()
            {
                var gr1 = new Graph();
                var gr2 = new Graph();

                var vfs   = new VfState(gr1, gr2);
                var match = vfs.Match();

                Assert.IsNotNull(match);                                        // Two empty graphs match
                gr2.InsertVertex();
                vfs   = new VfState(gr1, gr2);
                match = vfs.Match();
                Assert.IsNull(match);                                           // Graph with no vertices will not match one with a single isolated vertex
                gr1.InsertVertex();
                vfs   = new VfState(gr1, gr2);
                match = vfs.Match();
                Assert.IsNotNull(match);                                        // Two graphs with single isolated vertices match
                gr1.InsertVertex();
                vfs   = new VfState(gr1, gr2);
                match = vfs.Match();
                Assert.IsNotNull(match);                                        // Two isolated vertices match with one under default subgraph isomorphism
                gr1.AddEdge(0, 1);
                vfs   = new VfState(gr1, gr2);
                match = vfs.Match();
                Assert.IsNotNull(match);                                        // Connect the two and a subgraph isomorphism still works
            }
Example #5
0
        internal CandidateFinder(VfState vfs)
        {
            _vfs = vfs;

            if (
                !vfs.fnCmp(vfs.LstOut1.Count, vfs.LstOut2.Count) ||
                !vfs.fnCmp(vfs.LstIn1.Count, vfs.LstIn2.Count) ||
                !vfs.fnCmp(vfs.LstDisconnected1.Count, vfs.LstDisconnected2.Count))
            {
                _fFailImmediately = true;
                return;
            }
            if (vfs.LstOut2.Count > 0 && vfs.LstOut1.Count > 0)
            {
                _arinodGraph1 = new int[vfs.LstOut1.Count];
                vfs.LstOut1.CopyTo(_arinodGraph1);
                SetInitialMatch(vfs.LstOut1[0], vfs.LstOut2[0]);
            }
            else if (vfs.LstIn2.Count > 0 && vfs.LstIn1.Count > 0)
            {
                _arinodGraph1 = new int[vfs.LstIn1.Count];
                vfs.LstIn1.CopyTo(_arinodGraph1);
                SetInitialMatch(vfs.LstIn1[0], vfs.LstIn2[0]);
            }
            else if (vfs.LstDisconnected1.Count >= 0)
            {
                _arinodGraph1 = new int[vfs.LstDisconnected1.Count];
                vfs.LstDisconnected1.CopyTo(_arinodGraph1);
                SetInitialMatch(vfs.LstDisconnected1[0], vfs.LstDisconnected2[0]);
            }
        }
Example #6
0
 internal void Backtrack(VfState vfs)
 {
     foreach (BacktrackAction act in _lstActions)
     {
         act.Backtrack(vfs);
     }
 }
Example #7
0
            public void TestSetMapping()
            {
                VfState vfs = VfsTest();

                vfs.SetMapping(0, 1);
                Assert.AreEqual(1, vfs._arinodMap1To2[0]);
                Assert.AreEqual(0, vfs._arinodMap2To1[1]);
            }
Example #8
0
            public void TestMakeMove()
            {
                VfState vfs = VfsTest();

                vfs.MakeMove(1, 0, Groups.FromMapping);
                Assert.AreEqual(1, vfs._lstOut1.Count);
                Assert.AreEqual(5, vfs._lstDisconnected1.Count);
                Assert.AreEqual(Groups.FromMapping, vfs.Vfgr1.GetGroup(0));
            }
Example #9
0
        internal void SetMatch(int inod1, int inod2, VfState vfs)
        {
            MoveToGroup(1, inod1, Groups.ContainedInMapping, vfs);
            MoveToGroup(2, inod2, Groups.ContainedInMapping, vfs);

            vfs.SetMapping(inod1, inod2);

            // Add actions to undo this act...
            AddAction(new BacktrackAction(Action.deleteMatch, 1, inod1));
            AddAction(new BacktrackAction(Action.deleteMatch, 2, inod2));
        }
Example #10
0
            public void TestMatchComplex()
            {
                VfState vfs = VfsTest();

                Assert.IsTrue(vfs.FMatch());
                Graph graph2 = VfsTestGraph2();

                graph2.DeleteEdge(1, 4);
                graph2.InsertEdge(2, 4);
                vfs = new VfState(VfsTestGraph1(), graph2);
                Assert.IsFalse(vfs.FMatch());

                Graph graph1 = new Graph();

                graph1.InsertNodes(11);
                graph2 = new Graph();
                graph2.InsertNodes(11);

                graph1.InsertEdge(0, 2);
                graph1.InsertEdge(0, 1);
                graph1.InsertEdge(2, 4);
                graph1.InsertEdge(2, 5);
                graph1.InsertEdge(1, 5);
                graph1.InsertEdge(1, 3);
                graph1.InsertEdge(4, 7);
                graph1.InsertEdge(5, 7);
                graph1.InsertEdge(5, 8);
                graph1.InsertEdge(5, 6);
                graph1.InsertEdge(3, 6);
                graph1.InsertEdge(7, 10);
                graph1.InsertEdge(6, 9);
                graph1.InsertEdge(10, 8);
                graph1.InsertEdge(8, 9);

                graph2.InsertEdge(0, 1);
                graph2.InsertEdge(0, 9);
                graph2.InsertEdge(1, 2);
                graph2.InsertEdge(1, 10);
                graph2.InsertEdge(9, 10);
                graph2.InsertEdge(9, 8);
                graph2.InsertEdge(2, 3);
                graph2.InsertEdge(10, 3);
                graph2.InsertEdge(10, 5);
                graph2.InsertEdge(10, 7);
                graph2.InsertEdge(8, 7);
                graph2.InsertEdge(3, 4);
                graph2.InsertEdge(7, 6);
                graph2.InsertEdge(4, 5);
                graph2.InsertEdge(5, 6);

                vfs = new VfState(graph1, graph2, true);
                Assert.IsTrue(vfs.FMatch());
            }
Example #11
0
            public void TestConstructor()
            {
                VfState         vfs = VfsTest();
                CandidateFinder cf  = new CandidateFinder(vfs);
                Match           mch = cf.NextCandidateMatch();

                Assert.AreEqual(0, mch.Inod1);
                Assert.AreEqual(0, mch.Inod2);
                mch = cf.NextCandidateMatch();
                Assert.AreEqual(1, mch.Inod1);
                Assert.AreEqual(0, mch.Inod2);
            }
        /// <summary>
        /// Propose to map ivtx1 from the first graph to ivtx2 in the second for
        /// the isomorphism being formed
        /// </summary>
        /// <param name="ivtx1">Vertex index in the first graph</param>
        /// <param name="ivtx2">Vertex index in the second graph</param>
        /// <param name="vfs">State determining the isomorphism</param>
        internal void SetMatch(int ivtx1, int ivtx2, VfState <TVAttr, TEAttr> vfs)
        {
            // Add both vertices to the "In Mapping" group
            MoveToGroup(1, ivtx1, Group.ContainedInMapping, vfs);
            MoveToGroup(2, ivtx2, Group.ContainedInMapping, vfs);

            // Actually set the vertices to correspond in the isomorphism
            vfs.SetIsomorphic(ivtx1, ivtx2);

            // Add actions to undo this act...
            AddAction(new BacktrackAction(Action.DeleteMatch, 1, ivtx1));
            AddAction(new BacktrackAction(Action.DeleteMatch, 2, ivtx2));
        }
Example #13
0
        internal void Backtrack(VfState vfs)
        {
            switch (_act)
            {
            case Action.deleteMatch:
                vfs.RemoveFromMappingList(_iGraph, _inod);
                break;

            case Action.groupMove:
                vfs.MakeMove(_iGraph, _inod, _grpRestore);
                break;
            }
        }
Example #14
0
            public void TestRandomlyBig()
            {
                RandomGraph rg = new RandomGraph(0.3, 4000 /* seed */);
                Graph       graph1, graph2;
                VfState     vfs;

                // Vast majority of time spent here looking for 299,000 edges
                // in Isomorphic Pair...
                rg.IsomorphicPair(1000, out graph1, out graph2);

                // The actual match took less than 3 seconds on my machine
                vfs = new VfState(graph1, graph2);
                Assert.IsTrue(vfs.FMatch());
            }
Example #15
0
            public void TestMatchSubgraph()
            {
                // Note that "Subgraph" is defined as a graph derived from
                // deleting vertices from another graph.  Thus, the edges
                // between the remaining vertices must match with matches in the
                // original graph.  Adding edges between vertices in a graph does
                // not constitute a supergraph under this definition.

                var gr1 = new Graph();
                var gr2 = new Graph();

                gr1.InsertVertices(4);
                gr2.InsertVertices(3);
                gr1.AddEdge(0, 1);
                gr1.AddEdge(2, 0);
                gr1.AddEdge(3, 0);
                gr1.AddEdge(2, 3);
                gr2.AddEdge(0, 1);
                gr2.AddEdge(2, 0);
                var vfs     = new VfState(gr1, gr2);
                var matches = vfs.Matches().ToArray();

                Assert.AreNotEqual(0, matches.Length);

                gr1     = VfsTestGraph1();
                gr2     = VfsTestGraph2();
                vfs     = new VfState(gr1, gr2);
                matches = vfs.Matches().ToArray();
                Assert.AreNotEqual(0, matches.Length);
                gr1.InsertVertex();
                gr1.AddEdge(6, 3);
                gr1.AddEdge(6, 5);

                // Graph 2 is isomorphic to a subgraph of graph 1 (default check is for
                // subgraph isomorphism).
                vfs     = new VfState(gr1, gr2);
                matches = vfs.Matches().ToArray();
                Assert.AreNotEqual(0, matches.Length);

                // The converse is false
                vfs     = new VfState(gr2, gr1);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(0, matches.Length);

                // The two graphs are subgraph ismorphic but not ismorphic
                vfs     = new VfState(gr1, gr2, true /* fIsomorphism */);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(0, matches.Length);
            }
Example #16
0
        internal void Backtrack <TVAttr, TEAttr>(VfState <TVAttr, TEAttr> vfs)
        {
            switch (_act)
            {
            case Action.DeleteMatch:
                // Undo a matching
                vfs.RemoveFromMappingList(_iGraph, _ivtx);
                break;

            case Action.GroupMove:
                // Move back to previous group
                vfs.MakeMove(_iGraph, _ivtx, _grpRestore);
                break;
            }
        }
Example #17
0
            public void TestMatchNonConnected()
            {
                Graph gr1 = new Graph();
                Graph gr2 = new Graph();

                gr1.InsertNodes(4);
                gr2.InsertNodes(4);

                gr1.InsertEdge(0, 1);
                gr1.InsertEdge(2, 3);
                gr2.InsertEdge(2, 1);
                gr2.InsertEdge(0, 3);
                VfState vfs = new VfState(gr1, gr2);

                Assert.IsTrue(vfs.FMatch());
            }
Example #18
0
        internal void MoveToGroup(int iGraph, int inod, Groups grpNew, VfState vfs)
        {
            VfGraph vfg    = iGraph == 1 ? vfs.Vfgr1 : vfs.Vfgr2;
            Groups  grpOld = vfg.GetGroup(inod);

            if (grpOld == Groups.FromMapping && grpNew == Groups.ToMapping ||
                grpOld == Groups.ToMapping && grpNew == Groups.FromMapping)
            {
                grpNew = Groups.FromMapping | Groups.ToMapping;
            }
            if (grpOld != (grpOld | grpNew))
            {
                AddAction(new BacktrackAction(Action.groupMove, iGraph, inod, grpOld));
                vfs.MakeMove(iGraph, inod, grpNew);
            }
        }
Example #19
0
            public void TestMatchNonConnected()
            {
                var gr1 = new Graph();
                var gr2 = new Graph();

                gr1.InsertVertices(4);
                gr2.InsertVertices(4);

                gr1.AddEdge(0, 1);
                gr1.AddEdge(2, 3);
                gr2.AddEdge(2, 1);
                gr2.AddEdge(0, 3);
                var vfs     = new VfState(gr1, gr2);
                var matches = vfs.Matches().ToArray();

                Assert.AreNotEqual(0, matches.Length);
            }
Example #20
0
            public void TestContextCheck()
            {
                var graph1 = new Graph <VertexColor, Object>();
                var graph2 = new Graph <VertexColor, Object>();

                graph1.InsertVertex(new VertexColor("Blue"));
                graph1.InsertVertex(new VertexColor("Red"));
                graph1.InsertVertex(new VertexColor("Red"));
                graph1.InsertVertex(new VertexColor("Red"));
                graph1.InsertVertex(new VertexColor("Red"));
                graph1.AddEdge(0, 1);
                graph1.AddEdge(1, 2);
                graph1.AddEdge(2, 3);
                graph1.AddEdge(3, 4);
                graph1.AddEdge(4, 0);

                graph2.InsertVertex(new VertexColor("Red"));
                graph2.InsertVertex(new VertexColor("Red"));
                graph2.InsertVertex(new VertexColor("Red"));
                graph2.InsertVertex(new VertexColor("Blue"));
                graph2.InsertVertex(new VertexColor("Red"));
                graph2.AddEdge(0, 1);
                graph2.AddEdge(1, 2);
                graph2.AddEdge(2, 3);
                graph2.AddEdge(3, 4);
                graph2.AddEdge(4, 0);

                var vfs     = new VfState <VertexColor, Object>(graph1, graph2, true);
                var matches = vfs.Matches().ToArray();

                Assert.AreNotEqual(0, matches.Length);
                var mpMatch = matches[0].IsomorphismVid1ToVid2;

                // With no context checking, vertex 0 in the first graph can match
                // vertex 0 in the second graph
                Assert.AreEqual(0, mpMatch[0]);

                vfs     = new VfState <VertexColor, Object>(graph1, graph2, true, true);
                matches = vfs.Matches().ToArray();
                Assert.AreNotEqual(0, matches.Length);
                mpMatch = matches[0].IsomorphismVid1ToVid2;
                // With context checking, Blue in first circular graph has to map to blue
                // in second circular graph.
                Assert.AreEqual(3, mpMatch[0]);
            }
Example #21
0
            public void TestRandomly()
            {
                RandomGraph rg = new RandomGraph(0.3, 4000 /* seed */);
                Graph       graph1, graph2;
                VfState     vfs;

                for (int i = 0; i < 10; i++)
                {
                    rg.IsomorphicPair(100, out graph1, out graph2);
                    vfs = new VfState(graph1, graph2);
                    Assert.IsTrue(vfs.FMatch());
                }

                graph1 = rg.GetGraph(100);
                graph2 = rg.GetGraph(100);
                vfs    = new VfState(graph1, graph2);
                Assert.IsFalse(vfs.FMatch());
            }
Example #22
0
            public void TestMatchSubgraph()
            {
                // Note that "Subgraph" is defined as a graph derived from
                // deleting nodes from another graph.  Thus, the edges
                // between the remaining nodes must match with matches in the
                // original graph.  Adding edges between nodes in a graph does
                // not constitute a supergraph under this definition.

                Graph gr1 = new Graph();
                Graph gr2 = new Graph();

                gr1.InsertNodes(4);
                gr2.InsertNodes(3);
                gr1.InsertEdge(0, 1);
                gr1.InsertEdge(2, 0);
                gr1.InsertEdge(3, 0);
                gr1.InsertEdge(2, 3);
                gr2.InsertEdge(0, 1);
                gr2.InsertEdge(2, 0);
                VfState vfs = new VfState(gr1, gr2);

                Assert.IsTrue(vfs.FMatch());

                gr1 = VfsTestGraph1();
                gr2 = VfsTestGraph2();
                vfs = new VfState(gr1, gr2);
                Assert.IsTrue(vfs.FMatch());
                gr1.InsertNode();
                gr1.InsertEdge(6, 3);
                gr1.InsertEdge(6, 5);

                // Graph 2 is isomorphic to a subgraph of graph 1 (default check is for
                // subgraph isomorphism).
                vfs = new VfState(gr1, gr2);
                Assert.IsTrue(vfs.FMatch());

                // The converse is false
                vfs = new VfState(gr2, gr1);
                Assert.IsFalse(vfs.FMatch());

                // The two graphs are subgraph ismorphic but not ismorphic
                vfs = new VfState(gr1, gr2, true /* fIsomorphism */);
                Assert.IsFalse(vfs.FMatch());
            }
Example #23
0
            public void TestContextCheck()
            {
                Graph graph1 = new Graph();
                Graph graph2 = new Graph();

                graph1.InsertNode(new NodeColor("Blue"));
                graph1.InsertNode(new NodeColor("Red"));
                graph1.InsertNode(new NodeColor("Red"));
                graph1.InsertNode(new NodeColor("Red"));
                graph1.InsertNode(new NodeColor("Red"));
                graph1.InsertEdge(0, 1);
                graph1.InsertEdge(1, 2);
                graph1.InsertEdge(2, 3);
                graph1.InsertEdge(3, 4);
                graph1.InsertEdge(4, 0);

                graph2.InsertNode(new NodeColor("Red"));
                graph2.InsertNode(new NodeColor("Red"));
                graph2.InsertNode(new NodeColor("Red"));
                graph2.InsertNode(new NodeColor("Blue"));
                graph2.InsertNode(new NodeColor("Red"));
                graph2.InsertEdge(0, 1);
                graph2.InsertEdge(1, 2);
                graph2.InsertEdge(2, 3);
                graph2.InsertEdge(3, 4);
                graph2.InsertEdge(4, 0);

                VfState vfs = new VfState(graph1, graph2, true);

                Assert.IsTrue(vfs.FMatch());
                int[] mpMatch = vfs.Mapping1To2;
                // With no context checking, vertex 0 in the first graph can match
                // vertex 0 in the second graph
                Assert.AreEqual(0, mpMatch[0]);

                vfs = new VfState(graph1, graph2, true, true);
                Assert.IsTrue(vfs.FMatch());
                mpMatch = vfs.Mapping1To2;
                // With context checking, Blue in first circular graph has to map to blue
                // in second circular graph.
                Assert.AreEqual(3, mpMatch[0]);
            }
Example #24
0
 // Step 1: Find matchs.
 private static Rule FindMatchs(VFlibcs.Graph graphVF)
 {
     foreach (var rule in RandomOrderByWeight())
     {
         if (rule.QuantityLimitMax == 0)
         {
             continue;
         }
         // VfState: Calculate the result of subgraph isomorphic.
         VFlibcs.VfState vfs = new VFlibcs.VfState(graphVF, _ruleVFgraphTable[rule], false, true);
         if (vfs.FMatch())
         {
             // Reduce the quantity limit.
             if (rule.QuantityLimitMin > 0)
             {
                 rule.QuantityLimitMin -= 1;
             }
             if (rule.QuantityLimitMax > 0)
             {
                 rule.QuantityLimitMax -= 1;
             }
             _relatedNodes.Clear();
             for (int i = 0; i < vfs.Mapping2To1.Length; i++)
             {
                 // Set Index.
                 Node node = graphVF.GetNodeAttr(vfs.Mapping2To1[i]) as Node;
                 // Record this one is used in this iterating.
                 node.Explored = true;
                 _exploredNodeStack.Push(node);
                 if (node.IsEdge)
                 {
                     continue;
                 }
                 node.Index = (_ruleVFgraphTable[rule].GetNodeAttr(i) as Node).Index;
                 _relatedNodes.Add(node);
             }
             return(rule);
         }
     }
     return(null);
 }
        /// <summary>
        /// Move vertex to one of the four classifications:
        ///		+ unconnected to any vertex in isomorphism
        ///		+ points in to vertex in isomorphism
        ///		+ pointed to be a vertex in isomorphism
        ///		+ in the isomorphism
        /// Note that this call may be redundant - i.e., we may "move" a vertex
        /// to a group it's already in.  That's expected and we don't actually do
        /// anything in that case.
        /// </summary>
        /// <param name="iGraph">Graph to take action on</param>
        /// <param name="ivtx">Vertex index of vertex to act on</param>
        /// <param name="grpNew">New group to potentially move vertex to</param>
        /// <param name="vfs">State determining the isomorphism</param>

        internal void MoveToGroup(int iGraph, int ivtx, Group grpNew, VfState <TVAttr, TEAttr> vfs)
        {
            var vfg    = iGraph == 1 ? vfs.VfGraph1 : vfs.VfGraph2;
            var grpOld = vfg.GetGroup(ivtx);

            // If vertex is newly connected to the isomorphism, see if it was connected
            // in the opposite direction previously - if so, it's now connected both ways.
            if (grpOld == Group.FromMapping && grpNew == Group.ToMapping ||
                grpOld == Group.ToMapping && grpNew == Group.FromMapping)
            {
                grpNew = Group.FromMapping | Group.ToMapping;
            }

            // If we actually made a change, then add it to the action list and ensure that
            // it's recorded in the graph.
            if (grpOld != (grpOld | grpNew))
            {
                AddAction(new BacktrackAction(Action.GroupMove, iGraph, ivtx, grpOld));
                vfs.MakeMove(iGraph, ivtx, grpNew);
            }
        }
Example #26
0
        /// <summary>
        /// Find a candidate graph2 vertex and the list of possible matches from graph1
        /// </summary>
        /// <remarks>
        /// Find a candidate list from graph1 vertices for a particular graph2 vertex.  If we've got vertices
        /// in both out lists, take the first graph2 vertex in the outlist and use all the vertices in the
        /// graph1 out list as candidates.  If that doesn't work, do the same for the two respective
        /// in lists and finally for the vertices disconnected from the current isomorphism.
        /// </remarks>
        /// <param name="vfs">State to grab vertices from</param>
        internal CandidateFinder(VfState<TVAttr, TEAttr> vfs)
        {
            _vfs = vfs;

            // Check to see if degrees are valid - this is only available because we sort the vertices
            // by degree
            if (
                !vfs.FnCompareDegrees(vfs.LstOut1.Count, vfs.LstOut2.Count) ||
                !vfs.FnCompareDegrees(vfs.LstIn1.Count, vfs.LstIn2.Count) ||
                !vfs.FnCompareDegrees(vfs.LstDisconnected1.Count, vfs.LstDisconnected2.Count))
            {
                // Life isn't worth living - signal to ourselves to fail at the first call to
                // NextCandidateMatch().
                _fFailImmediately = true;
                return;
            }

            // Try to find a match in vertices pointed to from the isomorphism
            if (vfs.LstOut2.Count > 0 && vfs.LstOut1.Count > 0)
            {
                _graph1Candidates = new int[vfs.LstOut1.Count];
                vfs.LstOut1.CopyTo(_graph1Candidates);
                SetInitialMatch(vfs.LstOut1[0], vfs.LstOut2[0]);
            }
            // Try to find a match in vertices pointing into the isomorphism
            else if (vfs.LstIn2.Count > 0 && vfs.LstIn1.Count > 0)
            {
                _graph1Candidates = new int[vfs.LstIn1.Count];
                vfs.LstIn1.CopyTo(_graph1Candidates);
                SetInitialMatch(vfs.LstIn1[0], vfs.LstIn2[0]);
            }
            // Try to find a match in vertices unattached to the isomorphism
            else if (vfs.LstDisconnected1.Count >= 0)
            {
                _graph1Candidates = new int[vfs.LstDisconnected1.Count];
                vfs.LstDisconnected1.CopyTo(_graph1Candidates);
                SetInitialMatch(vfs.LstDisconnected1[0], vfs.LstDisconnected2[0]);
            }
        }
Example #27
0
            public void TestMultipleMatches()
            {
                var gr1 = new Graph();
                var gr2 = new Graph();

                gr1.InsertVertices(3);
                gr2.InsertVertices(3);
                gr1.AddEdge(0, 1);
                gr1.AddEdge(1, 2);
                gr1.AddEdge(2, 0);
                gr2.AddEdge(0, 2);
                gr2.AddEdge(2, 1);
                gr2.AddEdge(1, 0);

                var vfs     = new VfState(gr1, gr2);
                var matches = vfs.Matches().ToArray();

                Assert.AreNotEqual(0, matches.Length);
                Assert.AreEqual(3, matches.Length);

                vfs     = new VfState(gr1, gr2, true);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(3, matches.Length);

                gr2.AddEdge(0, 1);
                gr2.AddEdge(1, 2);
                gr2.AddEdge(2, 0);
                gr1.AddEdge(0, 2);
                gr1.AddEdge(2, 1);
                gr1.AddEdge(1, 0);

                vfs     = new VfState(gr1, gr2);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(6, matches.Length);

                vfs     = new VfState(gr1, gr2, true);
                matches = vfs.Matches().ToArray();
                Assert.AreEqual(6, matches.Length);
            }
Example #28
0
            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));
            }
Example #29
0
            public void TestMultipleMatches()
            {
                Graph   gr1 = new Graph();
                Graph   gr2 = new Graph();
                VfState vfs;

                gr1.InsertNodes(3);
                gr2.InsertNodes(3);
                gr1.InsertEdge(0, 1);
                gr1.InsertEdge(1, 2);
                gr1.InsertEdge(2, 0);
                gr2.InsertEdge(0, 2);
                gr2.InsertEdge(2, 1);
                gr2.InsertEdge(1, 0);

                vfs = new VfState(gr1, gr2, false, false, true);
                Assert.IsTrue(vfs.FMatch());
                Assert.AreEqual(3, vfs.Mappings.Count);

                vfs = new VfState(gr1, gr2, true, false, true);
                Assert.IsTrue(vfs.FMatch());
                Assert.AreEqual(3, vfs.Mappings.Count);

                gr2.InsertEdge(0, 1);
                gr2.InsertEdge(1, 2);
                gr2.InsertEdge(2, 0);
                gr1.InsertEdge(0, 2);
                gr1.InsertEdge(2, 1);
                gr1.InsertEdge(1, 0);

                vfs = new VfState(gr1, gr2, false, false, true);
                Assert.IsTrue(vfs.FMatch());
                Assert.AreEqual(6, vfs.Mappings.Count);

                vfs = new VfState(gr1, gr2, true, false, true);
                Assert.IsTrue(vfs.FMatch());
                Assert.AreEqual(6, vfs.Mappings.Count);
            }
Example #30
0
            public void TestMatch()
            {
                Graph gr1 = new Graph();
                Graph gr2 = new Graph();

                VfState vfs = new VfState(gr1, gr2);

                Assert.IsTrue(vfs.FMatch());
                gr2.InsertNode();
                vfs = new VfState(gr1, gr2);
                Assert.IsFalse(vfs.FMatch());
                gr1.InsertNode();
                vfs = new VfState(gr1, gr2);
                Assert.IsTrue(vfs.FMatch());
                gr1.InsertNode();
                vfs = new VfState(gr1, gr2);
                Assert.IsTrue(vfs.FMatch());
                gr1.InsertEdge(0, 1);
                vfs = new VfState(gr1, gr2);
                Assert.IsTrue(vfs.FMatch());
                vfs = new VfState(gr2, gr1);
                Assert.IsFalse(vfs.FMatch());
            }