Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/internals/irregular.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ See :doc:`the detailed description <irregular/tree_search_periodic_packing>`.
:hidden:

irregular/tree_search_periodic_packing
irregular/blocks

Tree search with maximal spaces
----------------------------------
Expand Down
51 changes: 51 additions & 0 deletions doc/internals/irregular/blocks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. _internals_irregular_blocks:

Blocks
======

A *block* is a set of items with fixed relative positions. The :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` and the :ref:`tree search with maximal spaces <internals_irregular_tree_search_maximal_spaces>` pack a block at each stage. A block is described by its items, its numbers of copies of each item type, and its dimensions: the dimensions of the bounding box of its items, plus the item-item minimum spacing, so that two blocks placed side by side respect the spacing.

Kinds of blocks
---------------

The blocks are built for the bin of the instance, from the :ref:`periodic packings <internals_irregular_tree_search_periodic_packing>` of the item types:

* the tilings of :math:`n_x \times n_y` unit cells of a periodic packing, as long as they fit in the bin and don't use more copies than available;
* the *clipped lattice* blocks: the bin is filled with the lattice of a periodic packing, for several positions of the lattice, and a block is made of the items whose top and right are below given thresholds. Unlike the tilings, these blocks may contain partial unit cells, which is often denser along the sides of the bin;
* the grid blocks: the items of an item type aligned on a grid of their bounding boxes, in each of its orientations;
* the framed blocks (see below).

Framed blocks
-------------

A *frame item* is an item type in an orientation whose bounding box has a large empty rectangle touching one of its sides, at least half of the bounding box, like an L-shape or a U-shape. Without the framed blocks, such items are poorly packed: the space in their empty rectangle is only used by chance.

A block is framed by one frame item in an orientation :math:`r`, by two in the orientations :math:`r` and :math:`r + 180°`, or by four in the orientations :math:`r`, :math:`r + 90°`, :math:`r + 180°` and :math:`r + 270°`. The frame items are placed one after the other, with the block in their empty rectangle, and moved away from the block and from the previous frame items until they don't overlap them; the position giving the smallest bounding box is kept. The frame items are placed using only their bounding box, their empty rectangle and the bounding box of the block, so the framed blocks are valid without computing any no-fit polygon.

The *saving* of a framed block is the space taken by the block and by the frame items packed separately, minus the space taken by the framed block. The space taken by the frame items packed separately is their area divided by the best density of the blocks of their item type alone. A framed block is only kept if its saving is non-negative. The framed blocks are framed again once.

The number of framed blocks of each frame item type is limited. For a framed block, the maximum number of copies of the block, given the numbers of copies of its item types, times the number of copies of the frame item type in the block, is the number of copies of the frame item type that this block can use. The sum of this number over the framed blocks of a frame item type, at both depths, doesn't exceed 4 times the number of copies of the frame item type. Without this limit, an instance with many item types with a single copy has a framed block for almost every pair of an item and of an L-shape.

The framed blocks kept are the ones with the largest savings. To avoid framing all the blocks, the saving is first bounded: the framed block is at least as large, in each dimension, as the block and as each of its frame items, so its saving is at most the space taken by the block and by the frame items packed separately, minus the area of this smallest possible bounding box. For each frame item type, the blocks are framed by decreasing bound, until the bound is smaller than the saving of the framed blocks which already reach the limit.

Dominance
---------

A block dominates another one if it contains the same item types, at least as many copies of each, and takes no more space in both dimensions. Dominated blocks are discarded as they are generated, except the blocks of a single item, which are always kept: they may be the only way to pack the last copy of an item type.

Resources
---------

The resource consumption of a block is the consumption of each resource of the bin by its items alone in the bin, the consumption of the copies of an item type starting at the first entry of its consumption schedule. The blocks which exceed the capacity of a resource which is not *penalize* are discarded. The consumption of a node of the tree searches is the sum of the consumptions of its blocks: it is exact for the uniform consumption schedules, and overestimates the consumption for a non-increasing schedule when the copies of an item type are in several blocks.

Use by the algorithms
---------------------

* The :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` uses all the blocks, described by their bounding boxes.
* The :ref:`tree search with maximal spaces <internals_irregular_tree_search_maximal_spaces>` uses a block for each item type in each of its orientations, with a single item, and the blocks of more than one item built from the periodic packings: the tilings and the clipped lattice blocks. The grid blocks and the framed blocks are not kept: the tree search with maximal spaces packs the items on their actual shapes, and the items of these blocks are placed using their bounding boxes only.

Source files
------------

* :code:`src/irregular/periodic_packing.hpp`, :code:`src/irregular/periodic_packing.cpp`: the periodic packings
* :code:`src/irregular/tree_search_periodic_packing.hpp`, :code:`src/irregular/tree_search_periodic_packing.cpp`: the blocks (:code:`compute_periodic_blocks`)
2 changes: 1 addition & 1 deletion doc/internals/irregular/tree_search_maximal_spaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The bin is also decomposed into trapezoids: a strip below the bin, a strip above
**Blocks.** A block is a set of items with fixed relative positions. The blocks are:

* one block for each item type in each of its orientations, with a single item;
* the blocks of the :ref:`periodic packings <internals_irregular_tree_search_periodic_packing>` of the instance, that is, only for the item types with many copies. The blocks of a single item, and the ones aligning the bounding boxes of the items on a grid, are not kept: packing these items one by one does at least as well on their actual shapes. If a periodic block uses an orientation which is not among the orientations of its item type, the trapezoid set of this orientation is built.
* the :ref:`blocks <internals_irregular_blocks>` of more than one item built from the :ref:`periodic packings <internals_irregular_tree_search_periodic_packing>` of the instance (the tilings and the clipped lattice blocks), that is, only for the item types with many copies. The grid blocks and the framed blocks are not kept: their items are placed using their bounding boxes only, and packing these items one by one does at least as well on their actual shapes. If a periodic block uses an orientation which is not among the orientations of its item type, the trapezoid set of this orientation is built.

The trapezoids of a block are the trapezoids of its items, shifted by their positions in the block. A block is described by:

Expand Down
15 changes: 4 additions & 11 deletions doc/internals/irregular/tree_search_periodic_packing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A periodic packing is a lattice packing: a *unit cell* of one or two items, repe
For each item type and each of its orientations, the following unit cells are considered:

* a single item;
* two items: the item in orientation :math:`r` and the item in orientation :math:`r + 180°`, when it is allowed. The candidate positions of the second item are the vertices of the no-fit polygon of the two items, where the second item touches the first one without overlapping it.
* two items: the item in orientation :math:`r` and the item in orientation :math:`r + 180°`, when it is allowed. The candidate positions of the second item are the vertices of the no-fit polygon of the two items, where the second item touches the first one without overlapping it, and its feasible elements and points (see below).

Given a unit cell, the region forbidden to the translations of the cell is the union of the no-fit polygons of its items with each other. The lattice vectors are then computed in two ways:

Expand All @@ -32,6 +32,8 @@ Given a unit cell, the region forbidden to the translations of the cell is the u

A rectangular lattice, where :math:`v_2` is perpendicular to :math:`v_1`, is also considered in each case. Each candidate lattice is checked on the actual shapes.

A no-fit polygon may contain translations of null area where the items don't overlap, for example when an item fits exactly the width of a slot of the other item: it can slide along a line segment in the slot, while all the translations around this segment make the items overlap. The union of the no-fit polygons can't represent them, so the shape library returns them separately, as the *feasible elements and points* of the no-fit polygon. They are candidate translations too, unless they are strictly inside another no-fit polygon of the forbidden region. With an item-item minimum spacing, the no-fit polygons are inflated by the spacing, and there is no such translation: the items would touch.

Periodic packings mixing item types are also built, for the items shaped like an L or a U: such a *wrapper* item has a large empty rectangle touching a side of its bounding box. A *base*, a single item of another item type or the unit cell of one of its periodic packings, is put in this empty rectangle, and a second copy of the wrapper, rotated by 180°, is put on the other side of the base.

The figure below shows a periodic packing of each kind, as computed by the solver: the unit cell is darker, and the arrows are the vectors of the lattice. The horizontal lattice of the hexagons is also rectangular; their vertical lattice is denser. Two triangles in rotations 0° and 180° form a square, and two L-shapes in rotations 0° and 180° wrapped around a rectangle tile the plane exactly:
Expand All @@ -44,16 +46,7 @@ The periodic packings only depend on the item types, so they are computed once,
Blocks
------

The blocks are built from the periodic packings, for the bin of the instance:

* the tilings of :math:`n_x \times n_y` unit cells, as long as they fit in the bin and don't use more copies than available;
* the *clipped lattice* blocks: the bin is filled with the lattice, for several positions of the lattice, and a block is made of the items whose top and right are below given thresholds. Unlike the tilings, these blocks may contain partial unit cells, which is often denser along the sides of the bin;
* the grid blocks: the items aligned on a grid of their bounding boxes, for the orientations without periodic packing;
* the *framed* blocks: a block surrounded by one, two or four copies of a wrapper item, in rotations :math:`r`, :math:`r + 180°`, and :math:`r + 90°` and :math:`r + 270°`. A framed block is only kept if it takes no more space than the block and the frame items packed separately. Framed blocks can be framed again once.

A block dominates another one if it contains the same item types, at least as many copies of each, and takes no more space in both dimensions. Dominated blocks are discarded as they are generated, except the blocks of a single item, which are always kept: they may be the only way to pack the last copy of an item type.

The resource consumption of a block is the consumption of each resource of the bin by its items alone in the bin, the consumption of the copies of an item type starting at the first entry of its consumption schedule. The blocks which exceed the capacity of a resource which is not *penalize* are discarded. The consumption of a node is the sum of the consumptions of its blocks: it is exact for the uniform consumption schedules, and overestimates the consumption for a non-increasing schedule when the copies of an item type are in several blocks.
The blocks are built from the periodic packings, for the bin of the instance: tilings of unit cells, clipped lattices, grids of bounding boxes, and blocks framed by L-shaped or U-shaped items. Their generation, their dominance and their resource consumption are described in :ref:`blocks <internals_irregular_blocks>`. This algorithm uses all of them, described by their bounding boxes.

Branching scheme
----------------
Expand Down
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(SHAPE_BUILD_TEST OFF)
FetchContent_Declare(
shape
GIT_REPOSITORY https://github.com/fontanf/shape.git
GIT_TAG 8e13e55a854260d4ef83a703d32da208d5f81c5e
GIT_TAG 841836162e377c46c7d65d216ec8e6e4bbe58e5a
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../shape/"
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(shape)
Expand Down
Loading
Loading