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 }
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 TestInsertEdge() { object attr; var gr = new Graph(); var idFrom = gr.InsertVertex(0); var idTo = gr.InsertVertex(1); gr.AddEdge(idFrom, idTo, 100); Assert.AreEqual(gr.OutEdgeCount(idFrom), 1); Assert.AreEqual(gr.OutEdgeCount(idTo), 0); var idEdge = gr.GetOutEdge(idFrom, 0, out attr); Assert.AreEqual(100, (int)attr); Assert.AreEqual(idTo, idEdge); // Try inserting the same edge twice to trigger exception... Assert.Throws(typeof(VfException), () => gr.AddEdge(0, 1, 200)); }
public void TestDeleteVertex() { var gr = new Graph(); Assert.AreEqual(0, gr.InsertVertex()); Assert.AreEqual(1, gr.InsertVertex()); Assert.AreEqual(2, gr.InsertVertex()); gr.AddEdge(0, 1); gr.AddEdge(1, 2); gr.AddEdge(2, 0); gr.DeleteVertex(0); Assert.AreEqual(1, gr.OutEdgeCount(1)); Assert.AreEqual(0, gr.OutEdgeCount(2)); // Trigger the exception - shouldn't be a zero vertex any more... Assert.Throws(typeof(VfException), () => gr.FindVertex(0)); }
public void TestDeleteEdge() { var gr = new Graph(); Assert.AreEqual(0, gr.InsertVertex()); Assert.AreEqual(1, gr.InsertVertex()); Assert.AreEqual(2, gr.InsertVertex()); gr.AddEdge(0, 1); gr.AddEdge(1, 2); gr.AddEdge(2, 0); gr.DeleteEdge(1, 2); Assert.AreEqual(1, gr.OutEdgeCount(0)); Assert.AreEqual(0, gr.OutEdgeCount(1)); Assert.AreEqual(1, gr.OutEdgeCount(2)); // Trigger the exception - no edge from 1 to 0... Assert.Throws(typeof(VfException), () => gr.DeleteEdge(1, 0)); }
public void TestInsertVertex() { var gr = new Graph(); gr.InsertVertex(1); var vtx = gr.FindVertex(0); Assert.IsNotNull(vtx); Assert.Throws(typeof(VfException), () => gr.FindVertex(1)); }
VfState VfsTest() { var graph1 = new Graph(); Assert.AreEqual(0, graph1.InsertVertex()); Assert.AreEqual(1, graph1.InsertVertex()); Assert.AreEqual(2, graph1.InsertVertex()); Assert.AreEqual(3, graph1.InsertVertex()); Assert.AreEqual(4, graph1.InsertVertex()); Assert.AreEqual(5, graph1.InsertVertex()); graph1.AddEdge(0, 1); graph1.AddEdge(1, 2); graph1.AddEdge(2, 3); graph1.AddEdge(3, 4); graph1.AddEdge(4, 5); graph1.AddEdge(5, 0); graph1.AddEdge(0, 3); var graph2 = new Graph(); Assert.AreEqual(0, graph2.InsertVertex()); Assert.AreEqual(1, graph2.InsertVertex()); Assert.AreEqual(2, graph2.InsertVertex()); Assert.AreEqual(3, graph2.InsertVertex()); Assert.AreEqual(4, graph2.InsertVertex()); Assert.AreEqual(5, graph2.InsertVertex()); graph2.AddEdge(1, 0); graph2.AddEdge(2, 1); graph2.AddEdge(3, 2); graph2.AddEdge(4, 3); graph2.AddEdge(5, 4); graph2.AddEdge(0, 5); graph2.AddEdge(4, 1); return new VfState(graph1, graph2); }
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); }
private Graph VfsTestGraph2() { var graph = new Graph(); Assert.AreEqual(0, graph.InsertVertex()); Assert.AreEqual(1, graph.InsertVertex()); Assert.AreEqual(2, graph.InsertVertex()); Assert.AreEqual(3, graph.InsertVertex()); Assert.AreEqual(4, graph.InsertVertex()); Assert.AreEqual(5, graph.InsertVertex()); // Same graph in reverse order with slightly offset "extra" edge at (4,1) graph.AddEdge(1, 0); graph.AddEdge(2, 1); graph.AddEdge(3, 2); graph.AddEdge(4, 3); graph.AddEdge(5, 4); graph.AddEdge(0, 5); graph.AddEdge(1, 4); return(graph); }
private Graph VfsTestGraph1() { var graph = new Graph(); Assert.AreEqual(0, graph.InsertVertex()); Assert.AreEqual(1, graph.InsertVertex()); Assert.AreEqual(2, graph.InsertVertex()); Assert.AreEqual(3, graph.InsertVertex()); Assert.AreEqual(4, graph.InsertVertex()); Assert.AreEqual(5, graph.InsertVertex()); // Circular graph with "extra" edge at (0,3) graph.AddEdge(0, 1); graph.AddEdge(1, 2); graph.AddEdge(2, 3); graph.AddEdge(3, 4); graph.AddEdge(4, 5); graph.AddEdge(5, 0); graph.AddEdge(0, 3); return(graph); }
VfState <Object, Object> VfsTest() { var graph1 = new Graph(); Assert.AreEqual(0, graph1.InsertVertex()); Assert.AreEqual(1, graph1.InsertVertex()); Assert.AreEqual(2, graph1.InsertVertex()); Assert.AreEqual(3, graph1.InsertVertex()); Assert.AreEqual(4, graph1.InsertVertex()); Assert.AreEqual(5, graph1.InsertVertex()); // Circular graph with "extra" edge at (0,3) graph1.AddEdge(0, 1); graph1.AddEdge(1, 2); graph1.AddEdge(2, 3); graph1.AddEdge(3, 4); graph1.AddEdge(4, 5); graph1.AddEdge(5, 0); graph1.AddEdge(0, 3); var graph2 = new Graph(); Assert.AreEqual(0, graph2.InsertVertex()); Assert.AreEqual(1, graph2.InsertVertex()); Assert.AreEqual(2, graph2.InsertVertex()); Assert.AreEqual(3, graph2.InsertVertex()); Assert.AreEqual(4, graph2.InsertVertex()); Assert.AreEqual(5, graph2.InsertVertex()); // Same graph in reverse order with slightly offset "extra" edge at (4,1) graph2.AddEdge(1, 0); graph2.AddEdge(2, 1); graph2.AddEdge(3, 2); graph2.AddEdge(4, 3); graph2.AddEdge(5, 4); graph2.AddEdge(0, 5); graph2.AddEdge(4, 1); return(new VfState <Object, Object>(graph1, graph2)); }
VfGraph SetupGraph() { var graph = new Graph(); Assert.AreEqual(0, graph.InsertVertex()); Assert.AreEqual(1, graph.InsertVertex()); Assert.AreEqual(2, graph.InsertVertex()); Assert.AreEqual(3, graph.InsertVertex()); Assert.AreEqual(4, graph.InsertVertex()); Assert.AreEqual(5, graph.InsertVertex()); graph.AddEdge(0, 1); graph.AddEdge(1, 2); graph.AddEdge(2, 3); graph.AddEdge(3, 4); graph.AddEdge(4, 5); graph.AddEdge(5, 0); graph.DeleteVertex(0); graph.DeleteVertex(1); graph.AddEdge(5, 2); graph.AddEdge(2, 4); return(new VfGraph(graph)); }