My apologies if this is a duplicate. I lack the Computer Science knowledge to know what to properly search for.
I need to find a matching algorithm. I’ve got a series of rooms, and a series of contents-for-rooms. The contents have a minimum size room in which they would fit – so some would happily fit in any room, some would only fit in one or two rooms. I’ll also be having a maximum size for some of the rooms, but I assume that this only effects when I determine if the room would be suitable.
Assuming (though – this won’t be guaranteed in my actual use) that there is a potential solution, how do I find the optimal allocation, such that each room is only used once and none of the contents are lacking a room?
You problem appears to be a maximum bipartite matching problem. You could think of your problem as an undirected graph
G(V,E)where the verticesVare the rooms and contents and the edgesEare possible connections between rooms and contents:contents(i)androom(j)if the room is big enough to hold the contents.A maximum matching produces the maximum number of pairings between vertices in the two sets (i.e. rooms and contents), ensuring that each vertex is only used once. The matching is said to be “perfect” if all vertices are matched. There are a number of algorithms that can be used for such problems, potentially the fastest is the Hopcroft-Karp method.
You could also consider a further optimisation of your problem, in which you try to minimse the total wasted space in the rooms. In this case a “weight” would be associated to the edges defined above based on the difference between the areas of the contents and the rooms.
You would then seek a maximum weight maximum matching.