本文整理汇总了C#中System.Edge.GetToVertex方法的典型用法代码示例。如果您正苦于以下问题:C# Edge.GetToVertex方法的具体用法?C# Edge.GetToVertex怎么用?C# Edge.GetToVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Edge
的用法示例。
在下文中一共展示了Edge.GetToVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddEdge
public virtual void AddEdge(Edge e)
{
//Check to see if the vertices belong to a different graph
//Not necessarily null
if (e.GetFromVertex().GetGraph() != this)
{
AddVertex(e.GetFromVertex());
}
if (e.GetToVertex().GetGraph() != this)
{
AddVertex(e.GetToVertex());
}
int fromIndex = vertices.IndexOf(e.GetFromVertex());
int toIndex = vertices.IndexOf(e.GetToVertex());
float val = matrix.GetValueAt(fromIndex, toIndex);
Edge oppositeEdge = new Edge(e.GetToVertex(), e.GetFromVertex(), e.Weight);
if (!float.IsInfinity(val))
{
//update existing edge
matrix.SetValueAt(fromIndex, toIndex, e.Weight);
if (!Directed)
{
matrix.SetValueAt(toIndex, fromIndex, e.Weight);
}
Edge existing = FindEdge(e);
existing.Weight = e.Weight;
Edge otherEdge = FindEdge(new Edge(e.GetToVertex(), e.GetFromVertex()));
if (otherEdge == null)
{
return;
}
otherEdge.Weight = e.Weight;
return;
}
vertices[fromIndex].AddOutEdge(e);
vertices[toIndex].AddInEdge(e);
if (!Directed)
{
vertices[toIndex].AddOutEdge(oppositeEdge);
vertices[fromIndex].AddInEdge(oppositeEdge);
}
edges.Add(e);
if (!Directed)
{
edges.Add(oppositeEdge);
edgeCount++;
}
edgeCount++;
float edgeWeight = e.Weight;
matrix.SetValueAt(fromIndex, toIndex, edgeWeight);
if (!Directed)
{
matrix.SetValueAt(toIndex, fromIndex, edgeWeight);
}
e.Directed = directed;
oppositeEdge.Directed = directed;
e.ShowLabel = showEdgeLabels;
oppositeEdge.ShowLabel = showEdgeLabels;
}
示例2: RemoveEdge
public virtual void RemoveEdge(Edge e)
{
bool success = edges.Remove(e);
if (success)
{
edgeCount--;
int fromIndex = vertices.IndexOf(e.GetFromVertex());
int toIndex = vertices.IndexOf(e.GetToVertex());
//If fromIndex or toIndex is -1, the vertex has already been removed, so don't worry about updating
//their information
if (fromIndex >= 0)
{
vertices[fromIndex].RemoveOutEdge(e);
}
if (toIndex >= 0)
{
vertices[toIndex].RemoveInEdge(e);
}
if (fromIndex < 0 || toIndex < 0)
{
return;
}
matrix.SetValueAt(fromIndex, toIndex, float.PositiveInfinity);
}
}