Shape Formation by Programmable Particles
Giuseppe A. Di Luna, Paola Flocchini, Nicola Santoro, Giovanni Viglietta, Yukiko Yamauchi
SShape Formation by Programmable Particles
Giuseppe A. Di Luna ∗ Paola Flocchini ∗ Nicola Santoro † Giovanni Viglietta ∗ Yukiko Yamauchi ‡ Abstract
Shape formation (or pattern formation ) is a basic distributed prob-lem for systems of computational mobile entities. Intensively studiedfor systems of autonomous mobile robots, it has recently been investi-gated in the realm of programmable matter , where entities are assumedto be small and with severely limited capabilities. Namely, it has beenstudied in the geometric
Amoebot model, where the anonymous enti-ties, called particles , operate on a hexagonal tessellation of the planeand have limited computational power (they have constant memory),strictly local interaction and communication capabilities (only withparticles in neighboring nodes of the grid), and limited motorial capa-bilities (from a grid node to an empty neighboring node); their acti-vation is controlled by an adversarial scheduler. Recent investigationshave shown how, starting from a well-structured configuration in whichthe particles form a (not necessarily complete) triangle, the particlescan form a large class of shapes. This result has been established underseveral assumptions: agreement on the clockwise direction (i.e., chiral-ity ), a sequential activation schedule, and randomization (i.e., particlescan flip coins to elect a leader).In this paper we obtain several results that, among other things,provide a characterization of which shapes can be formed determin-istically starting from any simply connected initial configuration of n particles. The characterization is constructive: we provide a univer-sal shape formation algorithm that, for each feasible pair of shapes( S , S F ), allows the particles to form the final shape S F (given in in-put) starting from the initial shape S , unknown to the particles. Thefinal configuration will be an appropriate scaled-up copy of S F depend-ing on n . ∗ University of Ottawa, Canada. E-mails: { gdiluna, paola.flocchini,gvigliet } @uottawa.ca . † Carleton University, Canada. E-mail: [email protected] . ‡ Kyushu University, Japan. E-mail: [email protected] . a r X i v : . [ c s . D C ] S e p f randomization is allowed, then any input shape can be formedfrom any initial (simply connected) shape by our algorithm, providedthat there are enough particles.Our algorithm works without chirality, proving that chirality iscomputationally irrelevant for shape formation. Furthermore, it worksunder a strong adversarial scheduler, not necessarily sequential.We also consider the complexity of shape formation both in termsof the number of rounds and the total number of moves performedby the particles executing a universal shape formation algorithm. Weprove that our solution has a complexity of O ( n ) rounds and moves:this number of moves is also asymptotically optimal. The term programmable matter , introduced by Toffoli and Margolus over aquarter century ago [26], is used to denote matter that has the ability tochange its physical properties (e.g., shape, color, density, etc.) in a pro-grammable fashion, based upon user input or autonomous sensing. Oftenprogrammable matter is envisioned as a very large number of very smalllocally interacting computational particles, programmed to collectively per-form a complex task. Such particles could have applications in a varietyof important situations: they could be employed to create smart materi-als, used for autonomous monitoring and repair, be instrumental in minimalinvasive surgery, etc.As recent advances in microfabrication and cellular engineering renderthe production of such particles increasingly possible, there has been a con-vergence of theoretical research interests on programmable matter from someareas of computer science, especially robotics, sensor networks, molecularself-assembly, and distributed computing. Several theoretical models of pro-grammable matter have been proposed, ranging from DNA self-assemblysystems (e.g., [8, 17, 18, 20, 21, 24]) to shape-changing synthetic moleculesand cells (e.g., [28]), from metamorphic robots (e.g., [4, 27]) to nature-inspired synthetic insects and micro-organisms (e.g., [12, 13, 16]), each modelassigning special capabilities and constraints to the entities and focusing onspecific applications.Of particular interest, from the distributed computing viewpoint, is the geometric Amoebot model of programmable matter [3, 6, 7, 9, 10, 11, 12]. Inthis model, introduced in [12] and so called because inspired by the behav-ior of amoeba, programmable matter is viewed as a swarm of decentralized2utonomous self-organizing entities, operating on a hexagonal tessellationof the plane. These entities, called particles , are constrained by having sim-ple computational capabilities (they are finite-state machines), strictly localinteraction and communication capabilities (only with particles located inneighboring nodes of the hexagonal grid), and limited motorial capabilities(from a grid node to an empty neighboring node); furthermore, their acti-vation is controlled by an adversarial (but fair) synchronous scheduler. Afeature of the Amoebot model is that particles can be in two modes: con-tracted and expanded . When contracted, a particle occupies only one node,while when expanded the particle occupies two neighboring nodes; it is in-deed this ability of a particle to expand and contract that allows it to moveon the grid. The Amoebot model has been investigated to understand thecomputational power of such simple entities; the focus has been on applica-tions such as coating [6, 11], gathering [3], and shape formation [9, 10, 12].The latter is also the topic of our investigation.The shape formation problem is prototypical for systems of self-organizingentities. This problem, called pattern formation in swarm robotics, requiresthe entities to move in the spatial universe they inhabit in such a way that,within finite time, their positions form the geometric shape given in in-put (modulo translation, rotation, scaling, and reflection), and no furtherchanges occur. Indeed, this problem has been intensively studied especiallyin active systems such as autonomous mobile robots (e.g., [1, 5, 14, 15, 25,29]) and modular robotic systems (e.g., [2, 19, 22]).In the Amoebots model, shape formation has been investigated in [9, 10,12], taking into account that, due to the ability of particles to expand, itmight be possible to form shapes whose size is larger than the number ofparticles.The pioneering study of [9] on shape formation in the geometric Amoebotmodel showed how particles can build simple shapes, such as a hexagon or atriangle. Subsequent investigations have recently shown how, starting froma well-structured configuration in which the particles form a (not necessarilycomplete) triangle, they can form a larger class of shapes [10]. This resulthas been established under several assumptions: availability of chirality (i.e.,a globally consistent circular orientation of the plane shared by all particles),a sequential activation schedule (i.e., at each time unit the scheduler selectsonly one particle which will interact with its neighbors and possibly move),and, more important, randomization (i.e., particles can flip coins to elect aleader).These results and assumptions immediately and naturally open funda-mental research questions, including: Are other shapes formable? What3an be done deterministically? Is chirality necessary? as well as some lesscrucial but nevertheless interesting questions, such as: What happens if thescheduler is not sequential? What if the initial configuration is not wellstructured?In this paper, motivated and stimulated by these questions, we continuethe investigation on shape formation in the geometric Amoebot model andprovide some definitive answers.
We establish several results that, among other things, provide a constructivecharacterization of which shapes S F can be formed deterministically startingfrom an unknown simply connected initial configuration S of n particles.As in [10], we assume that the size of the description of S F is constantwith respect to the size of the system, so that it can be encoded by eachparticle as part of its internal memory. Such a description is available to allthe particles at the beginning of the execution, and we call it their “input”.The particles will form a final configuration that is an appropriate scaling,translation, rotation, and perhaps reflection of the input shape S F . Sinceall particles of S must be used to construct S F , the scale λ of the finalconfiguration depends on n : we stress that λ is unknown to particles, andthey must determine it autonomously.Given two shapes S and S F , we say that the pair ( S , S F ) is feasible ifthere exists a deterministic algorithm that, in every execution and regardlessof the activation schedule, allows the particles to form S F starting from S and no longer move.On the contrary, a pair ( S , S F ) of shapes is unfeasible when the symme-try of the initial configuration S prevents the formation of the final shape S F . In Section 2, we formalize the notion of unbreakable symmetry of shapesembedded in triangular grids, and in Theorem 1 we show that starting froman unbreakable k -symmetric configuration only unbreakable k -symmetricshapes can be formed.Interestingly, for all the feasible pairs, we provide a universal shape for-mation algorithm in Section 3. This algorithm does not need any informationon S , except that it is simply connected.These results concern the deterministic formation of shapes. As a mat-ter of fact, our algorithm uses a deterministic leader election algorithm asa subroutine (Sections 3.1–3.4). If the initial shape S is unbreakably k -symmetric, such an algorithm may elect as many as k neighboring leaderparticles, where k ∈ { , , } . It is trivial to see that, with a constant number4f coin tosses, we can elect a unique leader among these k with arbitrarilyhigh probability. Thus, our results immediately imply the existence of a ran-domized universal shape formation algorithm for any pair of shapes ( S , S F )where S is simply connected. This extends the result of [10], which assumesthe initial configuration to be a (possibly incomplete) triangle.Additionally, our notion of shape generalizes the one used in [10], wherea shape is only a collection of triangles, while we include also 1-dimensionalsegments as its constituting elements. In Section 4, we are going to showhow the concept of shape can be further generalized to essentially includeanything that is Turing-computable.Our algorithm works under a stronger adversarial scheduler that acti-vates an arbitrary number of particles at each stage (i.e., not necessarilyjust one, like the sequential scheduler), and with a slightly less demandingcommunication system.Moreover, in our algorithm no chirality is assumed: indeed, unlike in [10],different particles may have different handedness. On the contrary, in theexamples of unfeasibility given in Theorem 1, all particles have the samehandedness. Together, these two facts allows us to conclude that chiralityis computationally irrelevant for shape formation.Finally, we analyze the complexity of shape formation in terms of thetotal number of moves (i.e., contractions and expansions) performed by n particles executing a universal shape formation algorithm, as well as in termsof the total number of rounds (i.e., spans of time in which each particle isactivated at least once, also called epochs ) taken by the particles. We firstprove that any universal shape formation algorithm requires Ω( n ) movesin the worst case (Theorem 2). We then show that the total number ofmoves of our algorithm is O ( n ) in the worst case (Theorem 9): that is, oursolution is asymptotically optimal. The time complexity of our algorithmis also O ( n ) rounds, and optimizing it is left as an open problem (we areable to reduce it to O ( n log n ), and we have a lower bound of Ω( n ): seeSection 4).Obviously, we must assume the size of S (i.e., the number of particlesthat constitute it) to be sufficiently large with respect to the input descrip-tion of the final shape S F . More precisely, denoting the size of S F as m , weassume n to be lower-bounded by a cubic function of m (Theorem 8). Asimilar restriction is also found in [10].5 Model and Preliminaries
Particles. A particle is a conceptual model for a computational entity thatlives in an abstract graph G . A particle may occupy either one vertex of G ortwo adjacent vertices: in the first case, the particle is said to be contracted ;otherwise, it is expanded . Movement.
A particle may move through G by performing successive expansion and contraction operations. Say v and u are two adjacent verticesof G , and a contracted particle p occupies v . Then, p can expand toward u , thus occupying both v and u . When such an expansion occurs, u is saidto be the head of p , and v is its tail . From this position, p can contractagain into its head vertex u . As a general rule, when a particle expandstoward an adjacent vertex, this vertex is by definition the particle’s head.An expanded particle cannot expand again unless it contracts first, anda contraction always brings a particle to occupy its head vertex. When aparticle is contracted, the vertex it occupies is also called the particle’s head;a contracted particle has no tail vertex.If a graph contains several particles, none of its vertices can ever beoccupied by more than one particle at the same time. Accordingly, a con-tracted particle cannot expand toward a vertex that is already occupied byanother particle. If two or more particles attempt to expand toward thesame (unoccupied) vertex at the same time, only one of them succeeds,chosen arbitrarily by an adversarial scheduler (see below). Scheduler.
In our model, time is “discrete”, i.e., it is an infinite orderedsequence of instants, called stages , starting with stage 0, and proceeding withstage 1, stage 2, etc. Say that in the graph G there is a set P of particles,which we call a system . At each stage, some particles of P are active , and theothers are inactive . We may think of the activation of a particle as an act ofan adversarial scheduler , which arbitrarily and unpredictably decides whichparticles are active at each stage. The only restriction on the scheduler is abland fairness constraint, requiring that each particle be active for infinitelymany stages in total. That is, the scheduler can never keep a particle inactiveforever. Sensing and reacting.
When a particle is activated for a certain stage,it “looks” at the vertices of G adjacent to its head, discovering if they arecurrently unoccupied, or if they are head or tail vertices of some particle.If the particle is expanded, it also detects which of these vertices is its The model in [10] allows a special type of coordinated move called “handover”. Sincewe will not need our particles to perform this type of move, we omit it from our model. anonymous ).Each active particle may then decide to either expand (if it is contracted),contract (if it is expanded), or stay still for that stage. All these operationsare performed by all active particles simultaneously, and take exactly onestage. So, when the next stage starts, a new set of active particles is selected,which observe their surroundings and move, and so on.
Memory.
Each particle has an internal state that it can modify every timeit is activated. The internal state of any particle must be picked from afinite set Q ; i.e., all particles have “finite memory”. Communication.
Two particles can also communicate by sending eachother messages taken from a finite set M , provided that their heads areadjacent vertices of G . Specifically, when a particle p is activated and seesthe head of particle p (cid:48) , it may send a message m to it along the orientededge ( u, v ) connecting their heads. Then, the next time p (cid:48) is activated, itwill receive and read the message m . That is, unless some particle (perhapsagain p ) sends another message m (cid:48) on the same oriented edge ( u, v ) before p (cid:48) is activated, in which case m is “overwritten” by m (cid:48) , unbeknownst to p (cid:48) andthe particle that sent m (cid:48) . In other words, upon activation, a particle willalways receive the most recent message sent to it from each of the verticesadjacent to its head, while older unread messages are lost. If p (cid:48) expandswhile p is sending a message to it (i.e., in the same stage), the message islost and is not received by any particle. When a message has been read bya particle, it is immediately destroyed. Triangular network.
In this paper, as in [10], we assume the graph G to be the dual graph of a regular hexagonal tiling of the Euclidean plane.So, in the following, G will be an infinite regular triangular grid. We alsodenote by G D a fixed “canonical” drawing of the abstract graph G in whicheach face is embedded in the Cartesian plane as an equilateral triangle ofunit side length with one edge parallel to the x axis. Port labeling.
Note that each vertex of G has degree 6. With each particle p and each vertex v is associated a port labeling (cid:96) ( p, v ), which is a numberingof the edges incident to v , from 0 to 5, in clockwise or counterclockwiseorder with respect to the drawing G D . For a fixed particle p , port labels areassumed to be invariant under the automorphisms of G given by translationsof its drawing G D . As a consequence, if the port labeling (cid:96) ( p, v ) assigns thelabel i to the edge ( v, u ), then the port labeling (cid:96) ( p, u ) assigns the label The model in [10] has a more demanding communication system, which assumes eachparticle to have some local shared memory that all neighboring particles can read andmodify. i + 3) mod 6 to the edge ( u, v ). However, different particles may havedifferent port labels for the same vertex v , depending on what edge (incidentto v ) is assigned the label 0, and whether the labels proceed in clockwiseor counterclockwise order around v . If they proceed in clockwise order,the particle is said to be right-handed ; otherwise, it is left-handed . So, the handedness of a particle does not change as the particle moves, but differentparticles may have different handedness. Stage structure.
Summarizing, an active particle p performs the followingactions during a single stage: it reads its current internal state q , it looksat the contents c , . . . c of the vertices adjacent to its head (each c i hasfour possible values describing the vertex corresponding to port i accordingto p ’s labeling: it may denote an unoccupied vertex, p ’s own tail, the headof another particle, or the tail of another particle), it reads the pendingmessages m , . . . , m coming from the vertices adjacent to its head (again,indices correspond to port labels, and some m i ’s may be the empty string ε ,denoting the absence of a message), it changes its internal state to q (cid:48) , it sendsmessages m (cid:48) , . . . , m (cid:48) to the vertices adjacent to its head, which possiblyreplace older unread messages (if m (cid:48) i = ε , no message is sent through port i ),and it performs an operation o (there are eight possibilities for o : stay still,contract, or expand toward the vertex corresponding to some port label).These variables are related by the equation A ( q, c , . . . , c , m , . . . , m ) =( q (cid:48) , m (cid:48) , . . . , m (cid:48) , o ), where A is a function.Recall that the set Q of possible internal states is finite, as well as the set M of possible messages. Hence A is a finite function, and we will identify itwith the deterministic algorithm that computes it.We assume that, when stage 0 starts, all particles are contracted, theyall have the same predefined internal state q , and there are no messagespending between particles. Shapes.
In this paper we study shapes and how they can be formed bysystems of particles. A shape is a non-empty connected set consisting ofthe union of finitely many edges and faces of the drawing G D . We stressthat a shape is not a subgraph of the abstract graph G , but it is a subset of R , i.e., a geometric set. A shape S is simply connected if the set R \ S isconnected (intuitively, S has no “holes”). The size of a shape is the numberof vertices of G D that lie in it.We say that two shapes S and S (cid:48) are equivalent if S (cid:48) is obtained from S bya similarity transformation, i.e., a composition of a translation, a rotation, In Section 4, we will show that our results hold also for a much more general notionof shape.
8n isotropic scaling by a positive factor, and an optional reflection. Clearly,our notion of equivalence is indeed an equivalence relation between shapes.Figure 1: Two systems of particles forming equivalent shapes. The shape onthe left is minimal; the one on the right has scale 3. Contracted particles arerepresented as black dots; expanded particles are black segments. Shapesare indicated by gray blobs.A shape is minimal if no shape that is equivalent to it has a smaller size.Obviously, any shape S is equivalent to a minimal shape S (cid:48) . The size of S (cid:48) is said to be the base size of S . Let σ be a similarity transformation suchthat S = σ ( S (cid:48) ). We say that the (positive) scale factor of σ is the scale of S . Lemma 1.
The scale of a shape is a positive integer.Proof.
Let S and S (cid:48) be equivalent shapes, with S (cid:48) minimal, and let σ be asimilarity transformation with S = σ ( S (cid:48) ). Observe that there is a uniquecovering of S by maximal polygons and line segments with mutually disjointrelative interiors. Each of these segments and each edge of these polygons isthe union of finitely many edges of G D , and therefore it has integral length.It is easy to see that the scale factor of σ must be the greatest commondivisor of all such lengths, which is a positive integer. Shape formation.
We say that a system of particles in G forms a shape S if the vertices of G that are occupied by particles correspond exactly tothe vertices of the drawing G D that lie in S .Suppose that a system forms a shape S at stage 0, and let all particlesexecute the same algorithm A every time they are activated. Assume thatthere exists a shape S F such that, however the port labels of each particleare arranged, and whatever the choices of the scheduler are, there is a stage9here the system forms a shape equivalent to S F (not necessarily S F ), andsuch that no particle ever contracts or expands after that stage. Then,we say that A is an ( S , S F ) -shape formation algorithm , and ( S , S F ) is a feasible pair of shapes. (Among the choices of the scheduler, we also includethe decision of which particle succeeds in expanding when two or more ofthem intend to occupy the same vertex at the same stage.)In the rest of this paper, we will characterize the feasible pairs of shapes( S , S F ), provided that S is simply connected and its size is not too small.That is, for every such pair of shapes, we will either prove that no shapeformation algorithm exists, or we will give an explicit shape formation al-gorithm. Moreover, all algorithms have the same structure, which does notdepend on the particular choice of the shapes S and S F . We could evenreduce all of them to a single universal shape formation algorithm , whichtakes the “final shape” S F (or a representation thereof) as a parameter, andhas no information on the “initial shape” S , except that it is simply con-nected. As in [10], we assume that the size of the parameter S F is constantwith respect to the size of the system, so that S F can be encoded by eachparticle as part of its internal memory. More formally, we have infinitelymany universal shape formation algorithms A m ( S F ), one for each possiblesize m of the parameter S F .Next, we will state our characterization of the feasible pairs of shapes,along with a proof that there is no shape formation algorithm for the unfeasi-ble pairs. In Section 3, we will give our universal shape formation algorithmfor the feasible pairs. Unformable shapes.
There are cases in which an ( S , S F )-shape formationalgorithm does not exist. The first, trivial one, is when the size of S is notlarge enough compared to the base size of S F . The second is more subtle,and has to do with the fact that certain symmetries in S cannot be broken.A shape is said to be unbreakably k -symmetric , for some integer k >
1, if it has a center of k -fold rotational symmetry that does not coincidewith any vertex of G D . Observe that the order of the group of rotationalsymmetries of a shape must be a divisor of 6. However, the shapes with a6-fold rotational symmetry have center of rotation in a vertex of G D . Hence,there exist unbreakably k -symmetric shapes only for k = 2 and k = 3.The property of being unbreakably k -symmetric is invariant under equiv-alence, provided that the scale remains the same. Lemma 2.
A shape S is unbreakably k -symmetric if and only if all shapesthat are equivalent to S and have the same scale as S are unbreakably k -symmetric. roof. Observe that any point of S with maximum x coordinate must bea vertex of G D . Let v be one of such vertices. Since S is connected andcontains at least one edge or one face of G D , there must exist an edge uv of G D that lies on the boundary of S . Consider a similarity transformation σ that maps S into an equivalent shape S (cid:48) with the same scale (hence σ is an isometry). Since v is an extremal point of S , it must be mapped by σ into an extremal point of S (cid:48) , which must be a vertex v (cid:48) of G D , as well.Analogously, σ ( uv ) must be a segment located on the boundary of S (cid:48) . Thelength of σ ( uv ) is the length of an edge of G D , and its endpoint v (cid:48) = σ ( v )is a vertex of G D . It follows that σ ( uv ) is an edge of G D . This implies thata point p is a vertex of G D if and only if σ ( p ) is a vertex of G D .Clearly, S is rotationally symmetric if and only if S (cid:48) is. Suppose that S has a k -fold rotational symmetry with center c , and therefore S (cid:48) has a k -fold rotational symmetry with center c (cid:48) = σ ( c ). By the above reasoning, c (cid:48) is a vertex of G D if and only if c is, which is to say that S (cid:48) is unbreakably k -symmetric if and only if S is.Nonetheless, if the scale changes, the property of being unbreakably k -symmetric may or may not be preserved. The next lemma, which extendsthe previous one, gives a characterization of when this happens. Lemma 3.
A shape S is unbreakably k -symmetric if and only if any minimalshape that is equivalent to S is also unbreakably k -symmetric, and the scaleof S is not a multiple of k .Proof. By Lemma 1, the scale of S is a positive integer, say λ . Let S (cid:48) be aminimal shape equivalent to S . Of course, equivalent shapes have the samegroup of rotational symmetries, and therefore S (cid:48) has a k -fold rotational sym-metry if and only if S does. We will first prove that, if S (cid:48) is not unbreakably k -symmetric, then neither is S . So, suppose that S (cid:48) has a k -fold rotationalsymmetry with center in a vertex v of G D . Let σ be the homothetic trans-formation with center v and ratio λ . Then, S (cid:48)(cid:48) = σ ( S (cid:48) ) is a shape withcenter v and scale λ , which is therefore not unbreakably k -symmetric. Since S is equivalent to S (cid:48)(cid:48) (as they are both equivalent to S (cid:48) ) and has the samescale, it follows by Lemma 2 that S is not unbreakably k -symmetric, either.Assume now that S (cid:48) is unbreakably k -symmetric. As already observed,we have two possible cases: k = 2 and k = 3. If k = 2 (respectively, k = 3),the center of symmetry c of S (cid:48) must be the midpoint of an edge uv of G D (respectively, the center of a face uvw of G D ). Consider the homothetictransformation σ with center u and ratio λ . It is clear that σ maps S (cid:48) into an equivalent shape S (cid:48)(cid:48) whose scale is λ and whose center of symmetry11s σ ( c ). As Figure 2 suggests, σ ( c ) is a vertex of G D if and only if λ iseven (respectively, if and only if λ is a multiple of 3). It follows that S (cid:48)(cid:48) isunbreakably k -symmetric if and only if λ is not a multiple of k . Since S and S (cid:48)(cid:48) are equivalent (because both are equivalent to S (cid:48) ), Lemma 2 impliesthat S is unbreakably k -symmetric if and only if its scale is not a multipleof k . = 1 λ = 2 λ = 3 λ = 4 λ Figure 2: If a shape is equivalent to an edge of G D , its center is a vertex of G D if and only if its scale λ is even. If a shape is equivalent to a face of G D ,its center is a vertex of G D if and only if its scale λ is a multiple of 3.The term “unbreakably” is justified by the following theorem. Theorem 1.
If there exists an ( S , S F ) -shape formation algorithm, and S is unbreakably k -symmetric, then any minimal shape that is equivalent to S F is also unbreakably k -symmetric.Proof. Assume that there is a k -fold rotation ρ that leaves S unchanged,and assume that its center is not a vertex of G D . Then, the orbit of anyvertex of G D under ρ has period k . The system is naturally partitioned into symmetry classes of size k : for any particle p occupying a vertex v of G D atstage 0, the symmetry class of p is defined as the set of k distinct particlesthat occupy the vertices v , ρ ( v ), ρ ( ρ ( v )), . . . , ρ k − ( v ).Assume that the port labels of the k particles in a same symmetry classare arranged symmetrically with respect to the center of ρ . Suppose that thesystem executes an ( S , S F )-shape formation algorithm and, at each stage,the scheduler picks a single symmetry class and activates all its members.12t is easy to prove by induction that, at every stage, all active particleshave equal views, receive equal messages from equally labeled ports, sendequal messages to symmetric ports, and perform symmetric contraction andexpansion operations. Note that, since only one symmetry class is active ata time, and the center of ρ is not a vertex of G D , no two particles ever tryto expand toward the same vertex, and so no conflicts have to be resolved.Therefore, as the configuration evolves, it preserves its center of symmetry,and the system always forms an unbreakably k -symmetric shape. Sinceeventually the system must form a shape S (cid:48) F equivalent to S F , it follows that S (cid:48) F is unbreakably k -symmetric. By Lemma 3, any minimal shape that isequivalent to S (cid:48) F (or, which is the same, to S F ) is unbreakably k -symmetric,as well.In Section 3, we are going to prove that the condition of Theorem 1 char-acterizes the feasible pairs of shapes, provided that S is simply connected,and the size of S is large enough with respect to the base size of S F . Measuring movements and rounds.
We will also be concerned to mea-sure the total number of moves performed by a system of size n executinga universal shape formation algorithm. This number is defined as the maxi-mum, taken over all the feasible pairs ( S , S F ) where the size of S is exactly n , all possible port labels, and all possible schedules, of the total numberof contraction and expansion operations that all the particles collectivelyperform through the entire execution of the algorithm.Next we will show a lower bound on the total number of moves of auniversal shape formation algorithm. Theorem 2.
A system of n particles executing any universal shape forma-tion algorithm performs Ω( n ) moves in total.Proof. Let d > n = 3 d ( d +1)+1particles forms a regular hexagon H d of side length d at stage 0. Let the finalshape S F be a single edge of G D . We will show that any ( H d , S F )-shapeformation algorithm A requires Ω( n ) moves in total.Since S F is an edge of G D , a system executing A from H d will eventuallyform a line segment S (cid:48) F of length at least n − s . Without lossof generality, we may assume that the center of H d lies at the origin of theCartesian plane, S (cid:48) F is parallel to the x axis, and at stage s the majority ofparticle’s heads have non-negative x coordinate.Observe that, at stage 0, each particle’s head has x coordinate at most d . So, if the x coordinate of a particle’s head at stage s is k/
2, for some non-13egative integer k , then the particle must have performed at least (cid:100) k/ (cid:101) − d expansion operations between stage 0 and stage s . Also, if the particle doesnot occupy an endpoint of S (cid:48) F , there must be another particle whose headhas x coordinate at least k/ (cid:100) k/ (cid:101) − d expansion operations, etc.It follows that a lower bound on the total number of moves that thesystem performs before forming S (cid:48) F is (cid:100) n/ (cid:101) (cid:88) i =0 ( i − d ) = (cid:6) n (cid:7) (cid:0)(cid:6) n (cid:7) + 1 (cid:1) − d (cid:16)(cid:108) n (cid:109) + 1 (cid:17) ≥ n (cid:16) n − d (cid:17) = Ω( n ) , because d = Θ( √ n ).To complete the proof, we should also show that ( H d , S F ) is a feasiblepair: indeed, the above lower bound would be irrelevant if there were noactual algorithm to form S F from H d . However, we omit the tedious de-tails of such an algorithm because we are going to prove a much strongerstatement in Section 3, where we characterize the feasible pairs in terms oftheir unbreakable k -symmetry. Note that the center of H d lies in a vertexof G D , and hence H d is not unbreakably k -symmetric. Therefore, accordingto Theorem 9, ( H d , S F ) is a feasible pair.In Section 3, we will prove that our universal shape formation algorithmrequires O ( n ) moves in total, and is therefore asymptotically optimal withrespect to this parameter.Similarly, we want to measure how many rounds it takes the system toform the final shape (a round is a span of time in which each particle isactivated at least once). We will show that our universal shape formationalgorithm takes O ( n ) rounds. Algorithm structure.
The universal shape formation algorithm takes a“final shape” S F as a parameter: this is encoded in the initial states of allparticles. Without loss of generality, we will assume S F to be minimal. Thealgorithm consists of seven phases:1. A lattice consumption phase , in which the initial shape S is “eroded”until 1, 2, or 3 pairwise adjacent particles are identified as “candi-date leaders”. No particle moves in this phase: only messages areexchanged. This phase ends in O ( n ) rounds.14. A spanning forest construction phase , in which a spanning forest of S is constructed, where each candidate leader is the root of a tree. Noparticle moves, and the phase ends in O ( n ) rounds.3. A handedness agreement phase , in which all particles assume the samehandedness as the candidate leaders (some candidate leaders may beeliminated in the process). In this phase, at most O ( n ) moves aremade. However, at the end, the system forms S again. This phaseends in O ( n ) rounds.4. A leader election phase , in which the candidate leaders attempt tobreak symmetries and elect a unique leader. If they fail to do so, and k > S isunbreakably k -symmetric, and therefore the “final shape” S F mustalso be unbreakably k -symmetric (cf. Theorem 1). No particle moves,and the phase ends in O ( n ) rounds.5. A straightening phase , in which each leader coordinates a group ofparticles in the formation of a straight line. The k resulting lines havethe same length. At most O ( n ) moves are made, and the phase endsin O ( n ) rounds.6. A role assignment phase , in which the particles determine the scale ofthe shape S (cid:48) F (equivalent to S F ) that they are actually going to form.Each particle is assigned an identifier that will determine its behaviorduring the formation process. No particle moves, and the phase endsin O ( n ) rounds.7. A shape composition phase , in which each straight line of particles,guided by a leader, is reconfigured to form an equal portion of S (cid:48) F . Atmost O ( n ) moves are made, and the phase ends in O ( n ) rounds.No a-priori knowledge of S is needed to execute this algorithm ( S just hasto be simply connected), while S F must of course be known to the particlesand have constant size, so that its description can reside in their memory.Note that the knowledge of S F is needed only in the last two phases of thealgorithm. Synchronization.
As long as there is a unique (candidate) leader p inthe system, there are no synchronization problems: p coordinates all otherparticles, and autonomously decides when each phase ends and the nextphase starts. 15owever, if there are k > • All the (candidate) leaders must always be pairwise adjacent, exceptperhaps in the last two phases of the algorithm (i.e., the role assign-ment phase and the shape composition phase) and for a few stagesduring the handedness agreement phase and the straightening phase. • Every time a (candidate) leader is activated, it sends all other (can-didate) leaders a message containing an identifier of the phase thatit is currently executing (the message may also contain other data,depending on the phase of the algorithm). • Whenever a (candidate) leader transitions from a phase into the next,it waits for all other (candidate) leaders to be in the same phase (exceptwhen it transitions to the last phase).This basic protocol is executed “in parallel” with the main algorithm,and it always works in the same way in every phase. In the following, we willno longer mention it explicitly, but we will focus on the distinctive aspectsof each phase.
Algorithm.
The goal of this phase is to identify 1, 2, or 3 candidate leaders .This is done without making any movements, but only exchanging messages.Each particle’s internal state has a flag (i.e., a bit) called
Eligible . Allparticles start the execution in the same state, with the Eligible flag set. Asthe execution proceeds, Eligible particles will gradually eliminate themselvesby clearing their Eligible flag. This is achieved through a process similar toerosion, which starts from the boundary of the initial shape and proceedstoward its interior.Suppose that all the particles in the system are contracted (which is trueat stage 0). Then, we define four types of corner particles , which will startthe erosion process: • a is an Eligible particle with no Eligible neighbors;16 a is an Eligible particle with exactly one Eligibleneighbor; • a is an Eligible particle with exactly two Eligibleneighbors p and p , such that p is adjacent to p ; • a is an Eligible particle with exactly three Eligibleneighbors p , p , p , with p adjacent to both p and p . p is calledthe middle neighbor .We say that a particle p is locked if it is a 3-corner particle and its middleneighbor p (cid:48) is also a 3-corner particle. If p is locked, it follows that p (cid:48) islocked as well, with p its middle neighbor. In this case, we say that p and p (cid:48) are companions .Figure 3: The particles in white or gray are corner particles; the two in grayare locked companion particles. Dashed lines indicate adjacencies betweenparticles.Each particle has also another flag, called Candidate (initially not set),which will be set if the particle becomes a candidate leader. Whenever aparticle is activated, it sends messages to all its neighbors, communicatingthe state of its Eligible and Candidate flags. When a particle receives sucha message, it memorizes the information it contains (perhaps overwritingoutdated information). Therefore, each particle keeps an updated copy ofthe Eligible and Candidate flags of each of its neighbors. Once a particleknows the states of all its neighbors (i.e., when it has received messages fromall of them), it also knows if it is a k -corner particle. If it is, it broadcaststhe number k to all its neighbors every time it is activated. In turn, theneighbors memorize this number and keep it updated.17here is a third flag, called Stable (initially not set), which is clearedwhenever a particle receives a message from a neighbor communicating thatits internal state has changed. Otherwise, the flag is set, meaning that thestates of all neighbors have been stable for at least one stage.The following rules are also applied by active particles, alongside withthe previous ones: • If a particle p does not know whether some if its neighbors were cornerparticles the last time they were activated (because it has not receivedenough information from them, yet), it waits. • Otherwise, p knows which of its neighbors were corner particles thelast time they were activated, and in particular which of them areEligible. This also implies that p knows if it is a corner particle, andif it is locked (for a proof, see Theorem 3). If p is not a corner particleor if it is locked, it waits. • Otherwise, p is a non-locked corner particle. If its Eligible flag is notset, or if its Candidate flag is set, or if its Stable flag is not set, itwaits. • Otherwise, p changes its flags as follows. – If p is a 0-corner particle, it sets its own Candidate flag. – Let p be a 1-corner particle. If its unique Eligible neighbor wasa 1-corner particle the last time it was activated, p sets its ownCandidate flag; otherwise, p clears its own Eligible flag. – Let p be a 2-corner particle. If both its Eligible neighbors were2-corner particles the last time they were activated, p sets its ownCandidate flag; otherwise, p clears its own Eligible flag. – If p is a 3-corner particle, it clears its own Eligible flag. Correctness.Lemma 4.
If a system of contracted Eligible particles forms a simply con-nected shape, then there is a corner particle that is not locked.Proof.
Let S be a simply connected shape formed by a system P of con-tracted Eligible particles. For each pair of companion locked particles of P ,let us remove one. At the end of this process, we obtain a reduced system P (cid:48) with no locked particles that again forms a simply connected shape S (cid:48) . Note18hat all corner particles of P (cid:48) are non-locked corner particles of P ; hence, itsuffices to prove the existence of a corner particle in P (cid:48) .By definition of shape, S (cid:48) can be decomposed into maximal 2-dimensionalpolygons interconnected by 1-dimensional polygonal chains, perhaps withramifications (if two polygons are connected by one vertex, we treat thisvertex as a polygonal chain with no edges). Since S (cid:48) is simply connected,the abstract graph obtained by collapsing each maximal polygon of S (cid:48) into asingle vertex forms a tree, which has at least one leaf. The leaf may representthe endpoint of a polygonal chain of S (cid:48) , which is the location of a 1-cornerparticle of P (cid:48) . Otherwise, the leaf represents a polygon S (cid:48)(cid:48) ⊆ S (cid:48) , perhapsconnected to the rest of S (cid:48) by a polygonal chain with an endpoint in a vertex v of S (cid:48)(cid:48) . Since S (cid:48)(cid:48) is a polygon, it has at least three convex vertices, at mostone of which is v . Each other convex vertices of S (cid:48)(cid:48) is therefore the locationof a 2-corner particle or a 3-corner particle of P (cid:48) . Lemma 5.
If a system of contracted Eligible particles forms a simply con-nected shape, and any set of non-locked corner particles is removed at once,the new system forms again a simply connected shape. Proof.
Instead of removing all the particles in the given set C at once,we remove them one by one in any order, and use induction to prove ourlemma. Let P be a system of contracted Eligible particles forming a simplyconnected shape, and let C (cid:48) be a set of corner particles of P such that, ifa particle of C (cid:48) is locked, then its companion is not in C (cid:48) . This conditionis obviously satisfied by the given set C , because it does not contain lockedcorner particles at all.Let p ∈ C (cid:48) , and let P (cid:48) = P \ { p } . We have to prove that P (cid:48) forms asimply connected shape, that C (cid:48) \ { p } is a set of corner particles of P (cid:48) , andthat C (cid:48) \ { p } does not contain any pair of companion locked particles of P (cid:48) .Note that the fact that P (cid:48) forms a simply connected shape is evident, since p is a corner particle of P . Therefore, any path in the subgraph of the grid G induced by P that goes through p may be re-routed through the neighborsof p in P .Now, if C (cid:48) = { p } , there is nothing else to prove. So, let p (cid:48) (cid:54) = p be anotherparticle of C (cid:48) . Suppose first that p (cid:48) is adjacent to p . Hence, removing p reduces the number of Eligible neighbors of p (cid:48) by one. The only case inwhich p (cid:48) could cease to be a corner particle would be if p were its middle For convenience, with a little abuse of terminology, we treat single vertices of G D andthe empty set as shapes, even if technically they are not, according to the definitions ofSection 2. p and p (cid:48) would be locked companions. But this isnot possible, because by assumption C (cid:48) does not contain a pair of lockedcompanion particles. Therefore, p (cid:48) is necessarily a corner particle of P (cid:48) .Note that p (cid:48) cannot be a 3-corner particle of P (cid:48) , because one of its Eligibleneighbors (namely, p ) has been removed. Hence p (cid:48) cannot be locked in P (cid:48) .Suppose now that p (cid:48) is not adjacent to p . Then, obviously, p (cid:48) is a cornerparticle of P (cid:48) , since removing p does not change its neighborhood. We onlyhave to prove that, if p (cid:48) is a locked 3-corner particle in P (cid:48) , then C (cid:48) \ { p } doesnot contain the companion of p (cid:48) . Assume the opposite: let p (cid:48) be a lockedparticle in P (cid:48) , let p (cid:48)(cid:48) be its companion, and let p (cid:48) and p (cid:48)(cid:48) be in C (cid:48) \ { p } , andhence in C (cid:48) . By assumption, p (cid:48)(cid:48) cannot be locked in P , or else C (cid:48) wouldcontain a pair of locked companion particles. So, p must be adjacent to p (cid:48)(cid:48) .Removing p reduces the number of Eligible neighbors of p (cid:48)(cid:48) , implying that p (cid:48)(cid:48) must have four Eligible neighbors in P (since p (cid:48)(cid:48) is a 3-corner particlein P (cid:48) ). It follows that p (cid:48)(cid:48) cannot be a corner particle of P , and therefore itcannot be in C (cid:48) , contradicting our assumption. Theorem 3.
Let P be a system of n contracted Eligible particles forming asimply connected shape S at stage 0. If all particles of P execute the latticeconsumption phase of the algorithm, there is a stage s , reached in O ( n ) rounds, where there are 1, 2, or 3 pairwise adjacent Candidate particles,and all other particles are non-Eligible. Moreover, at all stages from 0 to s ,the system forms S , and the sub-system of Eligible particles forms a simplyconnected shape.Proof. Recall that, in the lattice consumption phase, a particle never changesits Eligible or Candidate flags unless it is an Eligible, non-Candidate, Stable,non-locked corner particle that has enough information about its neighbors.Whenever a particle p is activated and reads the pending messages, ev-erything it knows about the internal flags of its neighbors is correct and upto date. Indeed, these flags can be changed only by the neighbors themselveswhen they are activated, and whenever this happens they send the updatedvalues to p . Therefore, p always reads the most recent values of the flags ofits neighbors, no matter how and when the scheduler activates them. So, p is able to correctly determine if it is a corner particle by just looking at theEligible flags of its neighbors and how they are arranged.On the other hand, when p receives a message from a neighbor p (cid:48) claimingthat p (cid:48) is or is not a k -corner particle, this information may be outdated,because a neighbor of p (cid:48) may have eliminated itself, and p (cid:48) may have beeninactive ever since. However, p is still able to determine if it is locked or20ot. Indeed, suppose that p has correctly determined that it is a 3-cornerparticle, implying that it currently has three consecutive Eligible neighbors p , p , and p . Suppose that its middle neighbor p has claimed to be a 3-corner particle in its last message. This statement was correct the last time p was active, implying that p had three consecutive Eligible neighbors.Because particles can become non-Eligible but never become Eligible again,the three Eligible particles that p saw must be p , p , and p , since they arecurrently Eligible. It follows that p is still a 3-corner particle and hence p is locked. The converse is also true, for the same reason.We deduce that a particle will eliminate itself only if it truly is a non-locked corner particle. Also note that no particle is allowed to move duringthe lattice consumption phase. So, the system will always form the sameshape S , and, by Lemma 5, the sub-system of Eligible particles will alwaysbe simply connected.Next we prove that, if a particle ever sets its Candidate flag, then thereis a stage where there are 1, 2, or 3 pairwise adjacent Candidates, and allother particles are non-Eligible. Say that at some point a particle p becomesa Candidate, which means that it was able to determine that it is a k -cornerparticle, with 0 ≤ k ≤ k = 0, then p is the only Eligible particle left, because the sub-system ofEligible particles must be connected. If k = 1, then p has a unique Eligibleneighbor p (cid:48) , which was a 1-corner particle the last time it was activated.This means that the only Eligible neighbor of p (cid:48) was p , and hence p and p (cid:48) are the only Eligible particles in the system. Eventually, p (cid:48) will becomeStable and will either eliminate itself or become a Candidate. If k = 2,then p has two adjacent Eligible neighbors p (cid:48) and p (cid:48)(cid:48) , which were 2-cornerparticles the last time they were activated. So, the only Eligible particles inthe system are p , p (cid:48) , and p (cid:48)(cid:48) , which are pairwise adjacent. Both p (cid:48) and p (cid:48)(cid:48) will eventually become Stable, and they will either eliminate themselves orbecome Candidates.We now have to prove that Eligible particles steadily eliminate them-selves until only Candidates are left. Assume the opposite, and supposethat the execution of the algorithm reaches a point where Eligible particlesstop becoming non-Eligible. By the above reasoning, we may assume thatthe system contains no Candidate particles at this point. As the sub-systemof Eligible particles is simply connected at any time, by Lemma 4 there arenon-Candidate non-locked corner particles. Since no particle ever changesits internal flags again, all of them will eventually become Stable. So, therewill be an Eligible, non-Candidate, Stable, non-locked corner particle thatwill either become non-Eligible or a Candidate, which contradicts our as-21umptions.It remains to prove that at least one particle will become a Candidate.Assume the opposite. At each stage, some non-locked corner particles possi-bly eliminate themselves, and this process goes on until there are no Eligibleparticles left. Let s be the stage when the last Eligible particles eliminatethemselves (simultaneously). As all of them have to be non-locked cornerparticles at stage s , it is easy to see that only three configurations are pos-sible: • At stage s there is only one Eligible particle. Since this is a 0-cornerparticle, according to the algorithm it will become a Candidate. • At stage s there are only two adjacent 1-corner particles p and p (cid:48) .Recall that a particle has to be Stable in order to eliminate itself.Since p is Stable at stage s , it means that there is a stage s (cid:48) < s during which p has already sent a message to p (cid:48) saying that it was a1-corner particle (otherwise, some neighbor of p would have eliminateditself in the meantime, implying that p would not be Stable). Since p (cid:48) is active at stage s , it must receive or have already received themessage sent at time s (cid:48) by p . So, p (cid:48) knows that p is a 1-corner, andhence it becomes a Candidate (and vice versa). • At stage s there are only three pairwise adjacent 2-corner particles.Reasoning as in the previous case, we see that, since all three particlesare Stable at stage s , they know that they are all 2-corner particles,and therefore they become Candidates.In all cases, at least one particle becomes a Candidate, contradicting ourassumption.Finally, the upper bound of O ( n ) rounds easily follows from the factthat, in a constant number of rounds, at least one corner particle becomesnon-Eligible or a Candidate. This happens at most n − Algorithm.
The spanning forest construction phase starts when 1, 2, or3 pairwise adjacent candidate leaders have been identified, and no otherparticle is Eligible. In this phase, each candidate leader becomes the root ofa tree embedded in G . Eventually, the set of these trees will be a spanningforest of the subgraph of G induced by the system P .22ach particle has a flag called Tree , initially not set, whose purpose isto indicate that the particle has been included in a tree. Moreover, eachparticle also has a variable called
Parent , which contains the local portnumber corresponding to its parent, provided that the particle is part of atree (the initial value of this variable is − Is-in-Tree flag and an
Is-my-Child flag corresponding to each neighbor. All these flag are initially notset.Finally, there is a
Tree-Done flag (initially not set) corresponding to eachneighbor, which is used in the last part of the phase.The following rules apply to all particles during the spanning forest con-struction phase: • If a particle’s Candidate flag is set and its Tree flag is not set, it setsits own Tree flag and leaves its own Parent flag to − • If a particle’s Tree flag is set, it sends a
Parent message to the portcorresponding to its own Parent variable (assuming it is not − Tree message to all other neighbors. • If a particle receives a Tree message from a neighbor, it sets the Is-in-Tree flag relative to its port. Similarly, if it receives a Parent messagefrom a neighbor, it sets both the Is-in-Tree and the Is-my-Child flagrelative to its port. • If a particle’s Candidate flag is not set, its Tree flag is not set, and theIs-in-Tree flags relative to some of its neighbors are set, then it setsits own Tree flag. Let k be the smallest port number correspondingto a neighbor whose relative Is-in-Tree flag is set. Then, the particlesets its own Parent flag to k (implying that that neighbor is now itsparent). • If a particle p ’s Tree flag is set, the Is-in-Tree flags corresponding to allits neighbors are set, and the Tree-Done flags relative to all it childrenare set (recall that its children are the neighbors whose relative Is-my-Child flag is set), then: – If p has a parent (i.e., its Parent variable is not − Tree-Done message to its parent.23 If p has no parent (i.e., it is a candidate leader), it sends a Tree-Done message to its Candidate neighbors. • If a particle receives a Tree-Done message from one of its children, itsets the corresponding Tree-Done flag.
Correctness.Theorem 4.
Let P be the system resulting from Theorem 3. If all particlesof P execute the spanning forest construction phase of the algorithm, thenthere is a stage, reached after O ( n ) rounds, where every particle has the Treeflag set, each non-Candidate particle has a unique parent, and each particlehas received a Tree-Done message from all its children. No particle movesin this phase.Proof. It is easy to prove by induction that, at every stage, the Tree parti-cles form a forest with a tree rooted in each Candidate particle, and that theParent variables of all Tree particles are consistent. Indeed, when any (posi-tive) number of neighbors of a non-Tree particle p become Tree particles andstart sending Tree messages to p , p chooses one of them as its parent as soonas it is activated, and sets its flags accordingly. It then communicates thischange to its neighbors, which update their Is-in-Tree and the Is-my-Childflags consistently.Since P forms a connected shape (because it results from Theorem 3),eventually all particles become part of some tree, and a spanning forest isconstructed. So, eventually, some leaves of the forest observe that all theirneighbors are Tree particles (because all their relative Is-in-Tree flags are set)and none of them is their child (because none of their relative Is-my-Childflags is set). These leaves send Tree-Done messages to their parents.As more leaves send Tree-Done messages to their parents, some internalparticles start observing that all their children are sending Tree-Done mes-sages, and all other neighbors are Tree particles. These internal particlestherefore send Tree-Done messages to their parents, as well. Eventually, theCandidate particles will receive Tree-Done messages from all their children.At this stage, every particle has the Tree flag set, each non-Candidate parti-cle has a unique parent, and each particle has received a Tree-Done messagefrom all its children.To show that the phase ends in O ( n ) rounds, it suffices to note thatin a constant number of rounds either a new particle sets its Tree flag orforwards the Tree-Done message to its parent (or its Candidate neighbors ifit has no parent). 24 .3 Handedness Agreement Phase When a candidate leader has received Tree messages from all its neighborsand Tree-Done messages from all its children, it transitions to the handed-ness agreement phase. Recall that each particle may label ports in clockwiseor counterclockwise order: this is called the particle’s handedness. By theend of this phase, all particles will agree on a common handedness. Theagreement process starts at the candidate leaders and proceeds through thespanning forest constructed in the previous phase, from parents to children.
Agreement among candidate leaders.
In the first stages of this phase,the candidate leaders agree on a common handedness. This may result inthe “elimination” of some of them. If there is a unique candidate leader,this part of the algorithm is trivial. So, let us assume that there are two orthree candidate leaders.Suppose that there are two candidate leaders p and p (cid:48) . Then, they haveexactly two neighboring vertices u and v in common. By now, the candidateleaders know if u and v are occupied or not. There are three cases. • Exactly one between u and v is occupied. Without loss of generality, u is occupied by a particle p u , and v is unoccupied. Then, both p and p (cid:48) send a You-Choose message to p u . When p u has received You-Choosemessages from both, it arbitrarily picks one between p and p (cid:48) , say p .Then p u sends a Chosen message to p and a Not-Chosen message to p (cid:48) . As a consequence, p (cid:48) ceases to be a candidate leader (by clearingits own Candidate and Eligible flags), and p becomes the parent of p (cid:48) (i.e., the Parent variable of p (cid:48) and the Is-my-Child variables of p areappropriately updated). • u is occupied by a particle p u and v is occupied by a particle p v .Let the edge { p, p (cid:48) } be labeled i by p , and observe that i − (cid:96) ( p, u ) ≡− i + (cid:96) ( p, v ) ≡ ± i − (cid:96) ( p, u ) ≡ p sends a You-Choose message to p u and a You-do-not-Choose message to p v . p (cid:48) does the same. If one between p u or p v receives both You-Choose messages, it arbitrarily eliminates onebetween p and p (cid:48) , as explained above. Otherwise, both p u and p v receive a You-Choose message and a You-do-not-Choose message. Thismeans that p and p (cid:48) have the same handedness. So, p u and p v send Same-Handedness messages to both p and p (cid:48) , who wait until theyreceive both messages. • Both u and v are unoccupied. As above, if the edge { p, p (cid:48) } is labeled i by p , then i − (cid:96) ( p, u ) ≡ − i + (cid:96) ( p, v ) ≡ ± i − (cid:96) ( p, u ) ≡ p attempts toexpand toward u . Meanwhile, p (cid:48) does the same. – If p fails to expand toward u , it means that p (cid:48) has done it ( p realizes that this has happened because it cannot see its own tailthe next time it is activated). In this case, p sends an I-am-Eliminated message to p (cid:48) . – Suppose now that p manages to expand toward u (it realizes thatit has expanded because it sees its own tail the next time it isactivated). Then, p looks back at p (cid:48) , which is found at port ( i +1)mod 6 (see Figure 4). If p sees a tail or an unoccupied vertex, itunderstands that p (cid:48) has expanded toward v . In this case, p and p (cid:48) have the same handedness, and p memorizes this information.If p sees the head of p (cid:48) , it sends a You-are-Eliminated message to p (cid:48) .After this, if p is still expanded, it contracts into u , it expands towardits original vertex, and contracts again. p (cid:48) does the same. Eventually,at least one between p and p (cid:48) has realized that their handedness isthe same, or has received a You-are-Eliminated or an I-am-Eliminatedmessage. This information is shared by p and p (cid:48) again when they areboth in their initial positions and contracted. If one of them has to beeliminated, it does so by clearing its Candidate and Eligible flags, andbecomes a child of the other candidate leader, as explained above. p ′ pu v i + 1 i − i + 1 i Figure 4: The case of the agreement protocol between candidate leaders inwhich u and v are unoccupied. If p expands toward the vertex correspondingto the label ( i −
1) mod 6, it finds p (cid:48) at the vertex corresponding to the label( i + 1) mod 6.Suppose now that there are three candidate leaders p , p (cid:48) , and p (cid:48)(cid:48) . So, p knows that there are candidate leaders corresponding to its local ports i and i (cid:48) , with i (cid:48) ≡ i +1 (mod 6). Then, p , sends an I-Choose-You message through26ort i and an I-do-not-Choose-You message through port i (cid:48) . Meanwhile, p (cid:48) and p (cid:48)(cid:48) do the same. Eventually, each candidate leader receives two messages. • If one of them, say p , receives two I-Choose-You messages, it sendsYou-are-Eliminated messages to both p (cid:48) and p (cid:48)(cid:48) . Then, p (cid:48) and p (cid:48)(cid:48) ceaseto be candidate leaders and become children of p . • Otherwise, each candidate leaders receives one I-Choose-You and oneI-do-not-Choose-You message. This means that all candidate leadershave the same handedness. Each of them sends an
I-am-not-Chosen message to the others. When they receive each other’s messages, theyrealize that their handedness is the same.
Basic handedness communication.
As a basic operation, we want tolet a parent “impose” its own handedness onto a child. Of course, thiscannot be done by direct communication, and we will therefore need a special handedness communication technique , which we describe next.Assume that a contracted particle p intends to communicate its handed-ness to one of its children, a contracted particle p (cid:48) . For now, we will makethe simplifying assumption that all other particles are contracted and idle.We will show later how to handle the general case in which several particlesare operating in parallel.Say that the edge { p, p (cid:48) } is labeled i by p and i (cid:48) by p (cid:48) . There are exactlytwo vertices u and v of G D that are adjacent to both p and p (cid:48) . Supposefirst that at least one between u and v is not occupied by any particle. Ifboth are unoccupied, p will arbitrarily choose one of them. Without lossof generality, let us assume that u is unoccupied, and p has chosen it. Let j = ( (cid:96) ( p, u ) − i ) mod 6, and observe that j = ±
1, since u is adjacent to p (cid:48) . • p memorizes i and j , and expands toward u . • Then, p computes the port corresponding to p (cid:48) as ( i − j ) mod 6, andsends p (cid:48) a Handedness-A message containing j . • Say p (cid:48) receives the Handedness-A message from port i (cid:48)(cid:48) , and let j (cid:48) =(Parent − i (cid:48)(cid:48) ) mod 6 (recall from Section 3.2 that Parent = i (cid:48) , because p is the parent of p (cid:48) ). Now, p and p (cid:48) have the same handedness if andonly if j = j (cid:48) . So, p (cid:48) memorizes this information and replies with a Handedness-OK to port i (cid:48)(cid:48) . • When p receives the Handedness-OK message, it contracts into u . • Then, p expands toward its original location and contracts again.27uppose now that u and v are both occupied by particles p u and p v ,respectively: this case is illustrated in Figure 5. We say that p u and p v are auxiliary particles . • p sends a Lock message to both p u and p v (the purpose of this messagewill be explained later). • p u and p v reply by sending Locked messages back to p . • When p has received Locked messages from both p u and p v , it sendsa Get-Ready message to p (cid:48) . • When p (cid:48) receives the Get-Ready message, it sets an internal Ready flag and sends an
I-am-Ready message back to p (the purpose of theReady flag will be explained later). • When p receives the I-am-Ready message from p (cid:48) , it sends the number( (cid:96) ( p, u ) − i ) mod 6 to p u and the number ( (cid:96) ( p, v ) − i ) mod 6 to p v . • Say that p u receives the number j from p . Then, p u sends a Handedness-B message containing the number j to the (at most two) commonneighbors of p and p u . Note that p (cid:48) is one of these neighbors (seeFigure 5). p v does the same thing. • Whenever a particle receives a Handedness-B message from a neighbor,it responds with a
Handedness-B-Acknowledged to the same neighbor. • Say that p (cid:48) receives a Handedness-B message containing the number j = ( (cid:96) ( p, u ) − i ) mod 6 from p u , and say that (cid:96) ( p (cid:48) , u ) = i (cid:48)(cid:48) . As before, p (cid:48) computes j (cid:48) = (Parent − i (cid:48)(cid:48) ) mod 6, and determines if it has thesame handedness as p by comparing j and j (cid:48) . If p (cid:48) receives a numberfrom p v , it does the same thing. • When p (cid:48) has received numbers from both p u and p v , it sends a Handedness-OK message to p . • When p receives the Handedness-OK message from p (cid:48) , it sends Unlock messages to both p u and p v . • When p u and p v receive an Unlock message from p and a Handedness-B-Acknowledged message from every neighbor to which they sent Handedness-B messages, they send an Unlocked message back to p . • p waits until it receives Unlocked messages from both p u and p v .28 ′′ p u p v p i j + i ′ i ′′ i ′ p ) j ( ) j ( Figure 5: The case of the handedness communication protocol in which u and v are occupied. Arrows indicate messages. The particles p and p (cid:48) havethe same handedness if and only if j ≡ i (cid:48) − i (cid:48)(cid:48) (mod 6). Main handedness agreement algorithm.
The main part of the hand-edness agreement algorithm starts when all the candidate leaders have thesame handedness. Next we describe the main algorithm for a generic particle p . If p is a candidate leader or if it receives a Begin-Handedness-Communication message from its parent, p starts communicating its handedness to its chil-dren. p picks one child and executes the handedness communication tech-nique with it. Then it does so with the next child, etc.When a child p (cid:48) realizes that its handedness is not the handedness of p , itsets a special internal flag that reminds it to apply the function f ( i ) = 5 − i to all its port labels. If the flag is not set, f is the identity function. Thecomposition (cid:101) (cid:96) = f ◦ (cid:96) , where (cid:96) is the labeling of p (cid:48) , is called the correctedlabeling of p (cid:48) , and will be used by p (cid:48) instead of (cid:96) . In other terms, p (cid:48) “pre-tends” to have the handedness of p , and it behaves accordingly for the restof the execution of the shape formation algorithm.When p has communicated its handedness to all its children, it sends aBegin-Handedness-Communication message to its first child. Then p waitsuntil the child has sent it a Done-Handedness-Communication message back.Subsequently, p sends a Begin-Handedness-Communication message to itssecond child, etc.When the last child of p has sent a Done-Handedness-Communicationmessage to it (or if p is a leaf of the spanning forest of P ), p sends a Done-Handedness-Communication message back to its father (provided that p isnot a candidate leader). Resolving conflicts.
Note that several pairs of particles may be executingthe handedness communication technique at the same time: precisely, asmany as the trees in the spanning forest, i.e., as many as the candidate29eaders. These particles may interfere with each other when they try toexpand toward the same vertex or when they send messages to the sameparticle. In the following, we explain how these conflicts are resolved.To begin with, each particle p memorizes which of its surrounding ver-tices are initially occupied by other particles. Then, when p executes thehandedness communication technique, it looks at its neighboring vertices u and v . If any of them is supposed to be occupied but is currently unoccupiedor it is a tail vertex, p waits.Similarly, if p fails to expand toward a supposedly empty vertex u becauseanother particle has expanded toward it at the same time, p waits until u is unoccupied again (recall that p realizes that its expansion attempt hasfailed if it cannot see its own tail).After an auxiliary particle p u has sent a Locked message to p , it ignoresall Lock messages from any other particle until it has sent an Unlockedmessage back to p . This prevents p u from becoming an auxiliary particle intwo independent handedness communication operations simultaneously.Similarly, when p u is an auxiliary particle of p and p (cid:48) , it sends Handedness-B messages to its common neighbors with p . So, another particle p (cid:48)(cid:48) (cid:54) = p (cid:48) ,which is not involved in the operation, might receive this message and be-have incorrectly. Three situations are possible: • If p (cid:48)(cid:48) has already been the recipient of a (completed) handedness com-munication operation, it simply ignores this message. • If p (cid:48)(cid:48) has never been the recipient of a handedness communicationoperation, its Ready flag is still not set. So, p (cid:48)(cid:48) just responds to p u witha Handedness-B-Acknowledged message without doing anything. Onthe other hand, p u will not become unlocked until it has received thismessage. Therefore, when p (cid:48)(cid:48) will indeed be involved in a handednesscommunication operation, there will not be a pending Handedness-Bmessage directed to p (cid:48)(cid:48) . • Suppose that p (cid:48)(cid:48) is currently involved in a handedness communicationoperation. We claim that p u cannot be an auxiliary particle of thisoperation. This is because p u has already been locked by p , whois involved in an operation with p (cid:48) , and therefore it cannot be anauxiliary particle in any other operation. Therefore, when p (cid:48)(cid:48) receivesa Handedness-B message from p u , it ignores it because it knows that p u is not its auxiliary particle ( p (cid:48)(cid:48) only responds with a Handedness-B-Acknowledged message). Correctness. heorem 5. Let P be the system resulting from Theorem 4, forming a shape S . If all particles of P execute the handedness agreement phase of the algo-rithm, then there is a stage, reached after O ( n ) rounds, where all candidateleaders have received a Done-Handedness-Communication message from alltheir children. At this stage, P forms S again, all candidate leaders havethe same handedness, and each other particle knows whether it has the samehandedness as the candidate leaders. In this phase, at most O ( n ) moves areperformed in total.Proof. The agreement protocol among candidate leaders works in a straight-forward way in every case. Indeed, only the candidate leaders are everallowed to move, and the other particles never send any message unlessprompted by the candidate leaders themselves.Eventually, all candidate leaders have the same handedness, and themain part of the handedness agreement phase starts. We have alreadyproved that there can be no conflicts, in that particles involved in differenthandedness communication operations do not interfere with one another.We only have to prove that there can be no deadlocks , and hence the execu-tion never gets stuck. There are essentially three ways in which a deadlockmay occur, which will be examined next.The first potential deadlock situation is the one in which a particle p intends to expand toward a vertex u that was originally unoccupied, butnow is occupied by some other particle q . According to the protocol, p has to wait for u to be unoccupied again. However, while p is temporarilyinactive, q may finish its operation and leave u , and another particle q (cid:48) mayoccupy u . If new particles keep occupying u before p does, then p will nevercomplete its operation. Observe that, if a particle q manages to occupy u ,then it is able to finish its handedness communication operation. Indeed, q will have to contract into u and then go back to its original location.In turn, the original location of q will necessarily be unoccupied, becausethe protocol prevents any particle from expanding into that vertex. Sinceno two particles perform a handedness communication operation togethermore than once, after a finite number of stages p will not have to contend u with any other particle, and will therefore be free to occupy it.The second potential deadlock situation is similar: p waits for someother particle p (cid:48) to contract or come back to its original location. If p (cid:48) keeps expanding to different locations to interact with other particles, p will wait forever. Again, this situation is resolved by observing that, once p (cid:48) has expanded, it necessarily terminates its handedness communicationoperation. Also, p (cid:48) can only be involved in finitely many such operations.31he final potential deadlock situation is the following. A particle p be-gins a handedness communication operation and locks an auxiliary particle q . However, the other particle that it intends to lock, q , is already lockedby some other particle p . In turn, p intends to lock another particle q that is already locked, etc. If the k th particle in this chain, p k , has locked q k but also wants to lock q , there is a deadlock. Observe that in a singletree of the spanning forest of P there can be at most one handedness com-munication operation in progress. Since there are at most three such trees(because there are at most three candidate leaders), k ≤ • If k = 1, obviously there can be no deadlock. • If k = 2, the sequence ( p , q , p , q ) is a cycle in G D (with a littleabuse of notation, we use particles’ names to indicate the vertices theyoccupy). p intends to communicate its handedness to its child, whichis a neighbor of p , q , and q : therefore, it must be p . However, p cannot be a child of p , because it lies in a different tree of thespanning forest. • If k = 3, the sequence ( p , q , p , q , p , q ) is a cycle in G D . The onlypossibility is for these six particles to form a regular hexagon in G D .Since the child of p must be a neighbor of p , q , and q , it mustoccupy the center of the hexagon. Similarly, the same particle mustbe the child of p and p , which is impossible, because a particle cannothave more than one parent.In any case, there can be no deadlock.Since no deadlocks can occur, eventually each non-Candidate particle isinvolved in a handedness communication operation with its parent, it learnsif it has the same handedness as its parent, and it sends Done-Handedness-Communication messages to it. The initial agreement protocol among can-didate leaders consists of a constant number of moves. Each handednesscommunication operation also consists of a constant number of moves, andexactly one such operation is performed for each non-Candidate particle of P . In total, at most O ( n ) moves are performed in this phase. Moreover,whenever a particle moves, it then goes back to its original location beforethe phase is finished. It follows that P forms S again when the phase ends.Similarly, since in a constant number of rounds a new particle eitherlearns if it has the same handedness as its parent or forwards a Done-Handedness-Communication to its parent, the phase terminates in O ( n )rounds. 32 .4 Leader Election Phase When a candidate leader receives a Done-Handedness-Communication mes-sage from its last child, it knows that its entire tree has agreed on the samehandedness. So, it transitions to the leader election phase. The goal of thisphase is to elect a single leader among the candidates, if possible.By Theorem 5, at the end of the handedness agreement phase the systemforms the initial shape S again. In order to elect a leader, the candidates“scan” their respective trees of the spanning forest, searching for asymmet-ric features of S that would allow them to decide which candidate shouldbecome the leader. This task is made possible by the fact that all particlesagree on the same handedness. If no asymmetric features are found and noleader can be elected, then S must be unbreakably k -symmetric, and thesystem will proceed to the next phase with k leaders.Technically, becoming a leader means setting an internal Leader flag(which is initially not set) and clearing the Candidate flag.
Neighborhood encoding.
We preliminarily define a finite-length code C ( p ) that a particle p can use to describe its neighborhood to other particles.The code is a string of six characters from the alphabet { L , P , C , N } . The i th character describes the content of the vertex v such that (cid:101) (cid:96) ( p, v ) = i ,where (cid:101) (cid:96) is the corrected labeling of p (refer to Section 3.3 for the definitionof corrected labeling). The character is chosen as follows: • L if v is occupied by a candidate leader; • P if v is occupied by the parent of p ; • C if v is occupied by a child of p ; • N otherwise.This information is readily available to p : indeed, at this point of the exe-cution of the algorithm, p is well aware of which of its neighboring verticesare occupied, where its parent is, where its children are, etc.Note that, by Theorem 5, using (cid:101) (cid:96) in all particles’ computations (as op-posed to (cid:96) ) is equivalent to assuming that all particles have the same hand-edness (i.e., the handedness of the candidate leaders). Basic election technique.
In the main leader election algorithm, thecandidate leaders will repeatedly use the following “tentative election pro-cedure”.Suppose that there are k = 2 candidate leaders in P , namely p and p .Let p know the neighborhood code C ( q ) of some particle q in its tree.33imilarly, p knows the neighborhood code C ( q ) of some particle q in itstree. Then, p sends C ( q ) to p , and p sends C ( q ) to p . When they knowboth codes, they compare them. If C ( q ) = C ( q ), the symmetry-breakingattempt fails, and the procedure ends. Otherwise, we can assume withoutloss of generality that C ( q ), as a string, is lexicographically smaller than C ( q ). So, p becomes a Leader particle and the parent of p , while p clearsits Candidate and Eligible flags, and becomes a child of p . Of course, if C ( q ) turns out to be lexicographically smaller, then p becomes the Leader.Suppose now that there are k = 3 candidate leaders p , p , and p . Leteach candidate p i know the neighborhood code C ( q i ) of some particle q i inits tree. As in the previous case, each candidate leader sends its code tothe other two. When a candidate leader knows all three codes, it comparesthem. Without loss of generality, assume that C ( q ) ≤ C ( q ) ≤ C ( q )(lexicographically). There are three cases: • If C ( q ) < C ( q ), then p becomes the unique Leader particle. p and p cease to be candidate leaders and become children of p . • If C ( q ) = C ( q ) and C ( q ) < C ( q ), then p becomes the uniqueLeader particle. p and p cease to be candidate leaders and becomechildren of p . • Otherwise, the three codes are equal, and the symmetry-breaking at-tempt fails.
Main leader election algorithm.
If there is only one candidate leader in P , it becomes a Leader particle, and the leader election phase ends there.So, let us assume that P contains k = 2 or k = 3 pairwise adjacent candidateleaders.Each candidate leader p i starts by sending its own neighborhood code C ( p i ) to the other candidate leaders, and the basic election procedure ex-plained above is executed. If a Leader particle is elected, the phase ends.If the election attempt fails, p i asks its first child p (cid:48) i to fetch the neigh-borhood codes of the first particle in its subtree (i.e., p (cid:48) i itself). When p i obtains this code, it uses it for another election attempt procedure. If theattempt fails, p i asks p (cid:48) i for the code of another particle in its subtree, etc.When p (cid:48) i has exhausted its entire subtree, it sends a Subtree-Exhausted message to p i , which proceeds to querying its second child, and so on.In turn, p (cid:48) i and all other internal particles of the trees act similarly. Whensuch a particle is instructed by its parent to fetch the neighborhood codes ofthe particles in its subtree, its starts with its own code, then queries its fist34hild, and the process continues recursively at all levels of the tree. Whenthere are no more particles to query in the subtree, the particle sends aSubtree-Exhausted message to its parent.If the candidate leader p i receives a Subtree-Exhausted message fromits last child, and no leader has been elected, then p i becomes a Leaderparticle (as we will see in Theorem 6, this means that S is unbreakably k -symmetric). Canonical order of children.
For this algorithm to work properly, wehave to define a canonical order in which a particle p queries its children fortheir codes.If p is a candidate leader, its base neighbor is defined as the uniquecandidate leader located in a vertex v such that the port label ( (cid:96) ( p, v ) + 1)mod 6 does not correspond to a vertex occupied by another candidate leader.If p is not a candidate leader, then its base neighbor is defined to be itsparent.The canonical order of the children of p is the order in which they arefound as p scans its neighbors in clockwise order starting from its baseneighbor. The “clockwise order” is defined according to the handedness ofthe candidate leaders, which p is supposed to know, due to Theorem 5. Synchronization.
There is one last addition to make to the above protocol,which pertains to synchronization. Recall that, when a candidate leader p obtains a code C ( q ) from one of the particles in its tree, it sends it to theother candidate leaders. Then, p waits until it has obtained codes from allother candidate leaders. Suppose that another candidate leader p obtainsthe code C ( q ) of a particle in its tree some stages after p . So, p sends C ( q ) to p and receives C ( q ) from it. Now p has all the codes it needs,and it executes the election procedure, failing to elect a leader. Therefore, p obtains a new code C ( q (cid:48) ) from another particle, and sends it to the othercandidate leaders, including p . However, as p was operating, the schedulermay have kept p inactive: as a result, the message containing C ( q ) wasoverwritten by the one containing C ( q (cid:48) ) before p was able to read it. When p is activated again, it compares C ( q ) with C ( q (cid:48) ) (instead of C ( q )), andit behaves incorrectly.To avoid this desynchronization problem, we put a counter modulo 2 (i.e.,a single bit) in the internal memory of each candidate leader. Whenever acandidate leader obtains a new code C ( q ) from a particle in its tree, itincrements the counter modulo 2 and it attaches its value to C ( q ) beforesending it to the other candidates.Now, if a candidate leader p receives a code with an unexpected counter35it from another candidate p , it implicitly knows that the previous electionattempt has failed. In that case, p obtains a new code from another particlein its tree, and proceeds with the protocol as usual.On the other hand, if a leader is elected, there are no particular prob-lems: as soon as a candidate leader p realizes that an election procedurehas succeeded, it transitions to the next phase, and communicates this in-formation to the other candidate leaders, as explained at the beginning ofSection 3. While doing so, p also adds information on who the Leader parti-cle is, so that the other candidate leaders can change their internal variablesconsistently, even if they have failed to receive the last code from p . Correctness.Theorem 6.
Let P be the system resulting from Theorem 5, forming a shape S . If all particles of P execute the leader election phase of the algorithm,then there is a stage s , reached after O ( n ) rounds, where one of the twofollowing conditions holds: • There is a unique Leader particle in P , which is the root of a well-defined spanning tree of P . • There are k = 2 or k = 3 mutually adjacent Leader particles in P ,and S is unbreakably k -symmetric. Each Leader particle is the rootof a well-defined tree: these k trees collectively form a spanning forestof P whose plane embedding has a k -fold rotational symmetry aroundthe center of S .At stage s , all non-Leader particles are non-Eligible. No particle moves inthis phase.Proof. Assume there are k = 2 or k = 3 candidate leaders at the beginningof this phase, because otherwise the theorem is trivial. Let c be the centerof the subsystem formed by the Candidate particles, and let ρ be the k -foldrotation around c .It is easy to prove by induction that the candidate leaders perform severaltentative election procedures, each time with the neighborhood code of anew particle in their respective tree, until a Leader is elected or no moreparticles are left in the tree of some candidate leader. Moreover, the fact thatall particles agree on the clockwise direction, the way the canonical orderof children is defined, and the information contained in the neighborhoodcodes imply that the candidate leaders will always compare the codes ofparticles that are symmetric under ρ , until asymmetric particles are found.36o, a Leader particle will definitely be elected if there are two particlesin the trees of two different candidate leaders whose neighborhoods are notsymmetric under ρ . This necessarily happens if the trees of the spanningforest are not symmetric under ρ (and it happens before a candidate leaderruns out of particles in its tree). If the trees are symmetric, then in partic-ular they have the same size, and S is unbreakably k -symmetric. In thiscase, particles that are symmetric under ρ may still produce different codes(because, in general, their codes are “rotationally equivalent”, but not nec-essarily identical), which results in the election of a Leader. Otherwise, allelection attempts will fail, the candidate leaders will run out of particles atthe same time, and they will all become Leaders.Since the phase terminates after O ( n ) election attempts, each of whichlasts O ( n ) rounds, the whole phase takes O ( n ) rounds. At the beginning of this phase, there are k = 1, k = 2, or k = 3 Leaders,each of which is the root of a tree of particles. These k trees are rotatedcopies of each other, and the Leaders are pairwise adjacent.The goal of each Leader is to coordinate the “straightening” of its tree.That is, in the final stage of this phase, the system must form k straight linesegments, each of which has a Leader located at an endpoint. Moreover,if k >
1, each Leader must also lie on the extension of another of the k segments. Choosing the directrices.
Each Leader p i will choose a ray in the plane(i.e., a half-line) as its directrix γ i . By the end of the straightening phase,all particles will be located on these k directrices.If k = 1, the unique Leader p arbitrarily chooses a neighboring vertex v , and picks the ray from p through v as its directrix γ .If k = 2, there are two adjacent Leaders p and p . p chooses itsneighbor v that is opposite to p , and the ray from p through v is itsdirectrix γ . On the other hand, p chooses the symmetric ray as its directrix γ . If k = 3, there are three pairwise adjacent Leaders p , p , and p . EachLeader p i picks its “left” neighboring Leader p j (according to its handed-ness), and lets v i be its neighboring vertex that is opposite to p j . Then, p i defines its directrix γ i to be the ray from p i through v i . Since the Lead-ers have the same handedness (see Theorem 5), their three directrices arepairwise disjoint and form angles of 120 ◦ with each other.37 asic pulling procedure. For this sub-protocol, we assume to have a lin-early ordered chain of particles Q ⊆ P , the first of which is called the Pioneer particle. Each particle of Q except the Pioneer has a unique Predecessor in Q , located in an adjacent vertex of G D . Similarly, each particle except thelast one has a unique Follower in Q , located in an adjacent particle. Allparticles of Q are initially contracted.Say the Pioneer particle q intends to move into a neighboring unoccupiedvertex v , which is called its destination . The pulling procedure will make q move into v , and will subsequently make each Follower move into the vertexpreviously occupied by it Predecessor. At the end of the procedure, theparticles of Q will still form a chain with the same Follower-Predecessorrelationships, and all particles will be contracted.To begin with, q sends a Follow-Me message to its Follower q (cid:48) , and thenit expands toward v and contracts again in v . q (cid:48) will read the message from q and will send a similar Follow-Me message to its Follower q (cid:48)(cid:48) . Then, assoon as q (cid:48) sees that the original location of q is empty, it expands toward itand contracts again.The procedure continues in this fashion until the last particle of Q hasmoved and contracted into its Predecessor’s original location. At this point,the last particle sends a Movement-Done message to its Predecessor, whichreads it and forwards it to its Predecessor, and so on. When the Pioneerreceives a Movement-Done message, the procedure ends.
Main straightening algorithm.
The idea of this phase is that each Leader p i will identify a directrix γ i (as explained above), and a Pioneer q i willwalk along γ i , pulling particles onto it from the tree T i of p i (executing thepulling procedure described above). While the Pioneer is doing that, theLeader remains in place, except perhaps for a few stages, when it is part ofa chain of particles that is being pulled by the Pioneer. Eventually, all theparticles of T i will form a line segment on the directrix, and the Leader willbe at an endpoint of such a segment, opposite to the Pioneer.If q i encounters another particle r on γ i , belonging to some tree T j , it“transfers” its role to r , and “claims” the subtree T (cid:48) j of T j hanging from r ,detaching r from its parent. The next time the new Pioneer r has to pull achain of particles, it will pull it from T (cid:48) j . For this reason, r is called an entrypoint of the directrix. This algorithm is summarized in Figure 6.Every time a Pioneer advances along its directrix, it notifies its Leader,who will synchronize with the other Leaders. This is to ensure that thestraightening of every tree proceeds at the same pace.Technically, a Pioneer is identified by an internal Pioneer flag, and an38 γ γ γ (a) Each Pioneer is obstructed by a particleon its directrix. γ γ γ (b) The obstructing particles detach fromtheir Parents and become the new Pioneers. γ γ γ (c) Each new Pioneer pulls a chain of parti-cles from the closest entry point. Figure 6: Three stages of the straightening phase. The particles in gray arethe Leaders; the ones in white are the Pioneers. The edges of the spanningforest are drawn in dark gray, and the arrows indicate where the particlesare directed in the pulling procedure.39ntry point is identified by an
Entry-Point flag. Both flags are initially notset. As the phase starts, each Leader sets its own Pioneer and Entry-Pointflags. Then, the following operations are repeated until the end of the phase. • The algorithm works in steps : when a Leader decides to start a newstep, it sends a
Pull message to the next particle on its directrix.This message is forwarded by the particles along the directrix, until itreaches the Pioneer (of course, if the Leader and the Pioneer are thesame particle, no message is actually sent). • When the Pioneer q receives the Pull message, it looks at the next ver-tex v along the directrix (i.e., in the direction opposite to the Leader).Suppose first that v is occupied by a (contracted) particle r . – q sends a You-are-a-Pioneer message to r and clears its ownPioneer flag. – r reads the message and becomes a Pioneer. If r has children, italso sets its own Entry-Point flag, becoming an entry point. – r informs its parent r (cid:48) that it is no longer its child, and erases itsown Parent variable. – r (cid:48) modifies its internal variables accordingly and sends a messageback to r . – When the new Pioneer r receives this message, it proceeds withthe algorithm. • Suppose now that v (i.e., the next vertex along the directrix) is unoc-cupied. – The Pioneer q starts executing the pulling procedure with desti-nation v . – When q reaches v , it makes sure that its Entry-Point flag is notset. – When the Follow-Me message that is forwarded along the direc-trix reaches the first entry point e (possibly, e is the Pioneeritself), e forwards the message to its first child according to thecanonical order defined in Section 3.4. Similarly, whenever a par-ticle in the subtree T hanging from e receives a Follow-Me mes-sage from its parent, it forwards it to its first child according tothe canonical order. 40 When e moves, it also clears its Entry-Point flag and sends a You-are-an-Entry-Point message to its Follower e (cid:48) (i.e., its firstchild). – If e (cid:48) has children, it sets its own Entry-Point flag upon receivingthis message. Otherwise, e (cid:48) does not become an entry point, andclaims the next particle on the directrix as its Follower (if such aparticle exists). – If e is a Leader, it clears its Leader flag, while e (cid:48) sets its own andbecomes the new Leader. – When a particle t of T sends a Follow-Me message to its first child t (cid:48) , it also attaches its neighborhood code C ( t ) to the message, asdefined in Section 3.4. t (cid:48) memorizes the code. – When t (cid:48) moves to take the place of t , it updates its internalvariables according to C ( t ). Of course, if t (cid:48) was a leaf of T , itdoes not include its previous location in the list of its children. – When a leaf of T moves to take the place of its Predecessor,it sends a Movement-Done message to its parent, which is for-warded to the Pioneer. When the Pioneer receives the message,it proceeds with the algorithm. • The Pioneer sends a
More-Entry-Points? message along its directrix,which is forwarded by the particles lying on it, until it reaches theLeader. • As the particles (including the Pioneer) forward the More-Entry-Points?message, they add information to it, i.e., they set a flag in the messageif they are entry points of the directrix. • When the Leader reads the More-Entry-Points? message, it knows ifthe phase is over (i.e., there are no more entry points on its directrix),or if it has to start another step (i.e., the Pioneer has to pull moreparticles). • If the phase is not over, the Leader p synchronizes with the otherLeaders (of course, if k = 1, this step is skipped). If any of the otherLeaders is not found in its usual position (because it is still executinga pulling procedure and is being replaced by a new Leader), p waitsfor the new Leader to appear. The actual synchronization is doneby exchanging Next-Straightening-Step messages, together with thevalue of a counter modulo 2, as described in the “Synchronization”41aragraph of Section 3.4. When p receives such messages from allother Leaders, its starts the next step. Correctness.Theorem 7.
Let P be the system resulting from Theorem 6, with k Leaderparticles. If all particles of P execute the straightening phase of the algo-rithm, then there is a stage, reached after O ( n ) rounds, where all particlesare contracted, the k Leaders are pairwise adjacent, and the system forms k equally long straight line segments, each of which has a Leader located at anendpoint. Moreover, if k > , each such segment has a second Leader lyingon its extension. In this phase, at most O ( n ) moves are performed in total.Proof. Suppose that k >
1. By assumption, as the phase starts, the span-ning forest of P is symmetric under a k -fold rotation of the plane. Also,each tree of the forest is attached to a directrix by an entry point (initially,only the Leaders are entry points). We can easily prove by induction thatthese properties are preserved after each step of the algorithm.This is because the k Leaders wait for each other at the end of everystep, until they are all ready to start the next step. Moreover, if a Pioneerencounters a vertex occupied by a particle r on its directrix, then so doall other Pioneers, and vice versa. Additionally, the subtree hanging from r is symmetric to the ones that are hanging from the particles that areencountered by the other k − r becomes an entry point, the tree to which it belongssplits in two, because r is detached from its parent, and the whole subtreehanging from r is attached to the directrix, as r becomes a new entry point.However, this keeps the structure connected.On the other hand, when a pulling procedure is executed, all the particlesin the chain that belong to a tree choose their Follower according to thecanonical order of their children. Hence, as k pulling procedures are executedby the k Pioneers and their chains during a step, symmetric particles ondifferent chains move in symmetric ways, and the overall symmetry of thesystem is preserved. Again, this keeps the structure connected.Because of this symmetry, no conflicts between different Pioneers canever arise. For instance, it is impossible for a leaf f of a tree to be pulledalong the chain led by a Pioneer while another Pioneer is sending a You-are-a-Pioneer message to f . Also, the k pulling procedures that are executed inthe same step involve disjoint chains: indeed, the k directrices are disjoint,and the subtrees hanging from different entry points are disjoint.42lso observe that, even as the chains move, no messages are ever lost.This is because, at any time, at most k independent pulling procedures arebeing executed. In each pulling procedure, every time a message is sent,the addressee is a still and contracted particle that necessarily receives andreads the message as soon as it is activated. Additionally, if a Leader is notin place because it is being substituted by its Follower, the other Leaders donot send synchronization messages its way, but wait until the new Leader isin position.Hence, each step correctly terminates and results in the advancement ofevery Pioneer and the addition of a new particle to every directrix. If theLeaders order the beginning of a new step, it is because the More-Entry-Points? messages have revealed the presence of more entry points on thedirectrices. The straightening phase only ends when no more entry pointsare found: since the structure is connected, this means that all particles areindeed aligned on the directrices, forming k line segments. By the symmetryof the system, these line segments must have the same length.To prove that at most O ( n ) moves are made in total, observe that eachpulling procedure causes a new particle to join the portion of a directrixlocated between a Leader and a Pioneer. The particles located in this portionnever leave the directrix, but only move along it. So, at most n pullingprocedures are performed. Also, each pulling procedure involves at most n particles, and causes each of them to perform a single expansion and asingle contraction. Since no other moves are made by the system, the O ( n )bound follows.Similarly, since a pulling procedure is completed after O ( n ) rounds, thewhole straightening phase takes O ( n ) rounds. At the end of the straightening phase, the system forms k equally long linesegments, arranged as described in Theorem 7, each of which contains aLeader particle. If k >
1, it means that the shape S that the particles orig-inally formed was unbreakably k -symmetric, as Theorems 3–7 summarize.Due to Theorem 1, if this is the case, we have to assume that the “finalshape” S F that the system has to form is also unbreakably k -symmetric.Recall that a representation of S F is given to all the particles as input,and resides in their internal memory since the first stage of the execution.For the purpose of the universal shape formation algorithm, we assume thesize of S F to be a constant with respect to the number of particles in thesystem, n (cf. Section 2). Also, we may assume S F to be a minimal shape: if43t is not, the particles replace its representation with that of a minimal shapeequivalent to S F , which has a smaller size and is readily computable. Finally,since the handedness agreement phase has been completed, all the particlescan be assumed to have the same handedness (see Theorem 5). Without lossof generality, we assume that their notion of clockwise direction coincideswith the “correct” one, i.e., the one defined by the cross product of vectorsin R .The goal of the role assignment phase is twofold: • The particles determine the scale of the shape S (cid:48) F , equivalent to S F ,that they are going to form. Indeed, if n is large enough, there is ascaled-up copy of S F that can be formed by exactly n particles, keepingin mind that, in the final configuration, particles can be contracted orexpanded. • Each particle is assigned a constant-size identifier, describing whichelement of S F (i.e., a vertex, the interior of an edge, or the interiorof a triangle) the particle is going to form in the shape compositionphase. Recall that we are assuming S F to be composed of a constant(i.e., independent of n ) number of triangles and edges, in accordanceto the definition of universal shape formation (see Section 2). The sizeof the identifier is proportional to the size of S F , and can therefore bestored in a single particle’s internal memory. Subdividing the final shape into elements.
Recall that a shape is theunion of finitely many edges and faces of G D . Of course, all edges of G D have length 1, and all faces of G D are equilateral triangles of side length 1.Let the final shape S F be of the form S F = e ∪ · · · ∪ e j ∪ t ∪ · · · ∪ t j (cid:48) , wherethe e i ’s are edges of G D and the t i ’s are (triangular) faces of G D .Let S (cid:48) F be a shape equivalent to S F . By Lemma 1, the scale of S (cid:48) F is apositive integer λ (recall that S F is minimal). That is, there is a similaritytransformation σ : R → R such that σ ( e i ) is a segment of length λ (i.e., itis the union of λ consecutive segments of G D ) contained in S (cid:48) F and σ ( t i ) isan equilateral triangle of side length λ contained in S (cid:48) F .Let B be the set of vertices of G D that are contained in S (cid:48) F . We partition B into three families of elements as follows: • If v is a vertex of G D contained in S F , then σ ( v ) constitutes a super-vertex of S (cid:48) F . • For every e i , the vertices of G D that are contained in σ ( e i ) and arenot super-vertices of S (cid:48) F constitute a super-edge of S (cid:48) F . Similarly, for44very side s of every triangle t i , the vertices of G D that are containedin σ ( s ) and are not in a super-vertex of S (cid:48) F constitute a super-edge of S (cid:48) F . • For every t i , the vertices of G D that are contained in σ ( t i ) and arenot super-vertices of S (cid:48) F or contained in super-edges of S (cid:48) F constitutea super-triangle of S (cid:48) F .Observe that every super-vertex of S (cid:48) F is a vertex of G D , every super-edgeof S (cid:48) F is a set of λ − G D , and every super-triangleof S (cid:48) F is a set of ( λ − λ − / G D whose convex hull is anequilateral triangle of side length max { , λ − } .There is a small exception to our previous definition of element. Supposethat the system executing the role assignment phase has k > S F is unbreakably k -symmetric. Suppose that S (cid:48) F is unbreakably k -symmetric, as well: so, by Lemma 3, λ is not a multiple of k . Finally,suppose that S (cid:48) F contains its own center. We have two cases: • If k = 2, then the center of S (cid:48) F is located in the midpoint of a super-edge e consisting of an even number of vertices of G D (see Figure 7a).So, e is divided by its midpoint into two partial super-edges e (cid:48) and e (cid:48)(cid:48) .In this case, e is not an element of S (cid:48) F , but e (cid:48) and e (cid:48)(cid:48) are. • If k = 3, then the center c of S (cid:48) F is located in the center of a super-triangle t consisting of a number of vertices of G D that is a multipleof 3 (see Figure 7b). Let v , v , v be the vertices of t , taken incounterclockwise order. Let ζ be the ray emanating from c in thedirection of the vector −−→ v v , and let ζ (cid:48) and ζ (cid:48)(cid:48) be the two rays emanatingfrom c and forming angles of 120 ◦ with ζ . These three rays partition t into three symmetric partial super-triangles t (cid:48) , t (cid:48)(cid:48) , and t (cid:48)(cid:48)(cid:48) (note thatno vertex of G D lies on any of these rays). In this case, t is not anelement of S (cid:48) F , but t (cid:48) , t (cid:48)(cid:48) , and t (cid:48)(cid:48)(cid:48) are.Observe that the set ζ ∪ ζ (cid:48) ∪ ζ (cid:48)(cid:48) has a 3-fold rotational symmetry, and so doesthe partition of t into the elements t (cid:48) , t (cid:48)(cid:48) , and t (cid:48)(cid:48)(cid:48) . Given t , different particlesmay disagree on which vertex is v and which vertex is v , and thus theymay disagree on the orientation of ζ . However, since all particles have thesame handedness, they agree on the clockwise direction: so they agree on ζ ∪ ζ (cid:48) ∪ ζ (cid:48)(cid:48) , and therefore also on the partition of t into elements.We denote by m v the number of super-vertices of S (cid:48) F , by m e the numberof its super-edges, and by m t the number of its super-triangles. Of course,these numbers are independent of the scale of S (cid:48) F , and only depend on S F .45 γ γ β β (a) An unbreakably 2-symmetric shape with scale 5 with aminimal equivalent shape consisting of two adjacent facesand two dangling edges β ′ β ′ β β β ′ β γ γ γ (b) An unbreakably 3-symmetric shape with scale 13 with aminimal equivalent shape consisting of a single face Figure 7: Subdivision into elements (gray blobs) of unbreakably k -symmetricshapes. The directrices, the backbone, and the co-backbone are also repre-sented.By definition, forming S (cid:48) F means occupying all vertices of B with par-ticles. This is equivalent to forming all super-vertices, all (partial) super-edges, and all (partial) super-triangles of S (cid:48) F , i.e., all the elements of S (cid:48) F . Combinatorial adjacency between elements.
For the next part of the46lgorithm, we have to define a symmetric combinatorial adjacency relationbetween elements of S (cid:48) F . This is slightly different from the relation inducedby the neighborhood of the vertices of G D that constitute the elements.The combinatorial adjacency rules are as follows: • A super-vertex located in a vertex v of G D and a (partial) super-edge e are combinatorially adjacent if e has an endpoint that neighbors v . • A (partial) super-edge e and a (partial) super-triangle t are combina-torially adjacent if every vertex of G D that is in e has a neighbor in t .Note that this relation induces a bipartite graph on the elements of S (cid:48) F :combinatorial adjacency only holds between a (partial) super-edge and asuper-vertex or a (partial) super-triangle, and never between elements ofthe same kind or between super-vertices or (partial) super-triangles. Subdividing the elements among Leaders.
Suppose that there are k > S (cid:48) F (similar to S F ) is unbreakably k -symmetric.We are going to show how each Leader selects the elements of S (cid:48) F that theparticles on its directrix will form in the shape composition phase. Theresult of this selection is exemplified in Figure 8.Let σ be a similarity transformation that maps S F to S (cid:48) F , and let c bethe center of S F . We will assume the scale of S (cid:48) F to be λ ≥ k rays, called the backbone of S (cid:48) F (see Figure 7).The backbone is an important structure that will be used extensively in theshape composition phase of the algorithm. Additionally, if k = 3, we willalso define a co-backbone of S (cid:48) F , which is another set of k rays that will onlybe used in the present paragraph. The definitions are as follows. • If k = 2, then c is located in the midpoint of an edge e of G D . Let v and v be the endpoints of the segment σ ( e ). One ray β of thebackbone is defined as the ray emanating from v in the directionopposite to v . The other ray β of the backbone emanates from v inthe direction opposite to v . • If k = 3, then c is located in the center of a triangular face t of G D . Let v , v , v be the vertices of the triangle σ ( t ), taken in counterclockwiseorder. One ray β of the backbone is defined as the ray emanatingfrom v in the direction opposite to v . Similarly, the second ray β emanates from v in the direction opposite to v , and the third ray β emanates from v in the direction opposite to v .47he first ray β (cid:48) of the co-backbone is obtained by translating β by 2in the direction parallel to the vector −−→ v v . Similarly, the second ray β (cid:48) is obtained by translating β by 2 in the direction parallel to thevector −−→ v v , and the third ray β (cid:48) is obtained by translating β by 2 inthe direction parallel to the vector −−→ v v .Suppose that there is a bijection between Leader particles and rays ofthe backbone upon which all particles agree. Without loss of generality, letus say that the Leader p i “claims” the ray β i of the backbone of S (cid:48) F , for1 ≤ i ≤ k . If k = 3, the Leader p i also claims the ray β (cid:48) i of the co-backbone.Now, each Leader p i selects the elements of S (cid:48) F that are fully contained inits own ray β i of the backbone. If k = 3, then p i also selects the elements of S (cid:48) F that have a non-empty intersection with its own ray β (cid:48) i of the co-backbone(recall that λ ≥
4, hence the super-edges consist of at least two points, andthe super-triangles consist of at least one point). Furthermore, p i selectsthe unique partial super-edge or partial super-triangle of S (cid:48) F (depending onwhether k = 2 or k = 3) that is closest to β i .Then, each Leader repeatedly selects an element of S (cid:48) F that is combina-torially adjacent to an element that it has already selected and that has notbeen selected by any Leader, yet. While doing so, it makes sure that, if ithas selected a super-vertex located on the backbone, then it also selects a(partial) super-edge that is combinatorially adjacent to it (in other words,there must be no “isolated” super-vertices in its selection). It is easy to seethat selecting elements in this fashion is always possible.The actual selection algorithm is not important, as long as it is deter-ministic and only depends on the combinatorial adjacency relation betweenelements of S (cid:48) F . Note that, since the algorithm is deterministic and S (cid:48) F isrotationally symmetric, the selections that the Leaders make are symmetric,too. In particular, the Leaders agree on each other’s selections, and even-tually S (cid:48) F is divided into k symmetric regions, each belonging to a differentLeader.Recall that S F has constant size, and hence S (cid:48) F has a constant numberof elements inducing a combinatorial adjacency relation of constant size. Ifthe selection algorithm only depends on the combinatorial structure of theelements of S (cid:48) F and on their local spatial layout (e.g., how different super-edges adjacent to the same super-vertex are laid out around it), then thealgorithm can be executed internally by any particle in a single stage, evenwith its limited memory capabilities. Turing machine analogy.
Let us focus on a single directrix. As the phaseproceeds, the Leader of this directrix will “walk” along it, “updating” the48 β ′ β ′ β β β ′ β Figure 8: The elements of an unbreakably 3-symmetric shape with a possi-ble subdivision among leaders. Blobs of the same color represent elementsselected by the same leader.states of the particles it encounters. Obviously, the Leader cannot physicallymove through another particle, but it will rather send it an
I-am-Moving-to-your-Location message. Then, the Leader will clear its own Leader flag,and the particle that receives the message will set its own. In other words,particles stay still, and the leadership is transferred from a particle to aneighboring one along the directrix.Additional information can be attached to the I-am-Moving-to-your-Location message, containing a constant-size “virtual internal state” of theLeader. So, a particle that is hosting the Leader has its own internal state49as usual), but can also access and update the virtual internal state of theLeader (through an exchange of messages). In the following, to help intu-ition, we will pretend that the Leader is not a virtual particle with a virtualstate, but a special particle with its own state that can walk through otherparticles.As the Leader walks along the directrix, it updates its own internal state,as well as the states of the particles it encounters, much like the head of aTuring machine does as it scans the cells of a tape. So, using the states ofthe particles located on the directrix, the Leader can compute any functionthat is computable by a deterministic Turing machine on an blank tapeof n/k cells. This already gives the Leader an arsenal of subroutines andtechniques with which it can operate on the states of the particles.Say that the Leader wants to perform the same operation on a row of j particles, where j is too large to be stored in the Leader’s internal memory.Suppose that the Leader has already constructed a representation of j , suchas a binary code that fits in the states of the first O (log j ) particles of thedirectrix. Then, the Leader can come back and decrement this number everytime it operates on a particle. When the counter reaches 0, the Leader knowsit has to stop.With this technique, the Leader can also “shift” the states of an entirerow of j particles by j (cid:48) positions to the left or to the right along the directrix,provided that the numbers j and j (cid:48) are represented in binary in the statesof a few particles. It can “swap” the states of two rows of j particles, etc.If the Leader has represented two numbers a and b in binary, it can easilycompute the binary representation of their sum or their product with stan-dard techniques, provided that the total number of particles on the directrixis at least O (log( a + b )). Furthermore, given the representation of a num-ber x , the Leader can compute any polynomial function of x with constantcoefficients, provided that there are O (log( x )) particles on the directrix. Linearization of the elements.
In the role assignment phase, the par-ticles will use a new internal variable, called
Role , whose initial value is
Undefined . By the end of the phase, each particle will have a well-definedRole. Assigning a Role to a particle essentially means telling the particlewhich element of S (cid:48) F it will contribute to forming in the shape compositionphase. Once a Leader has selected a set of elements of S (cid:48) F , it will “label”each such element with a unique identifier. Since the number of elementsis bounded by a constant, the Leader can memorize the correspondence be-tween identifiers and elements in its internal memory. Then, it will put anidentifier in the Role variable of each particle on its directrix, thus effectively50ssigning each particle an element. The way in which the Leader labels el-ements is deterministic: so, if the particles have the same representation of S F in memory, they implicitly agree also on the labeling of the elements of S (cid:48) F .The particles that are given the same element identifier will all be con-tiguous along the directrix: they will form a chunk . Chunks can be laid outin any order along a directrix, and can then be moved around and sortedwith the general techniques outlined above.Say that the scale of S (cid:48) F is λ . Then, the sizes of the chunks are as follows: • Each chunk corresponding to a super-vertex consists of a single parti-cle. • Each chunk corresponding to a super-edge consists of λ − • Each chunk corresponding to a super-triangle consists of ( λ − λ − / • The chunk corresponding to a partial super-edge consists of ( λ − / k = 2: so S F must be unbreakably 2-symmetric,and we assume λ to be odd (cf. Lemma 3). • The chunk corresponding to a partial super-triangle consists of ( λ − λ − / k = 3: so S F must be unbreakably3-symmetric, and we assume λ not to be a multiple of 3 (cf. Lemma 3).If we fix S F and we fix k , then the Leader has to assign super-vertexidentifiers to a constant number m v /k of particles, super-edge identifiers to( m e /k ) · ( λ −
1) particles (where m e /k is a constant), super-triangle identifiersto ( m t /k ) · ( λ − λ − / m t /k is a constant), plus perhapsthe identifiers corresponding to one partial super-edge or one partial super-triangle.For a fixed S F and a fixed k , the number of particles needed, as a functionof λ , is a second-degree polynomial function P ( λ ) = aλ + bλ + c , for someconstants a , b , c that can be easily computed from S F as linear expressionsof m v , m e , and m t . For instance, a = m t / (2 k ) if there is no partial super-triangle among the elements, and a = m t / P (cid:48) ( λ ) = b (cid:48) λ + c (cid:48) , for some constants b (cid:48) and c (cid:48) , which are again linear expressions of m v , m e , and m t . 51 ain role assignment algorithm. For the following algorithm to work,we assume the number of particles in the system, n , to be large enoughcompared to the base size of S F , which is a constant m . As we will show inTheorem 8, n has to be at least Θ( m ). An explicit multiplicative constantfor this Θ( m ) bound could be computed from the polynomials P ( λ ) and P (cid:48) ( λ ) defined above.We will focus on a single directrix, and thus we will describe the opera-tions of a single Leader. Of course, all Leaders in the system will do similaroperations on their respective directrices.The goal of the Leader is to find an appropriate scale λ for the shape S (cid:48) F , equivalent to S F , that the particles will form in the shape compositionphase. If P ( λ ) is smaller than n/k (i.e., the number of particles on thedirectrix), then the particles will not be able to fit in S (cid:48) F ; if P ( λ ) is toolarge, then there will not be enough particles to form S (cid:48) F . Of course, theremay not be a λ such that P ( λ ) is exactly n/k , but recall that some particlescan be expanded in the final configuration: this gives the system the abilityto roughly double the area it can occupy. For this reason, each particle hasa flag called Double , which is set if and only if the particle is going to beexpanded in the final configuration.As a first thing, the Leader converts the number n/k in binary, by simplyscanning every particle on its directrix and incrementing a binary counterevery time it reaches a new particle. This binary number is stored in thefirst O (log n ) particles on the directrix: each particle remembers one digit.Then, the Leader sets λ = 7, representing the binary number 7 in thestates of the first three particles on the directrix (these particles will thereforehave to remember two binary digits: one for λ and one for n/k ). Then itcomputes P ( λ ), again in binary, with standard multiplication and additionalgorithms. The result is again stored in the first particles on the directrix.This number is compared with n/k : if n is large enough, we may assumethat n/k > P (7), and so the computation continues.Since the current estimate of λ is too small, the Leader increments itsbinary representation by 6, so as to keep it from being a multiple of 2 orof 3, in accordance to Lemma 3 (if the scale of S (cid:48) F is a multiple of k , then S (cid:48) F is not unbreakably k -symmetric, and the system is unable to form it).The Leader repeats the above steps on this new λ , thus computing P ( λ ) andcomparing it with n/k . If P ( λ ) is still too small, the Leader increments λ by6 again, and so on. Observe that the Leader has enough space to compute P ( λ ), because it only needs a logarithmic amount of particles, which areabundantly available if n is greater than a (small) constant.Eventually, the Leader finds the first λ such that P ( λ ) ≥ n/k : this will be52he final scale of S (cid:48) F . The Leader also computes d = P ( λ ) − n/k , which is thenumber of particles that will have to be expanded in the final configuration.So, it sets the Double flag of the last d particles on the directrix: this isequivalent to converting the binary representation of d in unary. As wewill show in Theorem 8, if n is large enough, there are enough particles tocomplete this operation. As a result, d particles have the Double flag setand s = n/k − d = 2 n/k − P ( λ ) particles do not. Note that s + 2 d = P ( λ ):so, if each Double particles occupies two locations in the final configuration,the system covers an area equal to that of S (cid:48) F .Now that the Leader has determined the scale λ of S (cid:48) F , it has to subdividethe particles into chunks and assign Role identifiers to all of them. Note thatthe Leader still has a binary representation of λ stored in the states of thefirst O (log λ ) particles, and so it will be able to use it to count. As explainedbefore, the Leader can easily compute the amount of particles that it has toput in the same chunk, because this is a polynomial function of λ that onlydepends on whether the chunk corresponds to a super-vertex, a (partial)super-edge, or a (partial) super-triangle.The only thing the Leader has to decide is the order in which to arrangethe chunks. It begins by assigning the m v /k identifiers corresponding tosuper-vertices of S (cid:48) F to the first m v /k particles on the directrix. Then, ifthere is a partial super-edge among the elements of S (cid:48) F , the Leader assignsthe corresponding identifier to the next ( λ − / m e /k super-edges. If there is a partialsuper-triangle among the elements of S (cid:48) F , the Leader places its chunk rightafter the super-edges. Finally, it places all the chunks corresponding tothe m t /k super-triangles. As m v + m e + m t is bounded by a constant, theLeader can keep track of what identifier it has to assign next by using justits internal memory.Since the Double particles are the last ones on the directrix, they aremore likely to be found in super-triangle chunks. Actually, as we will showin Theorem 8, if n is large enough, all Double particles will belong to (partial)super-triangle chunks, while the (partial) super-edge chunks and the super-vertex chunks will have no Double particles. The only exception is the casein which S F has no triangles, and so no element of S (cid:48) F is a (partial) super-triangle. In this case, if n is large enough, all Double particles will be in thesame super-edge chunk. Correctness.Theorem 8.
Let P be the system with k Leader particles resulting fromTheorem 7, and let all particles of P execute the role assignment phase of he algorithm with input a representation of a final shape S F of constant basesize m . If k > , we assume that S F is unbreakably k -symmetric. Then, if n is at least Θ( m ) , there is a stage, reached after O ( n ) rounds, where allparticles have a Role identifier. Moreover, if S F has at least one triangle,then all the Double particles have Role identifiers corresponding to (partial)super-triangles; if S F consists only of edges, then all the Double particles onthe same directrix have a Role identifier corresponding to the same (partial)super-edge. No particle moves in this phase.Proof. Let us first assume that S F has some triangles, and so m t > λ is the scale of S (cid:48) F computed by the Leader, then exactly2 n/k − P ( λ ) particles do not have the Double flag set. We want theseparticles to include all the super-vertex chunks and the (partial) super-edgechunks, which in turn consist of P (cid:48) ( λ ) particles in total. This is true if andonly if 2 n/k − P ( λ ) ≥ P (cid:48) ( λ ), which is equivalent to2 nk ≥ P ( λ ) + P (cid:48) ( λ ) . (1)If λ is the scale on which the Leader has stopped, it means that λ − n/k > P ( λ − P ( λ − ≥ P ( λ ) + P (cid:48) ( λ ) . (2)Recall that P ( λ ) = aλ + bλ + c , where the coefficients a , b , c are linearexpressions of m v , m e , and m t . To express this fact, we can write a = A ( m v , m e , m t ), b = B ( m v , m e , m t ), and c = C ( m v , m e , m t ), where A , B , C are linear functions. So, P = A · λ + B · λ + C , where for brevity we haveomitted the arguments of A , B , C . Similarly, we have P (cid:48) ( λ ) = B (cid:48) · λ + C (cid:48) .Note that P ( λ −
6) = A · λ + B (cid:48)(cid:48) · λ + C (cid:48)(cid:48) , where the leading coefficientis the same as the one in P ( λ ), and B (cid:48)(cid:48) and C (cid:48)(cid:48) are again linear functions of m v , m e , and m t . Therefore, (2) becomes2 Aλ + 2 B (cid:48)(cid:48) λ + 2 C (cid:48)(cid:48) ≥ Aλ + Bλ + C + B (cid:48) λ + C (cid:48) , or Aλ ≥ ( B + B (cid:48) − B (cid:48)(cid:48) ) · λ + ( C + C (cid:48) − C (cid:48)(cid:48) ) . Since λ ≥
1, it suffices to obtain Aλ ≥ ( B + B (cid:48) − B (cid:48)(cid:48) + C + C (cid:48) − C (cid:48)(cid:48) ) · λ, or Aλ ≥ B + B (cid:48) − B (cid:48)(cid:48) + C + C (cid:48) − C (cid:48)(cid:48) = D, (3)54here D is a linear function of m v , m e , and m t .Since λ is the scale that caused the Leader to exhaust the n/k particleson the directrix, we have P ( λ ) ≥ n/k . Since λ ≥ A + B + C ) · λ ≥ P ( λ ) ≥ n/k, and so λ ≥ nk · ( A + B + C ) . Recall that A ( m v , m e , m t ) is proportional to m t : it is either m t / (2 k ) or m t / S F . Since we are assuming m t >
0, then necessarily
A >
0. Thus, we reduce (3) to A · nk · ( A + B + C ) ≥ D , or n ≥ D · k · ( A + B + C ) A . The right-hand side of the above inequality is clearly dominated by a cubicfunction of m v , m e , and m t , which in turn is dominated by Θ( m ). So, if n ≥ Θ( m ), then (1) is satisfied.Suppose now that S F has no triangles, and so P ( λ ) = P (cid:48) ( λ ) = B · λ + C ,by definition of P (cid:48) . At the end of the role assignment phase, there areexactly P ( λ ) − n/k Double particles, and we want all of them to be in thesame (partial) super-edge chunk, which has size at least ( λ − /
2. Thus,we have to obtain λ − ≥ P ( λ ) − nk . (4)As before, we have n/k > P ( λ − λ − ≥ P ( λ ) − P ( λ − . (5)Observe that P ( λ ) − P ( λ −
6) = 6 B , and so (5) becomes λ ≥ B + 1 . (6)Again, we have P ( λ ) ≥ n/k . So, ( B + C ) · λ ≥ n/k , and λ ≥ nk · ( B + C ) . nk · ( B + C ) ≥ B + 1 , or n ≥ (12 B + 1) · k · ( B + C ) , which is dominated by Θ( m ), and a fortiori by Θ( m ), as required.It remains to prove the upper bound on the number of rounds. Notethat, according to our Turing machine analogy, it does not take more thanone round to perform a single step of the machine. Indeed, for the machineto make any progress, the Leader has to be activated; when this happens,the Leader changes its state and sends a message to a neighboring particle inorder to transfer the leadership. Then, in at most one round the neighboringparticle is activated, so it reads the message, becomes the new Leader, mod-ifies its state, and transfers the leadership to another particle. Therefore,it will suffice to prove that a Turing machine can perform all the requiredoperations in O ( n ) steps.The first operation is the conversion of n/k (i.e., the length of the “tape”)in binary, and the naive algorithm works in O ( n ) steps: we scan the tapeone cell at a time, and every time we reach a new cell we set a flag in it, wego back to the beginning of a tape, and we increment a binary counter.Then we have to compute the optimal λ , starting from λ = 7 and incre-menting it by 6 at each iteration. This process continues until P ( λ ) > n/k ,which means that the binary representation of P ( λ ), and therefore that of λ , takes at most O (log n ) cells. Given a binary representation of λ , wecan compute P ( λ ) in O (log n ) machine steps: adding two integers of size O (log n ) takes O (log n ) steps, and multiplying them takes O (log n ) steps(with the usual long multiplication algorithm). Once we have P ( λ ), we cancompare it with n/k by doing a subtraction, which takes O (log n ) steps.Since the value of P ( λ ) strictly increases every time we increment λ ,we have to repeat the above computations at most n/k times, which takes O ( n log n ) = O ( n ) steps overall.When we have found the correct λ , we have to set the Double flags of thelast d particles, which takes O ( n ) steps with the naive algorithm (similarto the one we used to compute the binary representation of n/k ).Finally, we have to assign the Roles to all particles. The size of a chunkis polynomial in λ , so we can compute the size of all chunks in O (log n )time overall (since there is a constant number of chunks). Once we have thesize of a chunk as a binary number, we use it as a counter to assign a Roleto the particles in that chunk. Again, with the naive algorithm this can bedone in O ( n ) steps overall. 56 .7 Shape Composition Phase At the end of the role assignment phase, the particles are located on k directrices, each of which has a Leader. The scale λ of the final shape S (cid:48) F ,equivalent to the input shape S F , has been determined, and S (cid:48) F has beensubdivided among the Leaders in equal and symmetric parts. The particleson the same directrix, which are said to be a team , have been partitionedinto contiguous chunks, each of which corresponds to an element of S (cid:48) F . Inthe shape composition phase, the particles will finally form all the elementsof S (cid:48) F . If k >
1, the particles will actually form a copy of S (cid:48) F having centerin the center of S . Moving to the backbone.
Recall that, if k >
1, the elements of S (cid:48) F havebeen split among the Leaders based on their intersections with a structurecalled backbone (see Section 3.6). That is, the team that lies on the directrix γ i will form the elements of S (cid:48) F that lie on the ray β i of the backbone, as wellas other carefully chosen contiguous elements of S (cid:48) F . Thus, as a preliminarystep of the shape composition phase, it is convenient to relocate the wholeteam from γ i onto β i . Of course, if k = 1, this step is skipped.Let us consider the case k = 2 first. In this case, the endpoint of β i islocated on γ i , at distance ( λ − / G D from its endpoint. To relocatethe team, the Leader can reach the last particle on its directrix and executethe pulling procedure introduced in Section 3.5 ( λ − / λ is still represented in binary in the states of the some particles in the team(from the role assignment phase of the algorithm). So, the Leader can easilycompute a representation of the number ( λ − / k = 3. Then, β i is parallel to γ i , and its endpointis at distance 2( λ − / G D from the endpoint of γ i . To guide theteam to β i , the Leader first pulls it along γ i for ( λ − / ◦ and movesin that direction for another ( λ − / β i at distance n/k − ◦ and moves inthat direction, pulling the team, until the entire line of particles is straight(note that the Leader does not have to count to n/k − β i ,and the Leader is on its endpoint.In Theorem 9, we will show that we do not have to worry about colli-sions with particles from other teams during this preliminary step of the al-57orithm, even if different Leaders end up being completely de-synchronized,and one starts composing S (cid:48) F while another is still relocating its own teamto the backbone. Formation order.
Suppose that, if k >
1, all the particles on γ i have beenrelocated to the backbone ray β i , and now they are all contracted and forma line segment with an endpoint on the endpoint of β i . If k = 1, we definethe unique backbone ray β to be coincident with the unique directrix γ .Recall that in the role assignment phase the Leader of γ i has selectedsome elements of S (cid:48) F : these constitute a shape ( S (cid:48) F ) i ⊆ S (cid:48) F , which the teamparticles that is now on β i is going to form in the current phase of thealgorithm.We have to decide in what order the elements of ( S (cid:48) F ) i are to be formed.The super-vertices and the super-edges that lie on β i will be formed last,because β i serves as a “pathway” for the team to move and get into position.The other elements of ( S (cid:48) F ) i are formed starting from the ones adjacent to β i , and proceeding incrementally; super-vertices and super-edges are formedfirst.This is how the “ordered list” L i of elements of ( S (cid:48) F ) i is constructed: • If a (partial) super-edge e of ( S (cid:48) F ) i \ β i is combinatorially adjacent toa super-vertex lying on β i or to a super-vertex that has already beenincluded in L i , then e is appended to L i . • If a super-vertex v of ( S (cid:48) F ) i \ β i is combinatorially adjacent to a super-edge that has already been included in L i , then v is appended to L i . • If all the super-vertices and the (partial) super-edges of ( S (cid:48) F ) i \ β i have already been included in L i , then the (partial) super-trianglesare appended to L i in any order. • If all the elements of ( S (cid:48) F ) i \ β i have already been included in L i , thenthe elements lying on β i are appended to L i in increasing order ofdistance from the endpoint of β i .Once again, we remark that the Leader can store L i in its internal mem-ory, since the number of elements of ( S (cid:48) F ) i is bounded by a constant.The list L i does not have to be confused with the order in which thechunks are arranged along the backbone: the chunks can be ordered in anyway. Next we are going to show how the Leaders operate to bring the chunksinto their right positions and finally form all the elements of S (cid:48) F . Main shape composition algorithm.
The idea of the algorithm is thatthe i th Leader guides its team in the formation of ( S (cid:48) F ) i ⊆ S F , one element58t a time, following the list L i . At any time, the particles of the team thatdo not lie in ( S (cid:48) F ) i are all lined up on β i , and constitute a “repository” ofcontiguous chunks, each with a Role identifier corresponding to an elementof ( S (cid:48) F ) i .In this discussion, we will temporarily forget about the presence of Dou-ble particles in the repository. The formation of elements by chunks con-taining Double particles will be treated after the main parts of the algorithmhave been explained. Other details of the algorithm will be covered later,as well.The following steps are executed assuming that the i th Leader is on β i ,within the repository, and are repeated until there are no more elementson L i to form. The repository is assumed to consist of contracted particlesforming a connected sub-segment of β i ; moreover, the part of β i that followsthe repository is assumed to be devoid of particles. These conditions aresatisfied when the algorithm begins and will be satisfied again every timethe steps have been executed. • The Leader reads the identifier of the next element d on the list L i (i.e., the identifier of the first element on the list that has not beenformed, yet). • The Leader locates the particles in the repository that have Role iden-tifier corresponding to d (in our terminology, these particles constitutea chunk) and “shifts” them to the beginning of the repository (i.e., thepart of the repository that is closest to the endpoint of β i ). That is,the Leader swaps their Role identifiers and Double flags with the onesof the particles that precede them, until the desired particles are atthe beginning. This operation is simple to do, considering the Turingmachine analogy pointed out in Section 3.6. Note that the particles donot have to physically move, but only exchange messages and modifytheir internal states. • Suppose that d does not lie on β i . Since d is next on the list, it meansthat there is a sequence of elements of ( S (cid:48) F ) i connecting β i with d thathave already been formed (refer to the definition of L i ). More pre-cisely, there is a sequence W = ( v , e , v , e , . . . ), where the v j ’s aresuper-vertices and the e j ’s are super-edges, and each element is combi-natorially adjacent to the next, such that v lies on β i , all elements of W except v have already been formed, and the last element d (cid:48) (whichcould be a super-vertex or a super-edge) is combinatorially adjacentto d . Note that W induces a path in ( S (cid:48) F ) i , because it consists of59uper-edges and the super-vertices between them. Let q be the firstpoint along this path that neighbors a point of d .In the special case in which d is a super-triangle combinatorially ad-jacent to a super-edge e lying on β i , the above does not hold. In thiscase, we take both v and q to be the same endpoint of e .Then the following steps are performed: – The Leader pulls the entire repository along β i until the particlethat is closest to the endpoint of β i coincides with v (we willexplain how the Leader can find v later). No “obstructions” arefound on β i , because at this stage it does not contain formedelements, yet. – The Leader shifts along W all the particles of the chunk corre-sponding to d , in such a way that the first particle of the chunkgoes from v to q (and the other particles of the chunk occupythe positions on W before q , and perhaps also on β , if the chunkis too long). As a consequence, all the particles of W are shiftedback along W and into β by as many positions as the size of thechunk. – The Leader pulls the chunk into d , along with all of W and therest of the repository. As a result, the chunk forms d and theparticles of W are back into their original positions (i.e., the onesthey occupied in the previous step before being shifted). Thedetails of how the Leader arranges the chunk to form d , in case d is a (partial) super-triangle, will be explained later. – The Leader returns to v along d and W . • Suppose now that d lies on β i . The following steps are performed: – The Leader pulls the entire repository along β i until the particlethat is closest to the endpoint of β i coincides with the vertex of d that is farthest from the endpoint of β i . Since the elements of( S (cid:48) F ) i lying on β i have been inserted in L i in order of distancefrom the endpoint of β i , there are no particles on β i “obstructing”the repository while it is being pulled. Again, the details of howthe Leader finds this point on β i will be explained later. – If d is a super-vertex, it has already been formed. Otherwise, d isa super-edge: the Leader forms it by pulling the entire repositorytoward the endpoint of β i for λ − λ − λ − λ in therepository for as long as possible (i.e., as long as there are enough particlesin the repository). So, before removing a chunk that contains part of thisinformation, the Leader copies it to other chunks. Traveling long distances on the backbone.
In the algorithm above,the Leader is supposed to pull the repository along β i until it reaches acertain element of ( S (cid:48) F ) i , which can be far away. We have to explain howthis element can be found, considering that the Leader may not be able tomeasure this distance by counting. We can assume this element to be asuper-vertex: if it is a super-edge lying on β i , then β i also contains the twosuper-vertices that bound it, and the Leader may as well reach one of thoseinstead.Observe that, as the Leader executes the above steps, it always knowsin which element of ( S (cid:48) F ) i it is located, because it can keep track of it usingonly a constant amount of memory.Now, suppose that the Leader is located on a super-vertex u on β i and has to move to another super-vertex u , always on β i , while pulling therepository. Obviously, the distance between u and u is λ times the distancebetween the corresponding vertices in the minimal shape S F , which in turnis a known value that is bounded by a constant (because the base size of S F is a constant). It follows that the Leader can measure this distance if it cancount to λ .If the current repository contains a chunk corresponding to a (partial)super-edge or a (partial) super-triangle, then the Leader has enough particlesat its disposal to count to λ in binary, and the problem is solved.So, let us study the case in which the current repository only containschunks corresponding to super-vertices. We deduce that all the super-edgesof ( S (cid:48) F ) i have already been formed, and the Leader has to reach u to forma super-vertex v .Suppose first that v is not on β i . Then, there is a path consisting ofsuper-edges and super-vertices of ( S (cid:48) F ) i that connects u with v (due to theway the elements of ( S (cid:48) F ) i have been selected by the Leader; see Section 3.6).In particular, there is an edge e , combinatorially adjacent to u , that hasalready been formed. So, the Leader can simply proceed along β i until itfinds a particle with Role identifier corresponding to e among its neighbors.When it finds such a particle, the Leader is in u .Now suppose that v is on β i , and so u = v . Recall from Section 3.6 that,61f the Leader has selected u to be part of ( S (cid:48) F ) i , then it has also selecteda (partial) super-edge e that is combinatorially adjacent to it. Again, since e has already been formed, the Leader can proceed along β i until it finds aneighbor with Role identifier corresponding to e . Forming shapes with no triangles.
So far, we have ignored the pres-ence of Double particles, i.e., particles that have to be expanded in thefinal configuration. Next we will explain how to handle them in the shapecomposition algorithm.The issues arise from the fact that a Leader has to be able to movethrough contracted particles to reach different elements of ( S (cid:48) F ) i , as wellas pull chains of particles that are supposed to be contracted. In the shapecomposition algorithm, this happens when the Leader has to form an elementthat is reachable from β i through a path W consisting of super-vertices andsuper-edges. If W contains Double particles, which are either expanded orleave gaps between particles, then these operations are not straightforward.We first consider the case in which S F has no triangles and consists onlyof edges. Recall from Theorem 8 that, in this case, all the Double particlesare in a single chunk c that corresponds to a (partial) super-edge e . Notethat which chunk actually contains the Double particles is irrelevant forthe purposes of shape formation, and so we can choose to put them in aconvenient chunk.The chunk c (cid:48) we choose is the one corresponding to the super-edge e (cid:48) thatis last in the list L i . To do the switch, the Leader simply checks the Roleidentifiers of all the particles in the repository, and changes each occurrenceof the identifier corresponding to e into the one corresponding to e (cid:48) , and viceversa.The advantage of choosing e (cid:48) is that it will never be part of a path W that the Leader has to follow to reach the next element to form, exceptperhaps if such an element is a specific super-vertex v (cid:48) that is combinatoriallyadjacent to e (cid:48) . So, if v (cid:48) appears in the list L i after e (cid:48) , the Leader first seesif it can move v (cid:48) before e (cid:48) while respecting the constraints that define L i .This is possible if and only if ( S (cid:48) F ) i has a super-edge distinct from e (cid:48) thatis combinatorially adjacent to v (cid:48) . If this is not the case, the Leader mergesthe two chunks corresponding to e (cid:48) and v (cid:48) , and hence it will form e (cid:48) and v (cid:48) in a single step, as if they were a slightly longer super-edge.So, all the elements of ( S (cid:48) F ) i except e (cid:48) and perhaps v (cid:48) are formed as ex-plained in the main shape composition algorithm. Indeed, if v (cid:48) has to bepart of a path W as defined above, then it means that v (cid:48) has a combinato-rially adjacent super-edge in ( S (cid:48) F ) i other than e (cid:48) , and so v (cid:48) has been formed62s normal, and its chunk has not been merged with the one of e (cid:48) .We just have to show how to form e (cid:48) , and perhaps v (cid:48) if it is formedin the same step. The algorithm works as normal, until the chunk that isgoing to form e (cid:48) (and perhaps v (cid:48) ) has been pulled up to a point where oneof its particles neighbors an endpoint of e (cid:48) . Then, the following steps areexecuted: • The Leader pulls the chunk along e (cid:48) (also pulling the path W and therepository, as usual) until the last particle of the chunk has entered e (cid:48) . • The Leader makes the particle on which it currently is into a
Puller (by setting an internal flag). • The Leader leaves e (cid:48) and proceeds with the algorithm as normal. ThePuller waits for the Leader to leave e (cid:48) . • The Puller starts another pulling procedure. When the last Doubleparticle of e (cid:48) is pulled, it expands and sends a Movement-Done messageto its Predecessor without contracting again. • The above step is repeated until all the Double particles of the chunkare expanded.
Forming shapes with triangles.
Finally, we consider the case in which S F has at least one triangle. According to Theorem 8, in this case all theDouble particles are in chunks corresponding to (partial) super-triangles. So,all the paths consisting of super-vertices and super-edges that the Leaderhas to traverse to reach new elements of ( S (cid:48) F ) i are unaffected by Doubleparticles. Therefore, the shape composition algorithm works as we alreadyexplained, except for the formation of (partial) super-triangles.In the following, we will explain how to form a (partial) super-triangle t whose corresponding chunk c may contain Double particles. Recall that c enters t through an endpoint of a combinatorially adjacent (partial) super-edge, and therefore it starts covering t from one of its three corners.Suppose first that t is a super-triangle. The algorithm is roughly thesame as the one already used above for the super-edges, except that nowthe Leader has to fill a triangle t . The steps are as follows (refer to Figure 9): • The Leader pulls c (as well as the path W and the repository) followingthe boundary of t in the counterclockwise direction for λ − λ − λ − c .63 The Leader turns counterclockwise by 120 ◦ and pulls for another λ − t . • The Leader turns counterclockwise by 120 ◦ and pulls until it finds aparticle in front of it. • The previous step is repeated until the last particle of c enters t . • The Leader makes the particle on which it currently is into a Puller. • The Leader leaves t (following the chain it just pulled) and proceedswith the shape composition algorithm. The Puller waits for the Leaderto leave t . • The Puller pulls c , turning counterclockwise by 120 ◦ if it finds a par-ticle in front of it. When the last Double particle of c is pulled, it ex-pands and sends a Movement-Done message to its Predecessor withoutcontracting again. • The above step is repeated until all the Double particles of the c areexpanded.If t is a partial super-triangle, the algorithm is identical, with the onlydifference that now the Leader does not have to cover the perimeter of anequilateral triangle with sides of length λ −
3, but of an isosceles trapezoidwith sides of length ( λ − /
3, ( λ − /
3, ( λ − /
3, and 2( λ − / Correctness.
We can now prove the correctness of the universal shapeformation algorithm.
Theorem 9.
Let P be a system of n particles forming a simply connectedshape S at stage 0. Let S F be a shape of constant base size m that is un-breakably k -symmetric if S is unbreakably k -symmetric. If all particles of P execute the universal shape formation algorithm with input a representa-tion of the final shape S F , and if n is at least Θ( m ) , then there is a stage,reached after O ( n ) rounds, where P forms a shape equivalent to S F . Thetotal number of moves performed by P up to this stage is O ( n ) , which isasymptotically optimal; particles no longer move afterwards.Proof. Under these assumptions, Theorems 3–8 apply. So, we can assumethat at some stage the particles will be found on k directrices, each contain-ing exactly one Leader particle. Moreover, if k >
1, then S F is unbreakably k -symmetric. The Leaders have implicitly agreed on a shape S (cid:48) F and havesplit its elements among each other. Since the handedness on which the64 a) The chunk is pulled along the arrow.(b) The Double particles expand to cover the super-triangle. Figure 9: Formation of a super-triangle by a chunk containing some Doubleparticles. The Double particles are drawn in white; the other particles inthe chunk are drawn in gray.particles agree (cf. Theorem 5) may not be the “real” one, S (cid:48) F may actuallybe a reflected copy of S F . However, the definition of the shape formationproblem allows for any similarity transformation of the shape, which includereflections (see Section 2).If k = 1, the correctness of the shape composition algorithm follows byconstruction. If there is more than one Leader, we only have to show thatdifferent Leaders will never interfere with each other, and their respectiveteams will never get in each other’s way. This is because different teams are65onfined to move within different regions of G D throughout the phase. Thisis obvious if the k teams are all executing the preliminary relocation stepor if they are all executing the main composition algorithm. Suppose nowthat k = 3, and one team is moving from its directrix γ i to the backbone β i ,while another team is already executing the main composition algorithm.Recall from Section 3.6 that all the elements of S (cid:48) F that are incident to theco-backbone ray β (cid:48) i are selected by the Leader of γ i to be part of ( S (cid:48) F ) i : theseare precisely the elements that are incident with γ i , as well. So, as particlesare being pulled from γ i to β i , they only pass through elements that havebeen selected by their Leader, making it impossible for them to encounterparticles from other teams.Let us count the total number of moves of P and the number of roundsit takes to form S (cid:48) F . Up to the beginning of the shape composition phase, P performs at most O ( n ) moves in at most O ( n ) rounds, as Theorems 3–8imply. When a Leader relocates its team onto the backbone, it pulls allthe particles at most O ( n ) times, and the total number of moves, as well asrounds, is at most O ( n ). Then, in order to form one element of S (cid:48) F , a Leadermay have to pull at most O ( n ) particles for at most O ( n ) times along thebackbone to get the chunk into position: this yields at most O ( n ) movesand rounds. Then it has to pull at most O ( n ) particles for a number oftimes that is equal to the size of the element of S (cid:48) F , which is O ( n ). Since thenumber of elements of S (cid:48) F is bounded by a constant, this amounts to at most O ( n ) moves and rounds, again. All other operations involve only messageexchanges and no movements, so the O ( n ) upper bound on the number ofmoves follows. Due to the matching lower bound given by Theorem 2, ouruniversal shape formation algorithm is asymptotically optimal with respectto the number of moves.To conclude, observe that shifting chunks within a repository, computingpolynomial functions of λ , and using them as counters takes O ( n ) roundsoverall, since this has to be done at most once per chunk, i.e., a constantnumber of times. So, the upper bound of O ( n ) rounds follows, as well. We have described a universal shape formation algorithm for systems of par-ticles that performs at most O ( n ) moves, which is asymptotically optimal.The number of rounds taken to form the shape is O ( n ) as well: with aslight improvement on the last phases of out algorithm, we can reduce it to O ( n log n ) rounds, and the example described in Theorem 2 yields a lower66ound of Ω( n ) rounds. Determining an asymptotically optimal bound onthe number of rounds is left as an open problem.We have established that, given a shape S F of constant size m , a systemof n particles can form a shape geometrically similar to S F (i.e., essentially ascaled-up copy of S F ) starting from any simply connected configuration S ,provided that S F is unbreakably k -symmetric if S is, and provided that n is large enough compared to m . We only determined a bound of Θ( m ) forthe minimum n that guarantees the formability of S F . We could improveit to Θ( m ) by letting the Double particles be in any chunk and adoptinga slightly more sophisticated pulling procedure in the last phase. We maywonder if this modification would make our bound asymptotically optimal.When discussing the role assignment phase, when the particles are ar-ranged along straight lines, we have argued that the system can computeany predicate that is computable by a Turing machine on a tape of limitedlength. If we allow the particles to move back and forth along these lines tosimulate registers, we only need a (small) constant number of particles toimplement a full-fledged Turing machine with an infinite tape. So, in the roleassignment phase, we are actually able to compute any Turing-computablepredicate (although we would have to give up our upper bounds of O ( n )moves and stages).With this technique, we are not only able to replace our Θ( m ) withthe best possible asymptotic bound in terms of m , but we have a universalshape formation algorithm that, for every n and every S F , lets the systemdetermine if n particles are enough to form a shape geometrically similarto S F . This is done by examining all the possible connected configurationsof n particles and searching for one that matches S F , which is of course aTuring-computable task.Taking this idea even further, we can extend our notion of shape to itsmost general form. Recall that the shapes considered in [10] were sets of“full” triangles: when a shape is scaled up, all its triangles are scaled up andbecome larger full triangles. In this paper, we extended the notion of shapeto sets of full triangles and edges: when an edge is scaled up, it remains arow of points. Of course, we can think of shapes that are not modeled byfull triangles or edges, but behave like fractals when scaled up. For instance,we may want to include a discretized version of the Sierpinski triangle as a“building block” of our shapes, alongside full triangles and edges. Scaling upa discretized Sierpinski triangle is equivalent to increasing its “resolution”,which causes finer details to appear inside it. Clearly, these scaled-up copiesof the discretized Sierpinski triangle are Turing-computable.Generalizing, we can replace our usual notion of geometric similarity67etween shapes with any Turing-computable equivalence relation ∼ . Then,the shape formation problem, with input a shape S F , asks to form any shape S (cid:48) F such that S F ∼ S (cid:48) F . This definition of shape formation problem includesand greatly generalizes the one studied in this paper, and even applies toscenarios that are not of a geometric nature. Nonetheless, this generalizedproblem is still solvable by particles, thanks to the technique outlined above. Acknowledgments.
This research has been supported in part by the Natu-ral Sciences and Engineering Research Council of Canada under the Discov-ery Grant program, by Prof. Flocchini’s University Research Chair, and byProf. Yamauchi’s Grant-in-Aid for Scientific Research on Innovative Areas“Molecular Robotics” (No. 15H00821) of MEXT, Japan and JSPS KAK-ENHI Grant No. JP15K15938.
References [1] H. Ando, I. Suzuki, and M. Yamashita. Formation and agreementproblems for synchronous mobile robots with limited visibility. In
Pro-ceedings of the 10th IEEE Symposium on Intelligent Control , 453–460,1995.[2] D. Arbuckle and A. Requicha. Self-assembly and self-repair of arbitraryshapes by a swarm of reactive robots: algorithms and simulations.
Au-tonomous Robots , 28(2):197–211, 2010.[3] S. Cannon, J.J. Daymude, D. Randall, and A.W. Richa. A Markovchain algorithm for compression in self-organizing particle systems. In
Proceedings of the 35th ACM Symposium on Principles of DistributedComputing , 279–288, 2016.[4] G. Chirikjian. Kinematics of a metamorphic robotic system. In
Pro-ceedings of the 11th IEEE International Conference on Robotics andAutomation , 1:449–1:455, 1994.[5] S. Das, P. Flocchini, N. Santoro, and M. Yamashita. Forming sequencesof geometric patterns with oblivious mobile robots.
Distributed Com-puting , 28(2):131–145, 2015.[6] J.J. Daymude, Z. Derakhshandeh, R. Gmyr, A. Porter, A.W. Richa,C. Scheideler, and T. Strothmann. On the runtime of universal coat-ing for programmable matter. In
Proceedings of 22nd International onference on DNA Computing and Molecular Programming , 148–164,2016.[7] J.J. Daymude, R. Gmyr, A.W. Richa, C. Scheideler, and T. Stroth-mann. Improved leader election for self-organizing programmable mat-ter. arXiv:1701.03616, 2017.[8] E.D. Demaine, M.J. Patitz, R.T. Schweller, and S.M. Summers. Self-assembly of arbitrary shapes using RNAse enzymes: meeting the Kol-mogorov bound with small scale factor (extended abstract). In Pro-ceedings of the 28th Symposium on Theoretical Aspects of ComputerScience , 201–212, 2011.[9] Z. Derakhshandeh, R. Gmyr, A.W. Richa, C. Scheideler, and T. Stroth-mann. An algorithmic framework for shape formation problems in self-organizing particle systems. In
Proceedings of the 2nd InternationalConference on Nanoscale Computing and Communication , 21:1–21:2,2015.[10] Z. Derakhshandeh, R. Gmyr, A.W. Richa, C. Scheideler, and T. Stroth-mann. Universal shape formation for programmable matter. In
Pro-ceedings of the 28th ACM Symposium on Parallelism in Algorithms andArchitectures , 289–299, 2016.[11] Z. Derakhshandeh, R. Gmyr, A.W. Richa, C. Scheideler, and T. Stroth-mann. Universal coating for programmable matter.
Theoretical Com-puter Science , 671:56–68, 2017.[12] Z. Derakhshandeh, R. Gmyr, T. Strothmann, R.A. Bazzi, A.W. Richa,and C. Scheideler. Leader election and shape formation with self-organizing programmable matter. In
Proceedings of 21st InternationalConference on DNA Computing and Molecular Programming , 117–132,2015.[13] S. Dolev, S. Frenkel, M. Rosenbli, P. Narayanan, andK.M. Venkateswarlu. In-vivo energy harvesting nano robots. In the 3rd IEEE International Conference on the Science of ElectricalEngineering , 1–5, 2016.[14] P. Flocchini, G. Prencipe, N. Santoro, and P. Widmayer. Arbitrarypattern formation by asynchronous, anonymous, oblivious robots.
The-oretical Computer Science , 407(1):412–447, 2008.6915] N. Fujinaga, Y. Yamauchi, H. Ono, S. Kijima, and M. Yamashita. Pat-tern formation by oblivious asynchronous mobile robots.
SIAM Journalof Computing , 44(3):740–785, 2016.[16] K. Li, K. Thomas, C. Torres, L Rossi, and C.-C. Shen. Slime moldinspired path formation protocol for wireless sensor networks. In
Pro-ceedings of the 7th International Conference on Swarm Intelligence ,299–311, 2010.[17] O. Michail. Terminating distributed construction of shapes and pat-terns in a fair solution of automata.
Distributed Computing , to appear,DOI: 10.1007/s00446-017-0309-z.[18] O. Michail, G. Skretas, and P.G. Spirakis. On the transformation ca-pability of feasible mechanisms for programmable matter. In
Proceed-ings of the 44th International Colloquium on Automata, Languages, andProgramming , 136:1–136:15, 2017.[19] A. Naz, B. Piranda, J. Bourgeois, S.C. Goldstein. A distributed self-reconfiguration algorithm for cylindrical lattice-based modular robots.In
Proceedings of the 15th IEEE International Symposium on NetworkComputing and Applications , 254–263, 2016.[20] M.J. Patitz. An introduction to tile-based self-assembly and a surveyof recent results.
Natural Computing , 13(2):195–224, 2014.[21] P.W. Rothemund. Folding DNA to create nanoscale shapes and pat-terns.
Nature , 440(7082):297–302, 2006.[22] M. Rubenstein, A. Cornejo, and R. Nagpal. Programmable self-assembly in a thousand-robot swarm.
Science , 345(6198):795–799, 2014.[23] M. Rubenstein and W.-M. Shen. Automatic scalable size selection forthe shape of a distributed robotic collective. In
Proceedings of the 23rdIEEE/RSJ International Conference on Intelligent Robots and Systems ,508–513, 2010.[24] N. Schiefer and E. Winfree. Universal computation and optimal con-struction in the chemical reaction network-controlled tile assemblymodel. In
Proceedings of the 21st DNA Computing and Molecular Pro-gramming , 34–54, 2015. 7025] I. Suzuki and M. Yamashita. Distributed anonymous mobile robots:formation of geometric patterns.
SIAM Journal on Computing ,28(4):1347–1363, 1999.[26] T. Toffoli and N. Margolus. Programmable matter: concepts and real-ization.
Physica D: Nonlinear Phenomena , 47(1):263–272, 1991.[27] J.E. Walter, J.L. Welch, and N.M. Amato. Distributed reconfigurationof metamorphic robot chains.
Distributed Computing , 17(2):171–189,2004.[28] D. Woods, H.-L. Chen, S. Goodfriend, N. Dabby, E. Winfree, andP. Yin. Active self-assembly of algorithmic shapes and patterns in poly-logarithmic time. In
Proceedings of the 4th Conference on Innovationsin Theoretical Computer Science , 353–354, 2013.[29] M. Yamashita and I. Suzuki. Characterizing geometric patternsformable by oblivious anonymous mobile robots.
Theoretical ComputerScience , 411(26–28):2433–2453, 2010.[30] M. Yim, W.-M. Shen, B. Salemi, D. Rus, M. Moll, H. Lipson,E. Klavins, and G.S. Chirikjian. Modular self-reconfigurable robot sys-tems.