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


C# Graph.Clear方法代码示例

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


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

示例1: Simple

        public void Simple()
        {
            var graph = new Graph<int>(true);
            Assert.IsTrue(graph.IsEmpty);

            graph.AddVertex(5);
            Assert.IsFalse(graph.IsEmpty);

            graph.AddVertex(3);
            Assert.IsFalse(graph.IsEmpty);

            graph.Clear();
            Assert.IsTrue(graph.IsEmpty);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:14,代码来源:IsEmpty.cs

示例2: Run

        // This would be much more effective as a unit test.
        public void Run()
        {
            int testNum = 1;

            Graph<Node, Edge> graph = new Graph<Node, Edge>();
            graph.AddNode(new Node(graph.AvailableNodeIndex));
            graph.AddNode(new Node(graph.AvailableNodeIndex));
            graph.AddNode(new Node(graph.AvailableNodeIndex));
            graph.AddNode(new Node(graph.AvailableNodeIndex));
            graph.AddEdge(new Edge(0, 1));
            graph.AddEdge(new Edge(1, 2));
            graph.AddEdge(new Edge(2, 3));

            SysDbg.WriteLine("Test " + testNum++ + ":");
            outputResults(graph, 0, 3);

            graph.Clear();

            int numNodes = 7;
            for (int i = 0; i < numNodes; i++)
                graph.AddNode(new Node(graph.AvailableNodeIndex));

            graph.AddEdge(new Edge(0, 1));
            graph.AddEdge(new Edge(0, 2));
            graph.AddEdge(new Edge(0, 3));
            graph.AddEdge(new Edge(1, 4));
            graph.AddEdge(new Edge(1, 5));
            graph.AddEdge(new Edge(2, 6));
            graph.AddEdge(new Edge(3, 5));

            SysDbg.WriteLine("Test " + testNum++ + ":");
            outputResults(graph, 0, 0);
            outputResults(graph, 0, 1);
            outputResults(graph, 0, 2);
            outputResults(graph, 0, 3);
            outputResults(graph, 0, 4);
            outputResults(graph, 4, 6);
            outputResults(graph, 6, 4);
            outputResults(graph, 3, 1);
            outputResults(graph, 3, 0);
            outputResults(graph, 1, 4);
            outputResults(graph, 5, 5);
            outputResults(graph, 3, 4);
            outputResults(graph, 3, 1);
            outputResults(graph, 7, 7);
        }
开发者ID:Linusa,项目名称:AI_Project,代码行数:47,代码来源:BFSDebugger.cs

示例3: IsEmptyExample

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

            // The graph will be empty
            Assert.IsTrue(graph.IsEmpty);

            // Add a vertex to the graph
            graph.AddVertex(3);

            // The graph will have one vertex in it (non-empty)
            Assert.IsFalse(graph.IsEmpty);

            // Clear the graph, thereby making it empty again
            graph.Clear();
            Assert.IsTrue(graph.IsEmpty);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:18,代码来源:GraphExamples.cs

示例4: ClearExample

        public void ClearExample()
        {
            // 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);

            // There will be 2 edges and 3 vertices in the graph
            Assert.AreEqual(graph.Edges.Count, 2);
            Assert.AreEqual(graph.Vertices.Count, 3);

            // Clear the graph - thereby removing all vertices
            // and edges in the graph.
            graph.Clear();

            // The graph will be empty
            Assert.AreEqual(graph.Edges.Count, 0);
            Assert.AreEqual(graph.Vertices.Count, 0);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:26,代码来源:GraphExamples.cs

示例5: Run


//.........这里部分代码省略.........
            graph.AddNode(new Node(0));
            graph.AddEdge(new Edge(0, 1));
            graph.AddEdge(new Edge(2, 0));
            graph.AddEdge(new Edge(1, 0));
            graph.ChangeEdgeWeight(0, 2, 42.0);

            // Should print 0-2, 2-3, 2-0, and 3-2.
            SysDbg.WriteLine("Current edges.");
            foreach (Edge edge in graph.Edges)
                SysDbg.WriteLine("\tEdge " + edge.NodeFrom + " -> " + edge.NodeTo);

            // Remove 0-2 and 2-0.
            graph.RemoveEdge(2, 0);

            // Should print 2-3 and 3-2.
            SysDbg.WriteLine("Current edges.");
            foreach (Edge edge in graph.Edges)
                SysDbg.WriteLine("\tEdge " + edge.NodeFrom + " -> " + edge.NodeTo);

            SysDbg.WriteLine("Node 3 exists? " + graph.NodeExists(3));
            SysDbg.WriteLine("Node 1 exists? " + graph.NodeExists(1));
            SysDbg.WriteLine("Edge 2-3 exists? " + graph.EdgeExists(2, 3));
            SysDbg.WriteLine("Edge 3-2 exists? " + graph.EdgeExists(3, 2));
            SysDbg.WriteLine("Edge 0-1 exists? " + graph.EdgeExists(0, 1));
            SysDbg.WriteLine("Edge 1-0 exists? " + graph.EdgeExists(1, 0));

            graph.AddNode(new Node(1));
            graph.AddNode(new Node(4));
            graph.AddNode(new Node(5));
            graph.AddNode(new Node(6));
            graph.AddEdge(new Edge(2, 2, 3));
            for (int i = 2; i < 20; i++)
                graph.AddEdge(new Edge(i, 1, 9.999));

            // Should print nodes 0-6.
            SysDbg.WriteLine("Nodes");
            foreach (Node node in graph.Nodes)
                SysDbg.WriteLine("\tNode #" + node.Index);

            SysDbg.WriteLine("Current edges.");
            foreach (Edge edge in graph.Edges)
                SysDbg.WriteLine("\tEdge " + edge.NodeFrom + " -> " + edge.NodeTo);

            SysDbg.WriteLine("Current edges from node 1.");
            foreach (Edge edge in graph.EdgesFromNode(1))
                SysDbg.WriteLine("\tEdge " + edge.NodeFrom + " -> " + edge.NodeTo);

            graph.RemoveEdge(0, 5);
            graph.RemoveEdge(3, 2);

            // These all change the actualWeight.
            graph.ChangeEdgeWeight(1, 2, 9001);
            graph.GetEdge(6, 1).Weight = 33.2112;
            graph.GetEdge(1, 6).Weight = 2112.33;

            // Check for curEdge modification by iteration.
            foreach (Edge e in graph.Edges)
                e.Weight = 1.0;
            double weightMod = 10.0;
            foreach (Edge e in graph.Edges)
            {
                e.Weight += weightMod;
                weightMod += 10.0;
            }

            // Revert all weights back to 1.0.
            foreach (Edge e in graph.Edges)
                e.Weight = 1.0;

            // Check for curEdge modification by iteration over a node's edges.
            foreach (Edge e in graph.EdgesFromNode(1))
                e.Weight = 3.0;

            graph.Clear();

            int numNodes = 15;

            for (int i = 0; i < numNodes; i++)
                graph.AddNode(new Node(graph.AvailableNodeIndex));

            for (int i = 4; i < 7; i++)
                for (int j = 0; j < numNodes; j++)
                    graph.AddEdge(new Edge(i, j, 2.0));

            SysDbg.WriteLine("Current edges.");
            {
                int curEdgeNum = 0;
                foreach (Edge edge in graph.Edges)
                    SysDbg.WriteLine("\tEdge " + curEdgeNum++ + ": " + edge.NodeFrom + " -> " + edge.NodeTo);
            }

            graph.RemoveNode(4);

            SysDbg.WriteLine("Current edges.");
            {
                int curEdgeNum = 0;
                foreach (Edge edge in graph.Edges)
                    SysDbg.WriteLine("\tEdge " + curEdgeNum++ + ": " + edge.NodeFrom + " -> " + edge.NodeTo);
            }
        }
开发者ID:Linusa,项目名称:AI_Project,代码行数:101,代码来源:GraphDebugger.cs


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