Bitonic Travel Route Issues

Source: Internet
Author: User

Then one of the topics of the previous dynamic programming problem:

Euclid Traveling Salesman The problem is to determine a closed travel route for a connected point to a given n-point on a plane. Figure 1 (a) gives a solution to the seven point problem. Bitonic Travel Route The problem is the simplification of the Euclidean traveling salesman problem, which starts from the far left, strictly from left to right to the rightmost point, and then strictly from right to left to the starting point, to find the shortest path length. Figure 1 (b) gives a solution to the seven point problem.

Please design a polynomial-time algorithm to solve the Bitonic Travel route problem.

There seems to be no state at all, but if you think about it--avoid repeating it--the shortest route between any two points through point 1 is a problem that needs to be calculated repeatedly.

Moreover, this stage is divided into no-effect, optimal substructure and overlapping sub-problem.

The following is a reference analysis:

Analysis:

The first step is to sort by the x-coordinate of each node, labeled,..., n from left to right. The algorithm complexity can be O (N*log (n)).

The second step, build D[i][j] represents the shortest path length from the i->1->j. According to its definition, we can know d[i][j] = D[j][i]. So we only calculate the value when i>j. (Why not consider the value when i==j?) Because for D[n][n] the smallest time, there must be no intermediate node in the figure is walked two times. )
Construction W[i][j] represents the direct distance from I to j, and the coordinate operation is available.
At this point, consider two scenarios:
At 1 i>j+1, I may only be connected to the I-1 node at this time. Assuming that I can be connected directly to other nodes, the I>J,I-1>J,J cannot be the endpoint of any one of the two paths. So d[i][j] = D[i-1][j] + w[i][i-1].
At 2 i==j+1, I may be connected directly to all nodes that are less than J. So
Why not here min (D[i][k]+w[j][k]): Because I>j,d[i][k] already contains J-point--to figure out what the meaning of the two-dimensional array d is.

The third step, the initial value d[2][1] = w[2][1], the two-tier loop calculation D[i][j].
for (int i = 3; I <= n; ++i)
for (int j = 1; j < i; ++j)

Fourth step, calculate

The resulting d[n][n] is the value of the shortest two-tone route.

Code implementation is relatively simple to paste

Finish this topic--dynamic planning may need to do it yourself, to see how the problem needs to be solved, what the amount is, and what can be used as the basis for the state Division. And the discovery of a sub-problem.

Bitonic Travel Route Issues

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.