I am trying to find a reasonable algorithm for this problem:
Say you have a bunch of balls. Each ball has at least one color, but can also be multicolor. Each ball also has a number on it. There are also a bunch of boxes, each of which has only one color. The goal is to maximize the sum of the numbers on the balls in the boxes, and the only rules are:
- to put a ball in a box, it must have at least the color of the box on it
- You can only put one ball in each box.
For example, you can put a blue and green ball in a blue box or a green box, but not in a red frame.
I came up with several optimizations that help a lot in terms of run time. For example, you can sort the balls in descending order of the point value. Then, when you move from the highest to the lowest, if the ball has only one color, and there are no other balls with a higher point that contain this color, you can put it in this field (and thus remove this field and this ball from the rest of the combination).
I'm just curious if there is some kind of dynamic algorithm for this type of problem, or if it's just a traveling salesman problem in disguise. Would it help me if I knew that there are no more than X colors? Any help is appreciated. Thanks!
Edit is 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:
Optimal solution:
optimization algorithm dynamic-programming traveling-salesman
Kenny
source share