Presentation is loading. Please wait.

Presentation is loading. Please wait.

Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem.

Similar presentations


Presentation on theme: "Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem."— Presentation transcript:

1 Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem

2 2 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…

3 3 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

4 4 Creating a Graph for the MCST Step 1: Identify the Vertices. 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. Use one vertex for each of the 6 locations. the possibility of constructing a pipeline segment from location i to location j. R F5F4 F3 F2F1 60

5 5 Step 4: State the Objective R F5F4 F3 F2F1 45 40 75 50 82 10 73 65 25 34 37 45 35 30 42 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). Distance = 170

6 6 Step 4: State the Objective Key Observations: The set of edges you choose must: (1) Include all of the vertices. (2) Have a path from each vertex to R, that is, beconnected. (3) Have no cycles. (4) Have least total distance among all such spanning trees. Tree Span- ning Min Cost R F5F4 F3 F2F1 75 50 75 60 82 10 73 65 25 54 30 45 35 80 40

7 7 The MCST Problem 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 The Minimum Cost Spanning Tree Problem (MCST) Definition: A tree is a connected graph that has no cycle.

8 8 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. R F5F4 F3 F2F1 75 50 75 60 82 10 73 65 25 54 30 45 35 80 40 R F5 F1 F4 F2F3

9 9 Kruskal’s Greedy Algorithm Step 1: If T* is a spanning tree, then stop. Step 0: Set the partial solution T* = , k = 1, and sort the q edges in increasing order of cost so that Step 2: If T* + e k has no cycle, then Set k = k + 1 and return to Step 1. 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.

10 10 Kruskal’s Greedy Algorithm Step 1: If the number of edges in T* is n – 1, then stop. Step 0: Set the partial solution T* = , k = 1, and sort the q edges in increasing order of cost so that Step 2: If T* + e k has no cycle, then Set k = k + 1 and return to Step 1. Question: For Step 2, how will the you (and the computer) know if T* + e k has 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.

11 11 Kruskal’s Greedy Algorithm R F5F4 F3 F2F1 75 50 75 60 82 10 73 65 25 54 30 45 35 80 40 R F5 F1 F4 F2F3 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*.

12 12 Kruskal’s Greedy Algorithm Step 1: If the number of edges in T* is n – 1, then stop. Step 0: Set the partial solution T* = , k = 1, and sort the q edges in increasing order of cost so that Step 2: If e k connects two vertices in different components of T*, then set Set k = k + 1 and return to Step 1.

13 13 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(n 2 log(n)).

14 14 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. R F5F4 F3 F2F1 75 50 75 60 82 10 73 65 25 54 30 45 35 80 40 R F5 F1F2F3 F4

15 15 Prim’s Greedy Algorithm Step 0: Set the partial solution T* = {1}, B = {2,…, n}. Step 1: If B = , then stop. Step 2: Find vertices u*  T* and v*  B such that

16 16 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(n 2 log(n)).

17 17 Summary 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 The Minimum Cost Spanning Tree Problem (MCST) Kruskal’s Greedy Algorithms obtains an optimal solution by choosing the edges, one at a time, in O(n 2 log(n)) time. Prim’s Greedy Algorithms obtains an optimal solution by choosing the vertices, one at a time, in O(n 2 log(n)) time.

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


Download ppt "Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem."

Similar presentations


Ads by Google