|XP is just a number|
Assign guests to hotel roomsby richard5mith (Beadle)
|on Sep 15, 2005 at 12:12 UTC||Need Help??|
richard5mith has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to write code that assigns guests to hotel rooms. I have a certain number of adults, children and infants and an array containing a hashref of room types.
Each room type can take a maximum number of people, a max adults, a max children and a max infants. It also has a room id, a property id and a name.
This means that while a room can hold 4 people, it may only be allowed to hold 2 adults, or 2 children. Infants must be in a room with an adult, and realistically, children should be put in with adults as well when possible.
Somehow I need to work out the optimal combinations that the guests can fit into these rooms. While there are many combinations that will obviously work, I need to be able to decide on what are considered the "best" ones, which is really the ones that use the least number of rooms. All of these will then have to pass other tests (like is that combination of rooms actually available), so it doesn't have to pin it down to just one.
Each room can also be used more than once, meaning that if there are 6 adults, a valid combination is 3 double rooms that take 2 adults each, which is obviously better than 2 adults in the Double, 2 in the Triple and 2 in the Quad.
I've been going round and round in circles trying to write this, but really don't come close. Standard bin packing algorithms that I've written so far work great for bins of a set size, with no repeats, but not for bins that have more than one criteria and may be used again.
Any pointers in the right direction will be met with gracious approval.