當前位置: 首頁>>代碼示例>>C#>>正文


C# Edge.GetFromVertex方法代碼示例

本文整理匯總了C#中System.Edge.GetFromVertex方法的典型用法代碼示例。如果您正苦於以下問題:C# Edge.GetFromVertex方法的具體用法?C# Edge.GetFromVertex怎麽用?C# Edge.GetFromVertex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Edge的用法示例。


在下文中一共展示了Edge.GetFromVertex方法的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;
        }
開發者ID:bschwind,項目名稱:Graph-App,代碼行數:71,代碼來源:Graph.cs

示例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);
            }
        }
開發者ID:bschwind,項目名稱:Graph-App,代碼行數:27,代碼來源:Graph.cs


注:本文中的System.Edge.GetFromVertex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。