- From: Frederic Guinand <frederic.guinand AT univ-lehavre.fr>
- To: graphstream-users AT litislab.fr, gvdmoort AT skynet.be
- Subject: Re: Ancestors and descendants
- Date: Mon, 31 Mar 2014 23:41:50 +0200
Hello,
This piece of code should help you.
For a Node n you may use:
ArrayList<? extends Node>ancestors = new ArrayList<? extends Node>();
ArrayList<? extends Node>descendants = new ArrayList<? extends Node>();
Iterator<? extends Edge> inedges = n.getEnteringEdgeIterator();
while(inedges.hasNext()) {
ancestors.add(inedges.next().getOpposite(n));
}
Iterator<? extends Edge> outedges = n.getLeavingEdgeIterator();
while(outedges.hasNext()) {
descendants.add(outedges.next().getOpposite(n));
}
>
Can a graph mix directed and undirected edges ?
The answer is yes, when creating an edge, you just have to set the boolean to
true
graph.addEdge(myedgeId,sourceId,destId,true);
This is an arc from Node sourceId to Node destId.
Hope this helps,
Best,
Frederic
Le 31 mars 2014 à 21:13,
gvdmoort AT skynet.be
a écrit :
>
Hello,
>
>
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,
>
>
gvdm
- Re: Ancestors and descendants, Frederic Guinand, 31/03/2014
Archives gérées par MHonArc 2.6.16.