0

I am looking to solve a problem and would appreciate if someone can point me to algorithm that i can study to implement.

The problem is that we as a store are offering Game bundles. A bundle can have multiple games i.e.

B1 = {G1, G2, G3}, B2 = {G2, G4, G5}, B3 = {G1, G5}, B4 = {G2} etc.

There are no hardcoded bundles, we can create any new bundles based on any given game that we have in the market. The retailers can only buy bundles from us and not individual games however, they do tell us their preference i.e., A retailer may ask us that he wants a bundle which has game G5 and G4. Looking at this example, I should return him Bundle B2 but if he says that he wants a bundle whic has Game G1 and G4 then I have to return him B3 and B2 bundles.

Also, we would have count of how many bundles we are left with. Right now this is not the concern and i would like to look for best suitable bundles for the given request. A bundle can also consist of individual game like B4.

I tried googling some assignment algorithmg but i dont think so it can help me here.

Em Ae
  • 8,167
  • 27
  • 95
  • 162
  • The approximate number of bundles and games would help. For instance, if you have a retailer request for 3 games, you can search for 1, 2, and finally 3 bundles for a retailer. – Gilbert Le Blanc Jun 16 '15 at 01:48

1 Answers1

0

I would create a reverse lookup map/index of games : bundles eg. G1 = {B1, B3}, G2 = {B1, B2, B4}.

Then, when a user requests G1 and G2, you could use a SET AND operation on the results of each game in your lookup index. In the absence of a bundle that contains all the input games, you would have to define your own business logic from there (return a bundle with the most games included? cheapest bundle? return small bundles that contain each game separately? - the algorithm depends on what you want to accomplish)

You would just have to make sure that whenever you edit your bundles, you keep the index updated accordingly as well. (ie. whenever you do: bundles.put(bundle, game), you should also do games.put(game, bundle) and do the same with removals.

encrest
  • 1,757
  • 1
  • 17
  • 18
  • That will create lots of "combinations" that i would have to figure out at the end. Assume, we have 10 bundles and each bundle has only two games in common. A retailer requests for 10 different games, so most probably I will have 5 different bundles which will contain those games. Now we have to do intersection on each combination to sort out the minimum number of bundles. Think about it. – Em Ae Jun 16 '15 at 04:50
  • @EmAe If that's what you want, then I would recommend periodically calculating it my way, but storing every possible result in a lookup map (eg. G1G2 = B1 ). What you're requesting is essentially a search engine so you'll need an index builder as well as a query engine. – encrest Jun 16 '15 at 17:52