Keywords

1 Introduction

Programmable matter can be seen as modular robots (called modules or particles) able to fix to adjacent modules and send (receive) messages to (from) other modules fixed to the entity. Thus, the different modules form a geometric shape which is a network. Usually, a module can fix to another module using a finite number of ports (see Fig. 1 for an example of spherical modules). Also, the modules know the ports that are in contact with other modules and have a knowledge about the geographic position of their ports. Moreover, the ports are supposed to be homogeneously distributed along the surface of each module. Such assumptions imply that the way how the modules are on a plane can be modeled by a grid. In this paper, we only consider modules on a plane surface, i.e. two dimensional grids. In this context, the geometric amoebot model [6,7,8,9,10,11] aims to model the properties of a network for programmable matter.

Distributed algorithms aim to give a theoretical algorithmic framework in order to model the execution of an algorithm that runs on a network of computational elements that can cooperate in order to solve network problems. In distributed algorithm frameworks, it is often supposed that the different elements of the network do not have a unique identity, i.e., the network is anonymous. In anonymous networks, a natural question is how to perform a leader election, i.e., how to determine a singular element in an anonymous network. It is well known that for some network structures, the ring for example, there is no deterministic leader election algorithm [1].

In 1999, Mazurkiewicz [19] has presented a deterministic general algorithm to determine a leader (in the case it is possible to do so). In the situation where the elements have access to a random source, then it is also proven that no algorithm can correctly determine a leader in a ring with any probability \(\alpha >0\) [15]. Due to the assumption we make about the ports of the particles in the context of programmable matter (a particle knows the ports which are in contacts with other particles and knows the geographic position of its ports), the leader election problem becomes different than in the classical system. In particular, in the field of programmable matter, there exists a probabilistic algorithm that determine a leader (and in particular for a ring) with probability 1 [5].

Several projects aim to build programmable matter prototypes. One of such projects [20, 23], financed by the french National Agency for Research, aims to build cuboctahedral particles able to deform them-selves in order to move. This project can be split in two phases, one consists in manufacturing the hardware of prototype matters, the second consists in proposing algorithms for programmable matter. The final goal of this project is to sculpt a shape-memory polymer sheet with programmable matter. In the continuity of the algorithm phase of this project [20], we propose algorithms for the self-configuration, i.e., in order to create identifiers and spanning trees.

In the context of programmable matter [3, 4, 14, 18, 23, 24], it is supposed that a network can contain several millions of modules and that each module has possibly a nano-centimeter size. These two facts lead us to believe that even a \(O(\log (n))\)-space memory for each module, n being the number of modules, is not technically possible. Also, because of the large number of modules, it can be very challenging and time consuming to implement a unique identity to the modules when they are created. In this context, we suppose that the modules can not store a unique identity, i.e., that the network is anonymous. In this paper we propose deterministic O(1)-space memory algorithms to determine a leader in the network and to create k-local identifiers of the particles. A k-local identifier is a variable affected to each module of the network which is different for every two modules at distance at most k. Note that leader election [5, 13] plays a significant role in numerous problems of programmable matter.

Fig. 1.
figure 1

Five spherical particles forming a simple structure (circle: port of the particles).

Our contribution is the following: we introduce a leader election algorithm based on local computations and simple to implement. This algorithm works when the structure the particles form has no hole (see Sect. 3). Also, since the algorithm can be described as a sequence of local computations, its limits (message complexity, required memory-space, etc.) are easy to analyze. We present a distributed algorithm to construct a spanning tree in the context of programmable matter and, also, a distributed algorithm to re-organize the port numbers of the particles. Finally, we present an algorithm to assign a k-local identifier to each particle. In order to compute k-local identifiers, we suppose that we have done a leader election before. The k-local identifiers are determined using graph theoretical results about the coloring of the \(k^{\text {th}}\) power of the grids. An advantage of the given k-local identifiers is that they are really simple to update in case the particles move and, consequently, the structure that the particles form changes.

This paper is organized as follows: in Sect. 2, we present our algorithmic framework in the context of distributed algorithms for programmable network. In the third section, we present our leader election algorithm. Finally, in Sect. 4, we present our algorithm to assign k-local identifiers to the particles (using the colorings from Appendix D).

2 Notation, Definitions and Our Programmable Matter Algorithmic Framework

The geometric amoebot model [6,7,8,9,10,11] aims to model the computations that can occur in the context of programmable matter. In this paper, we use an algorithmic framework inspired by the geometric amoebot model. We assume that any structure the different particles can form is a subgraph of an infinite graph G. In this graph, V(G) represents all possible positions the particles can occupy and E(G) represents possible connections between particles. The set E(G) also represents the possible movements from a position to another position (for a particle). We suppose that two particles can bond each other, i.e., can communicate only in the case they are on adjacent positions. The two following paragraphs are dedicated to the notation and definitions we use for graphs.

For a graph G, we denote by V(G) the vertex set of G and by \(E(G)\subseteq V(G)\times V(G)\) the edge set of G. We denote by \(d_G(u,v)\), the usual distance between two vertices u and v in G. If we consider the distance in a subgraph H of G, the distance will be denoted by \(d_H(u,v)\). The diameter of G, denoted by \(\text {diam}(G)\), is \(\max (\{ d_{G}(u,v)|\ u,v\in V(G)\})\). The set \(N_G(u)=\{ v\in V(G) |\ uv \in E(G)\}\) is the set of neighbors of u. By \(\varDelta (G)\), we denote the maximum degree in G, i.e., the maximum cardinality of \(N_{G}(u)\), for \(u\in V(G)\). Finally, we denote by G[S], for \(S\subseteq V(G)\), the subgaph induced by the vertices from S and by \(G-S\) the subgraph of G induced by the vertices from \(V(G)\setminus S\).

Fig. 2.
figure 2

Subgraphs of the square (a), triangular (b) and king (c) grids, with the port numbers of two particles.

In the remaining part of this paper, the graphs considered will be the infinite square, triangular and king grids. We denote by \(\mathscr {S}\) the square grid, by \(\mathscr {T}\) the triangular grid and by \(\mathscr {K}\) the king grid. A subgraph of each of these three infinite graphs is represented in Fig. 2. Moreover, we suppose that these three grids are represented on a plane as in Fig. 2. For these grids, the considered vertex set is \(\{(i,j)|\ i,j \in \mathbb {Z}\}\) and the edge sets are the following:

  • \(E(\mathscr {S})=\{(i,j)(i\pm 1,j)|\ i,j \in \mathbb {Z} \}\cup \{(i,j)(i,j\pm 1)|\ i,j \in \mathbb {Z} \}\);

  • \(E(\mathscr {T})=E(\mathcal {S})\cup \{(i,j)(i+ 1,j-1)|\ i,j \in \mathbb {Z} \}\cup \{(i,j)(i-1,j+ 1)|\ i,j \in \mathbb {Z} \}\);

  • \(E(\mathscr {K})=E(\mathcal {T})\cup \{(i,j)(i+ 1,j+1)|\ i,j \in \mathbb {Z} \}\cup \{(i,j)(i-1,j- 1)|\ i,j \in \mathbb {Z} \}\).

We also remind the distance between two vertices (ij) and \((i',j')\) in the three different grids:

  • \(d_{\mathscr {S}}((i,j),(i',j'))=|i-i'|+|j-j'|\);

  • \(d_{\mathscr {T}}((i,j),(i',j'))= \left\{ \begin{array}{ll} \max (|i-i'|,|j-j'|), &{}\text {if } (i\,{\ge }\, i' \wedge j \,{\le }\, j' )\!\vee \! ( i\,{\le }\, i' \wedge j \,{\ge }\, j');\\ |i-i'|+|j-j'|, &{}\text {otherwise;} \end{array} \right. \)

  • \(d_{\mathscr {K}}((i,j),(i',j'))=\max (|i-i'|,|j-j'|)\).

Note that there is a way to draw the triangular grid in which each triangle is equilateral. However, we prefer to draw it as a subgraph of the king grid (see Fig. 2) in order to have illustrations for which the vertex set \(\{(i,j)|\ i,j \in \mathbb {Z}\}\) corresponds to the position of the vertices in the plane. In both representation, the notion of distance coincide but is easier to observe in our chosen representation. However, note that the representation of the triangular grid in which each triangle is equilateral corresponds to the optimal way to pack unit disks in the plane (the position of the vertices in this representation corresponds to the center of the unit disk and an edge represents a contact between two disks).

We also denote by \(i\pmod {p}\) or \(i_{\pmod p}\), depending on the context, the integer j such that \(j\equiv i \pmod {p}\) and \(0\le j <p\). The remaining part of this subsection is dedicated to our programmable matter algorithmic framework.

We give the following properties about the particles and vertices of the graph:

  • each particle occupies a single vertex and each vertex is occupied by at most one particle;

  • the subgraph induced by the occupied vertices is supposed to be connected.

The subgraph induced by the occupied vertices of V(G) is called the particle graph and is denoted by P. The vertex occupied by a particle p is denoted by s(p). For a particle p, \(N_G(p)=\{u\in V(G)|\ u\in N_G(s(p)) \}\). The ports of a particle are the endpoints of communication. Each particle has \(\varDelta (G)\) ports in a regular grid G (\(\varDelta (G)=4\) for \(G=\mathscr {S}\), \(\varDelta (G)=6\) for \(G=\mathscr {T}\) and \(\varDelta (G)=8\) for \(G=\mathscr {K}\)). The ports of a particle occupying a vertex u are represented by the edges incident with u. An edge between two vertices represents a possible communication between two particles \(p_{1}\) and \(p_{2}\) occupying these two vertices using each one a different port. A particle has the following properties:

  • each particle is anonymous, i.e., it does not have an identifier;

  • each particle has a collection of ports, each labeled by a different integer from \(\{0,\ldots ,\varDelta (G)-1\}\);

  • the port numbers are given as a function of the position of the edges on a plane representation of the grids (see Fig. 2);

  • each particle knows the labels of the ports that can communicate with particles from the neighborhood;

  • each particle knows the state of the neighbors.

In our algorithmic framework, we suppose that the particles have their ports labeled following the same clockwise order. Thus, consecutive port numbers correspond to consecutive edges around a vertex (as in the representation on the plane from Fig. 2). Note that the particles do not have the same notion of orientation, i.e., there is possibly not a unique label for ports that correspond to edges going in the same cardinal direction. In the presented algorithms, the state of a particle will contain a variable corresponding to the status of the particle in the leader election algorithm and the information regarding its parents and childs for a constructed spanning tree.

The proposed algorithms in our algorithmic framework are results of successive local computations [2, 21]. In particular, the first presented leader election algorithm from Sect. 3 can be described by a graph relabeling system [2] which is a local computation system. In this paper, the correct execution of the different algorithms is only guaranteed if the algorithms are ran in the order depicted in Fig. 3.

Fig. 3.
figure 3

An illustration of the algorithm dependency (arrow between algorithms/results: dependency of one algorithm to another algorithm/result).

We suppose the following:

  • each particle contains the same program and begins in the same state;

  • the computation process is represented by successive local computations;

  • no local computation occurs simultaneously on two particles at distance at most 2;

  • during a local computation, a particle can perform a bounded number of computations and can send messages to its neighbors;

  • a round is a sequence of successive local computations for which each particle does at least one local computation;

  • an algorithm finishes in k rounds if after any k successive rounds the algorithm is finished.

Note that the concept of rounds is used to bound the running time of the algorithms. In our algorithm framework we suppose that no two particles at distance at most 2 perform computations simultaneously in order to simplify the presentation of our results. However, this supposition can be removed by implementing, for example, a probabilistic leader election algorithm on the vertices at distance at most 2 of one of the two vertices, i.e., by computing a random value on the vertices at distance 2 and doing the local computation following the increasing order of the values. In order to compute the running time of an algorithm in case of a specific programmable matter prototype, the complexity of the algorithm should be computed using the required number of rounds and the required running time in order to avoid that two particles at distance at most 2 perform computations simultaneously.

3 Leader Election

In this section we present a new leader election algorithm. This algorithm is very easy to implement but requires that the particle graph has a specific structure. In this algorithm, the required memory space is constant, the messages have constant size, the required computation power of the particle has been optimized and the required number of rounds is less than 2n (n being the number of particles).

A hole in a subgraph \(G'\) of a graph G among the three grids is a subgraph H of G satisfying three properties:

  1. (i)

    V(H) is finite, H is connected and \(|V(H)|\ge 1\);

  2. (ii)

    \(V(H)\cap V(G')=\emptyset \);

  3. (iii)

    every vertex \(u\in V(H)\) satisfies \(N_G(u)\subseteq V(H)\cup V(G')\).

Less formally, a subgraph \(G'\) of one of the three grids contains a hole if there is a finite space only containing vertices from \(V(G)\setminus V(G')\) which are surrounded by vertices of \(G'\). A hole containing three vertices is illustrated in the left part of Fig. 4. We call \(G'\) hole-free, when \(G'\) has no holes.

If the particle graph P on G is hole-free, then every particle p which satisfies \(|N_G(p)\cap V(P))|<\varDelta (G)\) is at the geographical border of the shape of P. Moreover, we call the set of particles p which satisfy \(|N_G(p)\cap V(P))|<\varDelta (G)\) and such that the vertices \(N_G(p)- V(P)\) are not all in a hole of P, the border of P. The right part of Fig. 4 illustrates the border of P.

In addition, for a particle p occupying a vertex (ij) of the square grid, the four vertices \((i+1,j+1)\), \((i-1,j+1)\), \((i+1,j-1)\) and \((i-1,j-1)\) are the corners of p and the set of corners is denoted by C(p). The extended neighborhood of a particle p, denoted by \(M_G(p)\), is the set \(N_{G}(p)\) if G is the triangular grid or king grid or the set \(N_{G}(p)\cup C(p)\) if G is the square grid. Note that we define the extended neighborhood differently for the square grid in order to be able to present a generic algorithm (Algorithm 1) that works for all the three grids.

We give the following definition of S-contractible particle (see Fig. 5) that will be used in our leader election algorithm.

Fig. 4.
figure 4

A hole in P (on the left) and the border of P in the case P is hole-free (on the right; square: particle on the border of P).

Definition 1

Let G be an infinite grid among \(\mathscr {S}\), \(\mathscr {T}\) and \(\mathscr {K}\) and let \(S\subseteq V(P)\), for P the particle graph on G. A particle p is said to be S-contractible if it satisfies the following properties:

  1. (I)

    \(G[M_{G}(p)\cap S]\) is connected;

  2. (II)

    \(|N_{G}(p)\cap S|<\varDelta (G)\), i.e., there exists a neighbor of p in G which is not occupied by a particle from S.

Fig. 5.
figure 5

Two non S-contractible particles (at the center of the left and the middle drawing) and an S-contractible particle (at the center of the right drawing) in the triangular grid (square: particle in S; circle: particle not in S).

A particle p is an articulation of a connected subgraph \(G'\) of one of the three grids if \(G'-\{s(p)\}\) is not connected. Derakhshandeh et al. [8] proposed a randomized leader election algorithm in the geometric amoebot model in the case there is no particle which is an articulation. Our proposed leader election algorithm (Algorithm 1) works even if V(P) contains a particle p which is an articulation. However, in contrast with the leader election algorithm from Derakhshandeh et al. [8], Algorithm 1 does not work if P has holes. In the remaining part of this paper, Algorithm 1 is called the S-contraction algorithm.

Recently, Daymude et al. [5] have improved the algorithm from Derakhshandeh et al. [8] in order that it works when V(P) contains an articulation. However, it remains challenging to implement it.

Also, very recently, Di Luna et al. [13] have introduced a leader election algorithm called consumption algorithm. The consumption and the S-contraction algorithms both consist in successively removing the candidacy of the particles on the border of P. However, one can easily notice that, in our algorithm, we possibly remove the candidacy of particles having four or five neighbors (which is not considered in the consumption algorithm). Also, the consumption algorithm does not work on square and king grids and the considered theoretical frameworks for the two algorithms are different.

In the S-contraction algorithm (Algorithm 1), the particles can be in three different states: C (candidate), N (not elected) and L (leader). We suppose that every particle begins in the state C.

Let S be the particle in state C. Algorithm 1 consists in removing from S the particles which are both on the border of G[S] and not articulations of G[S]. An example of the execution of Algorithm 1 is illustrated by Fig. 6. Note that, depending on the order in which the local computations occur, the result of the execution of the algorithm could be different. For example, between the configuration of Fig. 6c and that of Fig. 6d, we suppose that the local computations occur in this order: first a local computation occurs for the bottom left particle, second it occurs for the upper left particle, third it occurs for the upper right particle and fourth it occurs for the last particle (we only consider the particles which are in state C).

figure a
Fig. 6.
figure 6

An example of the execution of S-contraction algorithm after one round (a), two rounds (b), three rounds (c) and after four rounds (d; circle: non S-contractible particle; square: S-contractible particle; triangle: particle in state N; pentagon: particle in state L; S being the set of particles in state C).

Theorem 1

Let S be the set of particles in state C and P be the particle graph on G. If P is hole-free, then at the end of the execution of the S-contraction algorithm, there will be exactly one particle in the state L.

In Appendix A, the proof of Theorem 1 is given. Also, a bound on the complexity of the S-contraction algorithm is given. In Appendix C, it is explained how to combine the S-contraction algorithm with a general leader election algorithm.

4 Assigning k-Local Identifiers to Particles

In this section, we combine the results from Sect. 3 and Appendix D in order to correctly compute a k-local identifier. In a first subsection, we describe a way to create a spanning tree of particles and a way to change the ports numbering of the different particles. In a second subsection, we describe how to compute k-local identifiers based on the coloring functions from Appendix D.

We suppose that Algorithms 2 and 3 are preceded by a leader election algorithm (which could be Algorithm 1). Then it follows that there is a single particle in a specific state (the leader) and all the remaining particles are in the same state (non elected).

4.1 Re-organizing the Particles

By \(N^{+}_{G}(u)\) we denote the set of port numbers which can communicate with particles occupying vertices from \(N_{G}(u)\). When there is a leader, we can easily compute a spanning tree using a distributed algorithm (see Appendix B). Now suppose that for each particle p, we have two set of ports \(\text {parent}(p)\) and \(\text {child}(p)\) which contains the port numbers of the particles in communication with its parent and with its children, respectively, in the spanning tree. In this way, the required memory in order to store where are the children and the parent of the particle in a spanning tree is constant (since the maximum degree is bounded in the considered grids).

In our proposed Algorithm 2, the goal is to change the way the port are numbered in order that every particle has its ports numbered by the same number going in the same cardinal direction in the different grids. This algorithm does not work if we do not have a leader among the different particles. The function \(r_{G}\) used in Algorithm 2 is defined, depending the choice of G, as follows: \(r_{\mathscr {S}}(i)=(i+2)\pmod {4}\), \(r_{\mathscr {T}}(i)=(i+3)\pmod {6}\) and \(r_{\mathscr {K}}(i)=(i+3)\pmod {6}\).

figure b
Fig. 7.
figure 7

One spanning tree of particles, a possible numbering of the ports of the particles before (a) and after the execution of Algorithm 2 (b) and the 4-identifier obtained by executing Algorithm 3 (c) in the square grid (square: leader; thick line: edge of the spanning tree; small number: port number of a particle; big number: 4-identifier of a particle).

The idea behind Algorithm 2 is to reproduce, in each particle, the way the ports are numbered in the leader particle. To achieve this goal, each particle p receives a message from its parent containing the port number of the parent connected to p and p renumbers its own ports in order that its port numbers are coherent with the sent number. Figures 7a and b illustrate the port numbers of particles before and after the execution of Algorithm 2.

4.2 The k-Local Identifiers

Now, we aim to give to each particle a variable id, called its k-local identifier, such that every two particles \(p_{1}\) and \(p_{2}\) with the same identifier satisfy \(d_{G}(s(p_{1}),s(p_{2}))>k\). If we suppose that the particles have not a memory of at least \(\log _{2}(n)\) bits, for \(n=|P|\), then it is not possible to record a unique variable for each particle. However, it is possible to have a k-local identifier in the three considered grids only using at most \(\log _{2}((k+1)^{2})\) bits where k is a parameter given by the user. Our proposed Algorithm 3 presents an optimal way (in term of memory) to compute k-local identifiers. We suppose that the port renumbering algorithm (Algorithm 2) has been done before executing Algorithm 3.

figure c

Algorithm 3 consists in assigning a variable which corresponds to a color in a coloring of the \(k^{\text {th}}\) power on the grid. More precisely, the function \(f_G^k\) consists in assigning a color depending the Cartesian coordinate of the vertices. Since the colors are given following a pattern, the Cartesian coordinate can be stored relatively to the size of the patterns. In Algorithm 3, the leader affects to itself the color 0 and following the direction where the messages are transmitted, the particles reproduce the coloring patterns given in Appendix D. The functions \(f^k_G\) and \(I^k_G\), \(J^k_G\), used in Algorithm 3 are defined, depending on the choice of G, as follows: \(f^k_{\mathscr {S}}(i,j)= (i+kj) \pmod {m_{k} }\), \(f^k_{\mathscr {K}}(i,j)= i_{\pmod {k+1}} +(k+1)j_{\pmod {k+1}}\) and \( f^k_{\mathscr {T}}(i,j)= (i_{\pmod {3(k+1)/2}}+j(3(k+1)/2)+ \lfloor 2 j/(k+1) \rfloor (k+1)/2)) \pmod {m'_{k}}\) if k is odd or \(f^k_{\mathscr {T}}(i,j)= (i+(3k/2+1) j) \pmod {m'_{k}}\) otherwise; \(I_{G}^{k}(i,a)=i\) if \((a=1;3\wedge G\cong \mathscr {S})\vee (a=1;4\wedge G\cong \mathscr {T})\vee (a=2;6\wedge G\cong \mathscr {K})\), \(I_{\mathscr {S}}^{k}(i,a)= i+1 \pmod {\lceil (k+1)^2/2 \rceil }\) if \(a=0\), \(I_{\mathscr {S}}^{k}(i,a)= i-1 \pmod {\lceil (k+1)^2/2 \rceil }\) if \(a=2\), \(I_{\mathscr {T}}^{k}(i,a)= i+1 \pmod {\lceil 3(k+1)^2/4 \rceil }\) if \(a=0;5\), \(I_{\mathscr {T}}^{k}(i,a)= i-1 \pmod {\lceil 3(k+1)^2/4 \rceil }\) if \(a=2;3\), \(I_{\mathscr {K}}^{k}(i,a)= i+1 \pmod {k+1}\) if \(a=0;1;7\) and \(I_{\mathscr {K}}^{k}(i,a)= i-1 \pmod {k+1}\) if \(a=3;4;5\); \(J_{G}^{k}(j,a)=i\) if \((a=0;2\wedge G\cong \mathscr {S})\vee (a=0;6\wedge G\cong \mathscr {T}) \vee (a=0;4 \wedge G\cong \mathscr {K})\), \(J_{\mathscr {S}}^{k}(j,a)= j+1 \pmod {\lceil (k+1)^2/2 \rceil }\) if \(a=1\), \(J_{\mathscr {S}}^{k}(j,a)= i-1 \pmod {\lceil (k+1)^2/2 \rceil }\) if \(a=3\), \(J_{\mathscr {T}}^{k}(j,a)= i+1 \pmod {\lceil 3(k+1)^2/4 \rceil }\) if \(a=1;2\), \(J_{\mathscr {T}}^{k}(j,a)= i-1 \pmod {\lceil 3(k+1)^2/4 \rceil }\) if \(a=4;5\), \(J_{\mathscr {K}}^{k}(j,a)= i+1 \pmod {k+1}\) if \(a=1;2;3\) and \(J_{\mathscr {K}}^{k}(j,a)= i-1 \pmod {k+1}\) if \(a=5;6;7\). Note that the functions \(I^k_G\) and \(J^k_G\) are used to determine the Cartesian coordinate of a particle using the Cartesian coordinate of a neighbor and the port number of this neighbor.

Since the values of \(f_{G}^{k}(i,j)\) is bounded by \(3(k+1)^2/4\), if G is isomorphic to one of the three grids, the size of the messages will not exceed \(\log _2(3(k+1)^2/4)\). As for Algorithm 2, the number of sent messages is \(|V(P)|-1\). Figure 7c illustrates the obtained 4-identifiers after the execution of Algorithm 3.

Since the particles can move during the execution of an algorithm, the k-local identifiers may become not valid anymore ( i.e., there may be two particles \(p_1\) and \(p_2\) with the same k-local identifier and with \(d_G(s(p_1),s(p_2))\le k\)) if the structure of the particle graph P on G changes. It is possible to keep a valid k-local identifier in case a particle moves in a direction of a port a by setting \(id=f^k_{G}(I^{k}_{G}(i,r_{G}(a)),J^{k}_{G}(j,r_{G}(a)))\) as the new k-local identifier. It corresponds to update the variable id which corresponds to a color in a coloring of the \(k^{\text {th}}\) power on the grid in function of the new position of the particle. Also, in the case a particle do \(\ell \) movements, by storing the successive directions of movement of the particle during these \(\ell \) movements, it is also possible to update the value of the k-local identifier in order that it remains valid.

Note that for both Algorithms 2 and 3 finish after at most h rounds, h being the height of the spanning tree. Also the number of sent messages in both Algorithms 2 and 3 is \(|V(G)|-1\) (the number of edges in a spanning tree).

5 Conclusion

In this paper, we have presented a new leader election algorithm based on local computation. We have also presented an algorithm which affects a different variable for every two particles \(p_{1}\) and \(p_{2}\) at distance at most k. All the presented algorithms only require a O(1)-space memory. This complexity makes it possible to use our algorithms for programmable matter. Moreover, in case of movements of particles, there is no need of communication in order to update the k-local identifiers.

As future work, it would be interesting to determine a more general deterministic leader election algorithm in our algorithmic framework that can take into account fault tolerance. Also, it would be interesting to extend the presented results to 3D grids. Another interesting question could be to use our results to clustering the set of particles in several sets which induce subgraphs of small diameter.