A randomized greedy algorithm for piecewise linear motion planning

Simplicial complexity (SC) is a discretized model for Farber's topological complexity (TC) of an autonomous system whose space of states is a polyhedron $K$. We describe a randomized algorithm that, given $K$, finds an explicit system of SC motion planners. An implementation of this algorithm revels that, unlike other discrete approached in the literature to Farber's TC, the SC approach performs satisfactorily well without having to introduce costly subdivisions of $K$.


Introduction
The notion of topological complexity (TC), introduced by Michael Farber in [3], is a mathematical model measuring the continuity instabilities in the motion planning problem in robotics. The theoretical aspects of Farber's idea have been extensively studied by algebraic topologists through more than fifteen years. As a result, the concept has found deep and fruitful connections in homotopy theory. Nonetheless, the more computational aspects of the TC-ideas have seen limited developments, while actual engineering-minded TC-applications seem to be inexistent. This paper focuses on the more applied features of Farber's TC, taking advantage of computational topology techniques and, more importantly, using randomized algorithms to find efficient solutions to the motion planning problem for autonomous systems. We implement our algorithms with successful and, as explained below, somehow unexpected results.
We use the model developed in [6]. Here is the basic idea (details are reviewed in the next section). Assume that the space of states of a given autonomous system is given by (the topological realization of) an abstract simplicial complex K where, for practical reasons, we assume K to be finite. Taking a linear order on the vertices of K, one considers the ordered simplicial product K ×K. In such a context, a piecewise linear motion planner defined on a subcomplex J of K × K is a chain of simplicial maps ϕ 0 , ϕ 1 , . . . , ϕ c : J → K (c ≥ 1) satisfying: • each ϕ i is contiguous to the subsequent map ϕ i+1 (0 ≤ i < c), and • ϕ 0 (ϕ c ) is the restriction to J of the projection K × K → K onto the first (second) factor.
The rationale behind such a definition is that, for any given pair (a, b) of initial-final points in the topological realization J of J, the sequence of points a, ϕ 0 (a, b), ϕ 1 (a, b), . . . , ϕ c (a, b), b flags a piecewise linear path in K from a to b depending continuously on a an b.
A motion planner defined on the full complex K × K exists only in the (topologically trivial) case that K is contractible. It is then natural to define SC strict (K), a discretized analogue of Farber's TC, as one less than the minimal number of subcomplexes covering K × K, on each of which there is a motion planner. A central result in [6] (coming from the Simplicial Approximation Theorem) is that, if we want to have a discretized invariant of K that recovers Farber's topological complexity of the realization K , then the above constructions have to be done within a limiting process where K ×K is allowed to be "sufficiently" subdivided, for instance, by taking b-iterated barycentric subdivisions Sd b (K × K). This yields the simplicial complexity (SC) of K, where SC b strict (K) is defined in terms of Sd b (K × K) in the same way as SC strict (K) is defined in terms of K ×K. As shown in [6,Theorem 3.5], SC(K) agrees with Farber's topological complexity of K . Remark 1.1. Arbitrary subdivisions ensures we can recast Farber's invariant in the simplicial category. However, any person familiar with computational aspects involving subdivisions will immediately realize that the proposal based on barycentric subdivisions soon becomes prohibitive for real applications. An alternative, already used in [6], is to allow for coarser/partial subdivisions. The option is however still not satisfactory, as there is no indication a priori of what portions of K × K should be subdivided.
The coarser subdivision alternative mentioned in Remark 1.1, together with human geometric intuition, led to recast in [6,Section 4], in simplicial terms, the fact that the topological complexity of the circle (the natural benchmark in [6]) is 1, namely, The motivation and main goal of this paper is to set a computer implementation that recovers (1), replacing the human geometric intuition ingredient by a heuristicbased computer search. Indeed, such an implementation would be central toward an engineering-minded usage of the TC ideas. We accomplish such a goal through a randomized algorithm. Surprisingly, the implementation we will present in this paper reports that, in the case of the circle, the subdivision ingredient is not needed in order to recast Farber's TC. Indeed, running on a personal laptop computer, our algorithm reports that SC 0 strict (∂∆ 2 ) = 1.
As indicated in Remark 1.1, avoiding the need of subdivisions is a key feature for eventual real-life applications, for otherwise complexity of the process is bound to get out of hands rather quickly. For instance, starting with the (single) barycentric subdivision Sd 1 (∂∆ 2 × ∂∆ 2 ), our implementation is able to recover (1) in about 10 hours running time, even though the stronger fact in (2) is settled, directly from ∂∆ 2 × ∂∆ 2 and on the same laptop computer, in less than a minute running time (see the final section).
Remark 1.2. The ability to recast Farber's TC in discrete terms without the need of subdivisions seems to be a convenient advantage of our SC-model over other discrete approaches. Specifically, the discrete topological complexity introduced in [5] of a simplicial complex whose geometric realization is a circle turns out to be one unit larger than TC(S 1 ) [5, Theorem 5.6]. Likewise, (if no subdivisions are allowed) the value of Tanaka's combinatorial complexity on the minimal finite space model of a circle is two units higher than TC(S 1 ) ([8, Example 3.7]).

Topological complexity
Let X and P (X) stand for a topological space and for the free path space on X, respectively. The reduced version of Farber's topological complexity of X, TC(X), is the reduced Schwarz genus of the end-point evaluation map e : P (X) → X × X, i.e., the fibration taking a free path γ ∈ P (X) to the pair (γ(0), γ(1)). In other words, TC(X) + 1 is the smallest cardinality of open covers {U i } i of X × X so that e admits a continuous section σ i on each U i . Note that we use reduced terms, so that a contractible space has zero topological complexity. The open sets U i in such an open cover are called local domains, the corresponding sections σ i are called local motion planners, and the family of pairs {(U i , σ i )} is called a system of local motion planners for X. A system of motion planners is said to be optimal if it has TC(X) + 1 local domains. In view of the continuity requirement on local rules, an optimal motion planner minimizes the possibility of accidents in the performance of a robot moving in a noisy environment. It is standard that, when X is the realization of an abstract simplicial complex, the requirement that local domains are open can be replaced (without altering the numerical value of TC(X)) by requiring that local domains are subcomplexes (see [6]). Furthermore, a local motion planner is really a (local) homotopy in disguise:

Simplicial complexity
In this section we review the basic constructions in [6] regarding the concept of simplicial complexity. As explained in the introduction, the subdivision component should be avoided as much as possible in actual applications. Consequently, subdivisions will in fact be neglected in what follows. Details on the topology and homotopy properties of the category of (abstract simplicial) complexes can be found, for instance, in [7,Chapter 3].
We start by recasting the notion of contiguity of simplicial maps in a form that is suitable for the applications we have in mind. 2. ϕ and ϕ ′ are said to be c-contiguous if there is a sequence of maps ϕ 0 , ϕ 1 , · · · , ϕ c : J → K, with ϕ 0 = ϕ and ϕ c = ϕ ′ , such that ϕ i−1 and ϕ i are contiguous for each i ∈ {1, 2, . . . , c}.
The sequence of maps ϕ j in Definition 2.2.2 is called a contiguity chain of length c between ϕ and ϕ ′ . We write ϕ ∼ c ϕ ′ to mean that there is such a sequence, and ϕ ∼ ϕ ′ to mean ϕ ∼ c ϕ ′ for some c. This is an equivalence relation in the set of simplicial maps J → K. The corresponding equivalence classes are called contiguity classes, and are denoted by [ψ], where ψ is any given representative.

Remark 2.3.
Contiguity classes of simplicial maps is a refinement of homotopy classes of their topological realizations. Indeed, from its bare definition, the topological realizations of a pair of contiguous simplicial maps are homotopic through a piecewise linear homotopy.
All (abstract simplicial) complexes we deal with are assumed to be finite and ordered, and their product will be taken in the category of ordered complexes. The hypothesis is reminiscent to the fact that the topological realization of such a product of complexes is homeomorphic to the product of the topological realizations of the factors. See [2] for the classical details on the construction. We stress however that maps of complexes are not required to preserve the given orderings.
A family {L i : i ∈ I} of subcomplexes of a given complex K is a cover provided K = i∈I L i . In such a case the family of realizations { L i : i ∈ I} covers K . Definition 2.4. Let K be an (ordered) complex and let c be a positive integer. The c-simplicial complexity SC c (K) of K is one less than the smallest cardinality of finite covers of K × K by subcomplexes J for each of which the compositions are c-contiguous. Here π i : K × K → K, i = 1, 2, stand for the projections to the axis. We set SC c (K) = ∞ if no such finite covering exists.
In analogy to the topological situation, the subcomplexes J appearing in the covers of Definition 2.4 are called piecewise linear local domains, and the contiguity chains connecting the two maps in (3) are called piecewise linear local motion planners. The term "piecewise linear" comes from the fact that the geometric relaization of contiguous simplicial maps are homotopic through a piecewise linear homotopy (see Remark 2.3).
The simplicial complexity of K, denoted by SC(K), is defined 1 as the eventual constant value of the monotonic sequence Note that TC( K ) is bounded from above by SC(K). In particular, it makes sense to say that a system of piecewise linear local motion planners for K is optimal provided the corresponding local domains covering K × K have cardinality TC( K ) + 1.
In the rest of the paper we describe a randomized algorithm whose implementation yields reasonably close-to-optimal systems of piecewise linear local motion planners for general simplicial complexes K. In the case of the circle ∂∆ 2 , our implementation constructs optimal systems of piecewise linear local motion planners.

Algorithms
We represent an (abstract simplicial) complex K by a pair (V K , F K ), where V K is the list of the vertices of K, and F K is the list of the facets (i.e. maximal simplices) of K. This encoding is convenient because of Definition 2.2.1 and, more importantly for our purposes, since a covering of a given complex (such as K × K in Definition 2.4) is completely determined by a covering of its facets (see the discussion at the beginning of Subsection 3.3).
In what follows we assume given an algorithm, Contiguous, that checks whether two simplicial maps are contiguous 2 . Such a function is available in standard mathematical software systems such as SageMath. In fact, our algorithms are easily implementable in SageMath, where in fact there are many other convenient features for our purposes, such as a function for spelling out (as a list of facets) the ordered simplicial product of ordered complexes.

Randomized local search of contiguity chains
Recall that, for finite abstract simplicial complexes J and K, the Simplicial Approximation Theorem characterizes homotopy classes of continuous maps J → K in terms of contiguity classes of maps J → K through a limiting process that takes finer and finer subdivisions of J. This classical fact is generalized in [1] by introducing a certain "contiguity complex" Contig(J, K) that approximates, as J becomes sufficiently subdivided, the homotopy type of the function space of continuous maps J → K . What is relevant for us is to remark that Blumberg and Mandell propose a certain randomized algorith in order to study the rate of growth (under subdivision of the domain) of the components of Contig(J, K). We adapt Blumberg-Mandell's algorithm (without the subdivision component) for our computer implemented search of piecewise linear local motion planners.
The randomized algorithm LocalSearch in this section inputs a pair of simplicial maps ϕ, ϕ ′ : J → K, a positive integer M, and a probability parameter r (r ∈ [0, 1]), and outputs a list Ψ that either contains a chain of maps satisfying the conditions in Definition 2.2.2 or, else, is empty, in case the randomized search for (5) is not successful. Starting at ϕ, the search is done through a random walk with local steps in the space of simplicial maps J → K. Actual steps in the walk are tried (and recorded in Ψ), at most M times on a "greedy" basis, with the probability parameter r used to break a situation where no greedy step has been taken after a number of consecutive tries. A greedy step is actually taken whenever the distance from the goal map ϕ ′ to the current position of the walk is larger than the distance from ϕ ′ to the potentially new position of the walk. Here, the distance between simplicial maps f, g : J → K is defined as where the summation runs over the vertices v of J, and d K stands for the graph distance on the 1-skeleton of K. We use the following variant of LocalSearch in our actual implementation. Start by noticing that, at each step of the iterative process (line 5), the potential new position f in the walk -a random single-vertex variant of φ-may fail to be contiguous to the current position φ, thus preventing us from taking the greedy step (line 10). The construction of f (lines 6 and 7) can then be replaced by a process that, first constructs a list L φ,w of all the simplicial maps that differ from φ on a single randomly chosen vertex w ∈ V J , and then chooses f randomly from L φ,w (provided L φ,w = ∅). Of course, with this modification, the first test condition in line 9 can safely be removed.

Reduction of contiguity chains
We have noted that the random walk performed by LocalSearch has a local-step basis: any two consecutive maps ϕ i and ϕ i+1 in a sequence (5) produced by LocalSearch differ only by their values at a single vertex of J. In particular, it is usual that LocalSearch outputs a long sequence of (hundreds and even thousands of) consecutive contiguous maps in between ϕ and ϕ ′ . This can be remedied by running a shortest path algorithm/heuristic on the contiguity graph generated by the maps ϕ i in the sequence. However, the construction of the graph is costly for large sequences. The simpler alternative described in this subsection works well given the random nature of LocalSearch. The algorithm Reduce below attempts to reduce the size of a contiguity sequence φ = (ϕ 0 , . . . , ϕ c ) by reporting the sequence φ ′ obtained from φ by discarding the terms ϕ ℓ+1 , ϕ ℓ+2 , . . . , ϕ ℓ+m−1 in chunks ϕ ℓ , ϕ ℓ+1 , . . . , ϕ ℓ+m whenever m > 1 is maximal with ϕ ℓ and ϕ ℓ+m contiguous.

Randomized contiguity subcomplexes
We approach the computational task in Definition 2.4 within a more general (but somehow simpler) setup. Let ψ, ψ ′ : L → K be simplicial maps. A subcomplex J of L is said to be a c-contiguity subcomplex (for ψ and ψ ′ ), if there exists a contiguity chain (5) satisfying the conditions in Definition 2.2.2 for the restrictions ϕ = ψ |J and ϕ ′ = ψ ′ |J . We say that J is a contiguity subcomplex if it is a c-contiguity subcomplex for some c. The c-contiguity rank of ψ and ψ ′ , denoted by CR c (ψ, ψ ′ ), is defined as one less than the smallest cardinality of finite covers of L by c-contiguity subcomplexes J, while the contiguity rank of ψ and ψ ′ , denoted by CR(ψ, ψ ′ ), is defined as the eventual constant value of the monotonic sequence Examples 3.1. Note that the subcomplex generated by any simplex of L is a contiguity subcomplex of any pair of simplicial maps provided (the topological realization of) K is connected. The latter assumption will be in force from this point on. Furthermore, in the notation of Subsection 2.2, the relation ψ ∼ c ψ ′ can be expressed through the equality CR c (ψ, ψ ′ ) = 0, while the equalities SC c (K) = CR c (π 1 , π 2 ) and SC(K) = CR(π 1 , π 2 ) hold for the two simplicial projections π 1 , π 2 : K × K → K.
For simplicial maps ψ, ψ ′ : L → K, the task of finding coverings of L by ccontiguity subcomplexes can be focused on facets of L. Indeed, by restricting to facets, a covering C of L by c-contiguity subcomplexes yields (in a non-unique way) a partition P of the facets of L. In such a situation, if J P stands for the subcomplex of L generated by the facets in a given P ∈ P, then C P := {J P : P ∈ P} is a covering of L by c-contiguity subcomplexes with Card(C P ) ≤ Card(C). The definition of CR c (ψ, ψ ′ ) can therefore be reformulated by limiting attention to coverings C P coming from a partition P of the facets of L as above. This is the viewpoint in the algorithms described next.
A random selection of a subset of the facets of L will most likely fail to generate a contiguity subcomplex. Likewise, a random selection of a partition P of the facets of L will most likely fail to produce a covering C P by contiguity complexes. A more careful randomized search is needed in both cases. As a first step, we describe in this subsection the randomized algorithm RCC (RandomContiguitysubComplex) that aims at constructing a maximal contiguity subcomplex for a given pair of simplicial maps. Then, in Subsection 3.4 we describe a randomized algorithm that searches for partitions P of the set of facets of L that yield a covering C P by contiguity subcomplexes. Lastly, the size of such a covering C P is optimized by the algorithm in Subsection 3.5. The latter algorithm is crucial for our purposes, as it gives us a real chance to get at systems of piecewise linear local motion planners that are optimal in the sense of Section 2.2.
We start with the algorithm AddFacet below, whose input is a pair of simplicial maps ψ, ψ ′ : L → K, and a contiguity subcomplex J for ψ and ψ ′ . It is implicitly assumed that J is generated by a set of facets of L. With this information, the algorithm looks randomly for the first facet σ of L not in J that, together with J, generates a contiguity subcomplex J ′ . If such a facet σ is found, AddFacet outputs J ′ , otherwise J is reported. Each testing is done by the algorithm LocalSearch with the restricted simplicial maps ψ| J ′ and ψ ′ | J ′ as parameters. Note that AddFacet requires in addition the two parameters M and r needed by LocalSearch. The main algorithm in this subsection, RCC, is an iteration of AddFacet. Starting with two simplicial maps ψ, ψ ′ : L → K as input, RCC applies AddFacet recursively, using the output of the previous application as (part of) the input for the next application (ψ and ψ ′ are kept as the rest of the input for all iterations of AddFacet). The iteration starts by using the contiguity subcomplex generated by a randomly chosen facet of L, which is a contiguity subcomplex in view of Examples 3.1. The iteration is applied at most Card(F L ) times, and is set to stop whenever the current application of AddFacet is unable to add an additional facet (this will hold, for instance, if the total complex L has been identified as a contiguity complex for ψ and ψ ′ ).
A slight generalization of RCC will also be needed in what follows. The algorithm AddFacets is an iteration of AddFacet on the same grounds as RCC, except that the starting contiguity subcomplex is a prescribed parameter.
For latter use in the global algorithm, an actual implementation of both AddFacets and RCC should keep track of the (reduced version of the) last non-empty contiguity sequence φ constructed by AddFacet, for this provides us with an explicit contiguity chain for the restrictions of ψ and ψ ′ to the output of AddFacets RCC.

Randomized coverings by contiguity subcomplexes
For simplicial maps ψ, ψ ′ : L → K, the algorithm Covering in this subsection constructs a partition P of F L as the one described in the paragraph following Examples 3.1. The process is an iteration of RCC. Assume we have constructed a family P of pairwise disjoint subsets of F L such that each P ∈ P generates a contiguity subcomplex J P for ψ and ψ ′ (P is empty at the start of the process). Then we execute RCC with the restricted maps ψ |I , ψ ′ |I : I → K as parameters, where I is the subcomplex of L generated by the facets of L that do not lie in any P ∈ P. The set of relevant facets of the resulting contiguity complex is appended to P. The process is iterated until the resulting P partitions F L .

Optimization of coverings
When applied to the two simplicial projections π 1 , π 2 : K × K → K, the algorithm Covering in the previous subsection constructs systems of piecewise linear local motion planners in rather short time. In addition, in some sporadic runs of Covering on cases for which we know the topological optimal TC( K )+1, the constructed systems have cardinality reasonably close to optimal. In this subsection we describe the randomized algorithm OptimizedCovering that addresses all other cases, i.e., those where the systems reported by Covering appear to have too many domains. This is achieved by using a greedy strategy that attempts to reduce the number of piecewise linear local domains by increasing the size of large domains. As advertised in the introduction, the combined use of OptimizedCovering and Reduce leads to the explicit and unexpected optimal piecewise linear motion planner reported in the final section of the paper.
OptimizedCovering starts with a partition P of F L produced by Covering, and goes into an iterative process that aims at shortening the length of P. Explicitly, assume that, after the i-th stage of the iteration, the original partition has evolved to become the partition {P 0 , P 1 , . . . , P p }. Then, using a control variable j (inductively assumed to lie in between 0 and p), the (i+1)-st recursive stage of OptimizedCovering performs the following actions: (1) Order the partition so that Card(P 0 ) ≥ Card(P 1 ) ≥ · · · ≥ Card(P p ).
(2) Use the algorithm RCC to generate a random contiguity subcomplex J P of J P j ∪P j+1 ∪···∪Pp . Keep in P the largest set of P and P j .
(3) Use the algorithm AddFacets to add as many facets of as possible to P , so to produce a contiguity subcomplex J Q containing J P . If j = 0, part P j−1 is inexistent in (6). If j > 0, keep in Q the largest set between Q and P j−1 .
The (i + 1)-st iteration of the process then finishes by constructing the new (optimized) partition where empty parts are eliminated. If j = 0, parts P 0 , P 1 , . . . , P j−2 and P j−1 − Q are inexistent in (7). Lastly, in preparation for the next iteration, the control variable j is incremented by one, unless its value has to be reset to zero so to meet the inductive hypothesis on j.
The rationale behind the above process is to use the best possible contiguity subcomplex that can be built from the facets in ∪ i≥j P i (step (2)) to greedily improve on the cardinality of P j−1 (step (3)). The net effect of such a recursive process is that new longer portions start "bubbling up" in the most recently produced partitions, while shorter portions tend to disappear from previously constructed partitions, as their elements get added to the longer emerging parts. As a consequence, the new partitions tend to have fewer domains than the old partitions.
For better results, the main recursive loop in the process above is meant to be repeated a large number of times (indicated by a parameter N prescribed by the user). The pseudocode we describe uses in addition a parameter t (also determined by the user) that breaks the recursion as soon as a partition with t elements or less is achieved. The value of t is to be provided on the basis of getting a "short enough" partition, either because the user would be happy with the prescribed bound, or simply because it does not make sense to insist on getting a partition of length smaller that the optimal TC( K ) + 1 (if the latter number is known in advance, say by theoretical but non-constructive means).

The circle
Let K := ∂∆ 2 , i.e., the most efficient triangulation of the circle, with vertices labelled 0, 1, 2. The (realization of the ordered) product structure on K × K is depicted in Figure 1, where opposite sides of the external square are identified as indicated. Using parameters M = 1000 and r = 0.1 for LocalSearch, OptimizedCovering yields, in about 57 seconds, the covering {J 0 , J 1 } of K × K, where J i is generated by the i-labelled triangles in Figure 1. Relevant stages in the actual process (performed by OptimizedCovering) leading to this cover are illustrated in Figure 2. Here, at each of the stages shown, the largest (smallest) subcomplex is highlighted in green (blue). OptimizedCover finishes as soon as the blue subcomplex has been incorporated into two large subcomplexes.  The corresponding contiguity chains (simplified by Reduce) for the restricted projections π 1 | J i , π 2 | J i : J i → K are described in Table 1 (for i = 0) and Table 2 (for i = 1). In particular, the optimal SC(∂∆ 2 ) = 1 is attained though contiguity chains of length no more than 10, i.e., SC 9 (∂∆ 2 ) = 1.
piecewise linear motion planners using parameters M = 20000 and r = 0.1 for Lo-calSearch. A detailed report of the resulting pair of piecewise linear domains and corresponding contiguity chains can be found in the Master's thesis of the first author. Despite the computer effort needed for such calculations, the output only gives that the optimal (1) can be attained though contiguity chains of length at most 26. Such an unsatisfactory state of matters supports the point made in the introductory section: avoid using simplicial subdivisions in concrete applications of the TC ideas.

A wedge of two circles
Consider the 1-dimensional complex K depicted in Figure 3. The geometric realization K has the homotopy type of a wedge of two circles, and it is well known that TC( K ) = 2. The corresponding contiguity chains are described in Tables 3-5.