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.generators.directed_grid_graph#
- directed_grid_graph(rows=None, cols=None, weights=None, bidirectional=False, multigraph=True)#
Generate a directed grid graph.
The edges propagate towards right and bottom direction if
bidirectional
isFalse
- Parameters:
rows (int) – The number of rows to generate the graph with. If specified,
cols
also need to be specified.cols (int) – The number of cols to generate the graph with. If specified,
rows
also need to be specified. rows*cols defines the number of nodes in the graph.weights (list) – A list of node weights. Nodes are filled row wise. If rows and cols are not specified, then a linear graph containing all the values in weights list is created. If number of nodes(rows*cols) is less than length of weights list, the trailing weights are ignored. If number of nodes(rows*cols) is greater than length of weights list, extra nodes with None weight are appended.
bidirectional – A parameter to indicate if edges should exist in both directions between nodes. Defaults to
False
.multigraph (bool) – When set to
False
the outputPyDiGraph
object will not be not be a multigraph and won’t allow parallel edges to be added. Instead calls which would create a parallel edge will update the existing edge.
- Returns:
The generated grid graph
- Return type:
- Raises:
IndexError – If neither
rows
orcols
andweights
are specified
import rustworkx.generators from rustworkx.visualization import mpl_draw graph = rustworkx.generators.directed_grid_graph(2, 3) mpl_draw(graph)