我正在使用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));我只需要一个图中没有" in“边(indegree=0)的顶点的列表。
发布于 2014-09-01 14:46:54
你可能需要一种不同的图形类型。深入QuickGraph的论坛和源代码,我发现了BidirectionalGraph类,它是
一种适用于稀疏图表示的可变有向图数据结构,需要对边外边和边内边进行枚举。所需内存是邻接图的两倍。
检索内度的方法似乎是在IBidirectionalIncidenceGraph上找到的,就像这一讨论暗示的那样。
您使用的数据结构不对传入的边进行簿记,因此您必须通过遍历所有边并查看它们的目标来检索顶点的内度,这对于大图来说可能是一项昂贵的操作。
BidirectionalGraph在这方面速度更快,但它占用的内存空间是簿记的两倍。使用它,您可以做如下事情:
var orphans = graph.Vertices.Where(v => graph.InDegree(v) == 0)https://stackoverflow.com/questions/25569164
复制相似问题