Discrete Applied Mathematics (
)
–
Contents lists available at ScienceDirect
Discrete Applied Mathematics journal homepage: www.elsevier.com/locate/dam
Computing simple paths from given points inside a polygon✩ ∗
Xuehou Tan a,b , , Bo Jiang a a b
School of Information Science and Technology, Dalian Maritime University, Linghai Road 1, Dalian, China School of Information Science and Technology, Tokai University, 4-1-1 Kitakaname, Hiratsuka 259-1292, Japan
article
info
Article history: Received 2 December 2015 Received in revised form 20 August 2018 Accepted 20 September 2018 Available online xxxx Keywords: Computational geometry Visibility graph Simple paths Shortest paths Dijkstra paradigm
a b s t r a c t Given a set X of points inside a polygonal region P, two distinguished points s, t ∈ X , we study the problem of finding a simple polygonal path that uses only the points of X as vertices and lies in P, from s to t. We present an O(n2 + n log n log(mn) + m log m) time and O(n2 + m) space algorithm for computing a simple path from s to t or reporting no simple paths exist, where n is the number of points of X and m is the number of vertices of P. This gives a significant improvement upon the previously known O(m2 n2 ) time and space algorithm, and O(n3 log m + mn) time and O(n3 + m) space algorithm. Our result is mainly obtained by showing that the visibility graph of X inside P, together with an implicit representation of the shortest paths from s to all other points of X , is sufficient to give a solution to the considered problem. © 2018 Elsevier B.V. All rights reserved.
1. Introduction Motivated by the work of generating random polygons with given vertices [1,10], the following problem has been studied in the literature [4,6]: Given a simple polygon P of m vertices, a set X of n points inside P, we want to find a simple polygonal path (without self-intersections) from a start point s ∈ X to an end point t ∈ X , which uses only the points of X as vertices and stays inside P. The desired path is called the simple (st , X )-path, see Fig. 1.(a). Note that the points of X may be on the boundary of P. It is worth pointing out that the problem of finding an arbitrary (st , X )-path can simply be solved using the visibility graph of X inside P. The visibility graph of X inside P is a graph whose arc set records all point pairs (x, y), x, y ∈ X , such that x is visible from y in P. If all arcs of the visibility graph of X are assigned with weight one, then a shortest (st , X )-path in the visibility graph (if it exists) gives the solution [4]. In Fig. 1, two types of the shortest (st , X )-paths consisting of four points of X are shown: One is simple and the other is self-intersected. Note that there are no simple (st , X )-paths in Fig. 1(b). Requiring that the found (st , X )-path be simple makes the problem substantially harder and more interesting, because it finds applications, say, in constructing a non-crossing railroad that connects some or all digging sites in a mine. A related, more difficult problem is to find a simple path that lies in P and uses all points of X as vertices, not just a subset. Clearly, it is equivalent to computing a simple Hamiltonian path from s to t. When P is convex, a simple Hamiltonian path can simply be found in O(n log n) time [4]. However, when P is an arbitrary polygon, no polynomial-time solution is known. Previous work. Cheng et al. [4] were the first to study the problem of finding a simple (st , X )-path inside P. A simple (st , X )-path R is shortcut-free if any two non-consecutive vertices of R are not mutually visible. They investigated the following ‘‘monotone’’ property of simple shortcut-free paths. ✩ A preliminary version of this paper appeared in the proceedings of FAW’2014, Lect. Notes Comput. Sci. Vol. 8497, pp. 229–239. ∗ Corresponding author at: School of Information Science and Technology, Tokai University, 4-1-1 Kitakaname, Hiratsuka 259-1292, Japan. E-mail addresses:
[email protected] (X. Tan),
[email protected] (B. Jiang). https://doi.org/10.1016/j.dam.2018.09.020 0166-218X/© 2018 Elsevier B.V. All rights reserved.
Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
2
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
Fig. 1. The shortest (st , X )-paths consisting of four nodes of the visibility graph of X inside P: (a) a simple path and (b) a self-intersected path.
Lemma 1 (See Lemma 4 of [4]). For any simple shortcut-free (st , X )-path with k points of X , there exists a corresponding sequence of k vertices of P such that the line segment connecting each of these k points and its corresponding vertex can be extended to partition P into two disjoint subpolygons, one containing s and the other containing t, and moreover, any subpolygon containing s is completely contained in the one immediately after it (in the order from s to t). The segment used to partition P into two subpolygons is called a cut. Cheng et al. [4] then considered a directed graph, whose node set denotes the set of cuts and whose arc set records all pairs of consecutive cuts that may appear in a simple shortcut-free (st , X )-path. The orders of cuts in possible simple (st , X )-paths are used to specify the orientations of constructed arcs. By considering s and t as two special cuts, a path between them in the graph gives a simple shortcut-free (st , X )-path. Clearly, the number of cuts is O(mn), and the total number of pairs of possible consecutive cuts is O(m2 n2 ). An O(m2 n2 ) time and space algorithm was finally reported using dynamic programming. Whether a more efficient algorithm (say, with running time O(mn(m + n))) can be given was left as an open problem [4]. (They also showed that finding a simple (st , X )-path among arbitrary obstacles is NP-complete.) Later, Daescu and Luo [6] gave a thorough study of the ‘‘3-shortcut-free’’ paths, which are oriented from s to t and to which no shortcut can be made among any three consecutive vertices of a path. Let G denote the visibility graph of X inside P. A so-called pyramid graph G′ was then constructed from G, in which a node of G′ corresponds to an arc of G and an arc of G′ corresponds to a particular pair of two (connected) arcs of G that may appear in a simple 3-shortcut-free path. Thus, the pyramid graph has O(n2 ) nodes and O(n3 ) arcs. Based on the pyramid graph, an O(n3 log m + mn) time and O(n3 + m) space solution was presented in [6]. The algorithm of Daescu and Luo resembled the single-source shortest-paths algorithm, which is usually called the Dijkstra paradigm [5]. The solution of Daescu and Luo can be considered as√an improvement upon the first one [4]. Specifically, the space bound was reduced from O(m2 n2 ) to O(n3 ) whenever m = ω( n), and the running time was improved whenever n = o(m2 /log m). The algorithm of Daescu and Luo [6] can also report O(n2 ) simple (st , X )-paths.1 However, the open problem of developing an efficient algorithm stands still open. Our result. A main drawback of existing algorithms is that both algorithms require to construct, from the visibility graph of X , a new graph of high complexity (O(m2 n2 ) or O(n3 )). An important observation made in this paper is that the visibility graph of X is almost sufficient to solve the considered problem. To this end, we present a new approach to finding a simple (st , X )-path inside P, in which only the visibility graph of X as well as the structure of shortest paths from s to all other points of X is employed. Let π (a, b) denote the shortest path between two points a and b inside P. The point set X can be partitioned into two subsets X1 and X2 by path π (s, t) as well as the extensions of its first and last segments inside P, see Fig. 2. If there exists a simple (st , X )-path, then there exists a simple shortcut-free (st , X )-path R such that for the points x0 (= s), x1 , x2 , . . . , xk , xk+1 (= t) of Xi (i = 1 or 2), appearing on R in this order, any two paths π (s, xj ) and π (xj+1 , t) (1 ≤ j ≤ k − 1) do not intersect. This result, termed the Shortest-path Dependence Theorem, can be used to check the simplicity of a shortcut-free (st , X )-path. It finally turns out that the visibility graph of X inside P, together with an implicit representation of the shortest paths from s to all other points of X , is sufficient to give a solution. Our algorithm runs in O(n2 + n log n log(mn) + m log m) time and O(n2 + m) space. This gives a significant improvement upon the previously known O(m2 n2 ) time and space algorithm, and O(n3 log m + mn) time and O(n3 + m) space algorithm. It also answers the open question posed by Cheng et al. [4]. The rest of this paper is organized as follows. We give basic definitions in Section 2, and present the Shortest-path Dependence Theorem in Section 3. The algorithm for finding a simple (st , X )-path or reporting the non-existence of simple (st , X )-paths is described in Section 4. Our algorithm is based on a combined application of the Dijkstra paradigm and Shortest-path Dependence Theorem to the visibility graph of X inside P. Concluding remarks are given in Section 5. 1 As in [4], the goal of this paper is to find a simple (st , X )-path, if it exists. Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
3
Fig. 2. A simple (st , X )-path (in dotted line) and two paths π (s, t) and π (se , te ) (in solid line)
2. Definitions Let P be a simple polygon (without holes) of m vertices. Two points p, q ∈ P are said to be mutually visible if the line segment connecting them, denoted by pq, is entirely contained in P. Suppose that a set X of n points, and two distinguished points s, t ∈ X are given in P. Assume that s and t are not mutually visible; otherwise, the problem is trivially solved. The visibility graph G of X inside P is defined as follows: The node set V (G) is the same as the point set X , and the arc set E(G) records all point pairs (u, v ), u, v ∈ X , such that u is visible from v in P. (Clearly, if u is visible from v , then v is also visible from u.) A polygonal path R from s to t is called the (st , X )-path, if it uses only the points of X and lies in P [4]. Thus, two consecutive vertices of a (st , X )-path are mutually visible. Path R is simple if it does not have self-intersections. We refer to the points of X , which are used in R, as the vertices of R. Let x and y be the two points (not necessarily vertices) of R such that x is closer to s than y on R. We denote by R[x, y] (R(x, y)) the closed (open) portion of R from x to y. Path R with k vertices (including s and t) is said to have the link distance k − 1. If the link distance of R is the minimum among all simple (st , X )-paths, then R is called a simple minimum-link (st , X )-path. Clearly, any simple minimum-link (st , X )path is shortcut-free, and its link distance is at most n − 1. In this paper, we use BN to denote a big number, which is larger than n. For two arbitrary points a and b inside P (a or/and b may belong to X ), denote by π (a, b) the shortest path between a and b, which lies in P. Assume that path π (a, b) is oriented from a to b. Let us extend the first and last segments of π (a, b), starting from a and b, until they first intersect the boundary of P. Denote by ae and be two such intersection points, respectively. Since the extended segments ae a and be b are co-linear (but do not overlap) with the first and last segments of π (a, b) respectively, the path consisting of ae a, π (a, b) and bbe is just π (ae , be ) (see Fig. 2). It is clear that π (se , te ) separates the interior of P into two regions, say, P1 and P2 . Denote by Xi the subset of the points x ∈ X ∩ Pi , i = 1 or 2. For the points of X on π (se , te ), we simply let them belong to X1 . Thus, X1 ∪ X2 = X and X1 ∩ X2 = {s, t }. For a point p ∈ Xi (i = 1 or 2), we call Xi the belonging set of p. A geodesic triangle with three vertices a, b, c ∈ P is the region bounded by three paths π (a, b), π (b, c) and π (c , a). 3. Shortest-path dependence theorem Two vertices x and y of a (st , X )-path are said to be Xi -adjacent (with respect to the (st , X )-path), i = 1 or 2, if both x and y belong to Xi and there is no other vertex z ∈ Xi between x and y on the (st , X )-path (see also Fig. 2). In this section, we prove the following Shortest-path Dependence Theorem: A shortcut-free (st , X )-path is simple if and only if for any two Xi -adjacent vertices x and y (i = 1 or 2), two paths π (s, x) and π (y, t) do not intersect. Lemma 2 (The Consecutive Intersection Property [4]). Let R be a simple shortcut-free (st , X )-path, and a, b ∈ P be two points that see each other in P. Let i1 , i2 , . . . , ik be the intersection points of R with the line segment ab, listed in the order in which they appear on R. Then, i1 , i2 , . . . , ik are consecutive on ab, that is, ij is between ij−1 and ij+1 for all j = 2, . . . , k − 1. A slightly stronger result than the Consecutive Intersection Property holds for path π (s, x), where x is a vertex of R. Lemma 3. Assume that R is a simple shortcut-free (st , X )-path and x (̸ = s) is a vertex of R. Let i0 (= s), i1 , i2 , . . . , ik , ik+1 (= x) be the intersection points of R with π (s, x), listed in the order in which they appear on R. Then, i1 , i2 , . . . , ik are ordered on π (s, x), that is, ij−1 is closer to s than ij on π (s, x), for all j = 2, . . . , k. Proof. Suppose first that only one line segment L of π (s, x) intersects R, i.e., all points i1 , i2 , . . . , ik are on L. We claim that i1 is closer to s than i2 (if it exists) on π (s, x). Otherwise, let z be the vertex of R(i2 , x] immediately after i2 (Fig. 3). Since it is assumed in the lemma that i1 is the first intersection point of R with L (among i1 , i2 , . . . , ik ), the simple path R[s, i1 ] and Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
4
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
Fig. 3. The disorder of points i1 , i2 , . . . , ik along π (s, x) contradicts the shortcut-free property of R.
π (s, i1 ) together give the boundary of a simple polygon Q . Then, z is contained in Q , and any point of Q is visible from at least one vertex of R[s, i1 ).2 So, z is visible from at least one vertex of R[s, i1 ), contradicting the shortcut-free property of R. The claim is thus proved. It then follows from our claim and Lemma 2 that all points i1 , i2 , . . . , ik are ordered on π (s, x). Suppose now that the segments L1 , L2 , . . . , Lh (h ≥ 2) of π (s, x), in this order, intersect R. It then follows from Lemma 1 as well as the definition of path π (s, x) that points i1 , i2 , . . . , ik appear on segments L1 , L2 , . . . , Lh , exactly in this order. If h = 2, then there is a point ij such that i1 , i2 , . . . , ij−1 are on L1 , and ij , ij+1 , . . . , ik are on L2 . From the lemma assumption, i1 and ij are the first intersection points of R with L1 and L2 , respectively. Hence, the above argument can apply to L1 and L2 , respectively. So, i1 , i2 , . . . , ij−1 as well as ij , ij+1 , . . . , ik are ordered on π (s, x). Since L1 precedes L2 on π (s, x), point ij−1 is closer to s than point ij on π (s, x), and the lemma is true. For the case of h ≥ 3, the same argument can apply to every pair of Lf and Lf +1 , 1 ≤ f < h. Therefore, the lemma follows. □ Lemma 4. Assume that R is a shortcut-free (st , X )-path in P. Let x, y be two Xi -adjacent vertices, i = 1 or 2, such that x precedes y on R. If two paths π (s, x) and π (y, t) intersect, then R is not simple. Proof. Assume by contradiction that although π (s, x) and π (y, t) intersect each other, path R is simple. Without loss of generality, assume that both x and y belong to X2 , i.e., they are contained in polygon P2 . Let xe be the boundary point of P2 , which is obtained by extending the last segment of π (s, x) from x until the boundary of P2 is reached. So, π (s, xe ) consists of π (s, x) and xxe . Since both s and xe are on the boundary of P2 , and since π (s, x) and π (y, t) intersect each other, π (s, xe ) separates y from t in P2 . Path R[y, t ] then goes across either π (s, x) or xxe . However, in the former case, since x is an intersection point of R with π (s, x), path R[y, t ] cannot intersect π (s, x) (Lemma 3), a contradiction. In the latter case, let p be the (last) common point of R(y, t ] (⊂ R(x, t ]) with segment xxe . Since R is simple, R[x, p] and xp together give the boundary of a simple polygon. Since π (x, s) and π (y, t) intersect and since R[y, t ] goes across xxe , path R(y, p) contains at least one vertex. The vertex of R(y, p) immediately before p is then visible from x (in the polygon formed by R[x, p] and xp), contradicting the shortcut-free property of R. Hence, the lemma follows. □ Theorem 1 (The Shortest-path Dependence Theorem). Assume that R is a shortcut-free (st , X )-path in P. Path R is simple if and only if for all pairs of Xi -adjacent vertices x and y, i = 1 or 2, such that x precedes y on R, two paths π (s, x) and π (y, t) do not intersect (i.e., they do not have any common point). Proof. The necessity follows from Lemma 4. We prove below the sufficiency by induction on the number of vertices of the shortcut-free path R. It is trivially true if R consists of three vertices. In the case that R consists of four vertices, say, s, x, y and t, there are only two types of shortcut-free paths: One is simple and the other is self-intersected (see also Fig. 1). If R is self-intersected, then four vertices belong to a same subset, say, X1 , and thus, π (s, x) and π (y, t) intersect, contradicting the sufficiency condition. Hence, the theorem is true when R consists of four vertices. Assume below that R consists of at least five vertices, and for any two Xi -adjacent vertices x and y of R(s, t), i = 1 or 2, two paths π (s, x) and π (y, t) do not intersect. Let a be the vertex of R, which immediately succeeds s. We first claim that the sufficiency condition holds for path R[a, t ], too. Denote by ae a′e and te te′ two line segments that are obtained by extending the first and last segments of π (a, t) respectively, until the boundary of P is reached, see Fig. 4(a). Let P1′ and P2′ denote two regions of P, which are separated by π (a′e , te′ ). As in Section 2, let Xj′ be the subset of the points x ∈ X ∩ Pj′ , j = 1 or 2. Thus, X1′ ∪ X2′ = X and X1′ ∩ X2′ = {a, t }. Let (u, v ) be an arbitrary pair of Xj′ -adjacent vertices of R(a, t), j = 1 or 2, such that u precedes v on R(a, t). We show below that π (a, u) and π (v, t) do not intersect. 2 Note that point i is not a vertex of path R. 1 Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
5
Fig. 4. Illustrating the proof of Theorem 1.
Denote by F the region that is the difference between the two partitions (P1 , P2 ) and (P1′ , P2′ ). See Fig. 4(a) for an example, where region F is shaded. Clearly, if te′ is identical to te , then F is a single region or simple polygon (Fig. 4(a)); otherwise, F consists of two subregions that have t as the only common point. We can then distinguish the following situations. Case 1. Both u and v belong to F . In this case, both u and v belong to either X1 or X2 . From the sufficiency condition, they are X1 - or X2 -adjacent, and thus, π (s, u) and π (v, t) do not intersect. Also, π (a, u) and π (v, t) do not intersect; otherwise, v is contained in the geodesic triangle bounded by sa, π (s, u) and π (a, u), and it is thus visible from at least one vertex of R[a, u), contradicting the shortcut-free property of R. Case 2. One of u and v belongs to F , and the other does not. By symmetry, we can assume that u belongs to F and v does not (e.g., two points d and e in Fig. 4(a)). In this case, u is the vertex of R immediately before v , and thus, u and v are mutually visible. Note that if F consists of two subregions, then u lies in the same subregion as both a and t; otherwise, π (t , v ) intersects π (a, u) as well as π (s, u), contradicting the sufficiency condition. Both π (a, u) and π (u, t) are then wholly contained in the same region of F , and thus, they do not intersect, except for the only common point u. Since u and v are mutually visible and since v does not belong to F , two paths π (a, u) and π (v, t) do not intersect, either. Case 3. Both u and v do not belong to F . In this case, u and v belong to the same set Xi , i = 1 or 2. If u and v are two Xi -adjacent vertices, then as in Case 1, π (v, t) does not intersect π (s, u) or π (a, u). If u and v are not Xi -adjacent (but they are Xj′ -adjacent), then R consists of some other points of X between u and v such that they belong to the same set Xi as both u and v , i = 1 or 2. (For instance, b and e in Fig. 4(a) are two such Xj′ -adjacent vertices.) By a simple argument on the sequence of all pairs of these Xi -adjacent vertices, i = 1 or 2, we also have that π (v, t) does not intersect π (s, u) or π (a, u). The above discussion enumerates all possible configurations among u, v and F , and our claim is thus proved. From the induction hypothesis, the shortcut-free path R[a, t ] is then simple. Analogously, the shortcut-free path R[s, b] is simple, where b denotes the vertex of R immediately preceding t. For the simplicity of R, the remaining job is to show that two segments sa and bt cannot intersect. Again, assume by contradiction that sa and bt intersect, say, at a point k (Fig. 4(b)). Then, R(a, b) cannot intersect ak or bk; otherwise, R[s, b] or R[a, t ] is not simple, a contradiction in either case. Since R is shortcut-free, all vertices of R[a, b] are then contained in the geodesic triangle bounded by ak, kb and π (a, b), and thus, they are to the same side of π (se , te ). This implies that all vertices of R[a, b] belong to a same subset, say, X1 . Let c be the vertex of R immediately after a. Two paths π (s, a) and π (c , t) then intersect, contradicting the sufficiency condition. The proof is complete. □ Finally, it has been known that a simple (st , X )-path can always be adjusted to a simple, shortcut-free (st , X )-path. Lemma 5 (See [4]). If there exists a simple (st , X )-path in P, then there exists a simple, shortcut-free (st , X )-path. Before closing this section, we give a simple method to determine whether two paths π (s, x) and π (y, t) intersect, where (x, y) is a pair of Xi -adjacent vertices, i = 1 or 2. Recall that P1 and P2 are two disjoint regions of P, which are separated by π (se , te ). For each point x ∈ Xi (i = 1 or 2), let xi,e be the point on the boundary of Pi , which is obtained by extending the last segment of π (s, x) from x, until Pi is reached. See Fig. 5. Note that for any point z ∈ X1 on π (se , te ), point z1,e is identical to z. Let ui,e and vi,e be two points on Pi , i = 1 or 2. If ui,e is encountered strictly before vi,e in the scan of the boundary of Pi , starting from s and then se , we simply write ui,e ≺ vi,e . For the instance given in Fig. 5, we have a1,e ≺ b1,e ≺ c1,e ≺ d1,e ≺ e1,e and f2,e ≺ g2,e ≺ h2,e ≺ i2,e . Lemma 6. Assume that R is a shortcut-free (st , X )-path in P. Let (x, y) be a pair of Xi -adjacent vertices, i = 1 or 2, such that x precedes y on R(s, t) and two paths π (s, x) and π (y, t) intersect. Then, yi,e ≺ xi,e holds. Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
6
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
Fig. 5. The points x1,e or x2,e on P1 and P2 .
Proof. Since R is shortcut-free, y (resp. x) cannot be on the line segment sse (resp. tte ). Also, x cannot be on sse ; otherwise, two vertices of the line segment of R[x, t ] intersecting the maximal segment inside P, which passes through s and is perpendicular to sx, are visible from s, contradicting the shortcut-free property of R. Analogously, y cannot be on tte , either. First, if both x and y are on π (s, t), then since π (s, x) and π (y, t) intersect, we simply have y1,e ≺ x1,e . (Recall that x and y belong to X1 in this special case.) Otherwise, as discussed above, neither x nor y can be on π (se , te ). Since x and y are both contained in Pi (i = 1 or 2), y is contained in the region bounded by π (s, xi,e ) and the portion of the boundary of Pi from s to xi,e , and so is yi,e . Thus, we have yi,e ≺ xi,e . □ 4. Algorithm In order to find a simple shortcut-free (st , X )-path, we will describe a combined application of the Dijkstra paradigm and Shortest-path Dependence Theorem to the visibility graph G of X inside P. The simplicity of the found path is checked using the Shortest-path Dependence Theorem, and the shortcut-free property is assured by the Dijkstra paradigm because our algorithm always reports a simple (st , X )-path of the minimum link distance, if it exists. 4.1. An overview of our approach We first give a brief review of the Dijkstra paradigm [5]. Let G(V , E) be a directed graph such that each arc of E has a non-negative weight. The length of a path in G is the sum of the weights of its constituent arcs. The shortest path from node u ∈ V to node v ∈ V is then defined as any path from u to v with the minimum length among all possible paths, provided there exists a path from u to v . The so-called single-source shortest-paths problem asks to find a shortest path from a given source node u ∈ V to each node v ∈ V , v ̸ = u. The Dijkstra’s algorithm solves this single-source shortest-paths problem using the greedy method. It maintains a set T of the nodes, to which the shortest paths have not yet been determined. Each step of the algorithm selects a node v from T such that the path from u to v is of the minimum length among the paths to all nodes of T , and then deletes v from T . Next, the paths to some nodes w of T are updated if a shorter path to w can be obtained using the shortest path to v . The algorithm stops (or finishes the loop) when T becomes empty. Consider now how the Dijkstra paradigm can be applied to our problem. The visibility graph G is first computed, and each arc of G is assigned weight one. Note that the node set V (G) is the same as the given point set X . The problem considered in this paper, called the single-pair shortest-path problem, is to find a shortest path of the minimum link distance, from the source point s to the target point t in G. The Dijkstra paradigm can still be used, except for that our algorithm stops as soon as the target t is chosen from T . For ease of presentation, our algorithm will first select t from T , if it is ever possible. Also, if there are two candidates v to be chosen from T and their belonging sets are same, we always select the one whose value vi,e (i = 1 or 2) is smaller in the relation ‘‘≺’’ (Lemma 6). For two candidates with different belonging sets, either of them can arbitrarily be chosen from T . A new part of our algorithm is the application of Shortest-path Dependence Theorem to checking the simplicity of found paths. However, before a simple (st , X )-path of the minimum link distance is reported, all other found paths from s do not end at t. We need to adjust the Shortest-path Dependence Theorem to this slightly different situation. Let L be a simple shortcut-free (sv, X )-path in P such that the vertex immediately preceding v on L is invisible from t, v ̸ = t. The path consisting of L and the line segment v t, without considering the visibility between v and t, is called the artificial-simple (st , X )-path of L. In the case that v is visible from t, the artificial-simple (st , X )-path of L is a simple shortcut-free (st , X )-path. Lemma 7 (The Shortest-path Dependence Theorem for Artificial-simple (st , X )-paths). Suppose that L is a simple shortcut-free (sv, X )-path in P such that the vertex immediately preceding v on L is invisible from t, v ̸ = t. If the Shortest-path Dependence Theorem applies to the artificial-simple (st , X )-path of L, then a simple shortcut-free (st , X )-path can initially follow L from s to v . Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
7
Proof. By noticing the fact that the artificial-simple (st , X )-path of L is shortcut-free, including the situation in which vertex v of L is visible from t, the lemma directly follows from Theorem 1. □ For each found path (sv, X )-path (of the minimum link distance), our algorithm will maintain two variables u and v ′ . The variable u records the vertex of the (sv, X )-path immediate before v . Hence, when a simple (st , X )-path of the minimum link distance is found, our algorithm can report it from t to s (in the reverse order). The variable v ′ maintains the last vertex on the (sv, X )-path, whose belonging set differs from that of v . (It is possible that u = v ′ .) Based on the information of u and v ′ , the Shortest-path Dependence Theorem can then be employed to check the simplicity of found paths. In the way described above, the Dijkstra paradigm can be modified to compute a simple (st , X )-path of the minimum link distance, provided that there exists a simple path from s to t (Lemma 5). After the algorithm stops, for all points v ∈ X − T , their simple (sv, X )-paths of the minimum link distance are found, no matter whether v = t or not (Lemma 7). It may occur that although there exists a simple (sa, X )-path, point a is finally kept in T , either because the Shortest-path Dependence Theorem does not hold for its artificial-simple (st , X )-path or t is chosen from T before a. The minimum link distances from s to the points that still belong to T are all reported as BN. 4.2. The algorithm description and implementation In this section, we describe our algorithm in detail and then analyze its running cost. To apply the Dijkstra paradigm to the visibility graph G, we define below a function W from the arcs of E(G) to non-negative integers: If (x, y) is an arc of G, then W (x, y) is equal to one. If (x, y) is not an arc, we let W (x, y) be BN. For each v ∈ V (G), we will compute a minimum link distance D[v] if there exists a simple (sv, X )-path of link distance D[v] and the Shortest-path Dependence Theorem applies to its simple or artificial-simple (st , X )-path (Theorem 1 and Lemma 7); otherwise, D[v] is set to BN. Initially, the value D[s] is zero, and any other D[x] is set to one if (s, x) ∈ E(G), or BN otherwise. The initial value of T is V − {s}. As described in the previous section, our algorithm maintains two variables u and v ′ , for each v ∈ V (G). Assume also that s is the vertex immediately before s itself. Consider now the main step of our algorithm, at which a point v is chosen (and then deleted) from T such that the path from s to v is of the minimum length among the paths to all points of T . Remember that our algorithm first selects t from T , if it is ever possible. And, if there are multiple candidates v belonging to the same set Xi (i = 1 or 2), the one with the smallest value vi,e is first chosen. For each point w ∈ T − {v}, its value D[w] is then updated if (i) D[v] + W (v, w ) < D[w] and (ii) π (s, v ) does not intersect π (w, t), or π (s, v ′ ) does not intersect π (w, t), depending on whether the belonging sets of v and w are same or not. In the case that D[w] is updated, w ′ is accordingly set to v or v ′ , and v is recorded as the vertex immediately preceding w on the found (sw, X )-path. For the instance given in Fig. 6(b), our algorithm first selects f , g and i from T , in this order, because f2,e ≺ g2,e ≺ i2,e . After f is chosen from T , both D[b] and D[c ] are updated to two, and b′ and c ′ are set to f . When i is lately selected from T , the value D[b] as well as b′ is kept unchanged. We give below the pseudo-code of our algorithm. Algorithm ModifiedDijkstraParadigm. Input. A (visibility) graph G = (V , E), two distinguished points s, t ∈ V (G) and the function W as defined above. Output. For each v ∈ V (G), a minimum link distance D[v] if there exists a simple (sv, X )-path of link distance D[v] and the Shortest-path Dependence Theorem applies to its artificial-simple (st , X )-path, or the simple (st , X )-path for v = t; otherwise, D[v] is equal to BN. 1. Let T = V (G) − {s}, s′ = s and v = s. 2. For all points x ∈ T , let D[x] = W (s, x). Also, let D[s] = 0. 3. While v ̸ = t, do the followings: (a) Select a point v from T such that D[v] is the minimum among those of all points of T ; the target t is first chosen from T if it is ever possible, and if there are multiple candidates v belonging to the same set Xi (i = 1 or 2), the one with the smallest value vi,e is first chosen. (For two candidates with different belonging sets, either of them can be chosen.) (b) If the belonging set of v is the same as that of u, then let v ′ = u′ . Otherwise, set v ′ = u. (Recall that u is the vertex immediately preceding v on the (sv, X )-path.) (c) Delete v from T (i.e., update T to T − {v}). (d) For each point w of T , let D[w] = D[v] + W (v, w ) if D[v] + W (v, w ) < D[w] and π (s, v ) does not intersect π (w, t), or π (s, v ′ ) does not intersect π (w, t), depending on whether the belonging sets of v and w are same or not. In the case that D[w] is updated, w ′ is accordingly set to v or v ′ , and v is recorded as the vertex immediately preceding w on the simple (sw, X )-path. 4. If D[t ] is not equal to BN, then output a simple minimum-link (st , X )-path, by starting from w = t and tracing back by using its preceding vertex (recorded in Step 3(d)), until s is reached. Otherwise, report ‘‘no simple (st , X )-paths exist’’. Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
8
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
Fig. 6. An example of the graph G and the running result on it.
Fig. 6 shows a running example of our algorithm. The visibility graph G is given in Fig. 6(a), in which every edge of G is considered as two symmetric arcs. The points with D[·] = 1 are f , g and i, see Fig. 6(b). The simple (sf , X )-path, (sg , X )-path and (si, X )-path are shown in bold dashed line. The points with D[·] = 2 are b and c. Since f2,e ≺ i2,e , the found (sb, X )-path uses f as one of its vertices, see Fig. 6(c). The point with D[·] = 3 is h. Again, since b1,e ≺ c1,e , the found (sh, X )-path uses b as one of its vertices, see Fig. 6(d). Although there exists a simple (sa, X )-path of link distance three, the Shortest-path Dependence Theorem does not hold for its artificial-simple (st , X )-path, and thus, the link distance to a is finally reported as BN. The point with D[·] = 4 is d, see Fig. 6(e). Finally, our algorithm reports a simple (st , X )-path of link distance five, which consists of s, f , b, h, d and t. See Fig. 6(f). Note that although there exists a simple (se, X )-path of link distance five, D[e] is reported as BN. This is because as soon as t is chosen from T (before e), our algorithm terminates, letting e be left in T . By now, we can give the main result of this paper. Lemma 8. For all points x ∈ X , x ̸ = s and x ̸ = t, it takes O((n + m) log m) time and O(n + m) space to compute their points x1,e or x2,e . Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
9
Proof. We preprocess P in O(m) time and space so that a shortest path query between any two points, or simply, from s to any other point inside P can be answered in logarithmic time plus the time required to report the path itself [7–9]. Also, we preprocess in O(m log m) time and O(m) space so that a ray-shooting query in P can be answered in O(log m) time [3]. For any point x ∈ X1 or x ∈ X2 , after the first line segment of path π (x, s) (directed from x to s) is computed in O(log m) time, its point x1,e or x2,e can be found in O(log m) time using a ray-shooting query.3 Since the number of points of X is n, the lemma thus follows. □ Theorem 2. The problem of finding a simple (st , X )-path inside a simple polygon P can be solved in O(n2 + n log n log(mn) + m log m) time and O(n2 + m) space, where n is the number of points of X and m is the number of vertices of P. Proof. All the simple paths of link distance one, from point s, can be found from the visibility graph G. If there exists a simple (sv, X )-path of link distance k ≥ 2, our algorithm finds the (sv, X )-path with the minimum point vi′,e (i = 1 or 2), among all possible candidates of v ′ . For any point w whose simple (sw, X )-path is of link distance at least k + 1, D[w] as well as w ′ is updated if D[v] + W (v, w ) < D[w] and the Shortest-path Dependence Theorem applies to its simple or artificial-simple (st , X )-path. Hence, the correctness of ModifiedDijkstraParadigm follows. Consider the running time of our algorithm. First, it takes O(n2 + n log n log(mn) + m) time and O(n2 + m) space to compute the visibility graph G of X inside P [2]. The function W on the arcs of G can thus be given in O(n2 ) time. For all points x ∈ X1 or x ∈ X2 , we compute their points x1,e or x2,e in O((n + m) log m) time and O(n + m) space (Lemma 8). Applying the modified Dijkstra’s algorithm to G can then find a simple minimum-link (st , X )-path or report no simple (st , X )-paths exist. Step 3(a) clearly takes O(n) time. In Step 3(d), we need to determine whether π (w, t) intersects π (s, v ) or π (s, v ′ ). Since only the last pair of Xi -adjacent vertices on the shortcut-free path R[s, w] needs to be considered, whether π (w, t) intersects π (s, v ) or π (s, v ′ ) can be determined in constant time (Lemma 6). Step 3 can thus be performed in O(n2 ) time. In Step 4, a simple (st , X )-path of the minimum link distance, if it exists, is reported in O(n). Hence, the algorithm ModifiedDijkstraParadigm itself takes O(n2 ) time [5]. In summary, the time complexity and the space requirement of our algorithm are O(n2 + n log n log(mn) + m log m) and O(n2 + m), respectively. □ 5. Concluding remarks In this paper, we study the problem of computing a simple polygonal path that uses only the points of the given set X as vertices and lies in the given polygon P, from a start point s to an end point t. We have presented an O(n2 + n log n log(mn) + m log m) time and O(n2 + m) space algorithm for outputting a simple (st , X )-path or reporting no simple (st , X )-paths exist, where n is the number of points of X and m is the number of vertices of P. This gives a significant improvement upon the previously known O(m2 n2 ) time and space algorithm, and O(n3 log m + mn) time and O(n3 + m) space algorithm [4,6]. Moreover, since our algorithm makes use of the standard paradigm and data structures, it is simpler than the previous ones. We pose several open questions for further research. Analogous to the Dijkstra paradigm, it is desirable to develop an algorithm for computing a simple minimum-link (sx, X )-paths for all points x ∈ X , x ̸ = s. A simple solution can be given by invoking our algorithm n − 1 times. Whether a more efficient algorithm can be developed is open. Also, it is an interesting work to find the application of the Shortest-path Dependence Theorem to other problems concerning simple paths or simple polygons [1,10]. Finally, it remains open to find a polynomial-time solution to the problem of computing a simple Hamiltonian path from s to t, which uses all points of X as vertices and stays inside P [4]. Note that even the problem of finding an arbitrary Hamiltonian path from s to t is still open. Acknowledgments The authors would like to thank the anonymous referees for their valuable comments and suggestions for improvements. Thanks are also due to Dr. Jun Luo of Shenzhen Institute of Advanced Technology for his comments on a preliminary version of this paper. This work was partially supported by JSPS KAKENHI grant number 15K00023 and the National Natural Science Foundation of China under the grant 61173034. References [1] T. Auer, M. Held, Heuristics for the generation of random polygons, in: Proc. 8th Canadian Conf. on Comput. Geom., 1996, pp. 38-44. [2] B. Ben-Moshe, O. Hall-Holt, M.J. Katz, J.S.B. Mitchell, Computing the visibility graph of points within a polygon, in: Proc. ACM Sympos. Comput. Geom., 2004, pp. 27-35. [3] B. Chazelle, L. Guibas, Visibility and intersection problem in plane geometry, Discrete Comput. Geom. 4 (1989) 551–581. [4] Q. Cheng, M. Chrobak, G. Sundaram, Computing simple paths among obstacles, Comput. Geom. 16 (2000) 223–233. [5] T.H. Corman, C.E. Leiserson, R.L. Rivest, C. Stein, Introduction to Algorithms, third ed., The MIT Press, 2009.
3 Note that the ray-shooting from a query point x can be performed inside P. After all ray-shooting points (x or x ) are obtained, they can be classified 1,e 2,e into the set of points y1,e and the set of points z2,e by a scan on the boundary of P. Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.
10
X. Tan, B. Jiang / Discrete Applied Mathematics (
)
–
[6] O. Daescu, J. Luo, Computing simple paths on points in simple polygons, in: Proc. KyotoCGGT’2007, in: Lect. Note Comput. Sci., vol. 4535, 2008, pp. 41–55. [7] L.J. Guibas, J. Hershberger, Optimal shortest path queries in a simple polygon, J. Comput. System Sci. 39 (1989) 126–152. [8] J. Hershberger, A new data structure for shortest path queries in a simple polygon, Inform. Process. Lett. 38 (1991) 231–235. [9] J.S.B. Mitchell, Geometric shortest paths and network optimization, in: J.-R. Sack, J. Urrutia (Eds.), Handbook of Computational Geometry, Elsevier Science, 2000, pp. 633–701. [10] C. Zhou, G. Sundaram, J. Snoeyink, J.S.B. Mitchell, Generating random polygons with given vertices, Comput. Geom. 6 (1996) 277–290.
Please cite this article in press as: X. Tan, B. Jiang, Computing simple paths from given points inside a polygon, Discrete Applied Mathematics (2018), https://doi.org/10.1016/j.dam.2018.09.020.