graph.directedPath

pyagrum.graph.directedPath(g, source, target)

A shortest directed path between two nodes (family A).

Parameters:
  • g (DiGraph | DAG | MixedGraph | PDAG | ChainGraph | CPDAG | MPDAG | EssentialGraph) – the graph (its edges are ignored)

  • source (int | str) – the first node of the path

  • target (int | str) – the last node of the path

Returns:

the nodes of the path, from source to target, or None if there is no directed path

Return type:

list[int] | None

Example

import pyagrum as gum
import pyagrum.graph as gg

g = gum.fastDAG("A->B->C;A->D->E->C")
gg.directedPath(g, "A", "C")
# [0, 1, 2]
print(gg.directedPath(g, "C", "A"))
# None