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 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); }
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); }
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]); }
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); }
public void TestMatchComplex() { var vfs = VfsTest(); var matches = vfs.Matches().ToArray(); Assert.AreEqual(1, matches.Length); var dict1 = matches[0].IsomorphismVid1ToVid2; var dict2 = matches[0].IsomorphismVid2ToVid1; Assert.AreEqual(1, dict1[0]); Assert.AreEqual(0, dict1[1]); Assert.AreEqual(5, dict1[2]); Assert.AreEqual(4, dict1[3]); Assert.AreEqual(3, dict1[4]); Assert.AreEqual(2, dict1[5]); Assert.AreEqual(1, dict2[0]); Assert.AreEqual(0, dict2[1]); Assert.AreEqual(5, dict2[2]); Assert.AreEqual(4, dict2[3]); Assert.AreEqual(3, dict2[4]); Assert.AreEqual(2, dict2[5]); var graph2 = VfsTestGraph2(); graph2.DeleteEdge(1, 4); graph2.AddEdge(2, 4); vfs = new VfState(VfsTestGraph1(), graph2); matches = vfs.Matches().ToArray(); Assert.AreEqual(0, matches.Length); var graph1 = new Graph(); graph1.InsertVertices(11); graph2 = new Graph(); graph2.InsertVertices(11); graph1.AddEdge(0, 2); graph1.AddEdge(0, 1); graph1.AddEdge(2, 4); graph1.AddEdge(2, 5); graph1.AddEdge(1, 5); graph1.AddEdge(1, 3); graph1.AddEdge(4, 7); graph1.AddEdge(5, 7); graph1.AddEdge(5, 8); graph1.AddEdge(5, 6); graph1.AddEdge(3, 6); graph1.AddEdge(7, 10); graph1.AddEdge(6, 9); graph1.AddEdge(10, 8); graph1.AddEdge(8, 9); graph2.AddEdge(0, 1); graph2.AddEdge(0, 9); graph2.AddEdge(1, 2); graph2.AddEdge(1, 10); graph2.AddEdge(9, 10); graph2.AddEdge(9, 8); graph2.AddEdge(2, 3); graph2.AddEdge(10, 3); graph2.AddEdge(10, 5); graph2.AddEdge(10, 7); graph2.AddEdge(8, 7); graph2.AddEdge(3, 4); graph2.AddEdge(7, 6); graph2.AddEdge(4, 5); graph2.AddEdge(5, 6); vfs = new VfState(graph1, graph2, true); matches = vfs.Matches().ToArray(); Assert.AreNotEqual(0, matches.Length); }