Efficiently assign games

44 views Asked by At

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.

1

There are 1 answers

2
encrest On

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.