QuickGraph - is there algorithm for find all parents (up to root vertex's) of a set of vertex's

前端 未结 3 1218
既然无缘
既然无缘 2021-01-13 15:56

In QuickGraph - is there algorithm for find all parents (up to root vertex\'s) of a set of vertex\'s. In other words all vertex\'s which have somewhere under them (on the w

3条回答
  •  难免孤独
    2021-01-13 16:48

    I used Doug's answer and found out that if there are more than one parent for a vertex, his solution only provides one of the parents. I am not sure why.

    So, I created my own version which is as follows:

        public IEnumerable GetParents(T vertexToFind)
        {
            IEnumerable parents = null;
    
            if (this.graph.Edges != null)
            {
                parents = this.graph
                    .Edges
                    .Where(x => x.Target.Equals(vertexToFind))
                    .Select(x => x.Source);
            }
    
            return parents;
        }
    

提交回复
热议问题