graph.descendants

pyagrum.graph.descendants(g, nodes)

The descendants of nodes (family A, or a marked graph): the nodes with a directed path from one of them.

The search starts from the children: a node of nodes belongs to the result only if it has a directed path from one of them (on a directed cycle, or descendant of another one).

Parameters:
  • g (DiGraph | DAG | MixedGraph | PDAG | ChainGraph | CPDAG | MPDAG | EssentialGraph | MarkedGraph | PAG | MAG) – the graph (the edges of a mixed graph are ignored; in a marked graph, the directed paths are made of edges ->)

  • nodes (int | str | Iterable[int | str]) – a node or several nodes, by id or by name

Returns:

the descendants

Return type:

set[int]

Example

import pyagrum as gum
import pyagrum.graph as gg

g = gum.fastDAG("A->B->C;A->D")
gg.descendants(g, "A")
# {1, 2, 3}
gg.descendants(g, {"A", "B"})  # B is a descendant of A
# {1, 2, 3}
gg.descendants(gum.fastDiGraph("A->B->A"), "A")  # a directed cycle
# {0, 1}
gg.descendants(gum.fastMarkedGraph("A->B<->C;B->D"), "A")
# {1, 3}