Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Algorithm Building and Rebuilding Pallets

I need an algorithm to build or rebuild pallets.  It's pretty straight forward.  200 boxes per pallet, all boxes the same size.  So, all I have to worry about is building as few pallets as possible.

An example:
Product #1, 100
Product #2, 73
Product #3, 48
etc.

They don't want products put on different pallets, so the 48 can't be split into 27 on one pallet and 21 on another.   I was going to just sort by qty and keep adding until I can't add anything else to the pallet (in this case, pallet #1 would have 173 and #2 would have 48).  This is an easy algorithm, but that won't build the most efficient pallets.

Any ideas?  

Thanks!
0
gebigler
Asked:
gebigler
  • 2
1 Solution
 
gpizzutoCommented:
This is a so-called "knapsack problem 0-1".
What you described is a Greedy Algorhitm:
Take ever the maximum box available that fits the remaining space on the pallet.
This algorhitm is not the best, but is best "locally" (in each step takes the best choice)

If you want the best solution you have to use Dynamic Programming (DP) .

have a look at:
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Dynamic/knapsackdyn.htm
0
 
petr_hlucinCommented:
This problem is NP-hard which (explained in a simple way) means that we don't know about polynomial algorithm which solves this problem. If you needed the most optimal solution the algorithm would be probably O(m^n) where m is pallettes count and n is boxes set count.

However an approximative solution would be like this:
sort sets of goods according to the size
while sets of goods are remaining do
  while largest set fits onto the current pallette
    put the largest set on the current pallette
  end while
  while smallest set fits onto the current pallette
    put the largest set from the remaining sets on the current pallette
  end while
  ship pallette
end while

For the test data the algorithm would work like this:
- put 100
- put 48
- ship pallette with 148
- put 73
- whip pallette with 73
0
 
gebiglerAuthor Commented:
This will meet the need.  Thanks!
0
 
gpizzutoCommented:
As you said,
This is an easy algorithm, but that won't build the most efficient pallets.

This because Greedy algorithm is optimal ONLY locally... and IS NOT the best solution !!!
Best wishes.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now