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


C# Vertex.AddUnDirectedEdge方法代码示例

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


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

示例1: TopologicalTest4

        public void TopologicalTest4()
        {
            var graf = new Graf<char>();

            var bVertex = new Vertex<char>('b');
            var cVertex = new Vertex<char>('c');
            var dVertex = new Vertex<char>('d');

            var aVertex = new Vertex<char>('a');
            var iVertex = new Vertex<char>('i');
            var eVertex = new Vertex<char>('e');

            var hVertex = new Vertex<char>('h');
            var gVertex = new Vertex<char>('g');
            var fVertex = new Vertex<char>('f');

            aVertex.AddUnDirectedEdge(4, bVertex);
            bVertex.AddUnDirectedEdge(8, cVertex);
            cVertex.AddUnDirectedEdge(7, dVertex);

            dVertex.AddUnDirectedEdge(9, eVertex);
            dVertex.AddUnDirectedEdge(14, fVertex);
            eVertex.AddUnDirectedEdge(10, fVertex);

            aVertex.AddUnDirectedEdge(8, hVertex);
            bVertex.AddUnDirectedEdge(11, hVertex);

            cVertex.AddUnDirectedEdge(2, iVertex);
            cVertex.AddUnDirectedEdge(4, fVertex);
            iVertex.AddUnDirectedEdge(7, hVertex);

            iVertex.AddUnDirectedEdge(6, gVertex);

            hVertex.AddUnDirectedEdge(1, gVertex);
            gVertex.AddUnDirectedEdge(2, fVertex);

            graf.AddVertex(aVertex);
            graf.AddVertex(bVertex);
            graf.AddVertex(cVertex);
            graf.AddVertex(dVertex);
            graf.AddVertex(iVertex);
            graf.AddVertex(eVertex);
            graf.AddVertex(hVertex);
            graf.AddVertex(gVertex);
            graf.AddVertex(fVertex);

            var components = graf.GetStronglyConnectedComponentsWithUnions();

            Assert.Equal(1, components.Count);
        }
开发者ID:yuriysl,项目名称:Algorithms,代码行数:50,代码来源:GrafTests.cs

示例2: MSTTest1

        public void MSTTest1()
        {
            var graf = new Graf<char>();

            var bVertex = new Vertex<char>('b');
            var cVertex = new Vertex<char>('c');
            var dVertex = new Vertex<char>('d');

            var aVertex = new Vertex<char>('a');
            var iVertex = new Vertex<char>('i');
            var eVertex = new Vertex<char>('e');

            var hVertex = new Vertex<char>('h');
            var gVertex = new Vertex<char>('g');
            var fVertex = new Vertex<char>('f');

            aVertex.AddUnDirectedEdge(4, bVertex);
            bVertex.AddUnDirectedEdge(8, cVertex);
            cVertex.AddUnDirectedEdge(7, dVertex);

            dVertex.AddUnDirectedEdge(9, eVertex);
            dVertex.AddUnDirectedEdge(14, fVertex);
            eVertex.AddUnDirectedEdge(10, fVertex);

            aVertex.AddUnDirectedEdge(8, hVertex);
            bVertex.AddUnDirectedEdge(11, hVertex);

            cVertex.AddUnDirectedEdge(2, iVertex);
            cVertex.AddUnDirectedEdge(4, fVertex);
            iVertex.AddUnDirectedEdge(7, hVertex);

            iVertex.AddUnDirectedEdge(6, gVertex);

            hVertex.AddUnDirectedEdge(1, gVertex);
            gVertex.AddUnDirectedEdge(2, fVertex);

            graf.AddVertex(aVertex);
            graf.AddVertex(bVertex);
            graf.AddVertex(cVertex);
            graf.AddVertex(dVertex);
            graf.AddVertex(iVertex);
            graf.AddVertex(eVertex);
            graf.AddVertex(hVertex);
            graf.AddVertex(gVertex);
            graf.AddVertex(fVertex);

            var mstGraf = graf.GetMSTGrafKruskal();

            double weigth = 0;
            for (int i = 0; i < mstGraf.Vertexes.Count; i++)
            {
                for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++)
                {
                    mstGraf.Vertexes[i].Edges[j].Marked = false;
                }
            }
            for (int i = 0; i < mstGraf.Vertexes.Count; i++)
            {
                for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++)
                {
                    var adjacentVertex = mstGraf.Vertexes[i].Edges[j].Other(mstGraf.Vertexes[i]);
                    if (!mstGraf.Vertexes[i].Edges[j].Marked)
                    {
                        weigth += mstGraf.Vertexes[i].Edges[j].Weigth;
                        mstGraf.Vertexes[i].Edges[j].Marked = true;
                    }
                }
            }
            Assert.Equal(37, weigth);
        }
开发者ID:yuriysl,项目名称:Algorithms,代码行数:70,代码来源:GrafTests.cs


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