Upload
hubert-greer
View
275
Download
0
Embed Size (px)
DESCRIPTION
Ex:((A 1 (A 2 A 3 ))(A 4 (A 5 A 6 ))) 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) Binary Tree for Triangulation:
Citation preview
Optimal polygon Optimal polygon triangulationtriangulation
B98570137 廖柏翰– 組長B96570112 陳裕仁 B98570118 詹燿鴻 B98570131 蔡宗翰 B98570153 林承毅
Characterize the structure of an optimal solution定義 weighting fuction : 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)
i1i vv
jivv
刻劃最佳解結構
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)
Binary Tree for Triangulation:
A triangulation of a polygon is a set T of chords of the polygonthat divide the polygon into disjoint trianglesT 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])
Dynamic ProgrammingDynamic Programming
OPTIMAL TRIANGULATION OPTIMAL TRIANGULATION PROBLEMPROBLEM求邊長數為 (n+2)的多邊形切成多個三角形後 ,內部所有三角形weighting function總和最小值最小。 key: 1.必成 (n+2)-2 = n 個三角形 , ex: ( 3+2 ) - 2 = 3 2. weighting function :W(ΔVi,Vj ,Vk) = Vi+Vj +Vk
V0
V4V1
V3V2
Input:0,6,4,3,2
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> ??
Vi-1
Vi
Vj
Vk
The weight of the middletriangle is :W(ΔVi-1+Vk+Vj)
AN OPTIMAL SOLUTION TO A PROBLEM COTAINS AN OPTIMAL SOLUTION TO A PROBLEM COTAINS WHITIN IT AN OPTIMAL SOLUTION TO WHITIN IT AN OPTIMAL SOLUTION TO SUBPROBLEMSSUBPROBLEMS
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.
j < i if)}(],1[],[{minj=i if0
],[
0. of weight a has <polygon Degenerate
...,<polygon theoftion triangulaoptimalan of weight theben j < i 1for j]Let t[i,
11-jki
1-
1-
jki
ii
jii
vvvwjktkitjit
vv
vvvVi-1
Vj
Vk
M
LR
由下往上計算一個最佳解由下往上計算一個最佳解Compute the value of an optimal
solution in a bottom‐up fashion.Example => Input :1 2 3 4 5 6
1 2
3
45
6
由下往上計算一個最佳解由下往上計算一個最佳解
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