Abstract

We propose a finite automaton based algorithm for identification of infinite clusters in a 2D rectangular lattice with cells. The algorithm counts infinite clusters and finds one path per infinite cluster in a single pass of the finite automaton. The finite automaton is minimal according to the number of states among all the automata that perform such task. The correctness and efficiency of the algorithm are demonstrated on a planar percolation problem. The algorithm has a computational complexity of and could be appropriate for efficient data flow implementation.

1. Introduction

After the publication of Shannon’s paper in 1951 [1], many scientists considered the behavior of systems of finite automata (FAs) in labyrinths, for example, in connected sets of cells of a grid or lattice. An overview of the obtained results is given in [2, 3]. Some problems of finite automaton (FA) traversing labyrinths can be found in [4, 5]. Many results indicate a limited power of FA. But, by introducing a collective of FAs, it was proved that there exists a collective of two FAs which can traverse all planar mosaic finite labyrinths [6]. Also, in [7, 8], the problem of FA recognition of some infinite classes of labyrinths (e.g., digits and letters) is studied.

Recognizing and labeling connected regions in binary images are important problems in image processing, machine vision, porous matter analysis, and many other fields of science. Studying site and bond percolation on any lattice is an important problem in computational physics [912]. Some algorithms from these studies are presented in [1318]. In [1921], polymerizing systems are presented, with branched or cross-linked polymers, which may go through distinct gelation transitions; a formed gel is seen as a two-dimensional lattice-percolation cluster and the authors use a “hull-generating walk” (HGW) algorithm.

The similarity between the papers [1921] and the present paper consists in the fact that here we use a similar algorithm (in fact, HGW algorithm and the algorithm from our paper are in the class of the so-called “maze solving algorithms” [22]). But in contrast to papers [1921], where HGW algorithm is used for generating perimeters of clusters in a 2D random binary grid, we use our algorithm for identifying and counting infinite clusters in such grid. This is a new, purely mathematical approach, in terms of the theory of finite automata, to the problem considered in our paper. It consists in the construction of a minimal finite automaton (FA) which can traverse the border of any cluster on any 2D binary grid and always stops in the planar site percolation model.

The planar site percolation model is represented by a 2D grid of square cells and each cell can exist in two different states, white or black. Any cell is colored black with probability and white with probability . These probabilities are independent for each cell. We use open boundary conditions with boundary cells on the top and on the bottom of the grid in different states, blue and red, respectively. Cells on the left and right boundaries are white.

We construct an initial FA which can traverse the border of any cluster in every planar 2D grid in accordance with the left-hand rule (which is also a kind of a HGW algorithm). The automaton can be launched from any cell of a grid. In any moment, the input of is information about von Neumann neighborhood of the present cell given in the form of a 5-tuple representing the state of the central cell and the states of its four neighbors. In the next moment, depending on its present state and its input, the FA proceeds from the present cell in one of the directions, defined by the output symbols , , , or (denoting the corresponding directions, east, north, west, or south, resp.), and moves into a corresponding neighbor cell or stays at the same place if output symbol is 0 (which means “no move”) and passes into a new state. On the bases of this automaton, we give an algorithm which can be used for finding/identifying and counting infinite clusters in the given grid. Such algorithm is simple to implement and does not need extra memory or stacks. The time complexity of the algorithm is linear and not larger than the time complexity of already existing algorithms. The FA has only four states, including the initial state. We have proved that this is the minimal FA according to the number of states.

The paper is organized as follows. In Section 2, general grid-related definitions and definitions of the FA and its properties are given. In Section 3, the FA-based algorithm for counting connected paths is described and its complexity is proved. The main conclusions and results are summarized in Section 4.

2. Definition

2.1. General Definitions

The planar site percolation model (see Figure 1) is represented by a two-dimensional lattice network (grid) of unit squares (cells) whose centers are in the integer lattice with cells, . The cell position is determined by its center. Each cell can exist in two different states, 0 or 1, where state 0 is usually called “white” and state 1 is usually called “black.” The boundary cells of the simulated grid are in a fixed state, which remains constant throughout the simulation. The boundary cells on the bottom edge of the grid are in state 2, which is called “red,” and the boundary cells on the top edge of the grid are in state 3, which is called “blue.” The boundary cells on the left and right edge of the grid are white. State 4, which is called “orange,” is used for the notation of labeled cells in the grid.

Two different cells and from a grid are adjacent (weakly adjacent) if (). Two black (white) cells and are connected if there exists a sequence of black (white) cells , , such that each pair and are adjacent; such sequence is called a path. Blue-red path is a path whose one end is adjacent to a blue and the other to a red cell. A set of cells is connected if any two cells from the set are connected. A maximum connected set of black cells is called a cluster. The infinite cluster is a cluster that contains a blue-red path.

Similarly, black (white) cells and are weakly connected if there exists a sequence of black (white) cells , , such that each pair and are weakly adjacent. A maximum weakly connected set of white cells is called a hole.

2.2. Definition of the Initial Finite Automaton

Let , , , and be basic Euclidean vectors. Denote by the set . We use the notations , , , and . For a cell in a grid, its neighbors are cells , , , and . Hence, the von Neumann neighborhood is used in this paper (see Figure 2(a)).

Let be the state of the cell and .

Let be a cyclic permutation. For , and , denote by the element , where , where is the set of natural numbers.

By a finite automaton (FA) , we mean a quintuple , where the finite nonempty sets , , and are the input alphabet, the set of states, and the output alphabet of the automaton, respectively; is its output function; and is its state-transition function. If we mark a state as an initial state of , we get an initial automaton (in other words, is a Mealy machine).

Further, we consider the initial FA supposing that , , and . The starting cell of this automaton in a grid is always the lowest right corner cell of the grid. If the output symbol of is , we say that FA proceeds in the direction . If the output symbol is , the FA stops. This way, FA simulates movements (goes around, traverses) through a grid.

An input symbol represents the state of a cell and the states of its von Neumann neighbors, consistent with the enumeration in Figure 2(b). For the input symbol , by we denote the central cell.

The FA starts in state and uses states from set until it finds a boundary cell on the top of the grid (blue one). In this moment, the algorithm increments the counter of infinite clusters and starts labeling cells with an orange color. The algorithm labels a path, until the FA finds a boundary cell on the bottom edge of the grid (red one). After finding the lowest left end of an infinite cluster, the FA proceeds in the (west) direction and it is on a white cell and in state . After that, the algorithm breaks labeling and starts with new counting of infinite clusters and the FA repeats the process of traversing. The algorithm stops when the output of the FA is 0.

The functions and are defined in the following way. Let be a cell and let , , and . Then, for and input , the functions and are defined by and , where (see Figure 3) except for some “starting,” “ending,” or “changing” parts which are given by the following:(i)If , then(a)for or , and ;(b)for , and ;(c)for and , and .(ii)If , then, for , and .

Notice two properties of the FA :(1)In the initial state, the FA is on the cell that has red cell on the south (). The FA goes in the west direction until it finds the black cell with black cell on the north. If it cannot find it, the FA stops.(2)The meaning of the fact that the FA is on the cell and is in the state is that the FA has arrived on the cell from the direction , (see Figure 3).

The initial automaton and the initial planar site percolation model , where is the cell on the lowest right corner of a grid , create the sequence , where represents the neighborhood of the cell (), , , , .

Let .

Properties of the FA , which will be crucial for the algorithm, are defined by the following theorem.

Theorem 1. A blue-red path exists in the planar site percolation model if and only if there exists a cell such that the sequence , , of the cells in the sequence creates a blue-red path.

Choosing the cyclic permutation in the definition of the FA , we define an orientation. Namely, if the FA comes on the cell from direction , then the right, ahead, left, and behind cell (from the cell ) are , , , and , respectively.

Let be a blue-red path in the grid and be the infinite cluster that encloses path . Let be the lowest right cell in the cluster and be the subset of the infinite hole which is on the right side of the cluster. Right boundary of the cluster , is weakly adjacent to some cell from , is connected and encloses a blue-red path. Notice that .

It is not hard to see that the FA implements “left-hand-on-wall” algorithm ([23]). Starting from the cell , the FA traverses , and the subsequence , for some , of the sequence creates a blue-red path.

If there is not a connected path between red and blue cells in the grid , then, for all cells , the sequence , , will not contain a cell with blue north neighbor. The grid is finite and the FA will stop on the lowest left cell of the grid.

Theorem 2. According to the number of states, the FA is the minimal initial finite automaton.

In the example from Figure 1(b), notice cell . It is in the infinite cluster and it is weakly adjacent by the right infinite hole. Traversing the cluster by the left-hand rule, the FA is four times in the cell (from south, east, north, and west sides). All the visits must be done in different automaton states (input is the same). Otherwise, the FA makes a cycle. Hence, for traversing a border of a cluster, it is necessary to have 4 states.

3. The FA Traversing Algorithm and Its Time Complexity

The algorithm for identification of infinite clusters is based on the FA . To ensure appropriate counting of infinite clusters, the algorithm uses three global variables: count, labeling, and countingCluster. The count counts the number of infinite clusters, labeling is an indicator for labeling cells, and countingCluster is an indicator for the counting of the infinite cluster.

Let be an initial grid, where is a grid and is its lowest right corner. Let be the initial state of the FA . The algorithm is presented as Algorithm 1.

Data: Initial grid
Result: is number of infinite clusters and labeled blue-red paths
;
;
;
Labeling = false;
countingCluster = true;
= neighbor of the ;
while   <> 0  do
if  labeling    then
  label ;
end
if  north neighbor of  is blue  cell  and  countingCluster
 then
   ;
   labeling  ;
   countingCluster = false;
end
if  ,   neighbor of  currentCell  is  red,  white, respectly, and
    then
   labeling = false;
   countingCluster = true;
end
;
;
= neighbor of the  ;
end

The FA starts in state and uses states from set until it finds a boundary cell on the top of the grid (blue one). In this moment, the algorithm increments the counter and sets the indicator labeling on true, and the variable countingCluster is set on false. The algorithm labels a path until the FA finds the lowest left cell on the bottom edge of the cluster. After finding the lowest left end of an infinite cluster, the FA goes in state and sets labeling on false and the countingCluster is set on true. After that, the algorithm repeats the process of traversing.

The algorithm stops when the FA outputs 0.

Lemma 3. The algorithm has linear time complexity.

The FA uses von Neumann neighborhood with four neighbors for each grid cell. The automaton is never on the same cell in the same state. Therefore, the FA cannot be more than four times in a particular cell during the execution of the algorithm. The complexity of the algorithm is therefore , where is the number of grid cells.

The algorithm was simulated in NetLogo programming environment. The algorithm was extensively evaluated on various test cases for different sizes of grid and initial density of black cells in initial configuration. In Figure 4, the last states on the initial grids from Figure 1 are shown. In Figure 5, a grid of dimension with probability 0.62, for a black cell, is shown with two infinity clusters, after termination of the FA algorithm. By increasing the probability of black cells, infinite clusters more often appear, as predicted also by the percolation theory. Also, the results of the algorithm are in accordance with site percolation thresholds in the square lattice ([16, 24]).

4. Conclusions

A FA-based algorithm for identification of connected paths between top and bottom boundary cells in an arbitrary square grid is proposed. The constructed FA is minimal according to the number of states. The algorithm is based on four essential states: , , , and . Using these states as FA input and assuming von Neumann neighborhood of the grid cells, we can traverse the boundaries of clusters. Because the FA is independent, there is a possibility of putting more than one automaton in different initial cells. Such a parallel approach could further speed up the proposed algorithm. Combining the property of FA, which is never on the same cell in the same state, with labeling, there is a possibility of using the FA in the detection of articulation cells ([25]). Finally, further investigation can be focused on the necessary extensions of the algorithm for 3D grids.

Conflicts of Interest

The authors declare that there are no conflicts of interest regarding the publication of this paper.

Acknowledgments

This work is supported by the Program of Science-Technological Cooperation between governments of Montenegro and Serbia, 2016–2018.