pyrobopath.process.utilities.batch_digraph#

pyrobopath.process.utilities.batch_digraph(dg: DependencyGraph, max_nodes: int) List[DependencyGraph][source]#

Split a directed graph into multiple subgraphs with at most max_nodes nodes each.

Parameters:
  • dg (DependencyGraph) – The input graph to be split into subgraphs.

  • max_nodes (int) – The maximum number of nodes allowed in each subgraph.

Returns:

subgraphs – A list of DependencyGraph instances, each containing at most max_nodes nodes. The subgraphs preserve the internal structure of the original graph for the included node subsets.

Return type:

List[DependencyGraph]

Notes

  • This function does not attempt to preserve connectivity between subgraphs.

  • Nodes are partitioned in the order returned by dg._graph.nodes.

  • The _graph attribute is deep-copied into each subgraph to ensure isolation.

Examples

>>> dg = DependencyGraph()
>>> # Assume dg._graph has 10 nodes
>>> subgraphs = split_digraph(dg, max_nodes=4)
>>> len(subgraphs)
3
>>> [len(sg._graph.nodes) for sg in subgraphs]
[4, 4, 2]