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 data/irregular/users/2026-11-08_many_item_types_1000.json

Large diffs are not rendered by default.

77,724 changes: 77,724 additions & 0 deletions data/irregular/users/2026-11-08_many_item_types_1000_solution.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/irregular/users/2026-11-08_many_item_types_2000.json

Large diffs are not rendered by default.

155,910 changes: 155,910 additions & 0 deletions data/irregular/users/2026-11-08_many_item_types_2000_solution.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/internals/algorithm_selection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ With a single bin, the problem is a single :code:`knapsack`, :code:`feasibility`
* :code:`rectangleguillotine`: depending on the number of stages, the cut type and the features used, the :ref:`tree search <internals_rectangleguillotine_tree_search>`, the :ref:`column generation strips <internals_rectangleguillotine_column_generation_strips>`, the :ref:`tree search with maximal spaces <internals_rectangleguillotine_tree_search_maximal_spaces>`, or the :ref:`tree search hypergraph with infinite copies <internals_rectangleguillotine_tree_search_hypergraph_infinite_copies>` when the item types have many copies; in the :code:`exact` mode, also the :ref:`tree search hypergraph <internals_rectangleguillotine_tree_search_hypergraph>` for the :code:`knapsack` and :code:`feasibility` objectives when it supports the instance;
* :code:`box`: the tree search; for the :code:`knapsack` and :code:`feasibility` objectives, only in the directions in which few items fit in a section of the bin (at most 8 on average), or the :ref:`tree search with maximal spaces <internals_box_tree_search_maximal_spaces>` if there is no such direction;
* :code:`boxstacks`: the :ref:`sequential one-dimensional / rectangle <internals_boxstacks_sequential_onedimensional_rectangle>` algorithm;
* :code:`irregular`: the tree search, or the :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` when the instance is dominated by item types with many copies (together with the tree search if fewer than 64 items fit in the bin), and the :ref:`local search <internals_irregular_local_search>` for the objectives it supports; in the :code:`exact` mode, the :ref:`Benders decomposition <internals_irregular_benders_decomposition>` for the :code:`knapsack` objective, and the :ref:`tree search on relative positions <internals_irregular_tree_search_relative_positions>` for the :code:`feasibility` objective, together with the :ref:`global nonlinear programming <internals_irregular_global_nonlinear_programming>` algorithm if an item type has continuous rotations and PackingSolver is built with SCIP.
* :code:`irregular`: the tree search, or the :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` when the instance is dominated by item types with many copies (together with the tree search if fewer than 64 items fit in the bin); for the :code:`knapsack` and :code:`feasibility` objectives, the :ref:`tree search with maximal spaces <internals_irregular_tree_search_maximal_spaces>` instead of the tree search when many items fit in a section of the bin in both directions (more than 4 on average); and the :ref:`local search <internals_irregular_local_search>` for the objectives it supports; in the :code:`exact` mode, the :ref:`Benders decomposition <internals_irregular_benders_decomposition>` for the :code:`knapsack` objective, and the :ref:`tree search on relative positions <internals_irregular_tree_search_relative_positions>` for the :code:`feasibility` objective, together with the :ref:`global nonlinear programming <internals_irregular_global_nonlinear_programming>` algorithm if an item type has continuous rotations and PackingSolver is built with SCIP.

Several bins
------------
Expand Down
2 changes: 1 addition & 1 deletion doc/internals/irregular/tree_search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The items are packed along a front, each against the items already packed. This
Automatic selection
-------------------

With a single bin, the tree search is run unless the instance is dominated by item types with many copies, in which case the :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` is run instead (and the tree search too if few items fit in the bin). With several bins, it is run when the item types have few copies compared to the number of items fitting in a bin, alongside the generic algorithms using it to solve their sub-problems. See :ref:`algorithm selection <internals_algorithm_selection>`.
With a single bin, the tree search is run unless the instance is dominated by item types with many copies, in which case the :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` is run instead (and the tree search too if few items fit in the bin). For the :code:`knapsack` and :code:`feasibility` objectives, the :ref:`tree search with maximal spaces <internals_irregular_tree_search_maximal_spaces>` is run instead when many items fit in a section of the bin in both directions. With several bins, it is run when the item types have few copies compared to the number of items fitting in a bin, alongside the generic algorithms using it to solve their sub-problems. See :ref:`algorithm selection <internals_algorithm_selection>`.

It can be forced with :code:`--use-tree-search 1` (CLI) or :code:`use_tree_search` (Python).

Expand Down
6 changes: 4 additions & 2 deletions doc/internals/irregular/tree_search_maximal_spaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The insertions of a node are computed as follows.

**2. Candidate blocks.** The candidate blocks are the valid blocks which may fit in the selected empty space.

**3. Candidate supporting parts.** The candidate supporting parts are the ones which touch the bottom side of the empty space: they overlap it horizontally, and their lowest point is at or below it while their highest point is at or above it. They are searched among the supporting parts of the bin and of the blocks already packed (only for the blocks whose bounding box crosses the bottom side of the empty space). The bottom side of an empty space is usually the top of a rectangle covering an item, which is also the top of the item, so the supporting part of the item at the top of this rectangle touches it.
**3. Candidate supporting parts.** The candidate supporting parts are the ones which touch the bottom side of the empty space: they overlap it horizontally, and their lowest point is at or below it while their highest point is at or above it. They are searched among the supporting parts of the bin and of the blocks already packed (only for the blocks for which the bounding box of their supporting parts crosses the bottom side of the empty space; the supporting parts are computed on the inflated shapes, so with an item-item spacing, this bounding box goes above the bounding box of the items). The bottom side of an empty space is usually the top of a rectangle covering an item, which is also the top of the item inflated by the item-item spacing, so the supporting part of the item at the top of this rectangle touches it.

**4. Obstacles.** For each candidate supporting part, the trapezoids which a block resting on it may overlap are selected among the trapezoids of the node: the ones whose right is to the right of the left side of the empty space minus the width of the widest candidate block, and which overlap vertically the supporting part extended, above and below, by the height of the highest candidate block. The other trapezoids can't be reached by the slides below.

Expand Down Expand Up @@ -190,7 +190,9 @@ Limitations
Automatic selection
-------------------

The algorithm is never selected automatically. It can be forced with :code:`--use-tree-search-maximal-spaces 1` (CLI) or :code:`use_tree_search_maximal_spaces` (Python).
With a single bin and the :code:`knapsack` or :code:`feasibility` objective, the algorithm is run instead of the :ref:`tree search <internals_irregular_tree_search>` when many items fit in a section of the bin in both directions: the height (resp. width) of the bin divided by the mean height (resp. width) of the bounding boxes of the items is larger than :code:`many_items_in_section_threshold` (4 by default). The number of insertions of a node of the tree search may then be large, and its search may stay shallow. The instances dominated by item types with many copies are not concerned when the :ref:`tree search with periodic packings <internals_irregular_tree_search_periodic_packing>` is run alone. This also applies to the knapsack sub-problems of the algorithms for several bins. See :ref:`algorithm selection <internals_algorithm_selection>`.

It can be forced with :code:`--use-tree-search-maximal-spaces 1` (CLI) or :code:`use_tree_search_maximal_spaces` (Python).

Source files
------------
Expand Down
10 changes: 10 additions & 0 deletions include/packingsolver/irregular/optimize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ struct OptimizeParameters: packingsolver::Parameters<Instance, Solution, Output>
/** Threshold to consider that a bin contains "many" items. */
Counter many_items_in_bins_threshold = 16;

/**
* Threshold to consider that a bin x (resp. y) section - a full-height
* (resp. full-width) strip as wide (resp. as tall) as the mean item -
* contains "many" items, i.e. bin height (resp. width) / mean item
* height (resp. width). With a single bin, when both sections contain
* many items, the tree search maximal spaces algorithm is run instead of
* the tree search for the 'Knapsack' and 'Feasibility' objectives.
*/
Counter many_items_in_section_threshold = 4;

/** Factor to consider that the number of copies of items is "high". */
Counter many_item_type_copies_factor = 1;

Expand Down
1 change: 1 addition & 0 deletions python/src/irregular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ void bind_irregular(nb::module_& m)
.def_rw("maximum_approximation_ratio_factor", &OptimizeParameters::maximum_approximation_ratio_factor)
.def_rw("minimum_maximum_approximation_ratio", &OptimizeParameters::minimum_maximum_approximation_ratio)
.def_rw("many_items_in_bins_threshold", &OptimizeParameters::many_items_in_bins_threshold)
.def_rw("many_items_in_section_threshold", &OptimizeParameters::many_items_in_section_threshold)
.def_rw("many_item_type_copies_factor", &OptimizeParameters::many_item_type_copies_factor)
.def_rw("periodic_packing_copies_threshold", &OptimizeParameters::periodic_packing_copies_threshold)
.def_rw("periodic_packing_max_items_threshold", &OptimizeParameters::periodic_packing_max_items_threshold)
Expand Down
57 changes: 57 additions & 0 deletions src/irregular/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,44 @@ ItemPos max_number_of_items_in_bin(const Instance& instance)
return number_of_items;
}

/**
* Compute the mean number of items in an x (resp. y) section of the (single)
* bin of the instance: a full-height (resp. full-width) strip as wide (resp.
* as tall) as the mean item, that is, the height (resp. width) of the bin
* divided by the mean height (resp. width) of the bounding boxes of the
* items. Only the copies which are not fixed are counted.
*/
void compute_mean_numbers_of_items_in_sections(
const Instance& instance,
double& mean_number_of_items_in_x_section,
double& mean_number_of_items_in_y_section)
{
double total_item_width = 0.0;
double total_item_height = 0.0;
ItemPos number_of_items = 0;
for (ItemTypeId item_type_id = 0;
item_type_id < instance.number_of_item_types();
++item_type_id) {
const ItemType& item_type = instance.item_type(item_type_id);
ItemPos copies = item_type.copies - item_type.copies_fixed;
if (copies <= 0)
continue;
AxisAlignedBoundingBox aabb = item_type.compute_min_max();
total_item_width += copies * (aabb.x_max - aabb.x_min);
total_item_height += copies * (aabb.y_max - aabb.y_min);
number_of_items += copies;
}
mean_number_of_items_in_x_section = 0.0;
mean_number_of_items_in_y_section = 0.0;
if (number_of_items == 0)
return;
const AxisAlignedBoundingBox& bin_aabb = instance.bin_type(0).aabb_orig;
mean_number_of_items_in_x_section = (bin_aabb.y_max - bin_aabb.y_min)
/ (total_item_height / number_of_items);
mean_number_of_items_in_y_section = (bin_aabb.x_max - bin_aabb.x_min)
/ (total_item_width / number_of_items);
}

/**
* Prove the instance infeasible if an item type doesn't fit in any bin type:
* with every objective but 'Knapsack', every item must be packed. The
Expand Down Expand Up @@ -1264,6 +1302,25 @@ packingsolver::irregular::Output packingsolver::irregular::optimize(
= !periodic_packing_runnable
|| max_number_of_items_in_bin(instance)
< parameters.periodic_packing_max_items_threshold;
// When many items fit in both an x section and a y section of
// the bin, the number of insertions of a node of
// 'tree_search' may be large, and its search may then stay
// shallow: run 'tree_search_maximal_spaces' instead.
if (use_tree_search
&& (instance.objective() == Objective::Knapsack
|| instance.objective() == Objective::Feasibility)) {
double mean_number_of_items_in_x_section = 0;
double mean_number_of_items_in_y_section = 0;
compute_mean_numbers_of_items_in_sections(
instance,
mean_number_of_items_in_x_section,
mean_number_of_items_in_y_section);
if (mean_number_of_items_in_x_section > parameters.many_items_in_section_threshold
&& mean_number_of_items_in_y_section > parameters.many_items_in_section_threshold) {
use_tree_search = false;
use_tree_search_maximal_spaces = true;
}
}
if (instance.objective() != Objective::Knapsack)
use_local_search_direct_trigonometry = true;
// In 'Exact' mode, also run the algorithms which can prove
Expand Down
8 changes: 3 additions & 5 deletions src/irregular/tree_search_maximal_spaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ BranchingSchemeMaximalSpaces::Block BranchingSchemeMaximalSpaces::build_block(
if (covered(item_pos, support.aabb, true))
continue;
block_trapezoid_set.supporting_parts.push_back(block.supporting_parts.size());
block.supporting_parts_aabb = shape::merge(block.supporting_parts_aabb, support.aabb);
block.supporting_parts.push_back(support);
}
}
Expand Down Expand Up @@ -545,11 +546,8 @@ void BranchingSchemeMaximalSpaces::select_empty_space(
}
for (const Node::PlacedBlock& placed_block: node.placed_blocks) {
const Block& block = blocks_[placed_block.block_id];
AxisAlignedBoundingBox block_aabb;
block_aabb.x_min = placed_block.x + block.trapezoid_set.x_min;
block_aabb.x_max = placed_block.x + block.trapezoid_set.x_max;
block_aabb.y_min = placed_block.y + block.trapezoid_set.y_min;
block_aabb.y_max = placed_block.y + block.trapezoid_set.y_max;
AxisAlignedBoundingBox block_aabb = block.supporting_parts_aabb;
block_aabb.shift(placed_block.x, placed_block.y);
if (!touches_bottom(block_aabb))
continue;
for (const Support& support: block.supporting_parts) {
Expand Down
6 changes: 6 additions & 0 deletions src/irregular/tree_search_maximal_spaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class BranchingSchemeMaximalSpaces
*/
std::vector<Support> supporting_parts;

/**
* Bounding box of the supporting parts, which are computed on the
* inflated shapes of the items, relative to the block.
*/
AxisAlignedBoundingBox supporting_parts_aabb;

/**
* Supported parts with which the block rests on a supporting part,
* relative to the block.
Expand Down
7 changes: 7 additions & 0 deletions test/irregular/tree_search_maximal_spaces_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@ INSTANTIATE_TEST_SUITE_P(
// worse than packing item types 0 and 2 (150).
fs::path("data") / "irregular" / "tests" / "knapsack_penalized_resource.json",
fs::path("data") / "irregular" / "tests" / "knapsack_penalized_resource_solution.json"
}, {
// With the item-item spacing, the empty spaces above the items
// start above the bounding boxes of their non-inflated shapes,
// at the top of their inflated shapes, where their supporting
// parts are: the second row of items rests on them.
fs::path("data") / "irregular" / "tests" / "knapsack_item_item_minimum_spacing.json",
fs::path("data") / "irregular" / "tests" / "knapsack_item_item_minimum_spacing_solution.json"
}}));
Loading