{"id":465,"date":"2026-04-06T19:42:58","date_gmt":"2026-04-06T19:42:58","guid":{"rendered":"https:\/\/permutationcity.co.uk\/bp\/?p=465"},"modified":"2026-04-07T08:40:25","modified_gmt":"2026-04-07T08:40:25","slug":"bin-packing-problem","status":"publish","type":"post","link":"https:\/\/permutationcity.co.uk\/bp\/2026\/04\/06\/bin-packing-problem\/","title":{"rendered":"Bin-packing problem"},"content":{"rendered":"\n<p>I&#8217;ve been woodworking for a while.\nBig things, cabinets and a kitchen table, and small things, jewellery boxes and drawers.\nI was given a wooden jigsaw puzzle at Christmas and\nthis led to my latest interest.\nA laser cutter is amazingly precise.\nThe beam is 0.1 mm wide and the parts can be whatever shape you can design.\nHowever everything has to be cut out of flat sheets and then assembled from there.\nIt feels like a different direction from taking a 2&#215;4 timber and a table saw.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"shape-placement\">Shape placement<\/h2>\n\n\n\n<p>Once you have your individual shapes you have to fit them on to, say, plywood sheets. To avoid waste you want to fit as many as possible on each sheet. Obviously this can be done by hand. It doesn&#8217;t take that long with 10-20 shapes. However if there&#8217;s lots then it&#8217;s easier to just let the software do it.<\/p>\n\n\n\n<p>I&#8217;ve been using\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Onshape\">Onshape<\/a>\nfor my designs.\nIt&#8217;s got a laser cutter plug-in to do this placement.\nIt&#8217;s quick but not optimal.\nFortunately there are other options.\nI&#8217;ve settled on\n<a href=\"https:\/\/www.deepnest.net\/en\/\">deepnest-next<\/a>.\nIt comes up with a basic solution and then iterates looking for better solutions.<\/p>\n\n\n\n<p>This is a computationally hard problem. The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bin_packing_problem\">bin packing problem<\/a> is part of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/NP-completeness\">NP-complete<\/a> family. You probably won&#8217;t be finding a perfect solution to any of these. Sometimes you need to quickly recognise that perfection is impossible and look for something that is good enough.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"apothecary-cabinet\">Apothecary cabinet<\/h2>\n\n\n\n<p>My latest design are for things like this,\na prototype for an\n<a href=\"https:\/\/www.smithersofstamford.com\/blog\/how-a-17th-century-doctors-cabinet-became-a-design-icon\/\">apothecary cabinet<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"507\" height=\"494\" src=\"https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/apothecary-cabinet.png\" alt=\"\" class=\"wp-image-462\" srcset=\"https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/apothecary-cabinet.png 507w, https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/apothecary-cabinet-300x292.png 300w\" sizes=\"auto, (max-width: 507px) 100vw, 507px\" \/><\/figure>\n\n\n\n<p>After iterating for a while this is what deepnest came up with this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"379\" height=\"347\" src=\"https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/deepnest-v1.svg\" alt=\"\" class=\"wp-image-482\" style=\"width:1000px\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>I&#8217;m struck by how messy it looks.\nThat doesn&#8217;t matter to the laser but is less convenient when I&#8217;m taking the parts out later.\nThe software is optimising for two things: space used and time to cut.\nThe first is obvious but the second less so.\nIf two parts can share an edge then the laser only has to make one cut.\nIt does look as though switching some parts around would increase sharing.\nWhat&#8217;s going on?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"details-matter\">Details matter<\/h2>\n\n\n\n<p>The laser cut is small, 0.1 mm.\nWhile that&#8217;s small it&#8217;s not nothing.\nYou have to account for this in your shapes.\nI&#8217;ve been relying on a <em>kerf offset<\/em> that automatically adjusts the beam by that amount as it cuts the shape.\nI told deepnest to leave at least this much room between the parts.\nIt could be that with gaps between all the shapes it can&#8217;t optimise them to share lines?<\/p>\n\n\n\n<p>Another option is to offset the shapes by 0.1 mm before you start.\nThis adds a manual step but gives deepnest the <em>real<\/em> shape to work with.\nLet&#8217;s see if it can do any better:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"357\" height=\"370\" src=\"https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/deepnest-v2.svg\" alt=\"\" class=\"wp-image-483\" style=\"width:1000px\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The big pieces are in the same places. The small pieces are scattered differently. No, no it can&#8217;t do better.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"manual-layout\">Manual layout<\/h2>\n\n\n\n<p>Here&#8217;s my own attempt:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"290\" height=\"296\" src=\"https:\/\/permutationcity.co.uk\/bp\/wp-content\/uploads\/2026\/04\/manual.svg\" alt=\"\" class=\"wp-image-478\" style=\"width:1000px\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This is what I mean by better. The laser cutting software predicts this will be faster to cut out, 24 minutes compared to 27 for the deepnest versions. By placing similar pieces next to each other I get them to share more of their lines. Not only that but the layout just <em>looks<\/em> better. Each type of shapes is grouped together. It&#8217;s going to be easier to sort the parts out. Plus there&#8217;s some left over plywood that I can reuse later. I know the deepnest software uses a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Genetic_algorithm\">genetic algorithm<\/a>. That means it has a method of evaluating cut patterns to assign them a score. In theory it could be extended to value putting like with like.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"in-the-end\">In the end<\/h2>\n\n\n\n<p>I want the software to do things it&#8217;s not been written to do.\nIt only cares about space and time,\nnot about making things neat.\nHowever in this <em>small<\/em> case I was able to do better with both myself.\nFor bigger cases I think the software would start winning.\nI can lay out a single sheet but\nif there a dozen sheets then I&#8217;m going to get tired and the software isn&#8217;t.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been woodworking for a while. Big things, cabinets and a kitchen table, and small things, jewellery boxes and drawers. I was given a wooden jigsaw puzzle at Christmas and this led to my latest interest. A laser cutter is amazingly precise. The beam is 0.1 mm wide and the parts can be whatever shape [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[22],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-general","tag-algorithms"],"_links":{"self":[{"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":9,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":486,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/posts\/465\/revisions\/486"}],"wp:attachment":[{"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/permutationcity.co.uk\/bp\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}