The way of algorithm re-picking--the optimal triangulation of convex polygon

Source: Internet
Author: User

*************************************** Reprint Please specify the Source: Http://blog.csdn.net/lttree ********************************************



Chapter Two: Dynamic programming



> Optimal triangulation < of convex polygon




Algorithm Description:

? Polygon: A piecewise linear closed curve on a plane. which consists of a series of straight line segments.

? A convex polygon is usually represented by a counter-clockwise sequence of polygonal vertices, that is, P = {v0,v1,..., vn-1} represents an N-edged, v0,v1,..., vn, where the convention V0 = vn.

   ? If VI and VJ are two vertices that are not adjacent to the polygon, The segment vivj is called a chord of the polygon. And the chord VIVJ divides the polygon into two different triangulation points.

   ? Optimal triangulation of convex polygon: a given convex polygon  < Span style= "Color:rgb (102,102,102); font-family:kaiti_gb2312; font-size:18px; line-height:26px ">p = {v0,v1,..., vn-1}, and a weight function w defined on a triangle composed of edge chords of a convex polygon. It is required to determine the triangulation of the convex polygon, so that the corresponding right of the triangulation, that is, the sum of the triangles in the triangle is minimized.




Algorithm Analysis:

? Defines the various weights of the triangles on the W. For example: w (VI,VJ,VK) = |vivj| + |vjvk| + |vkvi|, where |vivj| is the Euclidean distance of Point VI to VJ (definition can see the bottom annotation ①). The optimal triangulation of this weight function is the minimum chord length triangulation.

? Optimal substructure properties: if Convex (n+1) edge typeP = {v0,v1,..., vn-1} The optimal triangulation T contains the triangle v0vkvn,1≤k≤n-1, then the right of T is three parts of the right and: the right of the triangle V0VKVN, the child polygon {v0,v1,..., VK} and {vk+1,vk+2,..., V The sum of the weights of N}.

    can assert that the triangulation of these two sub-polygons determined by T is also optimal. Because a smaller triangulation of {v0,v1,..., VK} or {vk,vk+1,..., vn} will cause T to be inconsistent with the optimal triangulation.

? Recursive structure: Set t[i][j],1≤i

As a result, the recursive type can be:

Similar to matrix multiplication problem, the algorithm has a time complexity of O (n^3) space complexity O (n^2).




Algorithm program:


<span style= "Font-family:comic Sans ms;font-size:14px;" >//convex Polygon's right int weight[][n] = {{0,2,2,3,1,4},{2,0,1,5,2,3},{2,1,0,2,1,4},{3,5,2,0,6,2},{1,2,1,6,0,1},{4,3,4,2,1,0 }};//weight function int w (int a,int b,int c) {return weight[a][b] + weight[b][c] + weight[a][c];} int minweighttriangulation (int n, int** T, int** s) {//Initialize table for (int i = 1; I <= n; ++i) T[i][i]            = 0; R is the current calculated chain length (sub-problem scale) for (int r = 2; r <= N; ++r) {//n-r+1 is the last R-chain's front boundary for (int i = 1; I <= n-r +1;                        ++i) {//Compute the front boundary is R, chain length R is the back boundary of the chain int j = i+r-1;            Dividing the chain IJ into A (i) * (A[i+1:j]) here is actually k=i t[i][j] = T[i+1][j] + w (i-1,i,j);            S[I][J] = i; for (int k = i+1; k < i+r-1; ++k) {//to divide the chain ij into (a[i:k]) * (a[k+1:j]) int u = t[i][k                ]+t[k+1][j]+w (I-1,K,J);                    if (U < T[i][j]) {t[i][j] = u;               S[I][J] = k; }}}} return t[1][n-2];}    Construct the optimal solution void Traceback (int i,int j,int **s) {if (i==j) return;    Traceback (i,s[i][j],s);    Traceback (s[i][j]+1,j,s); cout<< "V" <<i-1<< ", V" <<j<< ", V" &LT;&LT;S[I][J]&LT;&LT;ENDL;} </span>



Related notes:

① Euclidean distance: Euclidean metric (Euclidean metric) is a commonly used distance definition, referring to the real distance between two points in m-dimensional space. For example, in two-dimensional space, the Euclidean distance of point A (x1,y1) and point B (x2,y2) is: D=sqrt ((x1-x2) ^2 + (y1-y2) ^2); Extended to three-dimensional space is: d=sqrt ((x1-x2) ^2 + (Y1-y2) ^2 + (Z1-Z2) ^2). This allows the Euclidean distance of the m-dimensional space to be introduced.

② picture source: Wind Zhong da Nyingchi



*************************************** Reprint Please specify the Source: Http://blog.csdn.net/lttree ********************************************

The way of algorithm re-picking--the optimal triangulation of convex polygon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.