<p>I am working on a project where I produce an aluminium extrusion cutting list.</p>

<p>The aluminium extrusions come in lengths of 5m.</p>

<p>I have a list of smaller lengths that need to be cut from the 5m lengths of aluminium extrusions.</p>

<p>The smaller lengths need to be cut in the order that produces the least amount of off cut waste from the 5m lengths of aluminium extrusions.</p>

<p>Currently I order the cutting list in such a way that generally the longest of the smaller lengths gets cut first and the shortest of smaller lengths gets cut last. The exception to this rule is whenever a shorter length will not fit in what is left of the 5m length of aluminium extrusion, I use the longest shorter length that will fit.</p>

<p>This seems to produce a very efficient (very little off cut waste) cutting list and doesn't take long to calculate. I imagine, however, that even though the cutting list is <strong>very</strong> efficient, it is not necessarily the <strong>most</strong> efficient.</p>

<p>Does anyone know of a way to calculate the most efficient cutting list which can be calculated in a reasonable amount of time?</p>

<p>EDIT: Thanks for the answers, I'll continue to use the "greedy" approach as it seems to be doing a very good job (out performs any human attempts to create an efficient cutting list) and is very fast.</p>

[{'answer_id': 22167, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 1, 'selected': False, 'text': "<p>That's an interesting problem because I suppose it depends on the quantity of each length you're producing. If they are all the same quantity and you can get Each different length onto one 5m extrusion then you have the optimum soloution.</p>\n\n<p>However if they don't all fit onto one extrusion then you have a greater problem. To keep the same amount of cuts for each length you need to calculate how many lengths (not necessarily in order) can fit on one extrusion and then go in an order through each extrusion.</p>\n"}, {'answer_id': 22170, 'author': 'Wheelie', 'author_id': 1131, 'author_profile': 'https://Stackoverflow.com/users/1131', 'pm_score': 5, 'selected': True, 'text': '<p>This is a classic, difficult problem to solve efficiently. The algorithm you describe sounds like a <a href="http://en.wikipedia.org/wiki/Greedy_algorithm" rel="noreferrer">Greedy Algorithm</a>. Take a look at this Wikipedia article for more information: <a href="http://en.wikipedia.org/wiki/Cutting_stock_problem" rel="noreferrer">The Cutting Stock Problem</a></p>\n'}, {'answer_id': 22182, 'author': 'Chris Roberts', 'author_id': 475, 'author_profile': 'https://Stackoverflow.com/users/475', 'pm_score': 2, 'selected': False, 'text': '<p>No specific ideas on this problem, I\'m afraid - but you could look into a \'<a href="http://en.wikipedia.org/wiki/Genetic_algorithm" rel="nofollow noreferrer">genetic algorithm</a>\' (which would go <em>something</em> like this)...</p>\n\n<p>Place the lengths to cut in a random order and give that order a score based on how good a match it is to your ideal solution (0% waste, presumably).</p>\n\n<p>Then, iteratively make random alterations to the order and re-score it.  If the score is higher, ditch the result.  If the score is lower, keep it and use it as the basis for your next calculation.  Keep going until you get your score within acceptable limits.</p>\n'}, {'answer_id': 23625, 'author': 'Mat Noguchi', 'author_id': 1799, 'author_profile': 'https://Stackoverflow.com/users/1799', 'pm_score': 2, 'selected': False, 'text': '<p>Actually, since the size of material is fixed, but the requests are not, it\'s a bin packing problem.</p>\n\n<p>Again, <a href="http://en.wikipedia.org/wiki/Bin_packing" rel="nofollow noreferrer">wikipedia to the rescue!</a></p>\n\n<p>(Something I might have to look into for work too, so yay!)</p>\n'}, {'answer_id': 39173, 'author': 'Xavier Nodet', 'author_id': 4177, 'author_profile': 'https://Stackoverflow.com/users/4177', 'pm_score': 2, 'selected': False, 'text': '<p>What you described is indeed classified as a <a href="http://en.wikipedia.org/wiki/Cutting_stock_problem" rel="nofollow noreferrer">Cutting Stock</a> problem, as <a href="https://stackoverflow.com/users/1131/wheelie">Wheelie</a> mentioned, and not a <a href="http://en.wikipedia.org/wiki/Bin_packing" rel="nofollow noreferrer">Bin Packing</a> problem because you try to minimize the waste (sum of leftovers) rather than the number of extrusions used.</p>\n\n<p>Both of those problems can be very hard to solve, but the \'best fit\' algorithm you mentioned (using the longest \'small length\' that fits the current extrusion) is likely to give you very good answers with a very low complexity.</p>\n'}, {'answer_id': 1764948, 'author': 'Diego Castro', 'author_id': 193971, 'author_profile': 'https://Stackoverflow.com/users/193971', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve been struggling with this exact ( the lenght for my problem is 6 m) problem here too.</p>\n\n<p>The solution I\'m working on is a bit ugly, but I don\'t settle for your solution. Let me explain: </p>\n\n<p>Stock size <strong>5 m</strong></p>\n\n<p>Needs to cut in sizes(1 of each): </p>\n\n<p>**3,5 </p>\n\n<p>1 </p>\n\n<p>1,5** </p>\n\n<p>Your solution:</p>\n\n<p><strong>3,5 | 1</strong> with a waste of 0,5</p>\n\n<p><strong>1,5</strong> with a left over of 3,5</p>\n\n<p>See the problem?</p>\n\n<p>The solution I\'m working on -> Brute force</p>\n\n<p>1 - Test every possible solution</p>\n\n<p>2 - Order the solutuion by their waste</p>\n\n<p>3 - Choose the best solution</p>\n\n<p>4 - Remove the items in the solution from the "Universe"</p>\n\n<p>5 - Goto 1</p>\n\n<p>I know it\'s time consuming (but I take 1h30 m to lunch... so... :) )</p>\n\n<p>I really need the optimum solution (I do an almoust optimum solution by hand (+-) in excel) not just because I\'m obsecive but also the product isn\'t cheap.</p>\n\n<p>If anyone has an easy better solution I\'d love it</p>\n'}, {'answer_id': 70222667, 'author': 'Scott Weiss', 'author_id': 13348563, 'author_profile': 'https://Stackoverflow.com/users/13348563', 'pm_score': 0, 'selected': False, 'text': '<p>The <a href="https://en.wikipedia.org/wiki/Column_generation" rel="nofollow noreferrer">Column generation algorithm</a> will quickly find a solution with the minimum possible waste.</p>\n<p>To summarize, it works well because it doesn\'t generate all possible combinations of cuts that can fit on a raw material length.  Instead, it iteratively solves for combinations that would improve the overall solution, until it reaches an optimum solution.</p>\n<p>If anyone needs a working version of this, I\'ve implemented it with python and posted it on GitHub: <a href="https://github.com/sweiss93/LengthNestPro/releases/latest" rel="nofollow noreferrer">LengthNestPro</a></p>\n'}]
['https://Stackoverflow.com/questions/22145', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1142/']