1 / 42

K NAPSACK

K NAPSACK. Given positive integers v i and w i for i = 1, 2, ..., n. and positive integers K and W. Does there exist a subset S of {1, 2, ..., n} such that:. and. A special case: S UBSET S UM. Given positive integers v i for i = 1, 2, ..., n. and an integer K.

louvain
Télécharger la présentation

K NAPSACK

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. KNAPSACK Given positive integers vi and wi for i = 1, 2, ..., n. and positive integers K and W. Does there exist a subset S of {1, 2, ..., n} such that: and

  2. A special case: SUBSET SUM Given positive integers vi for i = 1, 2, ..., n. and an integer K. Does there exist a subset S of {1, 2, ..., n} such that: 146 2120 1344 2688 2081 2082 1408 2065 769 14 1288 56 2336 258 265 3073 3328 4095 256 1160 592 EXACT COVER BY 3-SETS can be reduced to SUBSET SUM

  3. 2065 265 2082 1288 1408 1160 258 2081 146 56 256 2688 1344 769 14 3073 3328 592 2336 2120 4095

  4. A dynamic programming algorithm for KNAPSACK ”V(w,i) = largest value of elements from {1,...,i} that uses weight exactly w.” V(w,0) = 0 for all w. V(w,i+1) = max( V(w,i) , V(w-wi+1,i)+vi+1)

  5. Knapsack problem LKnapsackbinary is NP-hard. Knapsack can be solved in time O(n W) (on a random access machine). Therefore LKnapsackunary is in P: “Knapsack has a pseudopolynomial algorithm” Unless P=NP, any reduction of an NP-hard problem to KNAPSACK has to involve “large numbers”.

  6. Pseudopolynomial algorithms Let a problem Q involving integers be given. If LQunary is in P, we say that Q has a pseudopolynomial algorithm. If LQunary is NP-hard, we say that Q is strongly NP-hard. If a strongly NP-hard problem has a pseudopolynomial algorithm, then P=NP.

  7. ILP The reduction of 3SAT to ILP only generates coefficients in {0,1}. LILPunary is NP-hard: “Integer linear programming is strongly NP-hard”.

  8. Bin packing Given n positive integers a1, a2, ..., an (items), a positive integer B (number of bins) and a positive integer C (the capacity of a bin). Can the items fit into the bins? That is, can the items be partitioned into B subsets such that thesum of the items in each of the subset is at most C? TRIPARTITE MATCHING can be reduced to BIN PACKING with all integers in the output being O(n4). BIN PACKING is strongly NP-hard: A pseudopolynomial algorithm would imply P=NP.

  9. Idea of reduction Create a bin for each triple. Construct an item for each triple Construct an item for each occurance of boys, girls and houses One of each occurance is the ”real” occurance – the rest are copies We make sure each bin can fit exactly 4 items: the item for a triple and the corresponding items for the boy, girl and house.

  10. First occurences Numbers in M-ary (M sufficiently large: M=4m)

  11. Secondary occurances Numbers in M-ary

  12. Total capacity: mC Total sum of numbers: mC Conclusion: All bin must be filled exactly! Let a beany of the numbersproduced. a 12 M4 + nM3 + 8 < 40/3 M4 + 5 =C/3 a ≥8M4 + 4 > 8M4 + 3 = C/5 Conclusion: All bins must befilled with exactlyfour items.

  13. 40 = 10+10+10+10 = 11+11+8+10

  14. 40 = 10+10+10+10 = 11+11+8+10 No other selection of 4 numbers from {8,10,11} can give sum 40. Conclusion: The three items packed with a triple item are either - All first occurances. - All secondary occurances. A tripartite matching gives a packing of first occurances in bins and vice-versa!

  15. TSP HAMILTONIAN CYCLE MIN VERTEX COLORING SAT MAX INDEPENDENT SET SET COVER ILP MILP KNAPSACK TRIPARTITE MATCHING BINPACKING

  16. How to establish a problem to be NP-hard Reduce from known problem(very often special case in disguise) Modify known reduction Google is your friend!!

  17. Life as an algorithms designer Suppose your boss gives you the job of designing an efficient algorithm to solve a specific computational problem. For example, given a set of specifications for a task the company considers to bid for, can the company meet these requirements? What if, using all your skills learned from algorithms courses you can't come up with an efficient algorithm?

  18. Wrong way to approach boss

  19. Correct way to approach boss Unfortunately, often proving intractability is also not possible

  20. Best possible way to approach boss

  21. How (not) to use the theory of NP-completeness

  22. Common(!) Misuse! Arthur: I have a 150 cities on a map. I want to find the shortest cycle visiting all of them. Bill: Wait a sec.. That’s the TSP-problem! It’s NP-hard! You’ll never be able to do it!

  23. …. The solution was found by a java applet (implementing branch and cut) in less than a minute.

  24. What went wrong? ??? Bill only knows that no algorithm solving TSP has worst case polynomial complexity (assuming P is not NP). This says absolutely nothing about how hard it is to solve instances of size 150. Or even instances of size 10000000. Even if it did, it would say absolutely nothing about the particular instances of size 150 that Arthur wants to solve!

  25. The Eternity Puzzle

  26. June 1999: Christopher Monckton releases the Eternity Puzzle. The first person to solve the puzzle before 30 September 2003 wins £ 1 Million.

  27. Big Prize, but… He reckoned that by the time the world's puzzle-solving community had unlocked Eternity's secret (at £29.99 a go), he would have earned substantially more than £1 million in sales. Why?

  28. Eternity seems hard…. Solving jigsaw puzzles is NP-complete. Monckton: ”I worked out that there were about as many possible combinations of these 209 pieces as there were particles in the known universe, and that is a figure which is at least 621 digits long. As for a computer, I found it could solve a 12-piece puzzle in one-hundredth of a second, but from that point on the progress was exponential - which meant that even with quite sophisticated software, it would take one million billion years to solve a 209-piece puzzle.”

  29. … but was easier than expected A solution to Eternity was found on 15th May 2000 by Alex Selby and Oliver Riordan. Another solution was found independently by Günter Stertenbrink on 1st July 2000.

  30. Method used Branch and Bound tailored to the particular instance.

  31. June 2001: Monckton sells his home Crimonmogate, a nineteenth-centurymansion in Crimond, Aberdeenshire, for an estimated £1.2m.

  32. So, I took this course andhad to learn this theory thatcan only be misused!? Poor Bill …

  33. Excellent use! Arthur: Here is my suggestion for solving my problem. I’m not sure how efficient it is, but at least it’s correct. I’ll write down this linear program and… Bill: Wait a sec..This method would work in general and create a polynomial sized LP. It cannot be correct unless P=NP. I don’t even have to try and understand it!

  34. Excellent use! Bill: Wait a sec..This local search approach has polynomial sized meighborhoods. It cannot solve an NP-hard optimization Problem unless NP=coNP. And I don’t even have to try and understand it! Arthur: Okay, here is another suggestion. This clearly may take exponential time in the worst case and now I’m positive it’s correct. It’s a local search approach where you (bla bla)

  35. How to solve NP-hard problems Irony of NP-hardness: It is often easier to find the best way of solving an NP-hard problem than the best way of solving a problem in P, because you know which approaches (not) to try. Algorithmic patterns for NP-hard problems: branch-and-bound, branch-and-cut, branch-and-reduce. Alternative approach if exact solutions are too hard to obtain: Solve the problem approximately.

More Related