簡體   English   中英

QuickGraph查找頂點度

[英]QuickGraph finding indegree of Vertices

我正在使用QuickGraph創建有向無環圖。 我需要找到所有度數為零的頂點。 我在圖形的Vertices集合上看不到這種支持,也沒有使用LINQ進行過濾的方法。

這是我正在編寫的樣本數據結構:

var componentGraph = new AdjacencyGraph<Component, Edge<Component>>();

var serverOnMachineA = new TalismaServerComponent("CLTDEPAPI10");
var serverOnMachineB = new TalismaServerComponent("CLTDEPAPI11");
var appServerOnMachineB = new TalismaAppServerComponent("CLTDEPAPI11");
var webComponentsOnMachineC = new TalismaWebComponentsComponent("CLTDEPFE1");

componentGraph.AddVertex(serverOnMachineA);
componentGraph.AddVertex(serverOnMachineB);
componentGraph.AddVertex(appServerOnMachineB);
componentGraph.AddVertex(webComponentsOnMachineC);

componentGraph.AddEdge(new Edge<Component>(appServerOnMachineB, serverOnMachineA));
componentGraph.AddEdge(new Edge<Component>(webComponentsOnMachineC, appServerOnMachineB));
componentGraph.AddEdge(new Edge<Component>(webComponentsOnMachineC, serverOnMachineB));

我只需要此圖中沒有“入”邊(indegree = 0)的頂點的列表即可。

您可能需要其他圖形類型。 深入討論一下QuickGraph的論壇和源代碼,我發現了BidirectionalGraph類,它是

一種可變的有向圖數據結構,對於需要枚舉邊緣和邊緣的稀疏圖形表示有效。 需要的內存是鄰接圖的兩倍。

正如本次討論所暗示的IBidirectionalIncidenceGraph ,似乎可以在IBidirectionalIncidenceGraph上找到檢索度數的方法。

您使用的數據結構不會保留輸入邊的預訂,因此您必須通過遍歷所有邊並查看其目標來檢索頂點的入度,這對於大圖形而言可能是一項昂貴的操作。

為此, BidirectionalGraph更快,但用於簿記的內存空間是原來的兩倍。 使用它,您可以執行以下操作:

var orphans = graph.Vertices.Where(v => graph.InDegree(v) == 0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM