Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found