Note you need to prove your algorithm is indeed optimal A s
Note you need to prove your algorithm is indeed optimal. ?
A small business say, a photocopying service with a single large machine -faces the following scheduling problem. Each morning they get a set of jobs from customers. They want to do the jobs on their single machine in an order that keeps their customers happiest. Customer i\'s job will take r_i time to complete. Given a schedule (i.e., an ordering of the jobs), let C_i denote the finishing time of job i. For example, if job j is the first to be done, we would have C_j = t_j; and if job j is done right after job i, we would have C_j = C_j - t_i, Each customer i also has a given weight w_1 that represents his or her importance to the business. The happiness of customer i is expected to be dependent on the finishing time of i\'s job. So the company decides that they want to order the jobs to minimize the weighted sum of the completion limes. sigma_i = 1^n w_1 C_1. Design an efficient algorithm to solve this problem. That is. you are-given a set of n jobs with a processing time r_i and a weight w_i for each job. You want to order the jobs so as to minimize the weighted sum of the completion times, sigma_i = 1^n w_i C_i. Example. Suppose there are two jobs: the first takes time t_1 = 1 and has weight w_1 = 10, while the second job takes time t_2 = 3 and has weight w_2 = 2. Then doing job 1 first would yield a weighted completion time of 10 middot 1 + 2 middot 4 = 16, while doing the second job first would yield the larger weighted completion lime of 10 middot 4 + 2 middot 3 = 46.Solution
sort the jobs in descending order based on their weights and then calculate wieghted sum of completion time.
and if two weights are same then put the wight with lowest time ahead.
eg.
w1=8 t1=6
w2=4 t2=7
w3=5 t3=5
w4=8 t4=2
sorting in descending order:
wieghts completion time
8 2
8 6 +2
5 5+6+2
4 7+5+6+2
final product=8*2+8*(6+2)+5*(5+6+2)+4*(7+5+6+2)=225
reason for this algorithm:
since the c iincreases with i ,if the largest weight is kept last then the product of largest completion time and largest weight i.e Cn*Largest wieght =Very big. since cn=tn+tn-1+tn-2.......t1
hence largest weight is kept first so that it is multiplied by least amont of completion time.
If you sort in descending order according to time then also same problem arises Cn*Largest wieght =Very big.
Now when weights are same then sort then the one with lowest time must be kept first.
eg
w1=8 t1=2
w2=8 t2=6
8*2+8*(8) < 8*6+8*(8)

