Lecture 2 Geometric Algorithms.

Slides:



Advertisements
Similar presentations
Problem solving with graph search
Advertisements

Traveling Salesperson Problem
Comments We consider in this topic a large class of related problems that deal with proximity of points in the plane. We will: 1.Define some proximity.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
BackTracking Algorithms
 Distance Problems: › Post Office Problem › Nearest Neighbors and Closest Pair › Largest Empty and Smallest Enclosing Circle  Sub graphs of Delaunay.
Greed is good. (Some of the time)
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
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.
Steps in DP: Step 1 Think what decision is the “last piece in the puzzle” –Where to place the outermost parentheses in a matrix chain multiplication (A.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Clustering and greedy algorithms — Part 2 Prof. Noah Snavely CS1114
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
Backtracking.
GRAPH Learning Outcomes Students should be able to:
Lecture 2 Geometric Algorithms. A B C D E F G H I J K L M N O P Sedgewick Sample Points.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
1 Closest Pair of Points (from “Algorithm Design” by J.Kleinberg and E.Tardos) Closest pair. Given n points in the plane, find a pair with smallest Euclidean.
Image segmentation Prof. Noah Snavely CS1114
1 Combinatorial Problem. 2 Graph Partition Undirected graph G=(V,E) V=V1  V2, V1  V2=  minimize the number of edges connect V1 and V2.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Introduction to Genetic Algorithms. Genetic Algorithms We’ve covered enough material that we can write programs that use genetic algorithms! –More advanced.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Example Apply hierarchical clustering with d min to below data where c=3. Nearest neighbor clustering d min d max will form elongated clusters!
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
On the Ability of Graph Coloring Heuristics to Find Substructures in Social Networks David Chalupa By, Tejaswini Nallagatla.
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
MAT 110 Workshop Created by Michael Brown, Haden McDonald & Myra Bentley for use by the Center for Academic Support.
The NP class. NP-completeness
Traveling Salesperson Problem
Çizge Algoritmaları.
BackTracking CS255.
Routing Through Networks - 1
Advanced Algorithms Analysis and Design
CS 326A: Motion Planning Probabilistic Roadmaps for Path Planning in High-Dimensional Configuration Spaces (1996) L. Kavraki, P. Švestka, J.-C. Latombe,
Heuristic Search A heuristic is a rule for choosing a branch in a state space search that will most likely lead to a problem solution Heuristics are used.
Maximum Flow - Best algorithms
Types of Algorithms.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Heuristics Definition – a heuristic is an inexact algorithm that is based on intuitive and plausible arguments which are “likely” to lead to reasonable.
Lecture 11: Connectivity Paths in Undirected & Directed Graphs
The Art Gallery Problem
Hidden Markov Models Part 2: Algorithms
The Art Gallery Problem
CSE 589 Applied Algorithms Spring 1999
Heuristics Local Search
Advanced Analysis of Algorithms
Introduction Wireless Ad-Hoc Network
Applied Combinatorics, 4th Ed. Alan Tucker
Algorithms for Budget-Constrained Survivable Topology Design
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
traveling salesman problem
Networks Kruskal’s Algorithm
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Hamilton Paths and Hamilton Circuits
Graphs.
Spanning Trees Longin Jan Latecki Temple University based on slides by
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Graphs.
Approximation Algorithms
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Chapter 6 Centre of Gravity. Chapter 6 Centre of Gravity.
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Lecture 4: Tree Search Strategies
Mathematical Induction II
Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application may require that vertices be visited in some.
Presentation transcript:

Lecture 2 Geometric Algorithms

Sedgewick Sample Points B C D E F G H I J K L M N O P

Simple Closed Path (Anchor = I) B C D E F G H I J K L M N O P

Horizontal Sorting (X component) B C D E F G H I J K L M N O P

Vertical Sorting (Y component) B C D E F G H I J K L M N O P

Nearest Neighbor A B C D E F G H I J K L M N O P

Crossing Line Removal Algorithm B C D E F G H I J K L M N O P

Convex Hull A B C D E F G H I J K L M N O P

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), a Verification of Optimality (Step 3) Constraint Relaxation (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.

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

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.

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

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

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).

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.

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 R2

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.

The Euclidean distance between any two points is computed by,   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; We can build a simple nearest_neighbor sorting routine similar to exchange sort for scalar values.   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;

Given that the point set is P and the number of points is np Given that the point set is P and the number of points is np.  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

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.

For lack of a better name we will call this procedure switch_back. 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.

Before Crossing-Line Removal

One Pass Crossing Line Removal

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.

This comparison is given by, 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))

We must be careful in this case 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. 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;

The Reverse( ) Procedure

Applying the Cross( ) Procedure 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.

Summary In our example there was no further improvement after two applications of the cross( ) procedure.  Is this route minimal?  Later, we will show that cross( ) is not an optimal algorithm but the application of nearest_neighbor and cross( ) makes an good heuristic for near-optimal solutions to the minimal route problem. There are many other heuristics that can be applied to this problem. Since this is a sorting problem, consider methods analogous to the scalar sorts we already know, such as... Insertion Sort Exchange Sort Bubble Sort