Say we have a list of rooms with their capacities and a list of meetings with the number of attendees. We want to match each meeting with one room in the following way:
- A meeting can only be scheduled in a room with capacity equal to or greater than its attendance.
- If surplus rooms are present, meetings should be scheduled so that the largest possible room is left unscheduled.
- A meeting with a larger attendance should not be scheduled in a smaller room than a meeting with a smaller attendance.
- Obviously we should find out if it is impossible to schedule the given meetings in the given rooms.
Can we arrive at the schedule efficiently? A single pass would be nice, some backtracking is ok, but the only option I can get to work (a rough algorithm plus dynamically shaking out violations of rule 3) is slower than I would like.
This question is not as easy as it looks! The naive linear approaches fail at least one criterion:
We can sort each list from high-to-low and start pairing the largest room to the largest session, we will come up with a solution any time it is possible, but we will have the smallest possible rooms left over rather than the largest. (Consider the case of 10 and 15-person meetings scheduled in 200, 30, and 20-person capacity rooms.)
We can sort the meeting list from high-to-low and then walk down it, trying to find the smallest room that is just large enough to contain this meeting. But sometimes this will result in a larger room being scheduled for a smaller meeting. (Consider scheduling 40 and 30-person meetings in 40 and 80-person rooms.)
But surely there is a better way to solve this relatively simple problem.