flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > nesting algorithms.

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4364
Location: Now
edfed 05 Jan 2026, 01:04
hi; happy new year.

then, about nesting algorithms, i wonder how it can be made using ... fasm.

then, i wonder, how it can be made using.. computers, and the best...
how it can be made.

because i need a lot this algorithm (i make furnitures for food) i am at the point where i want to make it my own way.

i need to cut boards to make panels, and in theses boards, i should optimse a lot of things.
there are a lot of solutions to make it. but as always, not any is convenient for me.
they all lack something. and i have a strong feeling about the powerness of this algorithm.


if you think about it in 1D, it is just about managing tasks on a timeline.

what is the prioritary task? the more power consuming. then, the bigger board should be cut first. or at least, it should be positionned first.

and so on.

as long as you add tasks (or boards, or packages, etc..) onto the shelves, you see that the biggests should be made first.

it is the basics of task management.
the harder should be made first.

then, i come to the code itself.
it is not really code because code is not so important. it is about the algorithms.

Code:
nesting:
.shapes:
80,60
80,60
80,60
240,15
180,15
75,20
75,20
75,20
38,10
38,10
38,10
38,10
38,10
38,10
180,40
180,40
178,40
60,40
38,40
38,40
.boards:
250,125
250,125

.cuts:

1       250×125 x=60
2       250×60  y=80 80×60
3       170×60  y=80 80×60
4       90×60   y=80 80×60 remain 10×60
5       250×65  x=15 
6       250×15  y=240 240×15 remain 10×15
7       250×50  x=15 
8       250×15  y=180 180×15 remain 70×15
9       250×35  x=20 
10      250×20  y=75 75×20
11      175×20  y=75 75×20
12      100×20  y=75 75×20 remain 25×20
13      250×15  x=10 remain 250×5
14      250×10  y=38 38×10
15      212×10  y=38 38×10
16      174×10  y=38 38×10
17      136×10  y=38 38×10
18      98×10   y=38 38×10
19      60×10   y=38 38×10 remain 22×10

1       250×125 y=180
2       180×125 x=40 180×40
3       180×85  x=40 180×40
4       180×45  x=40 remain 180×5
5       180×40  y=178 178×40 remain 2×40
6       70×125  x=40 
7       70×40   y=60 60×40 remain 10×40
8       70×85   y=38 remain 32×85
9       38×85   x=40 38×40
10      38×45   x=40 38×40 remain 38×5



input:
.shapes
.boards

output:
.cuts

shape:
.name
.xl
.yl

board:
.name
.xl
.yl

cut:
.shape
.board
.x
.y

render:
.frame
.name
.x
.y
.xl
.yl
.color


;for 1 dimension
area:
;xl,yl
;return area of piece or board
makebucket:
;extract list of pointers to datas for bucket sort
bucketsort:
;sort a list of numbers using buckets, this list is used to point to datas
split:
;cut piece from board
;return position and remaining boards
fit:
;take a sorted list of numbers and fit them in one number
;return a string of fitted numbers, and a string of non fitted numbers

;for 2 dimensions
shapeSort:
;optional sort by shapes, Horizontal, Vertical or Square
ratioSort:
;optional sort by ratio between H and V dimensions
areaSort:
;sort by area


    


in this code, i will try to make the best fit of the panels inside boards. but before, i'll make a 1D nesting to fit execution times and files on hard disks, i'll also try to make a generic algo to optimise 1D parameters on a line.
then, try to make it 2D, 3D, and 4D.

in the 4D i think it is about storage in hubs, where you have spaces on shelves for a time, and the next day, all changes. if you manage it correctlly, you can optimise the flux of goods everywhere.

happy new year.
Post 05 Jan 2026, 01:04
View user's profile Send private message Visit poster's website Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 99
bzt 12 Feb 2026, 20:53
I'm not sure what you're asking, but what you describe doesn't sound like a nesting algorithm, rather a rectangle packing algorithm. So my answer might be off.

Quote:
in this code, i will try to make the best fit of the panels inside boards.
If I get this right, you have N panels (specified as width x height) and you want to place 'em on M boards (capacity also specified by width x height) wasting as few space as possible. This is a well known problem in IT. Rectangle packing sounds simple at first, but you'll fall pretty soon pretty deep into the NP-hard rabbit hole. There's no good solution to this problem, just compromises and trade-offs.

I personally think you should look up "rectangle packing" algorithms, maybe search for "binpacking", and to be specific take a look at the Skyline algorithm in particular. This latter isn't the best, but fast and relatively simple so that you can easily implement in Assembly.

Quote:
i'll also try to make a generic algo to optimise 1D parameters on a line.
Forget it. No generalized solution exists for packing, you are forced to make compromises, especially if you care about execution times and storage sizes.
Quote:
then, try to make it 2D, 3D, and 4D.
Forget it. No generalized solution exists that you can expand to arbitrary dimensions, especially not when you care about execution time. Each dimension adds exponential complexity, therefore you must use a specialized solution for a given dimension (well known solutions for 1D is first fit, best fit, worse fit; for 2D Steinberg's, O-trees, Skyline, etc.) But again, neither of these are general solutions, there's always a trade-off that you must consider.
Post 12 Feb 2026, 20:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.