Beispiel #1
0
        public void IsDirectedAcyclicGraphTest()
        {
            try
            {
                Graph2 glistDAG = new Graph2(9);

                glistDAG.AddEdge(1, 2);
                glistDAG.AddEdge(1, 4);
                glistDAG.AddEdge(2, 3);
                glistDAG.AddEdge(2, 7);
                glistDAG.AddEdge(4, 5);
                glistDAG.AddEdge(4, 6);
                glistDAG.AddEdge(4, 9);
                glistDAG.AddEdge(5, 8);
                glistDAG.AddEdge(5, 9);
                glistDAG.AddEdge(6, 7);
                glistDAG.AddEdge(7, 8);

                glistDAG.DisplayGraph();

                Console.WriteLine("--Processing graph...\n");

                glistDAG.IsDirectedAcyclicGraph();

                Graph2 glistNotDAG = new Graph2(6);
                glistNotDAG.AddEdge(1, 2);
                glistNotDAG.AddEdge(2, 3);
                glistNotDAG.AddEdge(2, 4);
                glistNotDAG.AddEdge(4, 5);
                glistNotDAG.AddEdge(5, 6);
                glistNotDAG.AddEdge(6, 4);
                glistNotDAG.AddEdge(6, 3);
                glistNotDAG.DisplayGraph();

                Console.WriteLine("--Processing graph...\n");

                glistNotDAG.IsDirectedAcyclicGraph();
            }

            catch (Exception e)
            {
                Console.WriteLine("Cannot access empty adjacency list of a node." + e.Message);
            }
        }
        public void FindGoodFeedbackSetTest()
        {
            try
            {
                Console.WriteLine("Find Good Feedback Vertex Set Demo");

                int    v     = 6;
                Graph2 glist = new Graph2(v);

                glist.AddEdge(1, 2);
                glist.AddEdge(2, 3);
                glist.AddEdge(2, 4);
                glist.AddEdge(4, 5);
                glist.AddEdge(5, 6);
                glist.AddEdge(6, 4);
                glist.AddEdge(6, 3);

                glist.DisplayGraph();
                glist.FindGoodFeedbackSet(v, false);

                Console.WriteLine("\nFind Good Feedback Edge Set Demo");

                glist = new Graph2(v);

                glist.AddEdge(1, 2);
                glist.AddEdge(2, 3);
                glist.AddEdge(2, 4);
                glist.AddEdge(4, 5);
                glist.AddEdge(5, 6);
                glist.AddEdge(6, 4);
                glist.AddEdge(6, 3);

                glist.DisplayGraph();
                glist.FindGoodFeedbackSet(v, true);
            }
            catch (Exception exception)
            {
                Console.WriteLine("You are trying to access empty adjacency list of a node. " + exception.Message);
            }
        }