private static void BuildDirectedCyclicGraph(IGraphBuilder graph)
        {
            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);

            var edgeId = new IntIdGenerator();

            graph.AddEdge(1, 2, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(2, 3, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(3, 1, edgeId.Next, EdgeDirectionType.Directed);
        }
        private void TestGraphBuilder(IGraphBuilder graph)
        {
            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            Assert.AreEqual(3, graph.Vertices.Count(), "Adding vertices(3)");

            graph.AddEdge(1, 3, 1);
            graph.AddEdge(2, 1, 2, EdgeDirectionType.Directed);

            Assert.AreEqual(2, graph.Edges.Count(), "Adding edges(2)");

            graph.RemoveVertex(1);
            Assert.AreEqual(2, graph.Vertices.Count(), "Remove vertex(2)");
            Assert.AreEqual(0, graph.Edges.Count(), "After remove vertex");

            Assert.ThrowsException <ArgumentException>(() => graph.RemoveVertex(1));
        }
Exemple #3
0
 public static void AddVertex(this IGraphBuilder graph, int vertex)
 {
     graph.AddVertex(new Vertex {
         Id = vertex
     });
 }
        private static void Build3ComponentsUndirectedGraph(IGraphBuilder graph)
        {
            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            graph.AddVertex(4);
            graph.AddVertex(5);
            graph.AddVertex(6);
            graph.AddVertex(7);
            graph.AddVertex(8);
            graph.AddVertex(9);
            graph.AddVertex(10);
            graph.AddVertex(11);
            graph.AddVertex(12);

            var edgeId = new IntIdGenerator();

            graph.AddEdge(1, 2, edgeId.Next);
            graph.AddEdge(2, 4, edgeId.Next);
            graph.AddEdge(4, 5, edgeId.Next);
            graph.AddEdge(5, 1, edgeId.Next);
            graph.AddEdge(3, 1, edgeId.Next);

            graph.AddEdge(6, 7, edgeId.Next);
            graph.AddEdge(7, 8, edgeId.Next);
            graph.AddEdge(8, 6, edgeId.Next);

            graph.AddEdge(9, 10, edgeId.Next);
            graph.AddEdge(10, 11, edgeId.Next);
            graph.AddEdge(11, 12, edgeId.Next);
            graph.AddEdge(12, 9, edgeId.Next);
        }
        private static void BuildDirectedAcyclicGraph(IGraphBuilder graph)
        {
            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            graph.AddVertex(4);
            graph.AddVertex(5);
            graph.AddVertex(6);
            graph.AddVertex(7);
            graph.AddVertex(8);
            graph.AddVertex(9);
            graph.AddVertex(10);
            graph.AddVertex(11);

            var edgeId = new IntIdGenerator();

            graph.AddEdge(1, 4, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(1, 7, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(1, 11, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(1, 9, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(2, 3, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(2, 4, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(3, 4, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(5, 2, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(8, 5, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(8, 6, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(8, 7, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(9, 10, edgeId.Next, EdgeDirectionType.Directed);
            graph.AddEdge(10, 11, edgeId.Next, EdgeDirectionType.Directed);
        }