This page details the algorithm behind the legacy cutlist calculator for those wishing to integrate it into a project of their own.

I do, at some point, intend to build reusable components that are actually designed for this.

Terminology

Throughout this document I will use the following terms:

Piece
A desired unit of output, specified in step 4 as "components"
Stock
A unit of input, specified in step 1 as "available stock"

Details

Inputs

The algorithm, unfortunately, parses all of its inputs from HTML rather than storing numeric values and using them later. This is bad design and done in haste. It reads the pieces to be calculated on lines 291-309 and the available stock on line 312.

Input validation is very basic. Line 314 checks that at least one length of stock was marked as available. Line 325 ensures that the longest piece fits into at least one length of stock.

Algorithm

Lines 335-375 are the main loop of the algorithm.

Each iteration starts by creating a new instance of the longest stock (lines 338-342) and placing as many pieces into it as will fit (lines 345-360).

The stock is then reduced to the smallest stock that all of the selected pieces still fit into (lines 363-367).

This is all repeated until no pieces remain.

Output

The results of the algorithm are then presented in lines 378-411.

Notes

This algorithm makes some assumptions that don't always hold up. It assumes that longer stock lengths are more desirable (they are often more cost effective but this is not universally true).

It also only presents one possible cutlist for the given set of stock and pieces. It is optimized in a way but it will not always be the most optimized, particularly if the above assumption does not hold true.

The interface is fragile and so is the algorithm. It was hacked together on a weekend to facilitate a project I was working on and I never properly cleaned and hardened it.

Ownership

While I haven't released this under any sort of open source license and legally retain ownership of my work, I have no intention of defending any of this against any reasonable reuse, commercial or otherwise. I plan to release it under some form of the creative commons license eventually, but in the interim you can feel free to adapt it however you want. I enjoy the emails I get from people who have modified it to some other purpose but you don't even have to do that. The code is all there on the page for you to have and I'm happy it's doing so much good for so many people.

If you want explicit legal permission to make derivative work based on my code or something else along those lines, you can email me at jonathan@overholt.org and I'll oblige.

This page last updated: Thu Jun 6 04:50:07 2024 (GMT)