hiperwalk.Grid#
- hiperwalk.Grid(dim, periodic=True, diagonal=False, multiedges=None, weights=None, copy=False)[source]#
Two-dimensionsal grid constructor.
The grid can be designed with either cyclic boundary conditions or borders. Moreover, the grid’s representation can be either natural or diagonal. In the natural representation, neighboring vertices lie along the X and Y axes, while in the diagonal representation, they lie along the diagonals.
- Parameters:
- dimint or tuple of int
Grid dimensions in
(dim[0], dim[1])
format, wheredim[0]
is the number of vertices in the X-axis, anddim[1]
is the number of vertices in the Y-axis. Ifdim
is an integer, creates a square grid.- periodicbool, default=True
True
if the grid has cyclic boundary conditions,False
if it has borders.- diagonalbool, default=False
True
if the grid has the diagonal representation,False
if it has the natural representation.- multiedges, weights: matrix or dict, default=None
See Graph Constructors.
- copybool, default=False
See Graph Constructors.
- Returns:
hiperwalk.Graph
See Graph Constructors for details.
See also
Notes
The order of neighbors depends on the grid.
- Natural Grid:
The natural grid is created when
diagonal=False
. The neighbors are given in the following order.00 = 0: right;
01 = 1: left;
10 = 2: up;
11 = 3: down.
The most significant bit corresponds to the axis: 0 represents the X-axis and 1 represents the Y-axis. The least significant bit indicates the direction along the given axis, with 0 signifying forward and 1 signifying backward.
Consider a vertex \((x, y)\). Then, \((x \pm 1, y)\) and \((x, y \pm 1)\) are adjacent vertices. The order of neighbors is depicted in Figure: The order of neighbors in the natural grid..
For example, consider the \(3 \times 3\) periodic natural grid (Figure: Periodic natural 3x3-grid.).
The neighbors of \((0, 0)\) and \((1, 1)\) with respect to the order of neighbors are
>>> nat = hpw.Grid(3, diagonal=False, periodic=True) >>> neigh = nat.neighbors((0, 0)) >>> [tuple(nat.vertex_coordinates(v)) for v in neigh] [(1, 0), (2, 0), (0, 1), (0, 2)] >>> >>> neigh = nat.neighbors((1, 1)) >>> [tuple(nat.vertex_coordinates(v)) for v in neigh] [(2, 1), (0, 1), (1, 2), (1, 0)]
- Diagonal Grid:
The diagonal grid is created when
diagonal=True
. The neighbors are given in the following order.00 = 0: right, up;
01 = 1: right, down;
10 = 2: left, up;
11 = 3: left, down.
Each binary value indicates the direction along a given axis, with 0 representing forward and 1 representing backward. The most significant bit corresponds to the direction along the X-axis, while the least significant bit corresponds to the direction along the Y-axis.
Consider a vertex \((x, y)\). Then, its four neighbors are \((x \pm 1, y \pm 1)\). The order of neighbors is depicted in Figure: The order of neighbors in the diagonal grid..
For example, consider the \(3 \times 3\) periodic diagonal grid (Figure: Periodic diagonal 3x3-grid.).
The neighbors of \((0, 0)\) and \((1, 1)\) with respect to the order of neighbors are
>>> diag = hpw.Grid(3, diagonal=True, periodic=True) >>> neigh = diag.neighbors((0, 0)) >>> [tuple(diag.vertex_coordinates(v)) for v in neigh] [(1, 1), (1, 2), (2, 1), (2, 2)] >>> >>> neigh = diag.neighbors((1, 1)) >>> [tuple(diag.vertex_coordinates(v)) for v in neigh] [(2, 2), (2, 0), (0, 2), (0, 0)]
In the case of a diagonal grid with borders, there exist two independent subgrids. In other words, a vertex in one subgrid is not accessible from a vertex in the other subgrid.
Two independent subgrids also occur if the diagonal grid has periodic boundary conditions and both dimensions are even. Figure Figure: 4x4-grid with cyclic boundary conditions. illustrates an example of this case.
Methods#
All methods are inherited from
hiperwalk.IntegerLattice
.