1 / 29

Dynamic Programming (1)

Dynamic Programming (1). Dynamic Programming. This is probably the most challenging topic in the course Dynamic Programming is not a specific problem with a specific solution (like everything else that we’ve done up to now)

oswald
Download Presentation

Dynamic Programming (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DynamicProgramming (1)

  2. Dynamic Programming • This is probably the most challenging topic in the course • Dynamic Programming is not a specific problem with a specific solution (like everything else that we’ve done up to now) • Dynamic Programming is a general approach to solving a large class of problems • The difficulty in Dynamic Programming (DP) is to: • Recognise that you have a problem that can be solved by DP • Work out how to apply the DP approach to that particular problem

  3. DP Solution Approach • Dynamic Programming is used to solve problems that can be split into a series of smaller subproblems (called stages) • The solution to one stage will be used in finding the solution to the next stage • The solution to the final stage will be the solution to the whole problem • This approach is difficult to visualise as it is so general • We are therefore going to look at 2 examples of DP solutions before coming back to the general idea • In these examples, don’t try now to understand where the solution technique has come from – we’ll do that later!

  4. The knapsack problem You are in Thailand and want to buy some fake goods. Once back in Ireland, you will sell them as real for a profit. Three things are available: boxed sets of CDs, Sony mini systems and jeans. However, what you buy has to fit inside your backpack. You know that you have a 5kg limit on the weight of fake goods that you can carry in it. The profit and weight of the 3 fake items are given in the table on the next slide.

  5. The knapsack problem Knapsack Problem: How many of each item to carry so that you make the most profit while keeping to the 5kg limit?

  6. The knapsack problem • In fact, this particular knapsack problem is easy to solve “by eye” after a moment’s thought. • It is easy to solve because there are not that many combinations of items that come in under the 5kg limit • However, a knapsack problem with many more items and/or a higher weight limit would quickly become impossible to solve by just looking, because the number of feasible combinations of items would be too big • DP will give us a way to solve the knapsack problem, regardless of the number of items and maximum weight limit

  7. DP solution to the knapsack problem • The DP approach is to try to split the problem up into smaller stages. • Here, we can do this by starting with just one item • We’ll choose boxed sets of CDs as the one available item (although we could have chosen one of the other 2). • We’ll look at the optimal solution for different amounts of available weight in our knapsack up to 5kg • For each weight, we calculate the most CD boxes we can take, their weight, and the profit we’ll make. • This is put in the table on the next page

  8. Knapsack problem – stage 1

  9. Knapsack problem – stage 2 • The previous table tells us the optimal thing to do if we only had CD boxes available • Now we move to stage 2 – we add another item. Let it be the mini hi-fi (although we could have chosen jeans). • So now we have the hi-fis and the CDs available • Again we build a table for what to do for different amounts of available weight. • We now think about the different number of hi-fi’s we could take for different weights • With the weight left after we do this, we know from stage 1 what is the optimal thing to do as regards no. of boxed CDs to take

  10. Knapsack problem – stage 2

  11. Knapsack problem – Stage 2 • In the table, columns 5 and 6 come directly from the stage 1 table solution • The last column is the profit from the number of CD boxes in the best solution to stage 1 (in column 6) and the number of hi-fis in that row • So we know from stage 1 what is the best thing to do with any remaining available weight • We see that for these 2 items, the best solution if 5kg is available is 1 hi-fi and 1 CD box; if 4kg is available then the solution is 2 CD boxes, etc. (shaded boxes for each weight)

  12. Knapsack problem – stage 3 • We now move to the final stage and consider all 3 items. We repeat what we did for stage 2. • We now add the last item - jeans • However, since this is the last stage, we only need to consider the full available weight of 5kg • Our table will look like that for stage 2 but now: • we consider all possible amounts of jeans for 5kg • we then do the optimal thing for the remaining available weight, according to the stage 2 solution

  13. Knapsack problem – stage 3

  14. Knapsack problem – solution • So the result of stage 3 is that we carry no jeans and use the 5kg for the optimal stage 2 solution • Going back to the stage 2 solution for 5kg, we see that we carry 1 hi-fi, leaving 2kg for the stage 1 solution • Going back to stage 1 solution for 2kg, we see that we carry 1 CD box. • Note that we used the stage 2 and 1 solutions to tell us the best thing to do with any remaining available weight Thus the solution is: 1 CD box, 1 hi-fi. Your profit is €240

  15. Knapsack solution • For this particular problem, what we have done is overkill (it’s a lot quicker to solve just by “looking at it”) • But you can see that this method could be equally applied to any kind of knapsack problem, with different numbers of items and/or a different weight limit.

  16. Knapsack problem: class example Now solve the following knapsack problem using the DP method that we’ve just looked at. A cargo plane is leaving Dublin for Oslo. The plane has a capacity of 6 tonnes. A company wants to carry several pieces of heavy equipment on the plane. Their weights and value (in thousands of €) are given in the table on the next slide. Determine how many of each piece of machinery should be carried on the plane in order to maximise the value of the shipment.

  17. Knapsack problem: class example

  18. Resource allocation problem The Kipper Tie Company has divided Ireland into 3 sales regions: North, West and South. There are 3 sales reps to allocate to these 3 regions. The company thinks that the profit it will make in each region, according to how many of its reps it allocates to that region, is given in the table on the next slide. The company wants to know how many sales reps to allocate to each region in order to maximise profit.

  19. Resource allocation problem

  20. Resource allocation problem • This is an example of a resource allocation problem • Resources (in this case reps) are to be allocated to different tasks (in this case marketing in different regions). • The objective is then to find the optimal allocation with respect to some measure like profit. • It is another problem that can be solved by DP • In this case, the stages are going to be the number of regions • So we start with just 1 region – let’s choose the South (Note: we could equally choose West or North)

  21. Stage 1 –South region only • With only 1 region, we look at how best to allocate reps for different number of available reps up to the actual number of 3. • We place this in a table • We then find the best allocations for each no. of available reps • This stage is in fact rather trivial since we would always put as many reps as possible into the region in order to get the largest profit.

  22. Stage 1 – South region only

  23. Stage 2 – add in the West region • In stage 2, we add in another region • We choose the West (it can be the North if you want) • Rather like in Stage 2 of the knapsack problem, we: • Consider the different number of reps available to allocate up to the actual number 3 • For each no. of reps available, look at the different number that we can allocate to the West • With the remaining that we do not allocate, we know the optimal number to assign to South from Stage 1 • Look for the allocation to West and South that gives the best profit for each number of available reps

  24. Stage 2

  25. Stage 3 • Now we add the one remaining region – North • Since this is the last stage, we need only consider allocations for the actual number of 3 reps. • Again, we look at all possible allocations of 3 reps to North • Then with the remaining reps we know the optimal allocation to South and West from Stage 2 • Then we look for the best total profit between allocation to North and the other 2 regions

  26. Stage 3

  27. Resource allocation solution • We see that the most profitable allocation is 1 rep to North, with the 2 remaining reps allocated according to Stage 2 • From Stage 2, the optimal allocation of 2 reps is that both go to West, leaving none to be allocated according to Stage 1 • So solution is: 1 rep to North, 2 reps to West, with profit of €24,000

  28. Class example Now use the DP solution approach to solve the following resource allocation problem: Encyclopedia Galactica has divided Earth into 3 sales regions: polar, temperate and equatorial. It has 4 interplanetary sales reps available to assign to Earth. The sales that it makes in each region for each number of reps allocated are given in the table on the next slide. What is the best allocation of reps to the 3 regions in order to maximise sales?

  29. Class example

More Related