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


C# IVertex.GetConnectingEdges方法代码示例

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


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

示例1: GetEdgeWeight

        //*************************************************************************
        //  Method: GetEdgeWeight()
        //
        /// <summary>
        /// Gets the edge weight between two vertices.
        /// </summary>
        ///
        /// <param name="vertex1">
        /// The first vertex.
        /// </param>
        ///
        /// <param name="vertex2">
        /// The second vertex.
        /// </param>
        ///
        /// <returns>
        /// The edge weight between the two vertices.
        /// </returns>
        ///
        /// <remarks>
        /// It's assumed that duplicate edges have been merged, and that the
        /// <see cref="ReservedMetadataKeys.EdgeWeight" /> key has been set on
        /// each of the graph's edges.
        /// </remarks>
        //*************************************************************************
        public static Double GetEdgeWeight(
            IVertex vertex1,
            IVertex vertex2
            )
        {
            Debug.Assert(vertex1 != null);
            Debug.Assert(vertex2 != null);

            Double dEdgeWeight = 0;

            // Get the edges that connect the two vertices.  This includes all
            // connecting edges and does not take directedness into account.

            ICollection<IEdge> oConnectingEdges =
            vertex1.GetConnectingEdges(vertex2);

            Int32 iConnectingEdges = oConnectingEdges.Count;
            IEdge oConnectingEdgeWithEdgeWeight = null;

            switch (vertex1.ParentGraph.Directedness)
            {
            case GraphDirectedness.Directed:

                // There can be 0, 1, or 2 edges between the vertices.  Only
                // one of them can originate at vertex1.

                Debug.Assert(iConnectingEdges <= 2);

                foreach (IEdge oConnectingEdge in oConnectingEdges)
                {
                    if (oConnectingEdge.BackVertex == vertex1)
                    {
                        oConnectingEdgeWithEdgeWeight = oConnectingEdge;
                        break;
                    }
                }

                break;

            case GraphDirectedness.Undirected:

                // There can be 0 or 1 edges between the vertices.  There can't
                // be 2 edges, because the duplicate edges (A,B) and (B,A) have
                // been merged.

                Debug.Assert(iConnectingEdges <= 1);

                if (iConnectingEdges == 1)
                {
                    oConnectingEdgeWithEdgeWeight = oConnectingEdges.First();
                }

                break;

            default:

                Debug.Assert(false);
                break;
            }

            if (oConnectingEdgeWithEdgeWeight != null)
            {
            dEdgeWeight = (Double)
                oConnectingEdgeWithEdgeWeight.GetRequiredValue(
                    ReservedMetadataKeys.EdgeWeight, typeof(Double) );
            }

            return (dEdgeWeight);
        }
开发者ID:haisreekanth,项目名称:NetMap,代码行数:94,代码来源:EdgeUtil.cs


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