An Heuristic Algorithm for the Minimum Weight Problem

Nicolau Andres Thio

Supervised by Dr Charl Ras

The University of Melbourne

Vacation Research Scholarships are funded jointly by the Department of Education and Training and the Australian Mathematical Sciences Institute. Abstract A triangulation is an edge-maximal graph on a set of points S such that no pair of edges intersect. The minimum weight triangulation problem consists on finding a triangulation of S such that the sum of the Euclidean lengths of the edges is a minimum. It has been shown that a variety of specific proximity graphs must be subgraphs of a minimum weight triangulation. In addition, many polynomial time algorithms have been discovered that construct minimum weight triangulations for sets of vertices with given properties. In this project we looked at creating a new approximation algorithm making use of the existing subgraphs for points in general position, and testing its performance against other known triangulations such as the Greedy and the Delaunay. We used a combined adaptation of Kruskals and Convex Triangulation algorithms to create a triangulation that was always better than the Greedy and . We also tried to locally optimize all three triangulations with a local search, which improved the Delaunay triangulation but did not improve ours. This has allowed us to conclude that the algorithm presented is locally optimal and always behaves better than both the Greedy and the Delaunay triangulations.

1. Introduction A triangulation is an edge-maximal graph on a set of points S such that no pair of edges intersect. This means that no new edges can be added to a triangulation that would not intersect any of the existing edges. Therefore a triangulation is a plane graph where every interior face is a , and the boundary of the exterior face coincides with the convex hull of S. The Minimum Weight Triangulation problem of a set of vertices S is defined as follows:

Definition 1. Given a set of vertices S, the Minimum Weight Triangulation problem (mwt(S)) consists of finding the triangulation of the set S such that the sum of the Eucledian lengths of the edges is a minimum.

The first appearance of the mwt(S) is atributed to D¨oppe and Gottschalk, proposed as a cartography related problem. It was early thought that the Delaunay triangulation was also the mwt, but this was quickly disproved by Lloyd [1]. It was labelled as on of the most important problems in by Mitchell and O’Roucke [2] in 2001, and it wasn’t until 2006 that it was proven to be NP-Hard [3]. With NP-Hardness being proved, approximations of the problem have become an inter- esting of research. It has been shown that natural triangulations such as Delaunay or Greedy can be worse than the optimum by a factor of Ω(n). Many algorithms have been developed for sets of points in particular arrangements, and subgraphs of the mwt have been discovered. In this study we present a new heuristic with good performance relative to the 1 Delaunay which seems to be locally optimal and works on points in general position; a set of points is in general position if no 4 points lie on the circumference of the same circle. We will compare it to the Delaunay and Greedy triangulations and run a local search to try to improve the given triangulations.

2. Current results 2.1. Subgraphs of the mwt(S) Several investigations have reported subgraphs of mwt(S). These are useful starting points before further edges are added to the graph in the search of an approximation. The convex hull of S is a trivial subgraph, since it is a subgraph of any triangulation of S. The Graham Scan finds the convex hull in O(n log n) [4]. Although optimal output-sensitive algorithms exist (such as Chan’s) with a complexity of O(n log h), where h is the size of the output, the Graham scan suits our needs in this paper. Yang, Chu and Yu [5] proved that the mutual nearest neighbours in a graph are connected in the mwt(S); a pair of points are mutual nearest neighbours if they are their mutual closest point. Adding the edges between these points creates this graph. A simple approach yields the Mutual Nearest Neighbour 2 Graph in O(n ) by looking at every pair of vertices.√ Finally, the circle-based definition of the so called β-skeleton is also a subgraph when β = 2 as shown by Keil [6].

2.2. Existing Algorithms Numerous algorithms which look at triangulating a set of points with certain properties have been developed. An interesting approach was presented by Anagnostou and Corneil [7], which looks at the points as h nested convex sets of points, providing an algorithm with complexity bounded by O(n3h+1). Triangulating a set of points in general position however is a different matter. Cheng, Golin and Tsang [8] showed that if a subgraph of mwt(S) with k connected components is given, then the complete mwt(S) can be computed in O(nk+2). This however is not applicable to large sets of points, since the subgraphs presented are not in general connected even for small sets of points. The algorithm here studied is based on the dynamic programming used to create the min- imum weight triangulation of a in O(n3). A similar approach was presented by Heath and Pemmaraj [9]; they created what they called a cell, a polygon with points within the polygon connected to the polygon vertices, and triangulated it. This algorithm also has a of O(n3) and creates a triangulation that is never worse than a greedy triangulation. Their study did not however make use of the mentioned subgaphs, and was only tested on small sets of up to 25 points. Here we will use a different approach to construct the cells and will test them on large sets of points, as well as running a local optimisation algorithm on the obtained triangulations.

2 3. Description of the Algorithms Used 3.1. Triangulation Algorithm

Figure 1: Combined subgraphs for 100 points Figure 2: Resulting connected graph

As mentioned above, the first step used in this study was to construct a subgraph of the problem, namely finding the convex hull, the mutual near- est graph and the β-skeleton of a set of points. For large sets of points, this produced graphs with a lot of components, so Cheng, Golin and Tsang’s algorithm was not really practical (see Figure 1; for 100 points about 40 components exist). To overcome this, we then applied a greedy connec- tor to create a connected graph. This is where the approximation occurs, since the graph obtained is Figure 3: Labelled Graph not a subgraph of the mwt anymore (some of the edges added might not be present in the optimal graph). Figure 2 shows the resulting graph. Now we used a labelling of the vertices of the graph to turn it into a polygon with repeated edges, so to speak. As an example, Figure 3 to the right shows a graph and its vertices. Through our labelling, the graph will be thought of as a polygon with vertex sequence 0 1 3 7 4 7 6 9 2 9 6 7 8 5; that is some of the edges and vertices are repeated. This produces a polygon that we can then trian- gulate. The triangulation is in fact an adaptation of the convex polygon triangulation algorithm and uses dynamic programming; the algorithm trian- Figure 4: Final Triangulation gulates bigger and bigger portions of the polygon, “picking” the best triangulation in each case, until the whole polygon is triangulated. The resulting graph is shown in Figure 4.

3 3.2. Local Search Optimization In this study we also created a local search op- timization algorithm for a given triangulation. It consisted of two parts. First looked for all the convex quadrilaterals and existing within the triangulation, using the algorithm presented by Dobkin, Edelsbrunner and Overmars [10]. We had to find whether the polygons found were present in the triangulation however, so that was our next step; as seen in Figure 5 the red pentagon is present in the triangulation whilst the purple one is not. The second step was to retriangulate the poly- Figure 5: Polygons of the set of vertices gons found and check if there was a local improve- ment. The best improvement was picked, the triangulation updated, and the algorithm run again. This was done until no improvement could be made to the solution.

4. Heuristics for MWTs 4.1. Pseudocode Next we present the pseudocode of the main part of our algorithm. The first algorithm, Connector, is a simple greedy algorithm; PolygonTriangulate is the adaptation of the con- vex polygon triangulation, and it uses a labelling and an edge input algorithm. Note the algorithms for the subgraphs can be found in the mentioned papers.

Input: A graph of the set of points S Output: A connected graph of the set of points S Create queue of ordered edges by length not present in graph while Still available edges do Add FirstEdge to graph for Each Edge in queue do if Edge intersect FirstEdge then Remove Edge from queue end if end for end while Algorithm 1: Connector

4 Input: A counter of labels, the current point, the previous point Output: A linked list with the labels of the points of S if previous == 0, current == 1, counter!=1 then Reached the beginning again, stop return True end if for each point connected to current do if point!=previous then Add option end if end for Order options by clockwise angle of previous-current-point Label this point, counter++ for each option do labelling(counter,current,option) if labelling returned True then return True end if label this vertex, counter++ end for return False Algorithm 2: Labelling

Input: The first and second points, the reference 2D array Output: Adds edges to graph determined during PolygonTriangulate if second-first == 1 then return end if addEdge(first,second) middle = reference[first][second] inputEdges(first,middle,reference) inputEdges(middle,second,reference) Algorithm 3: InputEdges

5 Input: A connected graph of the set of points S Output: A triangulation of S label node 0, count = 1 labels = labelling(count,0,1) //Start recursive labelling Initialize 2D arrays costs and midPoints for each label in labels do costs[label][label+1] = distance(label,label+1); end for Sort vertices by y-coord then x-coord for interval=2, interval

4.2. Computational Complexity As a whole, our algorithm works as follows. First the subgraph is created, combining the convex hull, the mutual nearest neighbour graph and the β-skeleton. Then a connected graph is created from the subgraph with Connector. This graph is then optimally triangulated by PolygonTriangulate. Following are the theorems that show our algorithm always works and prove its time complexity.

6 Theorem 1. Our algorithm always outputs a triangulation

Proof. The creation of the subgraph of the mwt will always produce a convex hull with a number of disconnected components within it. Note there could be as little as no discon- nected components at all (and so we have a connected subgraph), or every vertex within the convex hull could have degree 0 (in which case we have a maximum number of disconnected components). It follows Connector will always produce a connected graph (the workings of a greedy algorithm is straight forward). At this stage the graph is labelled and PolygonTriangulate begins. The following is important to us: If two labels a and b, a < b, can be joined i.e. the edge ab does not intersect any existing edge, then there exists a label c, a < c < b such that ac and cb do not intersect any existing edge. This means that for any given interval and a starting point, if an edge can be added, a subset triangulation can be obtained. Since the last iteration has an interval value of m − 1, where m is the number of labels, and the 1st and mth labels are connected by an edge, the whole connected graph can be divided into two graphs, which can in turn be divided into two themselves and triangulated. This keeps going until the interval is 2, where the triangulation is trivial. Thus thinking from the bottom up, a triangulation will always be created. The next two theorems look at the number of edges and labels, which will help us derive the complexities of our algorithm:

Theorem 2. The number of edges in a triangulation of n vertices is O(n).

Proof. This follows from a Lemma of Euler’s Formula for planar graphs |E| ≤ 3|V | − 6., where |V | is the number of vertices and |E| is the number of edges of the graph.

Theorem 3. The number of labels in the connected graph after Connector and Labelling have been run is O(n).

Proof. First note than once Connector has been run, the maximum degree of any one vertex is 6; a vertex of degree 7 or above will have two vertices connected to it which are closer between them than the vertex itself, which is not possible based on the workings of Connec- tor. Now since the number of times a vertex is labelled is the same as its degree (exluding the vertices on the convex hull), the number of labels is less than 6n, thus we have O(n) labels. Finally, we can derive the complexity of our algorithm:

Theorem 4. The final complexity of our algorithm is O(n3).

Proof. First note that creating the combined subgraph of the mwt is done in O(n2). As shown for the convex hull, mutual nearest neighbour graph and the β-skeleton in [4], [5] and [6] respectively, the complexities are O(n log n), O(n2) and O(n log n). The Connector algorithm has the sorting of its edges as the most expensive operation; since there is O(n2) edges, using a sorting algorithm gives a complexitiy of O(n2 log n). As seen in the pseudocode 7 of Labelling, each time the function is called a label is added to the graph. Since the number of labels is O(n), the complexity is also O(n). PolygonTriangulate has a triple nested loop, with each one iterating over all the labels. Once again, since the labels are of O(n), the complexity of PolygonTriangulate is O(n3). Finally, inputEdges is called once for each edge being added to the graph; since there is O(n) edges in any triangulation, its complexity is O(n). Therefore the biggest complexity is O(n3). The last algorithm presented in this paper is the straight forward local search. The following theorem gives its complexity:

Theorem 5. An iteration of the optimisation algorithm has complexity O(n2).

Proof. As shown in Dobkin, Edelsbrunner and Overmars’s [10] paper, finding the convex empty polygons of a set of n points has upper bound O(n2). Once the polygons are found, retriangulating them takes constant time (since the size of the polygons is at most 5 i.e. pentagons). Checking if the retriangulation is an improvement is also constant time, and so the final complexity is O(n2). Note that the final complexity of the optimization will depend on how many iterations are run however; this will deppend on the triangulation being optimised. In this study two other triangulations were created to compare them to ours; the first being the Delaunay triangulation which Peterson [11] gave a O(n log n) algorithm for, as well as a greedy algorithm which similarly to the Connector has O(n2 log n) complexity. To sum up then, the complexities of all the algorithms in this paper are:

• Convex Hull: O(n log n)

• Mutual Nearest Neighbours: O(n2)

• β-skeleton: O(n log n)

• Connector: O(n2 log n)

• Labelling: O(n)

• PolygonTriangulate: O(n3)

• inputEdges: O(n)

• Delaunay: O(n log n)

• Greedy: O(n2 log n)

• Local Search Optimisation: One iteration has upper bound O(n2)

8 5. Experimental Results Our data points go in intervals of 10 from 10 to 200, intervals of 30 from 200 to 350, and intervals of 50 from 350 to 600. For each value, 20 random sets of vertices were triangulated with the three different algorithms, and the resulting triangulations were optimized using our local search. The computer used to run this triangulations was a Mac with processor 2.8 GHz Intel core i5, with memory 16Gb 1867 MHz ddr3 and all code was written in C; the results are shown below.

5.1. Without local optimisation Looking at the weights obtained with the triangulations, it can be seen that our algorithm always obtains the lowest weight (the blue line can just be made out under the green line in Figure 6). As expected however, our algorithm is the one that took the longest, taking quite a long time for larger sets of data. Overall the Greedy triangulation had a 1.3-2.5% improvement over the Delaunay, while ours had a 1.5-2.7% improvement.

·105 20 Custom Custom Greedy Greedy 1.5 Delaunay 15 Delaunay

10 1 Time(s) Weight 5 0.5 0 0 0 100 200 300 400 500 600 0 100 200 300 400 500 600 Points Points

Figure 6: Weights without optimization Figure 7: Time taken without optimization

5.2. With local optimisation A really interesting result became apparent when the local search was run on the tri- angulations. Whilst the optimization didn’t have much of an effect on either the Greedy or our algorithm, it produced a notable improvement on the Delaunay triangulation. The optimization improved the Delaunay by 0.5-1%, as opposed to 0-0.002% on the output of our algorithm. It can be seen in figures 8 and 9 that while our triangulation barely changed, two different lines can be discerned in the improvement of the Delaunay weights. What this means is that even though the Delaunay could be obtained really quickly, the repeated local optimization took a long time. Not only that, but it can also be seen that after a long optimisation the Delaunay still was worse than both the Greedy and the Custom Algorithm. This was expected, since both ours and the Greedy looked at minimising locally, so it is not surprising that a local search can find no improvements. Was was interesting 9 ·105 ·105 Before Optim Before Optim After Optim After Optim 1.5 1.5

1 1 Weight Weight

0.5 0.5

0 0 0 100 200 300 400 500 600 0 100 200 300 400 500 600 Points Points

Figure 8: Weight of Custom Before/After Figure 9: Weight of Delaunay Before/After is that after combining both methods, our algorithm performed better than the Delaunay in both time and weight as seen in Figures 10 and 11; overall the Greedy had a 0.16-2.0% improvement over the Delaunay, while ours had a 0.4-2.2% improvement.

·105 Custom Custom 30 Greedy Greedy Delaunay 1.5 Delaunay 20 1 Time(s) Weight 10 0.5 0 0 0 100 200 300 400 500 600 0 100 200 300 400 500 600 Points Points Figure 11: Time taken with optimization Figure 10: Weights with optimization

6. Conclusion In conclusion, in this study we presented a new heuristic of the minimum weight tri- angulation problem with time complexity O(n3). In our experiments we observed that the algorithm presented never finds an approximation which is worse than the Greedy triangu- lation. We believe this to be true in general as the the connected graph which our algorithm optimally triangulates seems to be a subgraph of the greedy triangualtion, but this remains to be proven. Furthermore, a local search optimization does not seem to improve it a lot, if at all.

10 A further improvement on the subgraphs of the mwt would be beneficial to our algorithm. Different ways of creating a connected graph should also be looked at. Finally, a different kind of optimisation should also be looked at, since the one used aims at improving the triangulation locally, something that our algorithm is also doing.

References

[1] Lloyd E. L., 1977 On triangulations of a set of points in the plane. In Proceedings of the 18th Annual IEEE Symposium on Fundations of Computer Science, pp.228-240 [2] Mitchell, J.S. and O’ROURKE, J., 2001. Computational geometry column 42. International Journal of Computational Geometry & Applications, 11(05), pp.573-582. [3] Mulzer, W. and Rote, G., 2008. Minimum-weight triangulation is NP-hard. Journal of the ACM (JACM), 55(2), p.11. [4] Graham, R.L., 1972. An efficient algorithm for determining the convex hull of a finite planar set.Information processing letters, 1(4), pp.132-133. [5] Yang B. T., Xu Y. F., and You Z. Y., 1994 A Chain Decomposition Algorithm for the Proof of a Property on Minimum Weight Triangulations. Algorithms and Computation, Conf. Proc., Beijing, Lecture Notes in Computer Science 834, Springer-Verlag, 1994, pp. 423-427. [6] Keil J. M., 1994 Computing a subgraph of the minimum weight triangulation. Computational Geometry: Theory and Applications 4, pp.13-26. [7] Anagnostou, E. and Corneil, D., 1993. Polynomial-time instances of the minimum weight triangulation problem, Computational Geometry, 3(5), pp.247-259. [8] Cheng S., Golin M. and Tsang J., 1995 Expected Case Analysis of β-skeletons with Applications to the Construction of Minimum Weight Triangulations. CCCG Conf. Proc., Quebec City, pp.279-284. [9] Heath, L.S. and Pemmaraju, S.V., 1994. New results for the minimum weight triangulation problem. Algorithmica, 12(6), pp.533-552. [10] Dobkin, D.P., Edelsbrunner, H. and Overmars, M.H., 1990. Searching for empty convex polygons. Algorithmica, 5(1-4), pp.561-571. [11] Peterson, S., 1998. Computing constrained Delaunay triangulations in the plane. URL http://www. geom. umn. edu/ samuelp/del project. html. En del av Minnesota Center for Industrial Mathematics Undergraduate Industrial Mathematics Project.

11