causaldag.classes.dag.DAG.is_topological

DAG.is_topological(order: list) → bool[source]

Check that order is a topological order consistent with this DAG, i.e., if i->``j`` in the DAG, then i comes before j in the order.

Parameters:order – the order to check.

Examples

>>> import causaldag as cd
>>> g = cd.DAG(arcs={(1, 2), (1, 3)})
>>> g.is_topological([1, 2, 3])
True
>>> g.is_topological([1, 3, 2])
True
>>> g.is_topological([2, 1, 3])
False