Presentation is loading. Please wait.

Presentation is loading. Please wait.

Point-and-Line Problems. Introduction Sometimes we can find an exisiting algorithm that fits our problem, however, it is more likely that we will have.

Similar presentations


Presentation on theme: "Point-and-Line Problems. Introduction Sometimes we can find an exisiting algorithm that fits our problem, however, it is more likely that we will have."— Presentation transcript:

1 Point-and-Line Problems

2 Introduction Sometimes we can find an exisiting algorithm that fits our problem, however, it is more likely that we will have to modify a known algorithm to make it applicable to a specific application. Often we will have to develop an algorithm based on one or more of the general problem-solving methods covered in this course. The Munkres' Assignment algorithm is a combination of the Greedy Method (Step 1/Step 2), Resolution (Step 4/Step 6) and the Augmenting Path (Backtracking) algorithm (Step 5). Occasionally, even the general methods are not applicable and we are forced to develop a completely new algorithm to solve a problem. In this section we will consider a number of problems best represnted as graphs, trees, or paths in graphs. We will refer to these as dot-and-line problems.

3 Minimal Route Problem Given a set of points in the plane, find a minimal length path that connects the points.

4 Convex Hull Given a set of points in the plane, find the subset of points that defines a convex boundary which contains all the points.

5 Polygon Triangulation Given a set of points in the plane defining a convex polygon, find the chords with a minimal total length that triangulate the polygon

6 Track Correlation Given a sequence of M snapshots of a set of N points in the plane, obtain the N lists of M points representing the same point in each of the M frames. Each of the N points is assumed to be moving at a constant rate between frames

7 Euclidean Traveling Salesperson Problem Given a set of points in the plane, find a minimal length tour of all the points. This is a special case of the traveling salesperson problem. It can be shown that the solution to the minimal routing problem is, in general, NOT a subset of the solution of this problem (find a counterexample).

8 Maximal Disjoint Paths Problem Given an undirected graph as shown, find the maximum number of paths that connect a selected pair of nodes and share no edges. There is also a version of this problem in which the disjoint paths can have no common vertices (except the end vertices). In the figure on the right three edge-disjoint paths are shown for the red and green vertices. The violet and orange paths are also vertex-disjoint.

9 Minimal Route Problem The solution to this problem involves the arrangment of the n points so that the total distance between successive point pairs in the list is minimal. The brute-force approach to this problem is not practical for large n since there are n! arrangements of n points. So how do we procede? n=100 randomly ordered points in R 2

10 Let'st try the greedy method first. Start with any point (this could be a point selected at random or we could choose the point based on some criterion such as the point that is most distant from its nearest neighbor). Make this the first point in the list. Choose the nearest-neighbor to the first point to be the second point in the list. Now choose the nearest-neighbor (from the unselected set of points) of the second point as the third point in the list, and so on. At first this seems to be working quite well but as the number of unselected points diminishes the few remaining points are scattered around the point set distribution making the last few selections clearly non-optimal.

11 function dist(a,b : point) return float is begin return sqrt((float(a.x)-float(b.x))**2+(float(a.y)-float(b.y))**2); end dist; The Euclidean distance between any two points is computed by, procedure nearest_neighbor is begin for i in 1..np-1 loop for j in i+1..np loop if dist(P(i),P(j))<dist(P(i),P(i+1)) then swap(P(i+1),P(j)); end if; end loop; end loop; end nearest_neighbor; We can build a simple nearest_neighbor sorting routine similar to exchange sort for scalar values.

12 Given that the point set is P and the number of points is n p. Viewing the results of the nearest-neighbor routine shows an improved ordering but it is clear that there is room for improvement. We will use the graphical representation of the solution as a mechanism for improving our algorithm. As we have already noted, an algorithm that finds the minimal route is probably exponential in complexity. For most practical applications involving minimal routes a near-optimal solution is sufficient. We will try to build an optimal algorithm but we may succeed only in building a heuristic

13 For the moment, let's concentrate on a small portion of the the route obtained from the greedy method. Note that the path from b to c to d to e is clearly farther than the path from b to d to c to e. We will let dist(x,y) represent the distance between point x and point y. In this case we are saying that since dist(b,c) + dist(d,e) > dist(b,d) + dist(c,e) we will exchange the points c and d in our list of points.

14 How can be build this test into a search of the entire list? First of all, we need to refer to the points in a more general way than a,b,c etc. Since the points are in the list P we can make the following generalization: for i in 1..np-3 loop if dist(P(i),P(i+1))+dist(P(i+2),P(i+3)) > dist(P(i),P(i+2))+dist(P(i+1),P(i+3)) then swap(P(i+1),P(i+2)); end if; end loop; For lack of a better name we will call this procedure switch_back.

15 Before Switch-Back

16 After Switch-Back

17 The areas in red boxes are those portions of the point set ordering that were changed by the switch_back procedure. The total length of the route is improved but we still have a number of crossing lines. Let's take a closer look at the crossings to see if we can further improve our algorithm. By direct examination of the simplified example below, we know that there must be a shorter route when lines connecting the points are crossing.

18 This is true since the sum of the diagonals of the quadrilateral defined by points i, j, i+1, j+1 is greater than the sum of the opposite sides. This is true for any convex quadrilateral. The crossing lines can be any two lines in the route, therefore we need to use two nested loops to test all line pairs. In fact, we don't care if they are crossing, but rather if their sum exceeds the sum of the alternate pair of lines. This comparison is given by, dist(P(i),P(i+1))+dist(P(j),P(j+1)) > dist(P(i),P(j))+dist(P(i+1),P(j+1))

19 for i in 1..n-3 loop for j in i+2..n loop if dist(P(i),P(i+1))+dist(P(j),P(j+1)) > dist(P(i),P(j))+dist(P(i+1),P(j+1)) then reverse(i+1,j); end if; end loop; end loop; We must be careful in this case. If we decide make the exchange we must reverse all the points in the line segment from i+1 to j in our list of points.

20 The Reverse( ) Procedure

21 This procedure (call it cross) must be applied repeatedly since removal of one pair of crossed lines may create other crossing lines. We will apply this algorithm until there is no further reduction in total route length. For each of these procedures we note that we are comparing all line segments that will be affected by the change, so that we will only make the change if it improves the situation. Applying the Cross( ) Procedure

22 There is no further improvement after two applications of the cross( ) procedure. Is this route minimal? Later, we will show that this is not an optimal algorithm but the application of nearest_neighbor and cross( ) makes an excellent heuristic (relaxed algorithm) for near-optimal solutions to the minimal route problem. Summary

23


Download ppt "Point-and-Line Problems. Introduction Sometimes we can find an exisiting algorithm that fits our problem, however, it is more likely that we will have."

Similar presentations


Ads by Google