Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimization – Rearranging items of a specific type?
    primarykey
    data
    text
    <p>Optimization – Rearranging items of a specific type? Here’s a little optimization problem for a personal project I’m working on: so imagine you have many boxes of an item, and within each box, you know that the items must be shipped to various locations. </p> <p>Example: </p> <blockquote> <p>Box 1: 1000 items, 500 to location A, 500 to location B.</p> <p>Box 2: 1000 items, 500 to location A, 500 to location B. </p> </blockquote> <p>I want to be able to rearrange the items such that I can ship as many full boxes as I can to one destination. For instance, in the example above, I would be able to rearrange the items such that new_box 1 has 1000 items to location A, and 1000 to location B.</p> <p>Now you can imagine that this perfect rearrangement case will not always occur. What if I had:</p> <blockquote> <p>Box 1: 1000 items, 500 to location A, 300 to location B, 200 to location C.</p> <p>Box 2: 1000 items, 500 to location A, 500 to location B.</p> </blockquote> <p>Then, I would want to (a) optimize the number of full boxes to one destination, &amp; (b) minimize the number of <em>different</em> locations in every other box. For instance, having 3 boxes each with 2 different destinations would be better than having 3 boxes each with 3 different destinations. The optimum rearrangement of the second example above would be:</p> <blockquote> <p>New_box_1: 1000 items, 1000 to location A.</p> <p>New_box_2: 1000 items, 800 to location B and 200 to location C.</p> </blockquote> <p>My question is: <strong>How would I handle this situation for arbitrary number of boxes and arbitrary number of destinations per box?</strong> For the sake of the problem, let’s start with assuming that each box has the same number of items.</p> <p>What I’m thinking right now is to take a greedy approach:</p> <ol> <li>Go down the line for each subsequent box and keep a running sum of the destinations and the number of items that will be shipped to it.</li> <li>If any of these sum to a value that is greater than the box capacity, place these items in their own box.</li> <li>Then, take the highest number of items to one destination that is remaining, call this “x”, take the value (box capacity – x), (call this “y”), and find the value of the number of items to one destination that is both ABOVE “y” and the closest to “y”.</li> <li>Then, place “x” items to the first destination and “y items to the second destination in another box, and repeat. </li> </ol> <p>Any other suggestions, or insights? Thanks so much.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload