Libpcap 函式庫簡介

advertisement
Optimal polygon triangulation
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 對應於邊 vi1vi
Ai+1..j 對應於 vi v 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 the
polygon
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)的多邊形切成多個三角形後,內部所有三角形
weighting function總和最小
值最小。
key: 1.必成(n+2)-2 = n 個三角形, ex: ( 3+2 ) - 2 = 3
2. weighting function :W(ΔVi,Vj ,Vk) = Vi+Vj +Vk
V0
Input:0,6,4,3,2
V1
V2
V4
V3
 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.
Let t[i,j] for1  i < j  n be the weight of an optimal
triangulation of thepolygon< vi -1vi ...,v j 
Vj
Vi-1
M
Degeneratepolygon< vi -1vi  has a weight of 0.
R
L
if i = j
0
t[i, j ]  
{t[i, k ]  t[k  1, j ]  w(vi 1vk v j )} if i < j
imin
 k  j-1
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
5
4
由下往上計算一個最佳解
設W(Vi,Vj,Vk) = Vi + Vj + Vk
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
經由計算的資訊建立最佳解
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
Download