protected static void AddEdge_Throws_Clusters_Test( ClusteredAdjacencyGraph <int, Edge <int> > graph) { // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => graph.AddEdge(null)); AssertNoEdge(graph); // Both vertices not in graph Assert.Throws <VertexNotFoundException>(() => graph.AddEdge(new Edge <int>(0, 1))); AssertNoEdge(graph); // Source not in graph graph.AddVertex(1); Assert.Throws <VertexNotFoundException>(() => graph.AddEdge(new Edge <int>(0, 1))); AssertNoEdge(graph); // Target not in graph Assert.Throws <VertexNotFoundException>(() => graph.AddEdge(new Edge <int>(1, 0))); AssertNoEdge(graph); }
public void AddingClusterEdge() { var graph = new AdjacencyGraph <int, IEdge <int> >(); var clusteredGraph = new ClusteredAdjacencyGraph <int, IEdge <int> >(graph); ClusteredAdjacencyGraph <int, IEdge <int> > cluster1 = clusteredGraph.AddCluster(); cluster1.AddVertex(5); cluster1.AddVertex(6); var edge = new TaggedEdge <int, int>(5, 6, 1); cluster1.AddEdge(edge); Assert.IsTrue(ContainsEdgeParent(clusteredGraph, edge)); }
public void OutEdge_Throws() { var wrappedGraph1 = new AdjacencyGraph <TestVertex, Edge <TestVertex> >(); var graph1 = new ClusteredAdjacencyGraph <TestVertex, Edge <TestVertex> >(wrappedGraph1); OutEdge_NullThrows_Test(graph1); var wrappedGraph2 = new AdjacencyGraph <int, Edge <int> >(); var graph2 = new ClusteredAdjacencyGraph <int, Edge <int> >(wrappedGraph2); OutEdge_Throws_Test( graph2, vertex => graph2.AddVertex(vertex), edge => graph2.AddEdge(edge)); }
protected static void AddEdge_ParallelEdges_Clusters_Test( ClusteredAdjacencyGraph <int, Edge <int> > graph1, ClusteredAdjacencyGraph <int, Edge <int> > parent2, ClusteredAdjacencyGraph <int, Edge <int> > graph2) { // Graph without parent graph1.AddVertex(1); graph1.AddVertex(2); AssertNoEdge(graph1); // Edge 1 var edge1 = new Edge <int>(1, 2); Assert.IsTrue(graph1.AddEdge(edge1)); AssertHasEdges(graph1, new[] { edge1 }); // Edge 2 var edge2 = new Edge <int>(1, 2); Assert.IsTrue(graph1.AddEdge(edge2)); AssertHasEdges(graph1, new[] { edge1, edge2 }); // Edge 3 var edge3 = new Edge <int>(2, 1); Assert.IsTrue(graph1.AddEdge(edge3)); AssertHasEdges(graph1, new[] { edge1, edge2, edge3 }); // Edge 1 bis Assert.IsTrue(graph1.AddEdge(edge1)); AssertHasEdges(graph1, new[] { edge1, edge2, edge3, edge1 }); // Edge 4 self edge var edge4 = new Edge <int>(2, 2); Assert.IsTrue(graph1.AddEdge(edge4)); AssertHasEdges(graph1, new[] { edge1, edge2, edge3, edge1, edge4 }); // Graph with parent graph2.AddVertex(1); graph2.AddVertex(2); AssertNoEdge(parent2); AssertNoEdge(graph2); // Edge 1 Assert.IsTrue(graph2.AddEdge(edge1)); AssertHasEdges(parent2, new[] { edge1 }); AssertHasEdges(graph2, new[] { edge1 }); // Edge 2 Assert.IsTrue(parent2.AddEdge(edge2)); AssertHasEdges(parent2, new[] { edge1, edge2 }); AssertHasEdges(graph2, new[] { edge1 }); Assert.IsTrue(graph2.AddEdge(edge2)); AssertHasEdges(parent2, new[] { edge1, edge2 }); AssertHasEdges(graph2, new[] { edge1, edge2 }); // Edge 3 Assert.IsTrue(graph2.AddEdge(edge3)); AssertHasEdges(parent2, new[] { edge1, edge2, edge3 }); AssertHasEdges(graph2, new[] { edge1, edge2, edge3 }); // Edge 1 bis Assert.IsTrue(graph2.AddEdge(edge1)); AssertHasEdges(parent2, new[] { edge1, edge2, edge3 }); AssertHasEdges(graph2, new[] { edge1, edge2, edge3, edge1 }); // Edge 4 self edge Assert.IsTrue(graph2.AddEdge(edge4)); AssertHasEdges(parent2, new[] { edge1, edge2, edge3, edge4 }); AssertHasEdges(graph2, new[] { edge1, edge2, edge3, edge1, edge4 }); }
public void Run() { // create an adjacency graph AdjacencyGraph g = new AdjacencyGraph( new NamedVertexProvider(), new NamedEdgeProvider(), true ); // create a clustered graph ClusteredAdjacencyGraph cg = new ClusteredAdjacencyGraph(g); // adding some vertices to the main graph NamedVertex a = cg.AddVertex() as NamedVertex; a.Name = "a"; NamedVertex b = cg.AddVertex() as NamedVertex; b.Name = "b"; NamedVertex c = cg.AddVertex() as NamedVertex; c.Name = "c"; NamedEdge ab = cg.AddEdge(a, b) as NamedEdge; ab.Name = "ab"; NamedEdge ac = cg.AddEdge(a, c) as NamedEdge; ac.Name = "ac"; // adding a cluster ClusteredAdjacencyGraph cg1 = cg.AddCluster(); // adding vertices and edges to the cluster NamedVertex d = cg1.AddVertex() as NamedVertex; d.Name = "d"; NamedVertex e = cg1.AddVertex() as NamedVertex; e.Name = "e"; NamedVertex f = cg1.AddVertex() as NamedVertex; f.Name = "f"; NamedEdge de = cg1.AddEdge(d, e) as NamedEdge; de.Name = "de"; NamedEdge df = cg1.AddEdge(d, f) as NamedEdge; df.Name = "df"; // adding a second cluster ClusteredAdjacencyGraph cg2 = cg.AddCluster(); // adding vertices NamedVertex h = cg2.AddVertex() as NamedVertex; h.Name = "h"; NamedVertex i = cg2.AddVertex() as NamedVertex; i.Name = "i"; NamedEdge hi = cg2.AddEdge(h, i) as NamedEdge; hi.Name = "hi"; // adding a sub-sub-cluster ClusteredAdjacencyGraph cg21 = cg2.AddCluster(); // adding vertices NamedVertex k = cg21.AddVertex() as NamedVertex; k.Name = "k"; NamedVertex l = cg21.AddVertex() as NamedVertex; l.Name = "l"; NamedEdge ak = cg.AddEdge(a, k) as NamedEdge; ak.Name = "ak"; NamedEdge kl = cg21.AddEdge(k, l) as NamedEdge; kl.Name = "kl"; // interconnecting NamedEdge cd = cg.AddEdge(c, d) as NamedEdge; cd.Name = "cd"; NamedEdge bh = cg.AddEdge(b, h) as NamedEdge; bh.Name = "bh"; NamedEdge ei = cg.AddEdge(e, i) as NamedEdge; ei.Name = "ei"; GraphvizAlgorithm gw = new GraphvizAlgorithm( cg, "../cluster", GraphvizImageType.Svgz ); gw.FormatVertex += new FormatVertexEventHandler(this.FormatVertex); gw.FormatEdge += new FormatEdgeEventHandler(this.FormatEdge); gw.Write("cluster"); cg2.Colapsed = true; gw.Write("cluster_collapsed"); }