ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications ECE669 L10: Graph Applications March 2, 2004
Download ReportTranscript ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications ECE669 L10: Graph Applications March 2, 2004
ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications ECE669 L10: Graph Applications March 2, 2004 Outline ° Many applications can be modeled as graphs ° Graphs require determination of shortest paths, adjacency, and other values ° Efficient parallel algorithms exist which break up the search ° Used to model many applications • VLSI CAD • Mapping • Sales planning ECE669 L10: Graph Applications March 2, 2004 Graph ° A graph is a pair (V, E), where • V is a set of nodes, called vertices • E is a collection of pairs of vertices, called edges • Vertices and edges are positions and store elements ° Example: • A vertex represents an airport and stores the three-letter airport code • An edge represents a flight route between two airports and stores the mileage of the route SFO PVD ORD LGA HNL ECE669 L10: Graph Applications LAX DFW MIA March 2, 2004 Edge Types ° Directed edge • ordered pair of vertices (u,v) • first vertex u is the origin • second vertex v is the destination • e.g., a flight ° ORD flight AA 1206 PVD ORD 849 miles PVD Undirected edge • unordered pair of vertices (u,v) • e.g., a flight route ° Directed graph • all the edges are directed • e.g., route network ° Undirected graph • all the edges are undirected • e.g., flight network ECE669 L10: Graph Applications March 2, 2004 Applications ° Electronic circuits • Printed circuit board • Integrated circuit ° ° ° Transportation networks • Highway network • Flight network Computer networks • Local area network • Internet • Web cslab1a math.brown.edu cs.brown.edu brown.edu qwest.net att.net Databases • Entity-relationship diagram cox.net John Paul ECE669 L10: Graph Applications cslab1b David March 2, 2004 Terminology ° End vertices (or endpoints) of an edge • U and V are the endpoints of a ° Edges incident on a vertex • a, d, and b are incident on V ° Adjacent vertices • U and V are adjacent ° Degree of a vertex • X has degree 5 ° Parallel edges • h and i are parallel edges ° a U V b d h X c e g f Y Self-loop • j is a self-loop ECE669 L10: Graph Applications Z i W March 2, 2004 j Terminology ° Path • sequence of alternating vertices and edges • begins with a vertex • ends with a vertex • each edge is preceded and followed by its endpoints ° Simple path • path such that all its vertices and edges are distinct ° Examples • P1=(V,b,X,h,Z) is a simple path • P2=(U,c,W,e,X,g,Y,f,W,d,V) is a path that is not simple ECE669 L10: Graph Applications a U c V b d P2 P1 X e W g f March 2, 2004 Y h Z Terminology ° ° ° Cycle • circular sequence of alternating vertices and edges • each edge is preceded and followed by its endpoints Simple cycle • cycle such that all its vertices and edges are distinct Examples • C1=(V,b,X,g,Y,f,W,c,U,a,) is a simple cycle • C2=(U,c,W,e,X,g,Y,f,W,d,V,a,) is a cycle that is not simple ECE669 L10: Graph Applications a U c V b d C2 X e C1 g W f March 2, 2004 h Y Z Edge List Structure ° Vertex object • element • reference to position in vertex sequence ° u a Edge object v • element c b d w z • origin vertex object • destination vertex object • reference to position in edge sequence ° z w v Vertex sequence • sequence of vertex objects ° u a b Edge sequence • sequence of edge objects ECE669 L10: Graph Applications March 2, 2004 c d Traveling Salesman Problem • Goal is to find the shortest route that starts at one city and visit each of a list of other cities exactly once before returning to the first city. • For n cities there are (n-1)! diferent paths starting and ending in city 1. • In practice an exact solution is infeasible except for small values of n. • Many approximation algorithms are developed. ECE669 L10: Graph Applications March 2, 2004 Backtracking Algorithm One sequential solution is to examine all feasible paths. A path is feasible if it is not longer than the best complete path that has been determined so far. We start with city 1, there are n-1 possible cities to visit next. From each of these, there are n-2 possible cities to visit and so on. 1 4 2 3 4 3 4 3 ECE669 L10: Graph Applications 2 4 2 3 4 2 3 2 March 2, 2004 Backtracking Algorithm The standard method to examine all the paths in a tree is to use depth-first search method (DFS). There is no need to consider a path that is known to be longer than the shortest completed path that has been found so far. 1 4 2 3 4 3 4 3 ECE669 L10: Graph Applications 2 4 2 3 4 2 3 2 March 2, 2004 Parallel Solution • The paths are independent; thus, we could examine all of them in parallel. • The approach is to provide a fixed number of slave processes that share a pool of tasks. • Each task consists of a partial path, the number of cities visited on a path, and the path length. • Each process takes a partial path and extends it with every city which has not been considered. • If the length of the path is longer than the length of the shortest complete path, the path is discarded. ECE669 L10: Graph Applications March 2, 2004 Traveling Salesman ° Example 2 • 1 2 4 1 5 • 2 • 3 •4 7 2 6 2 5 3• •6 1 6 ° Find shortest tour: E.g. (1 2 5 6 3 4) and then back to 1 ECE669 L10: Graph Applications March 2, 2004 Exhaustive Search 1 ,c=0 • 1 6 2 c=5 3 • c=3 2 ,c=1 • 4 2 4 • 2 7 6 ,c=6 • 3 ,c=4 • 4 ,c=7 • • 5,c=3 XX • ° Find lowest c path, • • • X • But (n - 1) ! tours!!! 2 • Can exploit parallelism though! ECE669 L10: Graph Applications X 2 March 2, 2004 Branch and Bound Algorithms - Prune! ° Naive • 1,c=0 1 • 2,c=1 2 • 3,c=2 ECE669 L10: Graph Applications 7 • 4,c=7 6 • 6,c=6 March 2, 2004 Branch and Bound Algorithms - Prune! ° Naive • 1,c=0 1 • 2,c=1 • 3,c=2 4 2 3 c=5 2 4 c=3 2 7 • 4,c=7 6 • 6,c=6 5 c=3 • (1, 2 ...) Most promising, follow that lead -greedy ECE669 L10: Graph Applications March 2, 2004 Branch and Bound Algorithms - Prune! Naive 2,c=1 • 1 1,c=0 • 2 7 4 2 3 c=5 • 2 6 3,c=2 • • 4,c=7 4 c=3 5 c=3 4 2• c=6 6 4 • c=8 6,c=6 1 5 5 • c=7 6 • c=3 • (1, 2 ...) Most promising, follow that lead -greedy • (1, 3 ...) Most promising ECE669 L10: Graph Applications March 2, 2004 Branch and Bound Algorithms - Prune! 2,c=1 • 2 7 4 2 3 c=5 1,c=0 • 1 4 • c=3 5 2 3,c=2 c=3 4 6 • • 6,c=6 • 4,c=7 6 5 1 6 • 3 c =9 2• c=6 • c=8 4 • c=7 5 •6 c=3 5 • 5 c =14 2 • 6 c =16 5 •1 c =21 • (1, 2 ...) Most promising, follow that lead -greedy • (1, 3 ...) Most promising • Continue ... till a tour is found ECE669 L10: Graph Applications March 2, 2004 Branch and Bound Algorithms - Prune! 2,c=1 • 4 3 c=5 4 • c=3 6 5 • 5 c=14 2 • 6 c=16 5 6 • • 6,c=6 • 4,c=7 c=3 4 6 2 • 5 •4 c=8 2• c=6 • 3 c=9 •1 7 2 5 1,c=0 2 3,c=2 2 • 1 (1 2 4 3 5 6) BOUND: 21 19 1 •5 c=7 •6 c=3 6 c=5 1 • 3 c=6 6 • 4 c=12 c=21 7 • 1 c=19 • Continue ... ‘til a tour is found ECE669 L10: Graph Applications March 2, 2004 Representing Graphs Representing a graph in an algorithm may be accomplished via two different methods: adjacency matrix and linked list. 1. Consider a graph with n vertices that are numbered 1,2,…, n. The adjacency matrix of this graph can be defined as n x n matrix A with the following properties: 1 if (v(I), v(j)) E A(i, j) = 0 otherwise. ECE669 L10: Graph Applications March 2, 2004 Better Algorithm, but basically Branch and Bound ° Little et al. ° Basic Ideas: 2 Cost matrix 4 2 2 1 1 2 • 4 3 4 9 6 1 2 6 9 3 1 6 4 2 2 • 6 • 2 3 1 2 • 4 4 2 • 2 • ECE669 L10: Graph Applications 4 March 2, 2004 Better Algorithm, but basically Branch and Bound Little et al. 2 2 1 1 • 2 2 0 4 • 3 4 2 5 9 6 6 • 4 4 2 2 1 2 6 9 3 1 6 4 3 1 2 4 2 • • 4 2 • 4 2 To • Notion of reduction: 2 4 • Subtract same value from each row or column 1 • •3 9 6 At least ECE669 L10: Graph Applications March 2, 2004 4 • 4 Better Algorithm, but basically Branch and Bound Little et al. 2 2 1 1 • 0 3 4 2 5 4 4 9 4 1 2 3 4 2 1 2 1 1 0 1 • 6 2 2 6 9 • • 3 1 6 2 2 6 4 4 4 • 2 • 2 To From 2 • 2 2 4 1 3 1 • 2 4 ECE669 L10: Graph Applications At least 1 •3 9 6 At least 4 • 4 March 2, 2004 Better Algorithm, but basically Branch and Bound Little et al. 2 2 1 1 • 0 3 4 2 5 4 4 9 4 1 2 3 4 2 1 2 1 1 0 1 • 6 2 2 6 9 • • 3 1 6 2 2 6 4 4 4 • 2 • 2 To From 2 • 2 2 4 1 3 1 • 2 4 ECE669 L10: Graph Applications At least 1 •3 9 6 At least 4 • 4 March 2, 2004 Better Algorithm 2 1 2 0 • 1 0 21 3 2 5 4 4 6 64 • 4 5 • 0 9 4 2 1 4 3 4 10 0 • 2 1 • 21 42 1 • 20 2 2 9 1 4 2 1 3 1 6 1 2 6 4 To From 2 • 2 • 2 4 4 1 1 3 •3 9 ECE669 L10: Graph Applications Reduce all rows & columns 10 is cost of opt. tour 6 • 4 At least 1 2 2 1+1+2+1+1+4 At least 4 March 2, 2004 Further Analysis In other words, the Traveling Salesman Problem is stated as: Given a set of vertices and non-negative cost C(I,J) associated with each pair of vertices I and J, find a circuit containing every vertex in the graph so that the cost of the entire path is minimized. The problem can be classified as • Symmetric Salesman Problem – C(I,J)=C(J,I) for all I,J • Asymmetric Traveling Salesman Problem - C(I,J) for all I, J. ECE669 L10: Graph Applications March 2, 2004 C(J,I) Another Example 1 3 5 9 8 2 5 5 2 6 9 3 4 3 4 7 4 8 2 5 1 7 6 2 4 6 3 ECE669 L10: Graph Applications 7 March 2, 2004 Graph Coloring Problem Let G be undirected graph and let c be an integer. Assignment of colors to the vertices or edges such that no two adjacent vertices are to be similarly colored. We want to minimize the number of colors used. The smallest c such that a c-coloring exists is called the graph’s chromatic number and any such c-coloring is an optimal coloring. ECE669 L10: Graph Applications March 2, 2004 Coloring of Graph 1. The graph coloring optimization problem: find the minimum number of colors needed to color a graph. 2. The graph coloring decision problem: determine if there exists a coloring for a given graph which uses at most m colors. Two colors ECE669 L10: Graph Applications No solution with two colors March 2, 2004 Coloring of Graphs Practical applications: scheduling, time-tabling, register allocation for compilers, coloring of maps. A simple graph coloring algorithm - choose a color and an arbitrary starting vertex and color all the vertices that can be colored with that color. Choose next starting vertex and next color and repeat the coloring until all the vertices are colored. Four colors ECE669 L10: Graph Applications Three colors are enough March 2, 2004 Summary ° Many applications can be modeled as graphs ° Graphs require determination of shortest paths, adjacency, and other values ° Efficient parallel algorithms exist which break up the search ° Used to model many applications • VLSI CAD • Mapping • Sales planning ECE669 L10: Graph Applications March 2, 2004