June 20, 2008...1:04 am

Cutting glass with knapsacks

Jump to Comments

Suppose you are a thief and you stealthily enter a house carrying only a backpack. The residents astonishingly only have five objects in the house (as shown below). How do you maximize your profits so that everything you take fits in your backpack? If you can answer this question, then you have solved the knapsack problem. Like many problems, the knapsack problem is easy enough to state but tough to solve. For sufficiently large scenarios, no optimum solution can be found.

I have written some code in MATLAB that can find optimal solutions for the rectangular knapsack problem where you have to maximise the area used when fitting smaller rectangles into the larger tile. For example, in the diagram below, how do you fit the 2×3 and 3×4 rectangles into the 5×5 tile such that you use the most area in the 5×5 tile? Rectangular knapsack needs to be solved very often in many industries including the glass cutting industry where you want to complete your orders but don’t want to waste glass (in other words, maximise area used).

I used straightforward dynamic programming in the solution which means that I try to find the optimal solutions of the subproblems and then, combine the subproblems to find the optimal solution of the main problem. So, using the set of given rectangles, I optimise area used in 1×1 tile and then using those results, I optimise a 1×2 tile and so on, until I find the optimal solution for the 5×5 tile. Using such a method, we can solve pretty large problem instances in a reasonable amount of time.

Based on a lot of research, there are many interesting ways in which we can make the code even faster. One of the optimizations that I am using is discretization points [1] which preserves the optimality of the solution. These points are the only points where you can cut the tile and so, obviously, you need to only consider these points. With respect to the earlier example, we actually don’t need to consider the 1×1 tile sub-problem because it is never possible to have any rectangles in such a small tile. So, using this optimisation, we only need to consider a tiles with dimensions like 2×3 or 2×4.

Besides the rectangular knapsack (found in rk.m), I also consider the same problem allowing for rotation and allowing for staged cutting. All the code can be found here and the instructions to use the functions can be found in readme.rtf.

[1] Based on ideas in Algorithms for two-dimensional cutting stock and strip packing problems using dynamic programming and column generation by G.F. Cintra, F.K. Miyazawa, Y. Wakabayashi, E.C. Xavier

7 Comments

  • Anwar Mohammadi

    Hello

    I am trying to implement the RK algorithm in the article you have referenced to it in C#. But I can not get good solutions from it. I appreciate you if you can help me about that. If you want I can send the source code to you.

    Thanks

    • I don’t do C# anymore so I’m not sure how much I can help you with the debugging itself. But feel free to email me at abimanyuraja@gmail.com

      • Anwar Mohammadi

        Thank you for your reply.
        I have implemented the algorithm and I found my mistakes by tracing your Matlab program. I have tried to implement other algorithms (like SimplexCG) in the paper but I found some problems again. Have you implemented other algorithms in Matlab? If yes can you send me the source codes?
        Best regards.

  • @Anwar Glad you got it working! Yes, we did in fact implement SimplexCG in Matlab. But it was almost a year ago and I have changed hard disks since. I’ll try to find it.

  • Anwar Mohammadi

    Thank you for your time and attention
    My email is: anwar_mohammadi@yahoo.com
    If you found the program, I will appreciate you if you send it to me.

  • Roberto Guerzoni

    Hello
    I have lauched your implement the RK,RKR,SDP algorithms but can’t figure out how use the results.
    I got a series of 0,1, … while aspected the coordinates x,y of the cut and the direction, length.
    Can you explain me please where I’m wrong?
    Thank you
    Roberto Guerzoni

  • Wow, I didn’t heard about this topic until now. Cheers.


Leave a Reply