rustworkx.generators.directed_hexagonal_lattice_graph#

directed_hexagonal_lattice_graph(rows, cols, bidirectional=False, multigraph=True, periodic=False, with_positions=False)#

Generate a directed hexagonal lattice graph.

The edges propagate towards right and bottom direction if bidirectional is False

Parameters:
  • rows (int) – The number of rows to generate the graph with.

  • cols (int) – The number of rows to generate the graph with.

  • bidirectional – A parameter to indicate if edges should exist in both directions between nodes. Defaults to False.

  • multigraph (bool) – When set to False the output PyDiGraph 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.

  • periodic (bool) – When set to True the boundaries of the lattice will be joined to form a periodic grid. Requires cols to be even, rows > 1, and cols > 1.

  • with_positions (bool) – When set to True each node will be assigned a pair of coordinates (x, y) as a payload. This embeds the nodes in the plane so that each hexagon is regular (with side length 1).

Returns:

The generated directed hexagonal lattice graph.

Return type:

PyDiGraph

Raises:

TypeError – If either rows or cols are not specified

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.directed_hexagonal_lattice_graph(2, 3)
mpl_draw(graph)
../_images/rustworkx.generators.directed_hexagonal_lattice_graph_0_0.png