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. Ifdimis an integer, creates a square grid.- periodicbool, default=True
Trueif the grid has cyclic boundary conditions,Falseif it has borders.- diagonalbool, default=False
Trueif the grid has the diagonal representation,Falseif it has the natural representation.- multiedges, weights: matrix or dict, default=None
See Graph Constructors.
- copybool, default=False
See Graph Constructors.
- Returns:
hiperwalk.GraphSee 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..
![graph {
4 [pos="0,0!" label="(x, y)" width=1 height=1 fixedsize=True;]
0 [pos="2,0!" label="(x + 1, y)" width=1 height=1 fixedsize=True;]
1 [pos="-2,0!" label="(x - 1, y)" width=1 height=1 fixedsize=True;]
2 [pos="0,2!" label="(x, y + 1)" width=1 height=1 fixedsize=True;]
3 [pos="0,-2!" label="(x, y - 1)" width=1 height=1 fixedsize=True;]
4 -- 0 [headlabel=0 labeldistance=4 labelangle=-10];
4 -- 1 [headlabel=1 labeldistance=4 labelangle=10];
4 -- 2 [headlabel=2 labeldistance=4 labelangle=10];
4 -- 3 [headlabel=3 labeldistance=4 labelangle=-10];
}](../../_images/graphviz-545acde962481ea5bc4ec9df10aa6deb4bb29983.png)
Figure: The order of neighbors in the natural grid.#
For example, consider the \(3 \times 3\) periodic natural grid (Figure: Periodic natural 3x3-grid.).
![graph {
"(0, -1)" [pos="0.0,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(1, -1)" [pos="1.75,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 2)"]
"(2, -1)" [pos="3.5,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 2)"]
"(-1, 0)" [pos="-1.75,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(0, 0)" [pos="0.0,0.0!" width=0.75 height=0.75 fixedsize=True]
"(1, 0)" [pos="1.75,0.0!" width=0.75 height=0.75 fixedsize=True]
"(2, 0)" [pos="3.5,0.0!" width=0.75 height=0.75 fixedsize=True]
"(3, 0)" [pos="5.25,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(-1, 1)" [pos="-1.75,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 1)"]
"(0, 1)" [pos="0.0,1.75!" width=0.75 height=0.75 fixedsize=True]
"(1, 1)" [pos="1.75,1.75!" width=0.75 height=0.75 fixedsize=True]
"(2, 1)" [pos="3.5,1.75!" width=0.75 height=0.75 fixedsize=True]
"(3, 1)" [pos="5.25,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 1)"]
"(-1, 2)" [pos="-1.75,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 2)"]
"(0, 2)" [pos="0.0,3.5!" width=0.75 height=0.75 fixedsize=True]
"(1, 2)" [pos="1.75,3.5!" width=0.75 height=0.75 fixedsize=True]
"(2, 2)" [pos="3.5,3.5!" width=0.75 height=0.75 fixedsize=True]
"(3, 2)" [pos="5.25,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(0, 3)" [pos="0.0,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(1, 3)" [pos="1.75,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 0)"]
"(2, 3)" [pos="3.5,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(0, 0)" -- "(1, 0)";
"(0, 0)" -- "(0, 1)";
"(0, 0)" -- "(-1, 0)";
"(0, 0)" -- "(0, -1)";
"(1, 0)" -- "(2, 0)";
"(1, 0)" -- "(1, 1)";
"(1, 0)" -- "(1, -1)";
"(2, 0)" -- "(3, 0)";
"(2, 0)" -- "(2, 1)";
"(2, 0)" -- "(2, -1)";
"(0, 1)" -- "(1, 1)";
"(0, 1)" -- "(0, 2)";
"(0, 1)" -- "(-1, 1)";
"(1, 1)" -- "(2, 1)";
"(1, 1)" -- "(1, 2)";
"(2, 1)" -- "(3, 1)";
"(2, 1)" -- "(2, 2)";
"(0, 2)" -- "(1, 2)";
"(0, 2)" -- "(0, 3)";
"(0, 2)" -- "(-1, 2)";
"(1, 2)" -- "(2, 2)";
"(1, 2)" -- "(1, 3)";
"(2, 2)" -- "(3, 2)";
"(2, 2)" -- "(2, 3)";
}](../../_images/graphviz-604b567f0e4b43d016118ab180f1e7870b1371ee.png)
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(int(i) for i in nat.vertex_coordinates(v)) for v in neigh] [(1, 0), (2, 0), (0, 1), (0, 2)] >>> >>> neigh = nat.neighbors((1, 1)) >>> [tuple(int(i) for i in 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..
![digraph {
4 [pos="0,0!" label="(x, y)" width=1.5 height=1.5 fixedsize=True]
0 [pos="2,2!" label="(x + 1, y + 1)" width=1.5 height=1.5 fixedsize=True]
1 [pos="2,-2!" label="(x + 1, y - 1)" width=1.5 height=1.5 fixedsize=True]
2 [pos="-2,2!" label="(x - 1, y + 1)" width=1.5 height=1.5 fixedsize=True]
3 [pos="-2,-2!" label="(x - 1, y - 1)" width=1.5 height=1.5 fixedsize=True]
4 -> 0 [headlabel=0 labeldistance=5 labelangle=-10];
4 -> 1 [headlabel=1 labeldistance=5 labelangle=-10];
4 -> 2 [headlabel=2 labeldistance=5 labelangle=10];
4 -> 3 [headlabel=3 labeldistance=5 labelangle=10];
}](../../_images/graphviz-76751c6fc40ca6230c8fe584e9c564f0e154a01a.png)
Figure: The order of neighbors in the diagonal grid.#
For example, consider the \(3 \times 3\) periodic diagonal grid (Figure: Periodic diagonal 3x3-grid.).
![graph {
"(-1, -1)" [pos="-1.75,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 2)"]
"(0, -1)" [pos="0.0,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(1, -1)" [pos="1.75,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 2)"]
"(2, -1)" [pos="3.5,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 2)"]
"(3, -1)" [pos="5.25,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(-1, 0)" [pos="-1.75,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(0, 0)" [pos="0.0,0.0!" width=0.75 height=0.75 fixedsize=True]
"(1, 0)" [pos="1.75,0.0!" width=0.75 height=0.75 fixedsize=True]
"(2, 0)" [pos="3.5,0.0!" width=0.75 height=0.75 fixedsize=True]
"(3, 0)" [pos="5.25,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(-1, 1)" [pos="-1.75,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 1)"]
"(0, 1)" [pos="0.0,1.75!" width=0.75 height=0.75 fixedsize=True]
"(1, 1)" [pos="1.75,1.75!" width=0.75 height=0.75 fixedsize=True]
"(2, 1)" [pos="3.5,1.75!" width=0.75 height=0.75 fixedsize=True]
"(3, 1)" [pos="5.25,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 1)"]
"(-1, 2)" [pos="-1.75,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 2)"]
"(0, 2)" [pos="0.0,3.5!" width=0.75 height=0.75 fixedsize=True]
"(1, 2)" [pos="1.75,3.5!" width=0.75 height=0.75 fixedsize=True]
"(2, 2)" [pos="3.5,3.5!" width=0.75 height=0.75 fixedsize=True]
"(3, 2)" [pos="5.25,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(-1, 3)" [pos="-1.75,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(0, 3)" [pos="0.0,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(1, 3)" [pos="1.75,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 0)"]
"(2, 3)" [pos="3.5,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(3, 3)" [pos="5.25,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(0, 0)" -- "(1, 1)";
"(0, 0)" -- "(-1, 1)";
"(0, 0)" -- "(-1, -1)";
"(0, 0)" -- "(1, -1)";
"(1, 0)" -- "(2, 1)";
"(1, 0)" -- "(0, 1)";
"(1, 0)" -- "(0, -1)";
"(1, 0)" -- "(2, -1)";
"(2, 0)" -- "(3, 1)";
"(2, 0)" -- "(1, 1)";
"(2, 0)" -- "(1, -1)";
"(2, 0)" -- "(3, -1)";
"(0, 1)" -- "(1, 2)";
"(0, 1)" -- "(-1, 2)";
"(0, 1)" -- "(-1, 0)";
"(1, 1)" -- "(2, 2)";
"(1, 1)" -- "(0, 2)";
"(2, 1)" -- "(3, 2)";
"(2, 1)" -- "(1, 2)";
"(2, 1)" -- "(3, 0)";
"(0, 2)" -- "(1, 3)";
"(0, 2)" -- "(-1, 3)";
"(0, 2)" -- "(-1, 1)";
"(1, 2)" -- "(2, 3)";
"(1, 2)" -- "(0, 3)";
"(2, 2)" -- "(3, 3)";
"(2, 2)" -- "(1, 3)";
"(2, 2)" -- "(3, 1)";
}](../../_images/graphviz-56f78f0148bd1dff23da5481614ad31c7f5423b7.png)
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(int(i) for i in diag.vertex_coordinates(v)) for v in neigh] [(1, 1), (1, 2), (2, 1), (2, 2)] >>> >>> neigh = diag.neighbors((1, 1)) >>> [tuple(int(i) for i in 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.
![graph {
"(0, 0)" [pos="0.0,0.0!" width=0.75 height=0.75 fixedsize=True]
"(1, 0)" [pos="1.75,0.0!" width=0.75 height=0.75 fixedsize=True]
"(2, 0)" [pos="3.5,0.0!" width=0.75 height=0.75 fixedsize=True]
"(0, 1)" [pos="0.0,1.75!" width=0.75 height=0.75 fixedsize=True]
"(1, 1)" [pos="1.75,1.75!" width=0.75 height=0.75 fixedsize=True]
"(2, 1)" [pos="3.5,1.75!" width=0.75 height=0.75 fixedsize=True]
"(0, 2)" [pos="0.0,3.5!" width=0.75 height=0.75 fixedsize=True]
"(1, 2)" [pos="1.75,3.5!" width=0.75 height=0.75 fixedsize=True]
"(2, 2)" [pos="3.5,3.5!" width=0.75 height=0.75 fixedsize=True]
"(0, 0)" -- "(1, 1)";
"(1, 0)" -- "(2, 1)";
"(1, 0)" -- "(0, 1)";
"(2, 0)" -- "(1, 1)";
"(0, 1)" -- "(1, 2)";
"(1, 1)" -- "(2, 2)";
"(1, 1)" -- "(0, 2)";
"(2, 1)" -- "(1, 2)";
}](../../_images/graphviz-4b6b663f0d6bcf333a8f12c9c543ec8a06e92dcd.png)
Figure: Bounded 3x3-grid in the diagonal representation.#
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.
![graph {
"(-1, -1)" [pos="-1.75,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 3)"]
"(0, -1)" [pos="0.0,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 3)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(1, -1)" [pos="1.75,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 3)"]
"(2, -1)" [pos="3.5,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 3)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(3, -1)" [pos="5.25,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 3)"]
"(4, -1)" [pos="7.0,-1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 3)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(-1, 0)" [pos="-1.75,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 0)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(0, 0)" [pos="0.0,0.0!" width=0.75 height=0.75 fixedsize=True]
"(1, 0)" [pos="1.75,0.0!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(2, 0)" [pos="3.5,0.0!" width=0.75 height=0.75 fixedsize=True]
"(3, 0)" [pos="5.25,0.0!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(4, 0)" [pos="7.0,0.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(-1, 1)" [pos="-1.75,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 1)"]
"(0, 1)" [pos="0.0,1.75!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(1, 1)" [pos="1.75,1.75!" width=0.75 height=0.75 fixedsize=True]
"(2, 1)" [pos="3.5,1.75!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(3, 1)" [pos="5.25,1.75!" width=0.75 height=0.75 fixedsize=True]
"(4, 1)" [pos="7.0,1.75!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 1)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(-1, 2)" [pos="-1.75,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 2)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(0, 2)" [pos="0.0,3.5!" width=0.75 height=0.75 fixedsize=True]
"(1, 2)" [pos="1.75,3.5!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(2, 2)" [pos="3.5,3.5!" width=0.75 height=0.75 fixedsize=True]
"(3, 2)" [pos="5.25,3.5!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(4, 2)" [pos="7.0,3.5!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 2)"]
"(-1, 3)" [pos="-1.75,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 3)"]
"(0, 3)" [pos="0.0,5.25!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(1, 3)" [pos="1.75,5.25!" width=0.75 height=0.75 fixedsize=True]
"(2, 3)" [pos="3.5,5.25!" width=0.75 height=0.75 fixedsize=True fontcolor="white" fillcolor="darkgray" style="filled"]
"(3, 3)" [pos="5.25,5.25!" width=0.75 height=0.75 fixedsize=True]
"(4, 3)" [pos="7.0,5.25!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 3)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(-1, 4)" [pos="-1.75,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 0)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(0, 4)" [pos="0.0,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(1, 4)" [pos="1.75,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(1, 0)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(2, 4)" [pos="3.5,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(2, 0)"]
"(3, 4)" [pos="5.25,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(3, 0)" fontcolor="white" fillcolor="darkgray" style="filled,dashed"]
"(4, 4)" [pos="7.0,7.0!" width=0.75 height=0.75 fixedsize=True style="dashed" label="(0, 0)"]
"(-1, -1)" -- "(0, 0)"[];
"(0, -1)" -- "(1, 0)"[ color="black" style="dashed"];
"(1, -1)" -- "(2, 0)"[];
"(1, -1)" -- "(0, 0)"[];
"(2, -1)" -- "(3, 0)"[ color="black" style="dashed"];
"(2, -1)" -- "(1, 0)"[ color="black" style="dashed"];
"(3, -1)" -- "(2, 0)"[];
"(4, -1)" -- "(3, 0)"[ color="black" style="dashed"];
"(-1, 0)" -- "(0, 1)"[ color="black" style="dashed"];
"(0, 0)" -- "(1, 1)"[];
"(0, 0)" -- "(-1, 1)"[];
"(1, 0)" -- "(2, 1)"[ color="black" style="dashed"];
"(1, 0)" -- "(0, 1)"[ color="black" style="dashed"];
"(2, 0)" -- "(3, 1)"[];
"(2, 0)" -- "(1, 1)"[];
"(3, 0)" -- "(4, 1)"[ color="black" style="dashed"];
"(3, 0)" -- "(2, 1)"[ color="black" style="dashed"];
"(4, 0)" -- "(3, 1)"[];
"(-1, 1)" -- "(0, 2)"[];
"(0, 1)" -- "(1, 2)"[ color="black" style="dashed"];
"(0, 1)" -- "(-1, 2)"[ color="black" style="dashed"];
"(1, 1)" -- "(2, 2)"[];
"(1, 1)" -- "(0, 2)"[];
"(2, 1)" -- "(3, 2)"[ color="black" style="dashed"];
"(2, 1)" -- "(1, 2)"[ color="black" style="dashed"];
"(3, 1)" -- "(4, 2)"[];
"(3, 1)" -- "(2, 2)"[];
"(4, 1)" -- "(3, 2)"[ color="black" style="dashed"];
"(-1, 2)" -- "(0, 3)"[ color="black" style="dashed"];
"(0, 2)" -- "(1, 3)"[];
"(0, 2)" -- "(-1, 3)"[];
"(1, 2)" -- "(2, 3)"[ color="black" style="dashed"];
"(1, 2)" -- "(0, 3)"[ color="black" style="dashed"];
"(2, 2)" -- "(3, 3)"[];
"(2, 2)" -- "(1, 3)"[];
"(3, 2)" -- "(4, 3)"[ color="black" style="dashed"];
"(3, 2)" -- "(2, 3)"[ color="black" style="dashed"];
"(4, 2)" -- "(3, 3)"[];
"(0, 3)" -- "(1, 4)"[ color="black" style="dashed"];
"(0, 3)" -- "(-1, 4)"[ color="black" style="dashed"];
"(1, 3)" -- "(2, 4)"[];
"(1, 3)" -- "(0, 4)"[];
"(2, 3)" -- "(3, 4)"[ color="black" style="dashed"];
"(2, 3)" -- "(1, 4)"[ color="black" style="dashed"];
"(3, 3)" -- "(4, 4)"[];
"(3, 3)" -- "(2, 4)"[];
}](../../_images/graphviz-f561fbead76d7d24663ae5240cbf5f139de43a9b.png)
Figure: 4x4-grid with cyclic boundary conditions.#
Methods#
All methods are inherited from
hiperwalk.IntegerLattice.