aryagraph.generators.random.layered_dag#

aryagraph.generators.random.layered_dag(layers: Sequence[int], p: float = 0.4, *, seed: int | Generator | None = None, connected: bool = True) → DAG[source]#

Random layered DAG: arcs only between consecutive layers.

Nodes are integers numbered layer by layer and carry layer (0-based) and index (position within the layer). Each pair of nodes in layers k and k+1 is linked with probability p.

With connected (the default) the result is also repaired so that every node below the first layer has a parent in the previous layer, every node above the last layer has a child in the next one, and the DAG is weakly connected; layer then equals DAG.levels(). With a single layer there are no arcs at all.

>>> dag = layered_dag([3, 5, 5, 2], p=0.3, seed=4)