to prove the greedy solution is optimal

4
To prove the Greedy solution is optimal: Let X =< x 1 , x 2 . . . . . x n > denote the greedy solution vector, where x i , 0 ≤ x i ≤ 1 is the fraction of O i that is included in the knapsack. As per the description of the greedy algorithm, 0 or more of the X i s will be 1, followed by a fractional quantity, followed by 0s. Let j be the rst index such that x j != 1. Then x i = 1, i = 1, 2. . . . , j − 1 and x i = 0, i = j + 1, j + 2, . . . , n. Let Y =< y 1 , y 2 . . . . . y n > denote an arbitrary optimal solution vector. We will show that Y can be gradually transformed into X, without decreasing pro tability, while maintaining feasibility.

Upload: rajashreeraj

Post on 28-Jan-2016

225 views

Category:

Documents


0 download

DESCRIPTION

greedy solution

TRANSCRIPT

Page 1: To Prove the Greedy Solution is Optimal

To prove the Greedy solution is optimal:

Let X =< x1, x2. . . . . xn > denote the greedy solution vector, where xi, 0 ≤ xi≤ 1 is the fraction of Oi that is included in the knapsack. As per the description of the greedy algorithm, 0 or more of the Xi s will be 1, followed by a fractional quantity, followed by 0s. Let j be the first index such that xj != 1. Then xi = 1, i = 1, 2. . . . , j − 1 and xi = 0, i = j + 1, j + 2, . . . , n. Let Y =< y1, y2. . . . . yn > denote an arbitrary optimal solution vector. We will show that Y can be gradually transformed into X, without decreasing profitability, while maintaining feasibility.

Page 2: To Prove the Greedy Solution is Optimal

Greedy Method: Task Scheduling:

Set A of tasks is independent if there exist a schedule with no late tasks. Nt (A): number of tasks in A with deadlines t or earlier,t= 1, 2, .....n

ai (task) : 1 2 3 4 5 6 7di (deadline) :4 2 4 3 1 4 6wi (weight) : 70 60 50 40 30 20 10Step1: Sort them in decreasing order of weight

Page 3: To Prove the Greedy Solution is Optimal

Step2: Greedily select the task with max weightIts deadline is 4, so put it in slot 4.1 2 3 4 5 6 7a1Now select a2. Deadline is 2, so put it in slot 2.1 2 3 4 5 6 7a2 a1a3, deadline is 4. 4 is occupied, so put it in a slot less than 4, that is unoccupied and has the max value. Here 1 and 3 are unoccupied, so put it in 3. Or move backwards until u find an empty slot. If no slot found put it in the last slot.1 2 3 4 5 6 7a2 a3 a1a4, dealine is 4, so put it in 1. Thats the only unoccpied slot less than 4.1 2 3 4 5 6 7a4 a2 a3 a1a5, no empty slots less than 1...put it in 7.a6 no empty slots less than 4 put it in 6Add both the penalty's to penalty variable.a7 deadline 6, put it in 5.Finally we have1 2 3 4 5 6 7a4 a2 a3 a1 a7 a6 a5

Total Penalty 50.