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()); }
internal Graph IsomorphicShuffling(Random rnd) { Graph graph = new Graph(); int[] ariShuffle = new int[NodeCount]; for (int i = 0; i < NodeCount; i++) { ariShuffle[i] = i; } Shuffle <int>(ariShuffle, rnd); graph.InsertNodes(NodeCount); for (int inod = 0; inod < NodeCount; inod++) { int inodShuffled = ariShuffle[inod]; nNode nod = _nodes[inodShuffled]; foreach (eNode end in nod._edgesFrom.Values) { graph.InsertEdge(ariShuffle[PosFromId(end._idFrom)], ariShuffle[PosFromId(end._idTo)]); } } return(graph); }
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()); }
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()); }
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()); }
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); }
public Graph GetGraph(int cnod) { int cEdgesNeeded = (int)(cnod * (cnod - 1) * _pctEdges); int cEdgesSoFar = 0; Set <EdgeKey> setEdges = new Set <EdgeKey>(); Graph graph = new Graph(); graph.InsertNodes(cnod); while (cEdgesSoFar < cEdgesNeeded) { EdgeKey ekey = new EdgeKey(_rnd.Next(cnod), _rnd.Next(cnod)); if (setEdges.Contains(ekey) || ekey.From == ekey.To) { continue; } graph.InsertEdge(ekey.From, ekey.To); setEdges.Add(ekey); cEdgesSoFar++; } return(graph); }
public void TestPermutationMassage() { Graph graph1 = new Graph(); graph1.InsertNodes(4); graph1.InsertEdge(2, 3); Graph graph2 = new Graph(); graph2.InsertNodes(2); graph2.InsertEdge(1, 0); VfState vfs = new VfState(graph1, graph2); Assert.IsTrue(vfs.FMatch()); int[] arprm1To2 = vfs.Mapping1To2; int[] arprm2To1 = vfs.Mapping2To1; Assert.AreEqual(1, arprm1To2[2]); Assert.AreEqual(0, arprm1To2[3]); Assert.AreEqual(map_Illegal, arprm1To2[0]); Assert.AreEqual(map_Illegal, arprm1To2[1]); Assert.AreEqual(3, arprm2To1[0]); Assert.AreEqual(2, arprm2To1[1]); }