We have discussed one loss minimization strategy before: Job Sequencing Problem – Loss Minimization. In this article, we will look at another strategy that applies to a slightly different problem.
We are given a sequence of N goods of production numbered from 1 to N. Each good has a volume denoted by (Vi). The constraint is that once a good has been completed its volume starts decaying at a fixed percentage (P) per day. All goods decay at the same rate and further each good take one day to complete.
We are required to find the order in which the goods should be produced so that overall volume of goods is maximized.
Input: 4, 2, 151, 15, 1, 52, 12 and P = 10% Output: 222.503
Solution: In the optimum sequence of jobs, the total volume of goods left at the end of all jobs is 222.503
Input: 3, 1, 41, 52, 15, 4, 1, 63, 12 and P = 20% Output: 145.742
Solution: In the optimum sequence of jobs the total volume of goods left at the end of all jobs is 145.72
Since this is an optimization problem, we can try to solve this problem by using a greedy algorithm. On each day we make a selection from among the goods that are yet to be produced. Thus all we need is a local selection criteria or heuristic, which when applied to select the jobs will give us the optimum result.
Instead of trying to maximize the volume, we can also try to minimize the losses. Since the total volume that can be obtained from all goods is also constant, if we minimize the losses we are guaranteed to get the optimum answer.
Now consider any good having volume V
Loss after Day 1: PV
Loss after Day 2: PV + P(1-P)V or V(2P-P^2)
Loss after Day 3: V(2P-P^2) + P(1 – 2P + P^2)V or V(3P – 3P^2 + P^3)
As the day increases the losses too increase. So the trick would be to ensure that the goods are not kept idle after production. Further, since we are required to produce at least one job per day, we should perform low volume jobs, and then perform the high volume jobs. This strategy works due to two factors.
- High Volume goods are not kept idle after production.
- As the volume decreases the loss per day too decreases, so for low volume goods the losses become negligible after a few days.
So in order to obtain the optimum solution we produce the larger volume goods later on. For the first day select the good with least volume and produce it. Remove the produced good from the list of goods. For the next day repeat the same. Keep repeating while there are goods left to be produced.
When calculating the total volume at the end of production, keep in mind the good produced on day i, will have times its volume left. Evidently, the good produced on day N (last day) will have its volume intact since .
Step 1: Add all the goods to a min-heap Step 2: Repeat following steps while Queue is not empty Extract the good at the head of the heap Print the good Remove the good from the heap [END OF LOOP] Step 4: End
We perform exactly N push() and pop() operations each of which takes log (N) time. Hence time complexity is O( N * log(N) ).
Below is the Cpp implementation of the solution.
1 2 3 4 5 6 7 8 9 10 41.3811
- Job Sequencing Problem - Loss Minimization
- Activity Selection Problem | Greedy Algo-1
- Scheduling priority tasks in limited time and minimizing loss
- Selection Sort
- Stable Selection Sort
- Recursive Selection Sort
- 8086 program for selection sort
- Iterative selection sort for linked list
- C++ program for Sorting Dates using Selection Sort
- Sorting Algorithms Visualization | Selection Sort
- A sorting algorithm that slightly improves on selection sort
- Recursive selection sort for singly linked list | Swapping node links
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Program to sort an array of strings using Selection Sort
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai