本文整理汇总了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);
}