in reply to determine numbers of boxes needed per weight

There are a number of things you probably need to factor into your solution like:

It is hard to provide much help beyond "it's a knapsack problem" without a bit more detail about the constraints, and impossible to provide anything approaching an optimim solution.

On the other hand, with a little more information, this sort of problem is the sort of thing that monks like to find solutions for and your particular variant doesn't sound particuarly intractable.


DWIM is Perl's answer to Gödel
  • Comment on Re: determine numbers of boxes needed per weight

Replies are listed 'Best First'.
Re^2: determine numbers of boxes needed per weight
by Perl Mouse (Chaplain) on Nov 24, 2005 at 09:23 UTC
    But it's not a knapsack problem. It would be a knapsack problem if he has a set of fixed weights, and a set of fixed size boxes. But he doesn't - he can divide the weights anyway he wants to. He wants to minimize the number of different size boxes, with a limit on the size of an individual box. BrowserUK's solution will do. If you throw in an additional constraint on the minimum size of a box, there will be situations where you need two different size boxes.
    Perl --((8:>*

      Fair enough. However without knowing the box weight (and possibly size) constraints imposed by USPS and the nature of the items being packed, it was not at all clear that OP's problem wasn't a knapsack problem. Especially if there were other criteria such as weights and/or box sizes that were better economy than others.


      DWIM is Perl's answer to Gödel
Re^2: determine numbers of boxes needed per weight
by Anonymous Monk on Nov 24, 2005 at 06:35 UTC
    Hi. Here is some more information.

    For the sweet spot, I am not sure. But I would like to keep things between 50 and 70 pounds to make best use of the boxes.

    I don't want to go less than 50 lbs per box.

    The problem with different sizes boxes is I'd have to send a bot to the USPS site for each box. If they are all the same, I only need to parse their site once.

    This is for small products (candles, incense, soaps, etc) so no one item will take up a box, if that's what you mean.

    95% is definitely good enough.

    I really appreciate the help!

      Using the distribute function above, the minimum box weight would be 37.5 lbs, except where the total weight is less than that figure; and you will only ever need to look up one price as they will always be the same.

      If you need to limit your weight to greater than 50 lbs, then you will inevitably have to do 2 lookups more often than not.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      But you must go to a 10 lbs box for small orders surely? Or is there a minimum charge that equates to say, a 20 lbs box? For your 80 lbs shipment, why not two 40 lbs boxes?


      DWIM is Perl's answer to Gödel
        The boxes will be put together the best we can. If one is a few pounds heavier than the other, we wouldn't charge them again for shipping. If it's fairly accurate, that's more than suitable.

        As for smaller boxes, if the order is small enough we'll use small boxes. If it's over 70 pounds, we'll always use the medium boxes. We just want around 50lbs or higher if it's way over 70 lbs or half of the weight in each box for say 80lbs.

        Thanks again for all your help!