0

Sorry about the title, SO wasn't allowing the word "problem" in it. I have the following problem:

I have packages of things I want to sell, and each package has a price. When someone requests things X, Y and Z, I want to look through all the packages, some of which contain more than one item, and give the user the combination of packages that will cover their things and have the minimal price.

For example, I might suggest [(X, Y), (Z, Q)] for $10, since [(X), (Y), (Z)] costs $11. Since these are prices, I can't use the greedy weighted set cover algorithm, because two people getting the same thing for different prices would be bad.

However, I haven't been able to find a paper (or anything) detailing an optimal algorithm for the weighted set cover problem. Can someone help with an implementation (I'm using Python), a paper, or even a high-level description of how it works?

The packages I have are in the hundreds, and the things are 5-6, so running time isn't really an issue.

Thanks!

Stavros Korokithakis
  • 4,680
  • 10
  • 35
  • 42
  • If you have 6 different things, you can have only 2^6=64 different packages. – Thomash Jul 23 '13 at 14:48
  • We might add some things down the line, my point is that even exponential complexity algorithms should run pretty quickly, so I don't mind them. – Stavros Korokithakis Jul 23 '13 at 14:58
  • http://www.cs.uiuc.edu/class/sp08/cs473/Lectures/lec20.pdf has a decent explanation of the greedy solution, and http://en.wikipedia.org/wiki/Set_cover_problem#Greedy_algorithm is alright too. I'm pretty sure that's what you're looking for, but I could be wrong – vik Jul 23 '13 at 15:00
  • Ah, that's the greedy algorithm, not the optimal one... – Stavros Korokithakis Jul 23 '13 at 15:08
  • If you are looking for references, try this paper "**A better-than-greedy approximation algorithm for the minimum set cover problem**", *Refael Hassin and Asaf Levin*, February 3, 2005[ \[link\]](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.1615&rep=rep1&type=pdf) – Hrishikesh Jan 26 '14 at 22:17

1 Answers1

2

If you want an exponential algorithm, just try every subset of the set of packages and take the cheapest one that contains all the things you need.

Thomash
  • 6,339
  • 1
  • 30
  • 50