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.

@rooms = ( { roomid => 1, name => "Double", maxocc => 2, maxadults => +2, maxchildren => 0, maxinfants => 0, propertyid => 1 }, { roomid => 2, name => "Triple", maxocc => 3, maxadults => 3, maxchild +ren => 3, maxinfants => 2, propertyid => 1 }, { roomid => 3, name => "Quad", maxocc => 4, maxadults => 4, maxchildre +n => 2, maxinfants => 2, propertyid => 1 } );

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.


In reply to Assign guests to hotel rooms by richard5mith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.