# A Heuristic Algorithm for Solving Triangle Packing Problem

Authors: Ruimin Wang; Yuqiang Luo; Jianqiang Dong; Shuai Liu; Xiaozhuo Qi
Journal: Discrete Dynamics in Nature and Society
 (2013)

---

## Abstract

The research on the triangle packing problem has important theoretic significance, which has broad application prospects in material processing, network resource optimization, and so forth. Generally speaking, the orientation of the triangle should be limited in advance, since the triangle packing problem is NP-hard and has continuous properties. For example, the polygon is not allowed to rotate; then, the approximate solution can be obtained by optimization method. This paper studies the triangle packing problem by a new kind of method. Such concepts as angle region, corner-occupying action, corner-occupying strategy, and edge-conjoining strategy are presented in this paper. In addition, an edge-conjoining and corner-occupying algorithm is designed, which is to obtain an approximate solution. It is demonstrated that the proposed algorithm is highly efficient, and by the time complexity analysis and the analogue experiment result is found.


---

## Body

## 1. Introduction

Solving NP-hard problems is always the bottleneck task for computer science and techniques. However, in recent years, many research results have indicated that there is no a complete, accurate, and fast solving algorithm for this kind of problem at all. People tend to focus on searching for a quick and practical approximation algorithm; see, for example, [1].Triangle packing problem is that given a known length and width of rectangle empty container and N triangles of definite size and shape; namely, the three sides of a triangle are known, and the question is whether the N triangles can be placed into the rectangle container. If we can, then give position and orientation of each triangle in the rectangle. If no, give a negative answer to this problem. Since triangle in the plane can be continuously translated and rotated, there are infinite numbers of placements which are detrimental to solve the problem. And so the placement should be limited always. The strategy in [2] is only to allow a polygon to be rotated, but not to be translated, which translates the polygon packing problem to NP-complete problem.Triangular packing problem is a special case of a polygon packing problem but is still NP-hard. For now, there is no a quick and complete solving algorithm, and the heuristic method is still an ordinary method; see, for example, [3–7] and references therein. In this paper, a edge-conjoining and corner-occupying algorithm that is a quick and approximate method is designed based on the angle region-filling strategy. This paper has special significance for polygon packing problem, network resource optimization, and so forth, since it is a special case of a polygon packing problem; see, for example, [8–11].In Section2, the basic concepts such as angle region are given. The classification of angle region and the corner-occupying action are discussed, and the physical meaning has been analyzed in Section 3. In Section 4, two heuristics strategies and an approximate algorithm for solving triangle packing problem are proposed. Finally, the complexity of algorithm is also discussed and some results of the simulation example are given.


## 2. Formation of Angle Region

Definition 1.
Triangles in a same plane are said to be intersectant, if the overlapping area of two triangles is larger than zero. Or else the two triangles are said to be non-intersectant.Definition 2.
For two non-intersectant triangles in the same plane, if there exists one intersection at least between two edges which are from each triangle, then the two triangles are said to be tangent, as shown in Figure1.Tangent triangle.
(a)
(b)Definition 3.
For two edges from two tangent triangles, respectively, if the following conditions are satisfied:(1)
There exists only one intersection (O) for the two triangles;(2)
An angle formed by the two edges is a positive angle and less thanπ;(3)
In the angle of(2), there are no other edges of the two triangles except (1);then the angle in (2) is said to be the angle region of the two tangent triangles. Its size is called the angle of the angle region. The overlapping part of the initial edge of the angle in (2) and one of the two triangles is said to be the initial edge of the angle region; similarly, the overlapping part of the terminal edge of the angle in (2) and one of the two triangles is said to be the terminal edge of the angle region; the intersection in (1) is said to be a vertex of the angle region. As shown in Figure 2, △ ABC is tangent to △ DEF at O(A), and ∠ BOD is an angle region of the △ ABC and △ DEF; the angle size of the region angle is denoted by ∠ BOD; OB and OD are the initial edge and the terminal edge of the angle region, respectively; O is said to be the vertex of the angle region.Figure 2
Angle region.To judge whether there is an angle region formed by two tangent triangles, it is just to take out two edges with common vertex from each of triangles and judge that whether the two triangles form a positive angle less thanπ and verify that there is no other edges of the two triangles on the angle. The computational procedure can be realized according to vertex coordinate of the triangle.By the definition of angle region, whether the two edges of the tangent triangles can form angle region is unrelated to the size and shape of the triangle that will be put into the angle region.


## 3. The Classification of an Angle Region and the Corner-Occupying Action

Depending on the two triangles’ different positions, the two tangent triangles may form zero, one or two angle region, which is shown in Figures3 and 4(a)–4(c) and 5(a)–5(d), respectively.Figure 3
Zero angle region.One angle region.
(a)
(b)
(c)Two angle regions.
(a)
(b)
(c)
(d)These angle regions look like the scraps generated during the material machining processes. If we make use of these scraps, then the ratio of utilization of material can be increased on basis of practical production experiences. It is illustrated through practice to sufficiently increase the ratio of material, and then the position of the filter within the vessel should be stable. Whether a plane figure is precarious depends on shiftable degree of freedom and the rotatable degree of freedom. For a triangle, the rotatable degree of freedom refers to a clockwise or counterclockwise rotation of one triangle with the origin at one of its vertexes, and here the triangle is still in the rectangle container after be rotated, and the triangle cannot conflict with other triangles around it; namely, there is no overlapping part between the rotated triangle and other triangles, which means you can rotate the triangle freely; similarly, the translatable degree of freedom refers to a translation of one triangle along two opposite directions of one of the straight lines on which one edge of the triangle lies in the barycentric coordinate of the triangle as the initial point, when the triangle is still in the rectangle container after the manipulation of translating, and the triangle cannot conflict with other triangles around it; namely, there is no overlapping part between the translated triangle and other triangles, which means you can translate the triangle freely.If a triangle with the barycentric coordinate as the initial point can translate freely along any straight line where a edge of the triangle lies, then the triangle is deemed to be impending. Apparently, the position of this kind of triangle is unstable, such as the triangle 1 shown in Figure6.Figure 6
Instability of triangle.If a triangle can translate freely along one straight line only or rotate freely around a certain vertex, this kind of position is pushable and swingable, and also it is unstable, such as the triangles 2 and 3 shown in Figure6.Generally speaking, the position where a triangle cannot translate freely along one straight line only or rotate freely around a certain vertex is stable, such as the triangles 4, 5, 6, and 7 shown in Figure6.If one edge of the triangle 1 is conjoined with a edge of another triangle 2, namely, the length of the overlapping part is more than zero and the triangle 1 can only translate along the edge of the triangle 2, then the position of the triangle 1 is pushable. Pushing the triangle 1 along the edge of the triangle 2, if the triangle 1 is just tangent to a third triangle and the edge of the triangle 1 is still conjoined with the edge of the triangle 2, then the position of the triangle 1 is stable.In general, compared with the positions of triangles 4 and 7, the positions of triangles of 5 and 6 can easily divide the space, which is bad for making use of space. It is reasonable to assume that the positions of triangles 4 and 7 are better than those of triangles 5 and 6. For this reason, we have the following definitions.Definition 4.
Corner-occupying action: If one edge of a triangle is conjoined with a initial or terminal edge of a angle region, namely, the length of the overlapping part is more than zero and another edge of the triangle is conjoined with a terminal or initial edge of the region, then the process of putting the triangle into the angle region is called a corner-occupying action. In the case, the angle opposite to the third edge is called the cut-in angle.It can find a corner-occupying action in this way: pushing a edge which is conjoined with a initial or terminal edge of the triangle region of a triangle outside a rectangle container into the rectangle container, if when the triangle cannot be put away any more (when the triangle is tangent to the terminal or initial edge), the edge of the triangle is still conjoined with the initial or terminal edge of the angle region, then the process of putting the triangle into the position is called corner-occupying action. Therefore, the problem of putting a triangle into an angle region formed by two tangent triangles can be transformed to a issue of position relation between the edge of triangle and the line segment. Thereby, the search space can be confined in a limited number of points from a continuous Euclidean space.Definition 5.
The conjoint degree of a corner-occupying action: If one edge (the length isa1) of a triangle and one edge (the length is b1) of an angle region are conjoint and let the length of the overlapping part be c1, then the conjoint degree of corner-occupying action is c1/max(a1,b1). Specially, if another edge (the length is a2) of the triangle and another edge (the length is b2) of the angel region are conjoint and the length of the overlapping part is c2, then the conjoint degree of corner-occupying action is c1/max(a1,b1)+c2/max(a2,b2).Definition 6.
For two edges of an angle region, if the angle between a edge which is conjoined with a triangle and another edge which is tangent to the triangle isα and the size of the cutin angle is β, then the conformity degree of the corner-occupying action is min(α,β)/max(α,β).The conjoint degree and the conformity degree are used to measure the adjacent degree between the filling triangle and the position where the filling triangle will be placed. The bigger the conjoint degree and the conformity degree of a corner-occupying action are, the higher the adjacent degree is.


## 4. An Algorithm of Edge-Conjoining and Corner-Occupying

As shown in Figure7, a rectangle container can be deemed as a plane figure encircled by four triangles.Figure 7
Rectangle container.(a)
(b)
(c)
(d)Definition 7.
Pattern: A pattern refers to a kind of ordered pair〈P,Q,R〉, where P is the set of four triangles forming the rectangle container which some triangles have been put in (each element in the set is denoted by three vertices coordinates of the triangle), Q is the set of triangles out of the rectangle container (each element in the set is denoted by three edges of the triangle), and R is a set of angle region formed by triangles in P.
At the first moment,P contains only four triangles forming the rectangle container, and Q is the set of all triangles to be put in the rectangle container, and R is a set of four angle regions formed by four triangles in P, and then the pattern at this moment is called the initial pattern, which is denoted by 〈P0,Q0,R0〉. Starting with the initial pattern, the pattern formed by putting the kth triangle taken out from Q into the rectangle container is called kth pattern, which is denoted by 〈Pk,Qk,Rk〉. In the kth pattern, if Nk=∅, then it is called the terminal pattern.In thekth pattern before the terminal pattern, let a triangle perform corner-occupying action, if the triangle is still in the rectangle container and do not intersect with other triangle in Pk, then the corner-occupying action is called a reasonable corner-occupying action.Corner-Occupying Strategy. For two reasonable corner-occupying actions a1 and a2, let the conformity degree of both be p1 and p2, respectively. If p1>p2, then a1 is said to have a higher priority than a2.Edge-Conjoining Strategy. For two reasonable corner-occupying actions a1 and a2, let the conjoint degree of both be q1 and q2, respectively. If q1>q2, then a1 is said to have a higher priority than a2.Based on the edge-conjoining strategy and the corner-occupying strategy, a heuristic algorithm for solving triangle packing problem is provided below.Given the initial pattern〈P0,Q0,R0〉, where P0 is the set of four triangles forming the rectangle container, Q0 is the set of all triangles to be put in the rectangle container, and R0 is a set of four angle regions formed by four triangles in P0. Arrange the angle region and the reasonable corner-occupying action in time order.Step 1.
Sett=0, and the current pattern S is St.Step 2.
IfQ0=∅, then it is reported that all triangles have been put into the rectangle container, and stop; if Q0≠∅ and there is no reasonable corner-occupying action to perform in St, then the failure of algorithm is reported, and go to Step 3; if Q0≠∅ and in St, there exists a reasonable corner-occupying action to perform, and then go to Step 3.Step 3.
Choose a reasonable corner-occupying action with the highest priority to perform according to corner-occupying strategy. If there exists only one reasonable corner-occupying action according to corner-occupying strategy, then fill the triangle according to this corner-occupying action, and go to Step5; if not, choose a reasonable corner-occupying action with the highest priority to perform according to conjoining-occupying strategy, and go to Step 4.Step 4.
Choose a reasonable corner-occupying action with the highest priority to perform according to conjoining-occupying strategy. If there exists only one reasonable corner-occupying action according to conjoining-occupying strategy, then fill the triangle according to this corner-occupying action; if not, fill the triangle according to the first corner-occupying action.Step 5.
Add three vertical coordinates of the triangle performing the corner-occupying action to thePt, and remove three edges of the triangle performing the corner-occupying action from the Qt. Change Pt to Pt+1, Qt to Qt+1, and Pt+1 to Rt+1 which is the set of angle regions formed by triangles in Pt+1. Switch to a new pattern 〈Pt+1,Qt+1,Rt+1〉, and go to Step 2.


## 5. Time Complexity Analysis of the Algorithm of Edge-Conjoining and Corner-Occupying

For the initial pattern〈P,Q,R〉 if there are m triangles in P and n triangles in Q without generality, find out the reasonable corner-occupying action with the highest priority and calculate out the f(m,n) time units (step number of calculating) spent on performing the action.Firstly, calculate the time complexity of all the angle regions formed by m triangles inP.Given two triangles, take out one edge from each of them, if it will takea time units to judge whether the two edges can form an angle region. Then, it will take C(3,1)*C(3,1)*a=9a time units at most to find out all the angle regions formed by two given triangles.It will takeC(m,2)*9*a time units to find out all the angle regions formed by m triangles in P. By the definition of angle region, two triangles can form two angle regions at most. Therefore, there are 2*C(m,2) angle regions in R at most. In fact, there is little chance that a triangle is tangent to every triangle, where all the triangles are in the same rectangle container. Generally speaking, the total angle regions formed by m triangles are far less than 2*C(m,2). This is the root cause of the high speed of the proposed algorithm.Secondly, calculate the time complexity of all the corner-occupying actions of puttingn triangles which are in the Q into the angle regions in R.If it will takeb time units to put one triangle into the angle region along one of the edges of the triangle which is conjoined with a edge of the angle region, and 22*b time units at most to put one triangle into a given angle region with 22 different corner-occupying actions at most, then it will take 2*C(m,2)*22*b time units at most to put one triangle in Q into all the angle regions in R, and 2*C(m,2)*22*b*n time units at most to complete the corner-occupying actions of putting n triangles in Q into all the angle regions in R.Thirdly, calculate the time complexity of judging whether each corner-occupying action is a reasonable corner-occupying action.If it will takec1 time units to judge whether two triangles are intersecting and c2 time units to judge whether a triangle is in the rectangle container, then it will take 2*C(m,2)*22*(m*c1+c2) time units to find out all reasonable corner-occupying actions.Finally, calculate the time complexity of finding out the corner-occupying action with the highest priority from all the reasonable corner-occupying actions.If it will taked time units to compare the priorities of two corner-occupying action, then it will take 2*C(m,2)*22*n*d time units at most to find out a reasonable corner-occupying action with the highest priority. From the analysis above, the time spent on taking out the triangle corresponding to the corner-occupying action with the highest priority from Q is at most
(1)Cm2*9*a+2*Cm2*22*b*n+2*Cm2*22*(m*c1+c2)+2*Cm2*22*n*d≤4*22*m2*(m-1)*n*k0(k0=max(a,b,c1,c2,d))≤k*m2*(m-1)*n(k=88*k0).At this moment, a triangle has been put in the rectangle container, and then switch to a new pattern. it will takek*m2*(m-1)*n time units at most for each step. In other words,
(2)f(m,n)≤k*m2*(m-1)*n.Similarly,(3)f(m+1,n-1)≤k*(m+1)2*(m)*(n-1);⋮f(m+i,n-i)≤k*(m+i)2*(m+i-1)*(n-i),
where f(m+n,0)=0. From the initial pattern, it will reach the end of the algorithm after n steps at most. By the analysis above, the time complexity analysis of the proposed algorithm is
(4)∑0n-1‍f(m+i,n-i)=k*∑i=0n-1‍(m+i)2*(m+i-1)*(n-i)≤k*(m+n-1)2*(m+n-2)*n2≤k*(m+n)3*n2.In the initial pattern,m=4, n is the number of the triangles to be put in the rectangle container. So
(5)∑i=0n-1‍f(m+i,n-i)≤k*(n+4)3*n2=O(n5).That is to say, the time complexity of the proposed algorithm isO(n5). If there is no reasonable corner-occupying action to perform, then stop. Thus, the order of magnitude of the total computing time is not more than O(n5).


## 6. Some Illustrative Examples

In this section, we have developed a program to verify the effectiveness of the proposed algorithm, and the experimental data is included in Table1. This program is developed by using Visual C++6.0, which is realized on a computer with Pentium 2.8 GHz processor and 512 MB of RAM.Table 1
Experimental data.
Example no.
Edge lengths of rectangle containers
Edge lengths of triangles
Graphic outputs
Algorithm results
1
80, 80
(
80.0
,
56.6
,
56.6
)
×
2 (40.0,40.0,56.7)×4
Figure8(a)
two triangles leftUtilization: 75.0%Computing time: 0.008 sec
2
700, 400
225.0, 275.5, 160.0
Figure8(b)
one triangle leftUtilization: 71.4%Computing time: 0.006 sec
166.0, 174.9, 55.0
278.9, 134.0, 245.0
229.0, 190.0, 299.0
108.0, 260.0, 279.7
296.0, 278.2, 300.4
167.6, 293.2, 273.5
3
200, 200
(
100.0
,
100.0
,
100.0
)
×
6
Figure8(c)
Success!Utilization: 65.0%Computing time: 0.005 sec
4
400, 300
166.0, 174.9, 55.0
Figure8(d)
Success!Utilization: 96.7%Computing time: 0.007 sec
278.9, 134.0, 245.0
229.0, 190.0, 299.0
108.0, 260.0, 279.7
296.0, 278.2, 300.4
167.6, 293.2, 273.Input is the following:the length and width of rectangle container (error is 0.1),the edge length of each triangle to be put into (error is 0.000001).Output is the following:the utilization (error is 0.1%),computing time (error is 0.01 second),the sequence to put the triangles into the rectangle container,the vertex coordinates of triangles to be put,the calculating error is 0.000001; the display unit is pixels.



---

*Source: 686845-2013-12-19.xml*