This is a continuation of the post about offline packaging algorithms.



Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: level = 0; h (level + 1) = 0; H = 0; i = 0
2: while there is an unpacked rectangle do
3: i ++
4: if there is a level
5: pack rectangle left justified
6: if h (level + 1) <h (Li) then
7: h (level + 1) = h (Li)
8: end if
9: else [there is insufficient space on current level]
10: open the rectangle
11: H + = h (level + 1); level ++
12: end if
13: end while
14: print H and entire packing Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: level = 0; h (level + 1) = h (L1); H = h (L1); i = 1
2: while there is an unpacked rectangle do
3: i ++; level = 0
4: search for space level
5: if such a level exists then
6: pack rectangle left justified
7: if this is the level and h (level) <h (li) then
8: h (level) = h (Li)
9: end if
10: else [there is insufficient space in all existing levels]
11: create a new level above the top-most level
12: pack rectangle left justified
13: h (level) = h (Li); H + = h (Li)
14: end if
15: end while
16: print H and entire packing Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: level = 0; h (level + 1) = h (L1); H = h (L1); i = 0
2: while there is an unpacked rectangle do
3: i ++; level = 0
4: Search for the lowest level with minimum residual horizontal space
5: if such a level exists then
6: pack rectangle left justified
7: else [such a level does not exist]
8: create a new level above the top-most level
9: pack rectangle left justified
10: h (level) = h (Li); H + = h (Li)
11: end if
12: end while
13: print H and entire packing 
Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: level = 1; h (level) = 0; H = 0; i = 1
2: open a new bi-level
3: call 'pack on lower level'
4: print H and entire packing
Procedure 'pack on lower level'
1: the first rectangle packed is left justified
2: subsequent rectangles that fit are right justified
3: if there is insufficient space then
4: h (level) tallest rectangle packed
5: call 'pack on upper level'
6: end if
Procedure 'pack on the upper level'
1: if Li + 1 is the first rectangle packed then
2: left justify on top of Li
3: else
4: if Li + 2 is the first rectangle packed then
5: pack above min {h (Li); h (Li + 1)}
6: justify according to min {h (Li); h (Li + 1)}
7: else
8: if Li + j (j> 3) fits on the upper level then
9: left justify all other rectangles
10: else [rectangle does not fit]
11: H + = h (lower) + h (upper); open new bi-level
12: end if
13: end if
14: end if 


Input: The dimensions of the rectangles {w (Li); h (Li)}
w and strip width
Output: The height H and the packing.
1: shelf = 1; w (shelf) = 0;
h (shelf) = r ^ k for some integer k; i = 0; H = h (shelf)
2: while there is an unpacked rectangle do
3: i ++; compute k
4: if there is sufficient space and r ^ (k + 1) <h (Li) ≤ r ^ k then
5: Rectangle Packed Rectangle
6: else [there is insufficient space]
7: create one new shelf
Li and the pack.
8: shelf ++; H + = r ^ k
9: end if
10: end while
11: print H and entire packing. Input: The dimensions of the rectangles {w (Li); h (Li)}
w and strip width
Output: The height H and the packing.
1: shelf = 1; h (shelf) = r ^ k for some integer k;
i = 0; H = h (shelf); shelfnum = 1
2: while there is an unpacked rectangle do
3: i ++; compute k
4: search for low height
5: if such a shelf exists then
6: Pack Rectangle Pack
7: else [there is insufficient space in all shelves of
appropriate height or such a shelf does not exist]
8: create a new shelf above the top-most shelf
Li and the pack.
9: shelf ++; H + = r ^ k; shelfnum ++
10: end if
11: end while
12: print H and entire packing. Input: The dimensions of the rectangles {w (Li); h (Li)}
w and strip width
Output: The height H and the packing.
1: shelf = 1; h (shelf) = r ^ k for some integer k;
i = 0; H = h (shelf); shelfnum = 1
2: while there is an unpacked rectangle do
3: i ++; compute k
4: search all shelves (starting with the bottom) for one
with appropriate height and has minimum horizontal space.
5: if such a shelf exists then
6: Pack Rectangle Pack
7: else [there is insufficient space or
there is no shelf of appropriate height]
8: create a new shelf above the top-most shelf
Li on the new shelf.
9: shelf ++; H + = r ^ k; shelfnum ++
10: end if
11: end while
12: print H and entire packing. 
; 
Input: The dimensions of the rectangles {w (Li); h (Li)}
the parameters M and the strip width W.
Output: The height H and the packing.
1: shelf = 1; h (shelf) = r ^ k for some integer k; i = 0
2: while there is an unpacked rectangle do
3: i ++; compute k such that r ^ (k + 1) <h (Li) ≤ r ^ k
4: compute the value of p such that 1 / (p + 1) <w (Li) ≤ 1 / p
where 1 ≤ p <M
5: amongst shelves of height r ^ k find the one
with packing rectangles
6: if there is a r ^ k then rectangle of height
7:
8: shelf ++
9: end if
10: if rectangle
11: h (shelf) = r ^ k; H + = h (shelf)
12: end if
13: end while
14: print H and entire packing 
Input: The dimensions of the rectangles {w (Li); h (Li)}
the parameter Y and the strip width W.
Output: The height H and the packing.
1: h (level) = 0; w (level) = 0; level = 0
2: while there is an unpacked rectangle do
3: if w (Li) ≥ Y then
4: level ++; w (level) = w (Li); h (level) = h (Li); H + = h (level)
5: else [w (Li) <Y]
6: compute x and j such that
2 ^ (j-1) <h (Li) ≤ 2 ^ j and 2 ^ (- x-1) <w (Li) ≤ 2 ^ (- x)
7: search for the lowest (x, j) level
8: if no (x, j) level is available or Li is blocked then
9: level ++; h (level) = 2 ^ j; H + = h (level)
10: w (level) + = w (Li)
11: else [(x, j) level is available and not blocked]
12: w (level) + = w (Li)
13: end if
14: end if
15: end while
16: print H and entire packing 


Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: i = 0; H = 0
2: open new bi-level
3: packing on lower level is similar to BiNFL; H + = h (lowerlevel)
4: if there is a gap
5: call 'pack on the upper level'
6: end if
7: print H and entire packing
Procedure 'pack on the upper level'
1: while there is an unpacked rectangle do
2: if i ≥ 3 and Li is the first rectangle packed then
3: justify according to the shorter
of the rectangles
4: slide rectangle downwards if there is a sufficient space
and go to 12
5: else
6: if i ≥ 3 and Li is the second rectangle packed then
7: right justify and go to 12
8: else [rectangle does not fit]
9: H + = h (upperlevel); open new bi-level
10: end if
11: end if
12: end while Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: i = 0; H = 0
2: open a new bi-level
3: packing on lower level is similar to BiNFL; H + = h (lowerlevel)
4: if there is a gap
5: call 'pack on the upper level'
6: end if
7: print H and entire packing
Procedure 'pack on the upper level'
1: while there is an unpacked rectangle do
2: if h (Li)> VerticalSpace and w (Li) ≤ HorizontalSpace then
3: shift rectangle Li downwards; go to 11
4: else
5: if h (Li) ≤ VerticalSpace and W - w (level) ≥ w (Li) then
6: left justify; go to 11
7: else [rectangle does not fit]
8: H + = h (upperlevel); open a new bi-level
9: end if
10: end if
11: end while Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: i = 0; H = 0
2: open a new bi-level
3: packing on lower level is similar to BiNFL; H + = h (lowerlevel)
4: if there is a gap
5: call 'pack on the upper level'
6: end if
7: print H and entire packing
Procedure 'pack on the upper level'
1: while there is an unpacked rectangle do
2: if h (Li) ≤ VerticalSpace and w (Li) ≤ HorizontalSpace then
3: slide rectangle Li downwards; go to 11
4: else
5: if h (Li) ≤ VerticalSpace and W - w (level) ≥ w (Li) then
6: left justify; go to 11
7: else [rectangle does not fit]
8: H + = h (upperlevel); open new bi-level
9: end if
10: end if
11: end while Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: i = 0; H = 0
2: open a new bi-level
3: packing on lower level is similar to BiNFL; H + = h (lowerlevel)
4: if there is a gap
5: call 'pack on the upper level'
6: end if
7: print H and entire packing
Procedure 'pack on the upper level'
1: while there is an unpacked rectangle do
2: if w (Li) ≤ HorizontalSpace then
3: slide rectangle Li downwards; go to 11
4: else
5: if w (Li)> HorizontalSpace and W - w (level) ≥ w (Li) then
6: left justify, go to 11
7: else [rectangle does not fit]
8: H + = h (upperlevel); open new bi-level
9: end if
10: end if
11: end while 



Also, several areas can be created in one step at a time — the space below the rectangle is analyzed vertically and divided by the number of “steps”. On the middle photo, once again shows the division of the empty area into two after packing a rectangle there (by the way, it seems to me that in this place it would be better to split it horizontally ).
If none of the empty areas match, the packaging continues with the Burke method. I remember. A height map for the strip is constructed, and the rectangle is tried on the lowest area at the moment. If he does not enter there, the low place is “filled” to the level of the nearest step, and the search is repeated. So a potential place can be pushed to the very top, and then there is another option for the formation of empty space (see right). Input: The dimensions of the rectangles {w (Li); h (Li)} and the strip width W.
Output: The height H and the packing.
1: i = 0; H = 0
2: Create a linear array number of elements are equal to W
3: while there is an unpacked rectangle do
4: i ++
5: Li
6: if w (EmptyArea) ≥ w (Li) and h (EmptyArea) ≥ h (Li) then
7: pack rectangle in empty area
8: else
9: If the area is empty
10: Search for linear array for packing width
11: else [there is a space in linear array]
12: pack rectangle on top left justified
from the index leading to smaller space
13: end if
14: end if
15: end while
16: H = highest entry in the linear array
17: print H and entire packing | NFL | Ffl | Bfl | BiNFL | Nfs | Ffs | Bfs | HS | Azar y | CPF | CFF | CC | Of |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0.56 | 0.63 | 0.75 | 0.56 | 0.45 | 0.57 | 0.57 | 0.37 | 0.44 | 0.60 | 0.59 | 0.63 | 0.72 |
Source: https://habr.com/ru/post/160869/
All Articles