Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT – GRAPH THEORY. CONCEPT CHARACTERISTICS What is a Graph……Really?

Similar presentations


Presentation on theme: "UNIT – GRAPH THEORY. CONCEPT CHARACTERISTICS What is a Graph……Really?"— Presentation transcript:

1 UNIT – GRAPH THEORY

2 CONCEPT CHARACTERISTICS What is a Graph……Really?

3 GRAPH THEORY LEARNING OBJECTIVES—PART 1 You will understand how to model a project using graphs. You will be able to identify how many edges and vertices a graph has. You will be able to find the “critical path” of a project graph from start to finish and find Earliest Start Times for each task. You will be able to determine how much time it will take for a project to be complete.

4 GRAPHS:VERTICES AND EDGES How many Edges does this graph have? How many vertices does this graph have? The vertices are “tasks” and the “ “edges” show the time the task takes.

5 BRUSHING YOUR TEETH If the “project” is brushing your teeth, what are the “tasks” that occur from start to finish? Tasks? Let’s make sure they are in order. Let’s draw a directed graph of these tasks…..

6 IMAGINE Name the things you do each morning before you get to school. Lets make a list The things you do to before you get to school are TASKS, and the preparation/tasks you do before arriving at school “are” the PROJECT. Is there a way to show your “project” using a graph? Is this graph linear?

7 Let’s take our list of things (tasks) you do before you arrive at school. Are there things that have to happen before other things? What if you can’t do task B before task A is complete? What would you have to do to show this in a graph? What if tasks A and B can be done simultaneously? What if you add tasks C & D that must be done after A is complete? What if you add task E that is dependent on task B & D?

8 DIRECTED GRAPH A directed graph is a graphic way using vertices and edges to show the “path” or “paths” of a project leading from task to task. A “directed graph” from start to finish can be thought of as a “time line” from beginning to end…..

9 EXAMPLE OF A DIRECTED GRAPH What can you guess from the graph below?

10 PROJECT:MOWING THE LAWN WARM-UP:PUT THESE TASKS IN ORDER AND IDENTIFY ANY OF THE TASKS THAT CAN TAKE PLACE SIMULTANEOUSLY. TASKSTIME A.Picking up/ Clearing the lawn15 minutes B.Mowing the lawn45 minutes C.Gassing up the mower5 minutes D.Start mower3 minutes E.Getting mower out5 minutes F.Cleaning the mower off10 minutes G.Checking oil5 minutes H.Putting the mower away5 minutes

11 GRAPHING THE PROJECT Where do we start? What has to be done first? Can more than one thing be done first? What task(s) come next? From where? Next? Where to we end?

12 PRACTICAL EXAMPLE OF A PROJECT The Central High yearbook staff has only 16 days left before the deadline for completing their yearbook. They are running behind schedule and still have several tasks left to finish. The remaining tasks and time that it takes to complete each task are listed in the following table.

13 YEARBOOK TASKS IS IT POSSIBLE TO COMPLETE THE PROJECT IF THE TASKS HAVE TO BE DONE IN ORDER? TaskTime (in days) Start0 ABuy Film1 BLoad Camera1 CTake Club Photos3 DTake Sports Photos2 ETake Teacher Photos1 FDevelop Film2 GDesign the Layout5 HPrint and Mail Pages3

14 YEARBOOK TASKS WHAT IF SOME OF THE JOBS CAN BE DONE SIMULTANEOUSLY? DRAW A GRAPH USING ARROWS AS EDGES REPRESENTING A TASK BEING DONE AND VERTICES AS TASKS. TaskTime (in days)Prerequisite Task Start0None ABuy Film1None BLoad Camera1A CTake Club Photos3B DTake Sports Photos2C ETake Teacher Photos 1B FDevelop Film2D, E GDesign the Layout5D, E HPrint and Mail Pages 3G, F

15 GRAPH THE TASKS

16 YOU PRACTICE TASKTIMEPREREQUISITES Start0--- A5NONE B6A C4A D4B E8B, C F4C G10D, E, F FINISH

17 ONE MORE TASKTIMEPREREQUISITES START0---- A4NONE B3A C1A D6A E2B F3C, D G3E H1E, F FINISH

18 CRITICAL PATH Critical path is defined as the shortest path that will take you to the completion of a project AND ensure that ALL tasks are completed as well. There’s an entire profession devoted to this called Project Management….

19 CRITICAL PATH Identify the Earliest Start Time for each task!  Begin at the start  Label each vertex with the smallest possible time needed for that task to begin based on the prerequisites.  The critical path is actually the LONGEST path…..Why??????

20 WARM-UP – GRAPH THE PROJECT MANAGEMENT CHART TASKTIMEPREREQUISITE START0---- A5NONE B8A, D C9B, I D7NONE E8B F12I G4C, E, F H9NONE I5D, H FINISH

21 MAKE A CHART OF TASKS, TIMES AND PREREQUISITES---HOMEWORK BACK

22 MAKE A CHART OF TASKS, TIMES AND PREREQUISITES TaskTimePrerequisites

23 Propulsion System of a Nuclear Submarine --- Project Management Graph

24 GAME ROOM PROJECT--PARTNERS Pretend you are planning to build a game room in your home. Sketch out what you want it to look like. List the tasks that need to be done to complete your project. Estimate the time it will take to do each task in your project. Determine if any task in your project is “dependent” on another part. From start to finish, draw a “directed graph” from start to finish…think of this as a “time line” from beginning to end…..  Are there parts of your project that can be done simultaneously? If so, how do you show that graphically?

25 LET’S FIND THE EARLIEST START TIME

26 GRAPH AND FIND THE EARLIEST START TIMES FOR EACH TASK, CRITICAL PATH AND MINIMUM TIME TO COMPLETION FOR THE PROJECT TaskTimePrerequisites Start0--- A13NONE B10NONE C4A D8B E6B F7C, D, E G5F H8F FINISH

27 CREATE THE PROJECT CHART AND FIND THE EARLIES START TIMES AND CRITICAL PATH

28 WARM-UP PROBLEM Create the Project Management Chart/Table. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

29 DRAW A GRAPH TO REPRESENT THE PROJECT FIND THE CRITICAL PATH AND MINIMUM TIME TaskTimePerequisites Start0---- A2NONE B4 C3A, B D1 E5C, D F6 G7E, F

30 PARTNER PRACTICE Create the Project Table. Find the Earliest Starting times for each task…

31 GAME ROOM PROJECT What Should Be Finished TODAY….By Thursday!!  Sketch of your Game Room  Finalize your Task List and Time Estimates  Determine the prerequisite tasks for each task  Create a Project Management Chart/Table with four columns  Vertices Labels (alphabetical order)  Task description  Time for task  Prerequisite(s)

32 WARM-UP

33 REVIEW PROBLEM TaskTimePrerequisites A5None B7A C3A D2B, C E8D Finish Draw the Graph based on the Chart Below….. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

34 WORKSHEET #1

35 WORKSHEET #2

36 WORKSHEET #3

37 TASKTIMEPREREQUISITESE. S. T. START A B C D E F G H I J

38 Create the Project Management Chart/Table. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

39 WARM-UP PROBLEM Create the Project Management Chart/Table. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

40 GAME ROOM PROJECT What Should Be Finished TODAY….  Finalize your Task List and Time Estimates  Determine the prerequisite tasks for each task  Sketch of your Game Room  Create a Project Management Chart/Table with four columns  Vertices Labels (alphabetical order)  Task description  Time for task  Prerequisite(s)  Due in 30 minutes

41 WRITE DOWN THE WAYS THESE GRAPHS ARE SIMILAR WRITE DOWN THE WAYS THEY ARE DIFFERENT

42 GRAPH THEORY OBJECTIVES—PART 2 Describe a graph as Complete or Not Complete and explain why or why not…. Find the “degree” or “valence” of a particular vertex in a graph….  What is a “loop”?  What is a “multigraph”? Describe the relationship between objects or tasks based on a graph….  Connected vs Not Connected  Adjacent vs Not Adjacent

43 SO WHAT IS A GRAPH REALLY? A “Graph” is a set of points called vertices and their connecting lines called edges. We use graphs to model situations in which the vertices represent tasks or objects and the edges represent the relationship between the tasks or objects they connect. Other than the graphs we have been working with, what kind of graphs are you familiar with?

44 SORRY…..THERE ARE JUST SOME TERMS YOU NEED TO KNOW…….. Edge—a line segment/ray that connects tasks/objects and represents the relationship between the tasks/objects and (if applicable) the time required to do the preceding task. Vertex or Vertices—a vertex is a point on the graph where one or more edges converge and represents a task/object Connected Graph—a graph where there is a path between each pair of vertices Adjacent (Vertices)—two vertices that are connected by an edge Complete Graph—a graph in which every pair of vertices is adjacent

45 MORE TERMS…….. Degree (Valence) of a Vertex—the number of edges that have a specific vertex as an endpoint in a graph is known as the degree or valence of that vertex. When finding the degree of a vertex on which there is a loop, the loop is counted twice. Loop—is an edge that connects a vertex to itself Multigraph—if a graph contains a loop or multiple edges (more than one edge between two vertices), the graph is known as a multigraph.

46 So imagine you pick five students out of a crowd at a football game. Because you pick the five students randomly, it is possible there is no relationship between them at all. So the “graph” of the five and their relationships would just be five distinct points representing them as individuals. However, imagine if some of them are friends and you use “edges” to graph those relationships.

47 Degree of each vertex? Complete? Connected?

48 PRACTICE PROBLEM Find the degree of each vertex. Is this a complete graph? Why or Why Not?

49 PRACTICE GRAPHING Quinn bought six different types of fish. Some of the fish can live in the same aquarium, but others cannot. Guppies can live with Mollies, Swordtails can live with Guppies, Plecostomi can live with both Mollies and Guppies, Gold Rams can live with only Plecostomi, and Piranhas cannot live with any of the other fish. Draw a graph to illustrate this situation.

50 WARM-UP EXERCISE There are five permanent members of the United Nations Security Council: China, France, Russia, United Kingdom and the United States. There are also ten other members who are elected for two year terms: Angola, Egypt, Japan, Malaysia, New Zealand, Senegal, Spain, Ukraine, Uruguay and Venezuela. You are tasked with providing limousine transportation for one diplomat from each member from the UN building in New York City to a conference to discuss the “Syria situation” that is being held in Washington DC. Graph the scenario above based on the information in the next slide and use the graph to determine the minimum number of vehicles required to take all of the diplomats to the peace talks.

51 The US and United Kingdom diplomats have agreed they have no problem riding with any of the other members. Russia will only ride with Venezuela or Angola. China refuses to ride with Japan and Russia but will ride with any of the others. New Zealand will only ride with any of the African Group (Egypt, Senegal and Angola). France will ride with anybody. Uruguay is just happy to get a ride, but prefers to ride with it’s fellow Latin American member, Venezuela. Malaysia will only ride with China. Japan prefers to ride with anybody but China. Ukraine won’t ride with Russia or China, but prefers to ride with the US or United Kingdom. Egypt prefers to ride with the US or the United Kingdom but has agreed they would accept a ride with Japan and Spain. Spain has agreed they can ride with anybody.

52 Consider these graphs WHAT DO THEY REALLY TELL YOU?

53 INTERPRETING SETS THAT DESCRIBE GRAPHS Construct a graph representing the following sets of vertices and edges…. V = M, N, O, P, Q, R, S E = MN, SR, QS, SP, OP What is the valence of each vertex? Is your graph a “connected graph”? Why or why not? Is your graph a “complete graph”? Why or why not?

54 SET AND MATRIX REPRESENTATION WE NEED A WAY TO DESCRIBE THE GRAPH ONE WAY IS BY NAMING THE VERTICES AND EDGES AS SETS Vertices = A, B, C, D, E Edges = AC, CB, CE, CD, BD, BE ANOTHER WAY IS WITH AN “Adjacency Matrix” – a matrix which uses a 1 to signify there is an edge between two vertices in a graph, and a 0 to indicate there is no edge.

55 ADJACENCY MATRIX In an Adjacency Matrix, the rows and columns are labeled with the vertices of the graph…. A B C D E A00100A00100 B00111B00111 C11011C11011 D01100D01100 E01100E01100 ….and a 1 indicates there is an edge connecting the corresponding vertices…..what does a zero tell you???

56 TAKE A LOOK AT THESE TWO GRAPHS Create an Adjacency Matrix for These Graphs Then create a set representation of each graph

57 WARM-UP EXERCISE How would this graph look using set representation? Create an adjacency matrix. Find the Degree of each Vertex

58 PRACTICE GOING IN THE OTHER DIRECTION Draw a graph represented by the following Adjacency Matrix ABCDE A00010 B00200 C02011 D10101 E00112

59 REVIEW Consider the graph below: How would you represent this graph using sets? How would you represent the graph using an adjacency matrix?

60 GAME ROOM PROJECT What Your FINAL Room Project Must Include….  Final Task List and Time Estimates and Prerequisites in a Project Management Chart  Final Complete “in-color” scale drawing of your Room  Project Management Graph  Include Earliest Start Times  Include a vertex for each task  Include time for each task on edges  Include Label for each vertex with a “key” to the labels  Include the Critical Path for the Project  Due at the end of the Period

61 REVIEW B C H A I D J G F E What is the degree of each vertex? Is it a connected graph? Is the graph Complete?

62 REMINDER PROBLEM. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

63 ACCEPT THE CHALLENGE!!! Work in pairs to find a solution to the Konigsberg Challenge First group to find a solution and both members are able to explain the solution will receive five bonus points on the next quiz!!!

64 7 BRIDGES PROBLEM https://www.youtube.com/watch?v=_OiZrmnni9Y

65 PRACTICE In the graph below, determine if there is an Euler Path or an Euler Circuit and, if there is, find the path or circuit…..

66 2 POINTS

67 3 POINTS

68 4 POINTS

69 5 POINTS

70 BEGIN WHEREVER YOU WANT BUT DRAW ONLY ONE LINE THROUGH ALL OF THE DOORS AND YOU CAN ONLY GO THROUGH EACH OF THE DOORS ONCE!!!!!!

71 EULER PATH AND CIRCUIT /VIDEO https://www.youtube.com/watch?v=5M-m62qTR-s https://www.youtube.com/watch?v=REfC1-igKHQ

72 EULER PATHS AND CIRCUITS A PATH that uses each edge of a graph exactly once and ends at the starting vertex is call an Euler Circuit. An EULER CIRCUIT contains vertices that all have “even” degrees. If a connected graph has exactly two odd vertices (degree), it is possible to use each edge of the graph exactly once but to end at a vertex different from the starting vertex. Such a path is called an EULER PATH.

73 EULER PATHS AND CIRCUITS An Euler path is a path that uses every edge of a graph exactly once. An Euler circuit is a circuit that uses every edge of a graph exactly once. An Euler path starts and ends at different vertices. An Euler circuit starts and ends at the same vertex

74 IS THERE A EULER PATH OR CIRCUIT? If so, can you find it? Degree of each vertex? Set Representation? Adjacency Matrix?

75 ACTIVITY:MAP YOUR DAY AT SCHOOL Create a map using the relative locations of each room, entrance way, or exit you visit each day you are at school. Remember that vertices in a graph are used to represent people, places, events or things. The edges represent the path you walk between each room, entrance way, or exit. Also, create a vertex for each hallway turn you take on your path each day. Find the degree of each vertex. Is your graph connected? Is it complete? This is due at the end of the period.

76 REMINDER: EULER PATH AND CIRCUIT /VIDEO https://www.youtube.com/watch?v=5M-m62qTR-s https://www.youtube.com/watch?v=REfC1-igKHQ

77 EULER PATHS AND CIRCUITS A PATH that uses each edge of a graph exactly once and ends at the starting vertex is call an Euler Circuit. An EULER CIRCUIT contains vertices that all have “even” degrees. If a connected graph has exactly two odd vertices (degree), it is possible to use each edge of the graph exactly once but to end at a vertex different from the starting vertex. Such a path is called an EULER PATH.

78 EULER PATHS AND CIRCUITS An Euler path is a path that uses every edge of a graph exactly once. An Euler circuit is a circuit that uses every edge of a graph exactly once. An Euler path starts and ends at different vertices. An Euler circuit starts and ends at the same vertex

79 GRAPHS WITH DIRECTION There are many situations in the real world that graphs have a “direction” versus a path that can go in either direction. Can you think of an example? These are known as Digraphs. The vertices in a digraph still have “degrees” but beyond that, they have “indegrees” and “outdegrees.” Can you guess what that means?

80 DIGRAPHS A directed graph (or digraph) is a graph, or set of vertices connected by edges, where the edges have a direction associated with them.graph A directed graph is called a simple graph if it has no multiple arrows (two or more edges that connect the same two vertices) and no loops (edges that connect vertices to themselves). A directed graph is called a multigraph or multidigraph if it may have multiple arrows (and sometimes loops).simple graphmultigraph

81 FOR EXAMPLE, THE DIGRAPH BELOW Vertices?Ordered Edges? Indegrees? Outdegrees?

82 SO HOW DOES A DIGRAPH AFFECT THE ADJACENCY MATRIX? The adjacency Matrix for this digraph is: AA B C A0 0 0 B B1 0 1 C0 0 0 C

83 FIND THE ADJACENCY MATRIX

84 PRACTICE ON YOUR OWN Take a minute to draw a graph with six vertices and eight edges so that the graph has an Euler Circuit.

85 PRACTICE ACTIVITY Create the digraph described by this adjacency matrix… ABCDE A01010 B10101 C00010 D01100 E10010

86 IS THERE A EULER PATH OR CIRCUIT? If so, can you find it? Degree of each vertex? Set Representation? Adjacency Matrix?

87 HOW ABOUT NOW? In a digraph, there is an Euler circuit if the indegree and outdegree of each vertex are equal. There is an Euler Path if: the indegree = the outdegree in all vertices but two & at one of those two vertices, the indegree is one greater than the outdegree & at the other vertex, the outdegree is one greater than the indegree

88 IS THERE AN EULER PATH OR CIRCUIT? REMEMBER TO CHECK IN-DEGREES AND OUT-DEGREES FIRST! AB C DE F GH J

89 FLEURY'S ALGORITHM Euler Circuit Algorithm Euler's Theorems are examples of existence theorems existence theorems tell whether or not something exists (e.g. Euler circuit) …. but doesn't tell us how to create it! We want a constructive method for finding Euler paths and circuits Methods (well-defined procedures, recipes) for construction are called algorithms There is an algorithm for constructing an Euler circuit: Fleury's Algorithm https://www.youtube.com/watch?v=Lr6C8u-FDL8

90 1. Pick any vertex to start 2. From that vertex pick an edge to traverse (see below for important rule) 3. Darken that edge, as a reminder that you can't traverse it again 4. Travel that edge, coming to the next vertex 5. Repeat 2-4 until all edges have been traversed, and you are back at the starting vertex At each stage of the algorithm: The original graph minus the darkened (already used) edges = reduced graph Important rule: never cross a bridge of the reduced graph unless there is no other choice why must we observe that rule?

91 FLEURY'S ALGORITHM the same algorithm works for Euler paths before starting, use Euler’s theorems to check that the graph has an Euler path and/or circuit to find! when you do this on paper, you can erase each edge as you traverse it this will make the reduced graph visible, and its bridges apparent

92 FLEURY’S ALGORITHM PRACTICE Use Fleury’s Algorithm to find an Euler Path or Circuit if one exists….. A B G E CF D HJ

93 PRACTICE ON YOUR OWN Use Fleury’s Algorithm to find an Euler Circuit if one exists….

94 HAMILTONIAN CIRCUITS AND PATHS

95 EXPLORATION Let’s pretend that you are a city inspector and it is time for you to inspect the fire hydrants that are located at each of the street intersections. To optimize your route, you must find a path that begins at the garage, G, visits each intersection exactly once, and returns to the garage.

96 EXPLORATION ab c d e f G h i j

97 ONE PATH WORKS! One is path G, h, f, d, c, a, b, e, j, i, G. Also notice, that is not necessary that every edge of the graph be traversed when visiting each vertex exactly once.

98 SIR WILLIAM ROWAN HAMILTON In the 19 th century, an Irishman named Sir William Rowan Hamilton (1805-1865) invented a game called the Icosian game. The game consisted of a graph in which the vertices represented major cities in Europe.

99 THE ICOSIAN GAME The object of the game was to find a path that visited each of the 20 vertices exactly once. In honor of Hamilton and his game, a path that uses each vertex of a graph exactly once is known as a Hamiltonian path. If the path ends at the starting vertex, it is called a Hamiltonian circuit.

100 YOU TRY

101 HAMILTONIAN THEOREM This theorem guarantees the existence of a Hamilton circuit for certain kinds of graphs. If a connected graph has “n” vertices, where n>2 and each vertex has degree of at least n/2, then the graph has a Hamilton circuit.

102 HAMILTONIAN CIRCUITS If a graph has some vertices with degree less than n/2, the theorem does not apply. The second two of the figures that are drawn have vertices that have a degree less than 5/2, so no conclusion can be drawn. By inspection, the second figure has a Hamiltonian circuit but the last figure does not.

103 PRACTICE PROBLEMS Find which have Hamiltonian circuits. If a connected graph has “n” vertices, where n>2 and each vertex has degree of at least n/2, then the graph has a Hamilton circuit. However, this Hamilton theorem does NOT rule out a circuit or path.

104 WHERE ARE HAMILTONIAN-TYPE CIRCUITS USED? Get into groups of three and come up with your three best examples of professions or real-world businesses that require someone to “visit” a number of locations, cities, businesses regularly. Share your group’s three options….. The study of Hamiltonian Circuits and the Hamilton Theorem in general is usually characterized as the “Travelling Salesman Problem”

105 FINDING THE HAMILTONIAN CIRCUIT Since each of the five vertices of the graph has degrees of at least 5/2, the graph has a Hamiltonian circuit. Unfortunately, the theorem does not tell us how to find the circuit.

106 DEGREES Check the degrees of the figures in the graphs below.

107 THE TRAVELLING SALESMAN PROBLEM https://www.youtube.com/watch?v=SC5CX8drAtU https://www.youtube.com/watch?v=5WWcm-wW0nk

108 https://www.youtube.com/watch?v=BmsC6AEbkrw https://www.youtube.com/watch?v=HWHZAtQl1vI

109 GUIDED ACTIVITY Suppose Four teams play in the school soccer round robin tournament. The results are as follows: Draw a digraph to represent the tournament. Find a Hamiltonian path and then rank the participants from winner to loser. GameABACADBCBDCD WinnerBADBDD

110 USE OF HAMILTONIAN CIRCUITS As with Euler circuits, it often is useful for the edges of the graph to have a direction. If we consider a competition where every player must play every other player. This can be shown by drawing a complete graph where the vertices represent the players.

111 COMPETITION EXAMPLE In this situation, a directed arrow from vertex A to vertex B would mean that player A defeated player B. This type of digraph is known as a tournament. One interesting property of such a digraph is that every tournament contains a Hamilton path which implies that at the end of the tournament it is possible to rank the teams in order, from winner to loser.

112 EXAMPLE (CONT’D) Remember that a tournament results from a complete graph when direction is given to the edges. There is only one Hamiltonian path for this graph, DBAC. Therefore, D is first, B is second, A is third and C is fourth. A B C D

113 To determine a ranking, remember that a tournament results from a complete graph when direction is given to the edges. In this case, there is only one Hamiltonian path for the graph, D, B, A, C. Therefore, D finishes first, B is second, A is third, and C finishes fourth.

114 ROCK, PAPER, SCISSORS TOURNAMENT ACTIVITY Groups of five Each person plays every other person in your group. You are playing rock-paper-scissors. Keep a chart of who wins or loses and you are playing the best three out of five, and you have to play all five games. Also, keep track of how many games each person wins. From your results chart, create a digraph to represent those results and determine who finishes in first, second, third, fourth, and fifth.

115 WARM-UP PROBLEMS 1.Draw a tournament with five players, in which player A beats everyone, B beats everyone but A, C is beaten by everyone and D beats only E. 2.Find all the directed Hamiltonian paths for the following tournaments: D AB C A B D C

116 PREFERENCE SCHEDULES AND GRAPHING Consider the set of preference schedules: A B C D 8 B C D A 5 C B D A 6 D B C A 7

117 PRACTICE PROBLEMS (CONT’D) The first preference schedule could be represented by the following tournament: D C B A

118 PRACTICE PROBLEMS (CONT’D) a.Construct tournaments for the other three preference schedules.

119 THE TRAVELING SALESPERSON PROBLEM Home Think of this problem as a way to find the cheapest or shortest route….or some other criteria that will be given…..and the processes are designed to find the “optimal” route.

120 SO WHAT DO THE NUMBERS MEAN? First, the numbers can be distance…..or they can be cost….or they can be some other unit of measure that is important to the decision of the salesperson like time. In this case, the numbers are the cost of traveling between cities along that route. This type of labeling creates a “weighted graph”

121 THE TRAVELING SALESPERSON PROBLEM Since the salesman is always trying to minimize costs, how would he cover all four cities for the least amount of cost?

122 BRUTE FORCE METHOD Step 1: List every possible circuit along with its cost Since this particular problem has only four vertices, how many options are there for the circuit Step 2:Use a tree diagram to show them. Can you guess how many options there are if the salesman has 25 different cities to visit? There are over 19 million…..so how practical is that? Maybe there is a better way……

123 THE TRAVELING SALESPERSON PROBLEM How about the “Nearest Neighbor Algorithm”?

124 NEAREST NEIGHBOR ALGORITHM Step 1: From your starting vertex, go the next nearest vertex (city/neighbor)…. Step 2: Then the next, and the next and next until you have exhausted all other vertices and returned home……. Does this give you the cheapest route? An Algorithm that gives you a quick result and a reasonably close to optimal solution is known as a “heuristic method” https://www.youtube.com/watch?v=JH2IUFmP8JI

125 BRUTE FORCE VERSUS NEAREST NEIGHBOR

126 A 55 D C B

127 A 55 D C B

128 THE TRAVELLING SALESMAN GAME http://www.hoodamath.com/games/thetravellingsalesman.html

129 WARM-UP A delivery person must visit each of his warehouses daily. His delivery route begins and ends at his garage (G). The table below shows the approximate travel time (in minutes) between stops. Draw a weighted complete graph to represent this information. Use the nearest neighbor algorithm to find the quickest route. How much time does this route take? GABCD G----2516.51843 A25----2117.515 B16.521----23.519.5 C1817.523.5----21 D431519.521----

130 FIND THE OPTIMAL ROUTE USING THE NNA

131

132 PRACTICE PROBLEM Use the Nearest Neighbor algorithm to find a Hamilton circuit of reasonably minimal weight in each of the following graphs. For each, start at A, name the circuit and find its total weight.

133 DIJKSTRA’S ALGORITHM FOR SHORTEST ROUTE So imagine that you want to find the shortest route from one vertex (location) to another vertex (location) but you don’t have to go to EVERY location in the graph. Think about this……how many routes can you draw from Cox Mill High School to your house? Each turn represents a new vertex. What if you draw those routes and estimate the minutes each edge takes…..an edge is from where you are until you make a turn…..the next edge is from that turn to the next turn…….

134 Many more problems than you might at first think can be cast as shortest path problems, making Dijkstra’s algorithm a powerful and general tool. For example: Dijkstra’s algorithm is applied to automatically find directions between physical locations, such as driving directions on websites like Mapquest or Google Maps. In a networking or telecommunication applications, Dijkstra’s algorithm has been used for solving the min- delay path problem (which is the shortest path problem). For example in data network routing, the goal is to find the path for data packets to go through a switching network with minimal delay. It is also used for solving a variety of shortest path problems arising in plant and facility layout, robotics, transportation, and other design problems

135 DIJKSTRA’S ALGORITHM FOR SHORTEST ROUTE https://www.youtube.com/watch?v=U9Raj6rAqqs Step 1 Label the start vertex as 0. Step 2 Box this number (permanent label). Step 3 Label each vertex that is connected to the start vertex with its distance (temporary label). Step 4 Box the smallest number. Step 5 From this vertex, consider the distance to each connected vertex. Step 6 If a distance is less than a distance already at this vertex, cross out this distance and write in the new distance. If there was no distance at the vertex, write down the new distance. Step 7 Repeat from step 4 until the destination vertex is boxed.

136 LET’S TRY THE DIJKSTRA SHORTEST PATH ALGORITHM From A to G A D F 8 4 4 C 2 41 5 5G 5 B7E

137 TRY IT ON YOUR OWN From Albany to Ladue What if you have to go through Fenton first to deliver a package?

138 WHAT IF YOU HAVE A DIGRAPH? Find the shortest path from A to F.

139 WARM-UP PROBLEM TWO Use Dijkstra’s Shortest Path Algorithm to find the shortest from Pensacola to Pendleton… 2 5 3 32 8 3 4 4 10 4 2 3 5 Pendleton Pierre Pueblo Phoenix Peoria Pittsburgh Pensacola Princeton

140 WARM-UP PROBLEM Find the “indegrees and outdegrees” of each vertex. ABAB ECEC D If this graph represents a tournament, what do you think the arrows say?

141 WARM-UP PROBLEM Find the “indegrees and outdegrees” of each vertex. ABAB ECEC D If this graph represents a tournament, what do the arrows tell you?

142 TREE GRAPH Tree graphs are defined as a connected graph with no cycles. But what is a cycle? A cycle in a graph is any path that begins and ends at the same vertex and no other vertex is repeated.

143 OPTIMIZATION USING SPANNING TREES What does optimization mean? In terms of graphing it can mean one of two things…. Finding ways to connect the vertices of the graph with the least number of edges, and, Finding ways of connecting them with the least number of edges that have the smallest total weight…..

144 WHAT IS A SPANNING TREE? Definition:A spanning tree of a connected graph (G) is a tree that is a sub-graph of G and contains every vertex of G. It contains the minimum number of edges, Hits every vertex exactly once, Contains no cycles.

145 Take a look at this graph and try to connect the vertices using the least number of edges….. When you have found one that connects the vertices AND has no cycles you have found what is called a “Spanning Tree”

146 THE BREADTH-FIRST SEARCH ALGORITHM FOR FINDING SPANNING TREES Step 1:Pick a starting vertex, S, and label it with a 0; Step 2:Find all vertices that are adjacent to S and label them with a 1; Step 3: For each vertex labeled with a 1, find an edge that connects it with the vertex labeled 0. Darken those edges. Step 4:Look for unlabeled vertices adjacent to those with the label 1 and label them with a 2. for each vertex labeled 2, find an edge that connects it with a vertex labeled 1. darken that edge. If more than one edge exists, choose one arbitrarily. Step 5:Continue this process until there are no more unlabeled vertices adjacent to labeled ones. If not all vertices of the graph are labeled, then a spanning tree for the graph does not exist. If all vertices are labeled, the vertices and darkened edges are a spanning tree of that graph.

147 B EH C A FI D G J

148 9 13 5 6 7 8 10 15 15 9 20 5 12 16 15 Can you find a Spanning Tree that carries the least weight? This is the Minimum Spanning Tree

149 KRUSKAL’S MINIMUM SPANNING TREE ALGORITHM 1.https://www.youtube.com/watch?v=71UQH7Pr9kUhttps://www.youtube.com/watch?v=71UQH7Pr9kU 2.Examine the graph. If it is not connected, there will be no minimum spanning tree. 3.List the edges in order from shortest to longest. Ties are broken arbitrarily. 4.Darken the first edge on the list. 5.Select the next edge on the list. If it does not form a cycle with the darkened edges, darken it. 6.For a graph with “n” vertices, continue step 4 until n-1 edges of the graph have been darkened. The vertices and the darkened edges are a minimum spanning tree for the graph.

150 PRACTICE THE BREADTH FIRST SEARCH ALGORITHM B C H A I D J G F E

151 USE KRUSKAL’S ALGORITHM TO FIND THE MINIMUM SPANNING TREE A 4 B 8 C 6 D 5 5 6 4 48 6 5

152 THE TRAVELLING SALESMAN GAME http://www.hoodamath.com/games/thetravellingsalesman.html

153 WARM-UP Draw a tournament with five vertices in which there is a 3-way tie for first place.

154 TaskTimePrerequisites A7None B7 C9A, B D6A E5C, D F10B G3D Finish Draw the Graph based on the Chart Below….. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

155 TaskTimePrerequisites A1None B7A C3A, I D10None E19D F8B G14B, D, I H11B, I I6None J7C, D, H Finish Draw the Graph based on the Chart Below….. Find the Earliest Start Times for Each Task….. Calculate the minimum time needed to complete this project. What is the critical path?

156

157

158

159

160

161

162 This is a more modern version of Example 5.3. Madison County is a quaint old place, famous for its quaint old bridges. A beautiful river runs through the county, and there are four islands (A, B, C, and D) and 11 bridges joining the islands to both banks of the river (R and L) and one another (Fig.5-3). A famous photographer is hired to take pictures of each of the 11 bridges for a national magazine. The photographer needs to drive across each bridge once for the photo shoot. Moreover, since there is a $25 toll (the locals call it a “maintenance tax”) every time an out-of-town visitor drives across a bridge, the photographer wants to minimize the total cost of his trip and to recross bridges only if it is absolutely necessary. What is the optimal (cheapest) route for him to follow? The Bridges of Madison County

163

164 This is the conclusion of the routing problem first introduced in Example 5.4. A photographer needs to take photos of each of the 11 bridges in Madison County. Example 5.25The Bridges of Madison County: Part 2

165 A graph model of the layout (vertices represent land masses, edges represent bridges) is shown. Example 5.25The Bridges of Madison County: Part 2

166 The graph has four odd vertices (R, L, B, and D), so some bridges are definitely going to have to be recrossed. Example 5.25The Bridges of Madison County: Part 2

167 How many and which ones depends on the other parameters of the problem. (Recall that it costs $25 in toll fees to cross a bridge, so the baseline cost for crossing the 11 bridges is $275. Each recrossing is at an additional cost of $25.) The following are a few of the possible scenarios one might have to consider. Each one requires a different eulerization and will result in a different route. Example 5.25The Bridges of Madison County: Part 2

168 The photographer needs to start and end his trip in the same place. This scenario requires an optimal eulerization of the graph. Example 5.25The Bridges of Madison County: Part 2 This is not hard to do, and an optimal route can be found for a cost of $325.

169 The photographer has the freedom to choose any starting and ending points for his trip. In this case we can find an optimal semi- Example 5.25The Bridges of Madison County: Part 2 eulerization of the graph, requiring only one duplicate edge. Now an optimal route is possible at a cost of $300.

170 The photographer has to start his trip at B and end the trip at L. In this case we must find a semi-eulerization of the graph where B and L remain as odd vertices and R and D Example 5.25The Bridges of Madison County: Part 2 become even vertices. It is possible to do this with just two duplicate edges and thus find an optimal route that will cost $325.

171 After a rash of burglaries, a private security guard is hired to patrol the streets of the Sunnyside neighborhood shown next. The security guard’s assignment is to make an exhaustive patrol, on foot, through the entire neighborhood. Obviously, he doesn’t want to walk any more than what is necessary. His starting point is the southeast corner across from the school (S)–that’s where he parks his car. Being a practical person, the security guard would like the answers to two questions. (1) Is it possible to start and end at S, cover every block of the neighborhood, and pass through each block just once? (2) If some of the blocks will have to be covered more than once, what is an optimal route that covers the entire neighborhood? (Optimal here means “with the minimal amount of walking.”) Walking the ‘Hood’

172 (This is relevant because at the end of his patrol he needs to come back to S to pick up his car.) Walking the ‘Hood’

173 A mail carrier has to deliver mail in the same Sunnyside neighborhood. The difference between the mail carrier’s route and the security guard’s route is that the mail carrier must make two passes through blocks with houses on both sides of the street and only one pass through blocks with houses on only one side of the street; and where there are no homes on either side of the street, the mail carrier does not have to walk at all. In addition, the mail carrier has no choice as to her starting and ending points–she has to start and end her route at the local post office (P). Much like the security guard, the mail carrier wants to find the optimal route that would allow her to cover the neighborhood with the least amount of walking. (Put yourself in her shoes and you would do the same–good weather or bad, she walks this route 300 days a year!) Delivering the Mail

174

175

176


Download ppt "UNIT – GRAPH THEORY. CONCEPT CHARACTERISTICS What is a Graph……Really?"

Similar presentations


Ads by Google