Пример #1
0
        private void Run()
        {
            graph = new StdNamedGraph();

            int numNodes = 10;
            int numEdges = 20;

            List <Node> nodes = new List <Node>(numNodes);

            for (int i = 0; i < numNodes; i++)
            {
                nodes.Add(Node.CreateNode(graph));
            }

            Random rnd = new Random(4);

            for (int i = 0; i < numEdges; i++)
            {
                Edge.CreateEdge(graph, nodes[rnd.Next(numNodes)], nodes[rnd.Next(numNodes)]);
            }

            using (VCGDumper dumper = new VCGDumper("test.vcg"))
                GraphDumper.Dump(graph, dumper);

            int       visitorID = graph.AllocateVisitedFlag();
            DFSWalker dfs       = new DFSWalker(graph, PreWalker, PostWalker, visitorID);

            dfs.DoDFS(nodes[0]);
            Console.WriteLine("Visited nodes DFS: pre=" + countedNodesPre + " post=" + countedNodesPost);

            graph.ResetVisitedFlag(visitorID);
            countedNodesPre = 0;
            BFSWalker bfs = new BFSWalker(graph, PreWalker, visitorID);

            bfs.Mode = WalkerMode.Incident;
            bfs.DoBFS(nodes[0]);

            Console.WriteLine("Visited nodes BFS: " + countedNodesPre);

            graph.FreeVisitedFlag(visitorID);
        }
Пример #2
0
        private void Run()
        {
            graph = new StdNamedGraph();

            int numNodes = 10;
            int numEdges = 20;

            List<Node> nodes = new List<Node>(numNodes);
            for(int i = 0; i < numNodes; i++)
                nodes.Add(Node.CreateNode(graph));

            Random rnd = new Random(4);
            for(int i = 0; i < numEdges; i++)
                Edge.CreateEdge(graph, nodes[rnd.Next(numNodes)], nodes[rnd.Next(numNodes)]);

            using(VCGDumper dumper = new VCGDumper("test.vcg"))
                GraphDumper.Dump(graph, dumper);

            int visitorID = graph.AllocateVisitedFlag();
            DFSWalker dfs = new DFSWalker(graph, PreWalker, PostWalker, visitorID);
            dfs.DoDFS(nodes[0]);
            Console.WriteLine("Visited nodes DFS: pre=" + countedNodesPre + " post=" + countedNodesPost);

            graph.ResetVisitedFlag(visitorID);
            countedNodesPre = 0;
            BFSWalker bfs = new BFSWalker(graph, PreWalker, visitorID);
            bfs.Mode = WalkerMode.Incident;
            bfs.DoBFS(nodes[0]);

            Console.WriteLine("Visited nodes BFS: " + countedNodesPre);

            graph.FreeVisitedFlag(visitorID);
        }