180 likes | 197 Views
Two Discrete Optimization Problems. Problem #2: The Minimum Cost Spanning Tree Problem. Formulating Graph Problems. You already know the following steps for formulating a graph problem (such as the TSP and the Shortest-Path Problem):
E N D
Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem
Formulating Graph Problems You already know the following steps for formulating a graph problem (such as the TSP and the Shortest-Path Problem): 1. Identify the vertices that represent objects in a problem. 2.Identify the edges that are lines connecting selected pairs of vertices to indicated a relationship between the objects associated with the two connected vertices. 3. Identify additional data by writing those values next to the corresponding vertices and/or edges. 4. State the objective in the context of the graph and given data. Let’s do this for a new problem…
The MCST Problem Hexxon Oil wants to build a pipeline network for shipping oil from 5 fields to a refinery. It is possible to pump oil from one field through other fields before reaching the refinery. The cost of building is proportional to the total distance of the pipeline. Given the following distances in kilometers, how should the pipeline be constructed? Distances in Kilometers Between Locations
F1 F2 R F3 F5 F4 the possibility of constructing a pipelinesegment from location i to location j. Creating a Graph for the MCST Step 1: Identify the Vertices. Use one vertex for each of the 6 locations. 60 Step 2: Identify the Edges. Use an edge to connect a vertex i to a vertex j to represent Step 3: Identify Additional Data. The additional data are the distances associated with the arcs.
50 F1 F2 75 40 45 25 35 37 34 65 73 R F3 42 30 82 10 F5 F4 45 Step 4: State the Objective Distance = 170 Question: You want to construct a pipeline of least total distance to ship oil from all fields to the refinery, so, to determine this pipeline, what do you have to decide in the graph above? Answer: You have to decide which edges of the graph to use (and you will then build those pipeline segments).
60 F1 F2 75 50 45 25 35 30 54 65 73 R F3 40 80 82 10 F5 F4 75 Step 4: State the Objective Key Observations: The set of edges you choose must: (1) Include all of the vertices. Span-ning (2) Have a path from each vertex to R, that is, be connected. Tree (3) Have no cycles. Min Cost (4) Have least total distance among all such spanning trees.
The MCST Problem Definition: A tree is a connected graph that has no cycle. The Minimum Cost Spanning Tree Problem (MCST) Given a complete graph on n vertices together with a nonnegative “cost” c(e) associated with each edge e, find a spanning tree T* so as to
60 F1 F2 75 50 45 25 35 30 54 65 73 R F3 40 80 82 10 F5 F4 75 F2 Kruskal’s Greedy Algorithm A greedy algorithm, developed by Kruskal, is presented now for solving this problem. This greedy algorithm works with the edges, one at a time. F1 F4 R F3 F5
Step 0: Set the partial solution T* = , k = 1, andsort the q edges in increasing order of cost so that Step 2: If T* + ek has no cycle, then Set k = k + 1 and return to Step 1. Kruskal’s Greedy Algorithm Step 1: If T* is a spanning tree, then stop. Question: For Step 1, how will the you (and the computer) know if T* is a spanning tree? Answer: You can prove that if T* has no cycles and the number of edges in T* is n – 1, then T* is a spanning tree.
Step 0: Set the partial solution T* = , k = 1, andsort the q edges in increasing order of cost so that Step 2: If T* + ek has no cycle, then Set k = k + 1 and return to Step 1. Kruskal’s Greedy Algorithm Step 1: If the number of edges in T* is n – 1, then stop. Question: For Step 2, how will the you (and the computer) know if T* + ekhas no cycles? Answer: You can prove that if T* has no cycles and the number of edges of T* is n – 1, then T* is a spanning tree.
60 F1 F2 75 50 45 25 35 30 54 65 73 R F3 40 80 82 10 F5 F4 75 F2 Kruskal’s Greedy Algorithm Question: In KA, how will you know if adding a new edge to the partial solution T* results in a cycle? Answer: The new edge e will form a cycle if e connects two vertices in the same component of T*. F1 F4 R F3 F5
Step 0: Set the partial solution T* = , k = 1, andsort the q edges in increasing order of cost so that Step 2: If ek connects two vertices in different components of T*, then set Set k = k + 1 and return to Step 1. Kruskal’s Greedy Algorithm Step 1: If the number of edges in T* is n – 1, then stop.
Two Important Questions Whenever you solve a problem with an algorithm, you should ask two important questions: Question 1: How do you know if the final solution produced by your algorithm solve the problem? Answer: For KA, it is possible to prove so. However, you may not be able to for either of the following reasons: • The algorithm was not “smart” enough to guarantee getting an optimal solution. In this case, you can try another alg. • The problem is so difficult (NP-complete) that no one has been able to find a polynomial algorithm to solve the problem. Question 2: How efficient is your algorithm? Kruskal’s algorithm is O(n2 log(n)).
60 F1 F2 75 50 45 25 35 30 54 65 73 R F3 40 80 82 10 F5 F4 75 F2 Prim’s Greedy Algorithm A greedy algorithm, developed by Prim, is presented now for solving the MCST problem. This greedy algorithm works with the vertices, one at a time. F1 R F4 F3 F5
Step 2: Find vertices u* T* and v* B such that Prim’s Greedy Algorithm Step 0: Set the partial solution T* = {1}, B = {2,…, n}. Step 1: If B = , then stop.
Two Important Questions Question 1: Does Prim’s Algorithm always produce an optimal solution to the MCST Problem? Answer: Yes (you can prove it). Question 2: How efficient is the algorithm? Answer: With some effort, the running time is O(n2 log(n)).
Summary The Minimum Cost Spanning Tree Problem (MCST) Given a complete graph on n vertices together with a nonnegative “cost” c(e) associated with each edge e, find a spanning tree T* so as to Kruskal’s Greedy Algorithms obtains an optimal solution by choosing the edges, one at a time, in O(n2 log(n)) time. Prim’s Greedy Algorithms obtains an optimal solution by choosing the vertices, one at a time, in O(n2 log(n)) time.
Summary Formulating a graph problem involves the following steps: 1. Identify the vertices by using circles to represent objects in a problem. 2.Identify the edges by using lines to connect selected pairs of vertices to indicated a relationship between the objects associated with the two connected vertices. 3. Identify other data by writing those values next to the corresponding vertices and/or edges. 4. State the objective in the context of a general graph and given data. If helpful, identify variables, an objective function, and constraints.