Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.layers#

layers(dag, first_layer, /, index_output=False)#

Return a list of layers

A layer is a subgraph whose nodes are disjoint, i.e., a layer has depth 1. The layers are constructed using a greedy algorithm.

Parameters:
  • graph (PyDiGraph) – The DAG to get the layers from

  • first_layer (list) – A list of node ids for the first layer. This will be the first layer in the output

  • index_output (bool) – When set to to True the output layers will be a list of integer node indices.

Returns:

A list of layers, each layer is a list of node data, or if index_output is True each layer is a list of node indices.

Return type:

list

Raises:

InvalidNode – If a node index in first_layer is not in the graph