-
-
Save squarethecircle/4648e9fa57ea423c100087d553b5d4c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bp (…) { | |
if all items have been placed in bins | |
return the total number of bins used | |
for each bin that we can place the next item in | |
place the item in that bin | |
call bp() recursively to find the minimum number of bins used to store all of the items given that the items already stored cannot be moved | |
remove the item from the bin | |
return the minimum number of bins needed | |
} | |
To reduce the amount of backtracking required to find the optimal solution, the following heuristics are used: | |
a. Presort the sizes in decreasing order. | |
b. Compute a lower bound on the number of bins by adding the sizes together, | |
dividing by the capacity, and rounding up to the nearest integer; and | |
quit when an assignment requiring that number of bins is found. | |
c. Keep track of the smallest number of bins found previously (initially | |
this is just the number of items) and do not consider any (partial) | |
assignment that would require at least that many bins. | |
d. When the current item has the same size as an item stored in the partial | |
assignment, never place it in a bin to the left of the bin in which that | |
item was stored. | |
e. Never place an item in a bin that has the same amount of room remaining | |
as one that was tried previously for this item. | |
f. When looping over bins in which to place an item, try them in decreasing | |
order of capacity *remaining*. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment