I'm trying to come up with a reasonable algorithm for this problem:
Let's say you have a bunch of balls. Each ball has at least one color, but can also be multicolored. Each ball also has a number on it. There are also a bunch of boxes which are each only one color. The goal is to maximize the sum of the numbers on the balls in the boxes, and the only rules are:
- in order to place a ball in a box, it has to at least have the box's color on it
- you can only put one ball in each box.
For example, you can put a blue and green ball into a blue box or a green box, but not into a red box.
I've come up with a few optimizations that help a lot in terms of running time. For example, you can sort the balls in descending order of point value. Then as you go from highest number to lowest, if the ball only has one color, and there are no other higher-point balls that contain that color, you can put it in that box (and thus remove that box and that ball from the remaining combinations).
I'm just curious is there's some kind of dynamic algorithm for this type of problem, or if it's just the traveling salesman problem in disguise. Would it help if I knew there were at most X colors? Any help is greatly appreciated. Thanks!
Edit - here's a simple example:
Balls:
- 1 red ball - 5 points
- 1 blue ball - 3 points
- 1 green/red ball - 2 points
- 1 green/blue ball - 4 points
- 1 red/blue ball - 1 point
Boxes:
- 1 red
- 1 blue
- 1 green
Optimal Solution:
- red ball in red box
- blue ball in blue box
green/blue ball in green box
Total value: 12 points (5 + 3 + 4)