当前位置: 首页>>代码示例>>C#>>正文


C# Graph.DepthFirstTraversal方法代码示例

本文整理汇总了C#中Graph.DepthFirstTraversal方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.DepthFirstTraversal方法的具体用法?C# Graph.DepthFirstTraversal怎么用?C# Graph.DepthFirstTraversal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.DepthFirstTraversal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompletedVisitor

        public void CompletedVisitor()
        {
            var graph = new Graph<int>(true);

            var vertex1 = new Vertex<int>(1);
            var vertex2 = new Vertex<int>(2);
            var vertex3 = new Vertex<int>(3);
            var vertex4 = new Vertex<int>(4);
            var vertex5 = new Vertex<int>(5);
            var vertex6 = new Vertex<int>(6);
            var vertex7 = new Vertex<int>(7);

            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);
            graph.AddVertex(vertex3);
            graph.AddVertex(vertex4);
            graph.AddVertex(vertex5);
            graph.AddVertex(vertex6);
            graph.AddVertex(vertex7);

            graph.AddEdge(vertex1, vertex2);
            graph.AddEdge(vertex1, vertex3);
            graph.AddEdge(vertex1, vertex5);
            graph.AddEdge(vertex5, vertex3);

            graph.AddEdge(vertex3, vertex6);
            graph.AddEdge(vertex3, vertex4);
            graph.AddEdge(vertex2, vertex7);

            graph.DepthFirstTraversal(new PreOrderVisitor<Vertex<int>>(new CompletedTrackingVisitor<Vertex<int>>()), vertex1);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:31,代码来源:DepthFirstTraversal.cs

示例2: DepthFirstTraversalExample

        public void DepthFirstTraversalExample()
        {
            // Initialize a new graph instance.
            var graph = new Graph<int>(true);

            // Add three vertices to the graph.
            var vertex1 = graph.AddVertex(1);
            var vertex2 = graph.AddVertex(2);
            var vertex3 = graph.AddVertex(3);

            // Add edges between the vertices.
            graph.AddEdge(vertex1, vertex2);
            graph.AddEdge(vertex2, vertex3);

            // Create a new counting visitor, which will keep track
            // of the number of objects that are visited.
            var countingVisitor = new CountingVisitor<Vertex<int>>();

            // Define in which order the objects should be visited -
            // we choose to do a pre-order traversal, however, you can
            // also choose to visit post-order.  Note that In-Order is
            // only available on Binary Trees, and not defined on graphs.
            var orderedVisitor = new PreOrderVisitor<Vertex<int>>(countingVisitor);

            // Perform a depth first traversal on the graph with
            // the ordered visitor, starting from node vertex1.
            graph.DepthFirstTraversal(orderedVisitor, vertex1);

            // The visitor will have visited 3 items.
            Assert.AreEqual(countingVisitor.Count, 3);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:31,代码来源:GraphExamples.cs

示例3: Colorize

        /// <summary>
        /// Colorizes the specified graph by means of a traversal.
        /// </summary>
        /// <remarks>This is just an example of how to use the traversal algorithms within RadDiagram.</remarks>
        /// <param name="g">The graph to colorize.</param>
        /// <param name="nodeMap">The node map.</param>
        /// <param name="center">The center from which the traversal starts.</param>
        private void Colorize(Graph g, IDictionary<Node, RadDiagramShape> nodeMap, Node center)
        {
            //var geo = App.Current.Resources["glass"] as PathGeometry;
            //var glassfill = App.Current.Resources["glassfill"] as RadialGradientBrush;
            //var spherefill = App.Current.Resources["spherefill"] as RadialGradientBrush;

            // you can use a directed traversal but it will obviously not always reach all nodes
            g.IsDirected = false;

            var colors = new List<Color>();
            for (var i = 0; i < 30; i++) colors.Add(ColorUtilities.RandomBlues);

            var group = new TransformGroup();
            @group.Children.Add(new ScaleTransform(.7, .7, 05, 05));
            @group.Children.Add(new TranslateTransform(0.02, 0.3));
            g.DepthFirstTraversal((node, i) =>
                {
                    var shape = nodeMap[node];
                    shape.Width = 30;
                    shape.Height = 30;
                    //shape.Geometry = geo;
                    shape.BorderBrush = Brushes.LightSteelBlue;

                    var spherefill = new RadialGradientBrush(new GradientStopCollection { new GradientStop(colors[i], 1d), new GradientStop(Colors.White, .4d), }) { Transform = @group };

                    shape.Background = spherefill;
                    shape.Content = i;
                }, center);
        }
开发者ID:jigjosh,项目名称:xaml-sdk,代码行数:36,代码来源:MainView.xaml.cs

示例4: DirectedPostVisit

        public void DirectedPostVisit()
        {
            var graph = new Graph<int>(true);
            var vertex1 = new Vertex<int>(1);
            var vertex2 = new Vertex<int>(2);
            var vertex3 = new Vertex<int>(3);
            var vertex4 = new Vertex<int>(4);
            var vertex5 = new Vertex<int>(5);
            var vertex6 = new Vertex<int>(6);
            var vertex7 = new Vertex<int>(7);

            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);
            graph.AddVertex(vertex3);
            graph.AddVertex(vertex4);
            graph.AddVertex(vertex5);
            graph.AddVertex(vertex6);
            graph.AddVertex(vertex7);

            graph.AddEdge(vertex1, vertex2);
            graph.AddEdge(vertex1, vertex3);
            graph.AddEdge(vertex1, vertex5);
            graph.AddEdge(vertex5, vertex3);

            graph.AddEdge(vertex3, vertex6);
            graph.AddEdge(vertex3, vertex4);
            graph.AddEdge(vertex2, vertex7);

            var trackingVisitor = new TrackingVisitor<Vertex<int>>();
            var postOrderVisitor = new PostOrderVisitor<Vertex<int>>(trackingVisitor);

            graph.DepthFirstTraversal(postOrderVisitor, vertex1);

            Assert.AreEqual(trackingVisitor.TrackingList.Count, graph.Vertices.Count);

            Assert.AreEqual(trackingVisitor.TrackingList[0].Data, 7);
            Assert.AreEqual(trackingVisitor.TrackingList[1].Data, 2);
            Assert.AreEqual(trackingVisitor.TrackingList[2].Data, 6);
            Assert.AreEqual(trackingVisitor.TrackingList[3].Data, 4);
            Assert.AreEqual(trackingVisitor.TrackingList[4].Data, 3);
            Assert.AreEqual(trackingVisitor.TrackingList[5].Data, 5);
            Assert.AreEqual(trackingVisitor.TrackingList[6].Data, 1);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:43,代码来源:DepthFirstTraversal.cs

示例5: ExceptionNullVisitor

 public void ExceptionNullVisitor()
 {
     var graph = new Graph<int>(true);
     graph.DepthFirstTraversal(null, new Vertex<int>(4));
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:5,代码来源:DepthFirstTraversal.cs

示例6: ExceptionNullVertex

 public void ExceptionNullVertex()
 {
     var graph = new Graph<int>(true);
     graph.DepthFirstTraversal(new PreOrderVisitor<Vertex<int>>(new TrackingVisitor<Vertex<int>>()), null);
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:5,代码来源:DepthFirstTraversal.cs


注:本文中的Graph.DepthFirstTraversal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。