GraphStream Users

Archives de la liste Aide

Re: Ancestors and descendants

Chronologique Discussions 
  • From: Stefan Balev <stefan.balev AT>
  • To: "graphstream-users AT" <graphstream-users AT>, gvdmoort AT
  • Subject: Re: Ancestors and descendants
  • Date: Tue, 1 Apr 2014 09:53:26 +0200


Yes, a graph can mix directed and undirected edges. Undirected edges are considered as both outgoing and incoming.

Unfortunately breadth-first and depth-first iterators cannot follow the edges in the opposite direction so you can use them to find the descendants but not the ancestors of a given node. However, it is not very difficult to make your custom depth-search. Something like this should do what you want:

public void findAncestors(Node n) {
  if (!n.hasAttribute("visited")) {
  n.addAttribute("visited", true);
  for (Edge e : n.getEachEnteringEdge())

After calling this method all the ancestors of the parameter node will have a "visited" attribute.

Good luck,


2014-03-31 21:13 GMT+02:00 <gvdmoort AT>:

At first sight, your library seems to fit with my needs. But I don't find in
the API an easy way to get the set of all the descendants or ancestors of a
given node in a directed graph. For the descendants, it's possible to use the
BreadthFirstIterator, but for the ancestors ? Is it necessary to make an
"inversed copy" of the graph ?

I don't find mention of directed or undirected graphs. Can a graph mix directed
and undirected edges ?

Thanks in advance,


Archives gérées par MHonArc 2.6.16.

Top of page