繁体   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