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

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

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

Two Discrete Optimization Problems

Problem #2:

The Minimum Cost Spanning Tree Problem

2

Formulating Graph ProblemsYou 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

The MCST ProblemHexxon 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

From/To F1 F2 F3 F4 F5 R F1 60 75 50 35 25 F2 45 30 54 65 F3 40 80 73 F4 75 82 F5 10

4

Creating a Graph for the MCSTStep 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 ofconstructing a pipeline segment from location i to location j.

R

F5 F4

F3

F2F160

5

Step 4: State the Objective

R

F5 F4

F3

F2F1

45

4075

50

8210

7365

2534

37 4535

3042

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

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

F5 F4

F3

F2F1

75

5075

60

8210

7365

2554

30 4535

8040

7

The MCST Problem

treespanning a is s.t.

)()cost(min

T

ecTTe

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

Kruskal’s Greedy AlgorithmA greedy algorithm, developed by Kruskal, is presented now for solving this problem.

This greedy algorithm works with the edges, one at a time.

R

F5 F4

F3

F2F1

75

5075

60

8210

7365

2554

30 4535

8040

R

F5

F1

F4

F2

F3

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

).()()( 21 qececec

Step 2: If T* + ek has no cycle, then

. ** keTT 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

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

).()()( 21 qececec

Step 2: If T* + ek has no cycle, then

. ** keTT Set k = k + 1 and return to Step 1.

Question: For Step 2, how will the you (and the computer) know if T* + ek 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

Kruskal’s Greedy Algorithm

R

F5 F4

F3

F2F1

75

5075

60

8210

7365

2554

30 4535

8040

R

F5

F1

F4

F2

F3

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

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

).()()( 21 qececec

Step 2: If ek connects two vertices in different components of T*, then set

. ** keTT Set k = k + 1 and return to Step 1.

13

Two Important QuestionsWhenever 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)).

14

Prim’s Greedy AlgorithmA 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

F5 F4

F3

F2F1

75

5075

60

8210

7365

2554

30 4535

8040

R

F5

F1 F2

F3

F4

15

Prim’s Greedy Algorithm

.1 Step Return to

.*}{ and ** **Set vBBvuTT

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

}. and*:)(min{*)*( BvTuuvcvuc

16

Two Important QuestionsQuestion 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)).

17

Summary

treespanning a is s.t.

)()cost(min

T

ecTTe

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

18

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