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


C# AdjacencyGraph.AddEdge方法代码示例

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


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

示例1: Removing_Explicit_Edges_2

		public void Removing_Explicit_Edges_2()
		{
			var graph = new AdjacencyGraph<int, Edge<int>>();
			graph.AddVertex(1);
			graph.AddVertex(2);
			graph.AddVertex(3);
			graph.AddVertex(4);
			graph.AddVertex(5);
			graph.AddVertex(6);
			graph.AddVertex(7);
			graph.AddEdge(new Edge<int>(1, 3));
			graph.AddEdge(new Edge<int>(1, 4));
			graph.AddEdge(new Edge<int>(1, 6));
			graph.AddEdge(new Edge<int>(3, 6));
			graph.AddEdge(new Edge<int>(4, 6));
			graph.AddEdge(new Edge<int>(2, 4));
			graph.AddEdge(new Edge<int>(2, 5));
			graph.AddEdge(new Edge<int>(2, 7));
			graph.AddEdge(new Edge<int>(4, 7));
			graph.AddEdge(new Edge<int>(5, 7));

			GraphHelper.RemoveExplicitEdges(graph);

			Assert.AreEqual(8, graph.EdgeCount);
			Assert.IsTrue(graph.ContainsEdge(1, 3));
			Assert.IsTrue(graph.ContainsEdge(1, 4));
			Assert.IsTrue(graph.ContainsEdge(2, 4));
			Assert.IsTrue(graph.ContainsEdge(2, 5));
			Assert.IsTrue(graph.ContainsEdge(3, 6));
			Assert.IsTrue(graph.ContainsEdge(4, 6));
			Assert.IsTrue(graph.ContainsEdge(4, 7));
			Assert.IsTrue(graph.ContainsEdge(5, 7));
		}
开发者ID:penartur,项目名称:CCNet.Extensions,代码行数:33,代码来源:GraphHelperTest.cs

示例2: CheckPredecessorLineGraph

        public void CheckPredecessorLineGraph()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            Edge<int> e12 = new Edge<int>(1, 2); g.AddEdge(e12);
            Edge<int> e23 = new Edge<int>(2, 3); g.AddEdge(e23);

            var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
            var vis = new VertexPredecessorRecorderObserver<int, Edge<int>>();
            using(vis.Attach(dij))
                dij.Compute(1);

            IEnumerable<Edge<int>> path;
            Assert.IsTrue(vis.TryGetPath(2, out path));
            var col = path.ToList();
            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(e12, col[0]);

            Assert.IsTrue(vis.TryGetPath(3, out path));
            col = path.ToList();
            Assert.AreEqual(2, col.Count);
            Assert.AreEqual(e12, col[0]);
            Assert.AreEqual(e23, col[1]);
        }
开发者ID:GovorukhaOksana,项目名称:QuickGraph,代码行数:27,代码来源:DijkstraShortestPathAlgorithmTestOld.cs

示例3: createGraphWizDotFile

    	//DC this version was using the old QuickGraph MarkedEdge
        public static void createGraphWizDotFile(AdjacencyGraph<String, TaggedEdge<String, String>> gGraphWizToPopulate,
                                                 TreeNode tnTreeNode, bool bOrder, bool bFilterName, bool bFilterClass,
                                                 int iFilterClassLevel)
        {
            if (bFilterClass)
                tnTreeNode.Text = FilteredSignature.filterName(tnTreeNode.Text, false, false, true, 0, true, true,
                                                               iFilterClassLevel);
            TaggedEdge<String, string> meTemp;
            if (gGraphWizToPopulate.ContainsVertex(tnTreeNode.Text))
            {
            }
            else
                gGraphWizToPopulate.AddVertex(tnTreeNode.Text);

            foreach (TreeNode tnChild in tnTreeNode.Nodes)
            {
                if (bFilterClass)
                    tnChild.Text = FilteredSignature.filterName(tnChild.Text, false, false, true, 0, true, true,
                                                                iFilterClassLevel);
                createGraphWizDotFile(gGraphWizToPopulate, tnChild, bOrder, bFilterName, bFilterClass, iFilterClassLevel);
                if (bOrder)
                {
                    if (false == gGraphWizToPopulate.TryGetEdge(tnTreeNode.Text, tnChild.Text, out meTemp))
                        gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnTreeNode.Text, tnChild.Text,
                                                                                   "marker"));
                }
                else if (false == gGraphWizToPopulate.TryGetEdge(tnChild.Text, tnTreeNode.Text, out meTemp))
                    gGraphWizToPopulate.AddEdge(new TaggedEdge<String, string>(tnChild.Text, tnTreeNode.Text, "marker"));

                //gGraphToPopulate.AddEdge(tnTreeNode.Text, tnChild.Text);
                //    gGraphToPopulate.AddEdge(Analysis_CallFlow.display.filterName(tnChild.Text, false, false, false), Analysis_CallFlow.display.filterName(tnTreeNode.Text, false, false, false));
                //else
            }
        }
开发者ID:pusp,项目名称:o2platform,代码行数:35,代码来源:O2Graph.cs

示例4: TwoVertexCycle

        public void TwoVertexCycle()
        {
            AdjacencyGraph<string, Edge<string>> g = new AdjacencyGraph<string, Edge<string>>(true);
            g.AddVertex("v1");
            g.AddVertex("v2");
            g.AddEdge(new Edge<string>("v1", "v2"));
            g.AddEdge(new Edge<string>("v2", "v1"));
            StronglyConnectedComponentsAlgorithm<string, Edge<String>> strong = new StronglyConnectedComponentsAlgorithm<string, Edge<String>>(g);
            strong.Compute();
            Assert.AreEqual(1, strong.ComponentCount);

            checkStrong(strong);
        }
开发者ID:buptkang,项目名称:QuickGraph,代码行数:13,代码来源:StronglyConnectedComponentsAlgorithmTest.cs

示例5: BuildDependencyGraph

        public static AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>> BuildDependencyGraph(Type viewModelType)
        {
            var directDependencies = ViewModelConventions.GetViewModelProperties(viewModelType).ToDictionary(p => p, GetDirectDependentProperties);

            var graph = new AdjacencyGraph<PropertyInfo, STaggedEdge<PropertyInfo, string>>();

            foreach (var directDependency in directDependencies)
            {
                var property = directDependency.Key;
                graph.AddVertex(property);

                foreach (var dependentProperty in directDependency.Value)
                {
                    var sub = dependentProperty.SubPath;
                    var propertyType = property.PropertyType;
                    if (GetCollectionType(propertyType) != null) propertyType = GetCollectionType(propertyType);

                    if (String.IsNullOrEmpty(sub) && ViewModelConventions.IsViewModel(propertyType))
                        sub = "*";

                    graph.AddEdge(new STaggedEdge<PropertyInfo, string>(property, dependentProperty.Property, sub));
                }
            }

            return graph;
        }
开发者ID:oliverhanappi,项目名称:notifui,代码行数:26,代码来源:PropertyDependencies.cs

示例6: GenerateDotFile

        public void GenerateDotFile()
        {
            var graph = new AdjacencyGraph<string, TaggedEdge<string, string>>();

            for (int i = 0; i < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); i++)
            {
                graph.AddVertex(String.Format("{0}", i));
            }
            for (int i = 0; i < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); i++)
            {
                for (int j = 0; j < Math.Sqrt(Convert.ToDouble(m_Matrix.Length)); j++)
                {
                    if ((m_Matrix[i, j] == true) & (i < j))
                    {
                        graph.AddEdge(new TaggedEdge<string, string>(String.Format("{0}", i), String.Format("{0}", j), String.Format("{0}", i)));
                    }
                }
            }

            var graphViz = new GraphvizAlgorithm<string, TaggedEdge<string, string>>(graph, @".\", QuickGraph.Graphviz.Dot.GraphvizImageType.Png);
            graphViz.FormatVertex += (sender, e) =>
            {
                e.VertexFormatter.Shape = QuickGraph.Graphviz.Dot.GraphvizVertexShape.Circle;
            };

            graphViz.FormatEdge += (sender, e) =>
            {
                e.EdgeFormatter.Dir = QuickGraph.Graphviz.Dot.GraphvizEdgeDirection.None;
            };

            graphViz.Generate(new FileDotEngine(), m_Name);
        }
开发者ID:Butyava,项目名称:DemoGraphWPF,代码行数:32,代码来源:Graph.cs

示例7: Removing_Explicit_Edges_1

		public void Removing_Explicit_Edges_1()
		{
			var graph = new AdjacencyGraph<int, Edge<int>>();
			graph.AddVertex(1);
			graph.AddVertex(2);
			graph.AddVertex(3);
			graph.AddEdge(new Edge<int>(1, 2));
			graph.AddEdge(new Edge<int>(2, 3));
			graph.AddEdge(new Edge<int>(1, 3));

			GraphHelper.RemoveExplicitEdges(graph);

			Assert.AreEqual(2, graph.EdgeCount);
			Assert.IsTrue(graph.ContainsEdge(1, 2));
			Assert.IsTrue(graph.ContainsEdge(2, 3));
		}
开发者ID:penartur,项目名称:CCNet.Extensions,代码行数:16,代码来源:GraphHelperTest.cs

示例8: RunOnLineGraph

        public void RunOnLineGraph()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            g.AddEdge(new Edge<int>(1,2));
            g.AddEdge(new Edge<int>(2,3));

            var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
            dij.Compute(1);

            Assert.AreEqual<double>(0, dij.Distances[1]);
            Assert.AreEqual<double>(1, dij.Distances[2]);
            Assert.AreEqual<double>(2, dij.Distances[3]);
        }
开发者ID:GovorukhaOksana,项目名称:QuickGraph,代码行数:17,代码来源:DijkstraShortestPathAlgorithmTestOld.cs

示例9: OneTwo

 public void OneTwo()
 {
     var graph = new AdjacencyGraph<int, Edge<int>>();
     graph.AddVertex(1);
     graph.AddVertex(2);
     graph.AddEdge(new Edge<int>(1, 2));
     var t = new TopologicalSortAlgorithm<int, Edge<int>>(graph);
     t.Compute();
 }
开发者ID:buptkang,项目名称:QuickGraph,代码行数:9,代码来源:TopologicalSortAlgorithmTest.cs

示例10: RunOnDoubleLineGraph

        public void RunOnDoubleLineGraph()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            Edge<int> e12 = new Edge<int>(1, 2); g.AddEdge(e12);
            Edge<int> e23 = new Edge<int>(2, 3); g.AddEdge(e23);
            Edge<int> e13 = new Edge<int>(1, 3); g.AddEdge(e13);

            var dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, e => 1);
            dij.Compute(1);

            Assert.AreEqual(0.0, dij.Distances[1]);
            Assert.AreEqual(1.0, dij.Distances[2]);
            Assert.AreEqual(1.0, dij.Distances[3]);
        }
开发者ID:GovorukhaOksana,项目名称:QuickGraph,代码行数:18,代码来源:DijkstraShortestPathAlgorithmTestOld.cs

示例11: ComputeShortestPaths

        public static FloydWarshallAllShortestPathAlgorithm<int, UndirectedEdge<int>> ComputeShortestPaths(Dictionary<int, Node> nodes, IEnumerable<Edge> edges)
        {
            var graph = new AdjacencyGraph<int, UndirectedEdge<int>>();
            foreach (int nodeId in nodes.Keys)
            {
                graph.AddVertex(nodeId);
            }
            foreach (Edge edge in edges)
            {
                graph.AddEdge(new UndirectedEdge<int>(edge.StartNodeId, edge.EndNodeId));
                graph.AddEdge(new UndirectedEdge<int>(edge.EndNodeId, edge.StartNodeId));
            }

            Func<UndirectedEdge<int>, double> edgeCost = e => GetEdgeCost(nodes, e);
            var pathFinder = new FloydWarshallAllShortestPathAlgorithm<int, UndirectedEdge<int>>(graph, edgeCost);
            pathFinder.Compute();
            return pathFinder;
        }
开发者ID:shlee0817,项目名称:studmap,代码行数:18,代码来源:NavigationService.cs

示例12: AddEdgeToBoth

        //graph, tgraph, sourceNode, endNode, weight
        public static void AddEdgeToBoth(AdjacencyGraph<string, Edge<string>> graph, AdjacencyGraph<string, Edge<string>> tGraph, Dictionary<Edge<string>, double> edgeCost, Dictionary<Edge<string>, double> tEdgeCost, string sourceString, string endString, int weight)
        {
            Edge<string> curEdge = new Edge<string>(sourceString, endString);
            graph.AddEdge(curEdge);
            edgeCost.Add(curEdge, weight);

            Edge<string> transposeEdge = new Edge<string>(endString, sourceString);
            tGraph.AddEdge(transposeEdge);
            tEdgeCost.Add(transposeEdge, weight);
        }
开发者ID:joefs,项目名称:BidirectionalDijkstra,代码行数:11,代码来源:PA1Solver.cs

示例13: RunOnLineGraph

        public void RunOnLineGraph()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            g.AddEdge(new Edge<int>(1,2));
            g.AddEdge(new Edge<int>(2,3));

            Dictionary<Edge<int>,double> weights = 
                DijkstraShortestPathAlgorithm<int,Edge<int>>.UnaryWeightsFromEdgeList(g);
            DijkstraShortestPathAlgorithm<int, Edge<int>> dij = new DijkstraShortestPathAlgorithm<int, Edge<int>>(g, weights);
            dij.Compute(1);

            Assert.AreEqual<double>(0, dij.Distances[1]);
            Assert.AreEqual<double>(1, dij.Distances[2]);
            Assert.AreEqual<double>(2, dij.Distances[3]);
        }
开发者ID:sayedjalilhassan,项目名称:LearningPlatform,代码行数:19,代码来源:DijkstraShortestPathAlgorithmTest.cs

示例14: RootIsNotAccessible

        public void RootIsNotAccessible()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(0);
            g.AddVertex(1);
            g.AddEdge(new Edge<int>(0, 1));

            target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
            target.RandomTreeWithRoot(0);
        }
开发者ID:sayedjalilhassan,项目名称:LearningPlatform,代码行数:10,代码来源:CyclePoppingRandomTreeAlgorithmTest.cs

示例15: IncrementalConnectedComponent

        public void IncrementalConnectedComponent()
        {
            var g = new AdjacencyGraph<int, SEquatableEdge<int>>();
            g.AddVertexRange(new int[] { 0, 1, 2, 3 });
            var components = AlgorithmExtensions.IncrementalConnectedComponents(g);

            var current = components();
            Assert.AreEqual(4, current.Key);

            g.AddEdge(new SEquatableEdge<int>(0, 1));
            current = components();
            Assert.AreEqual(3, current.Key);

            g.AddEdge(new SEquatableEdge<int>(2, 3));
            current = components();
            Assert.AreEqual(2, current.Key);

            g.AddEdge(new SEquatableEdge<int>(1, 3));
            current = components();
            Assert.AreEqual(1, current.Key);
        }
开发者ID:buptkang,项目名称:QuickGraph,代码行数:21,代码来源:IncrementalConnectedComponentsAlgorithmTest.cs


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