120 likes | 418 Views
Optimal polygon triangulation. B98570137 廖柏翰 – 組長 B96570112 陳裕仁 B98570118 詹燿鴻 B98570131 蔡宗翰 B98570153 林承毅. 刻劃最佳解結構. Characterize the structure of an optimal solution 定義 weighting fuction : w ( v i v j v k ) = ( Vi+Vj +Vk) = P i P j P k
E N D
Optimal polygon triangulation B98570137 廖柏翰– 組長 B96570112 陳裕仁 B98570118 詹燿鴻 B98570131 蔡宗翰 B98570153 林承毅
刻劃最佳解結構 Characterize the structure of an optimal solution 定義weightingfuction :w(vivjvk)= (Vi+Vj +Vk) =PiPjPk We start with vi-1 rather than vi , to keep the structure as similar as possible to the matrix chain multiplication problem. Ai對應於邊 Ai+1..j對應於 故 矩陣連乘為最佳三角化之特例 q = t[i, k]+ t[k+1, j]+w(vi-1vkvj)
Binary Tree for Triangulation: Ex:((A1(A2A3))(A4(A5A6))) The associated binary tree has n leaves, and hence n-1 internal nodes. Since each internal node other than the root has one edge entering it, there are n-2 edges between the internal nodes. full binary tree (n-1 leaves) triangulation (n sides)
Dynamic Programming A triangulation of a polygon is a set T of chords of thepolygon that divide the polygon into disjoint triangles T contains v0vkvn. w(T)=w(v0vkvn)+t[1,k]+t[k+1,n] The two subproblem solutions must be optimal or w(T) would be less. –Suppose the optimal solution has the first split at position k, we will divide polygon into A1..k (t[i,k]) Ak+1..n (t[k+1,n])
OPTIMAL TRIANGULATION PROBLEM 求邊長數為(n+2)的多邊形切成多個三角形後,內部所有三角形weightingfunction總和最小 值最小。 key: 1.必成(n+2)-2 = n 個三角形, ex: ( 3+2 ) - 2 = 3 2. weightingfunction :W(ΔVi,Vj ,Vk) = Vi+Vj +Vk V0 V1 V4 Input:0,6,4,3,2 V3 V2
Let t[i,j] is W<Vi-1,Vi,….,Vj> • Chose a point k for i≦ k<j • W<Vi-1,Vi,..,Vj> = W<Vi-1,Vi,..,Vk> + W<Vk+1,Vi,..,Vj> ?? Vj Vi-1 Vi The weight of the middle triangle is :W(ΔVi-1+Vk+Vj) Vk
AN OPTIMAL SOLUTION TO A PROBLEM COTAINS WHITIN IT AN OPTIMAL SOLUTION TO SUBPROBLEMS • Let is a optimal answer to V0-7 • The yellow lines is a optimal answer to V0-4,why?? Proof by contradiction
用遞迴定義最佳解 • Recursively define the value of an optimal solution. Vj Vi-1 M R L Vk
由下往上計算一個最佳解 • Compute the value of an optimal solution in a bottom‐up fashion. • Example => Input :1 2 3 4 5 6 1 2 6 3 4 5
由下往上計算一個最佳解 i = 1 , j = 3 , find t[1,3] : • t[1,1] + t[2,3] + w(v0,v1,v3) = 0 + 9 + (1+2+4) = 16 • t[1,2] + t[3,3] + w(v0,v2,v3) = 6 + 0 + (1+3+4) = 14 設W(Vi,Vj,Vk) = Vi + Vj + Vk
經由計算的資訊建立最佳解 • Construct an optimal solution from computed information. • Output : Triangle<0,1,2> Triangle<0,2,3> Triangle<0,3,4> Triangle<0,4,5>
程式實作結果 • int WeightingFunction(int i, int j, int k){ • return i+j+k; • } • MatrixChain() • printTable() • OptimalAnswer() • // Polygon Triangulation.c