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
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/bins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,5,0,inf
3 changes: 3 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
10,10,10,1000,2,2,0,1
5,5,5,125,3,3,0,1
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,bin-packing
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/reduced_bins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,3,0,inf
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/reduced_items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
5,5,5,125,3,3,0,1
7 changes: 7 additions & 0 deletions data/box/tests/bin_packing_full_bin_items/solution.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION
BIN,0,2,0,0,0,0,10,10,10,
ITEM,0,1,0,0,0,0,10,10,10,XYZ
BIN,0,1,1,0,0,0,10,10,10,
ITEM,1,1,1,0,0,0,5,5,5,XYZ
ITEM,1,1,1,5,0,0,5,5,5,XYZ
ITEM,1,1,1,0,5,0,5,5,5,XYZ
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,5,0,100
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
10,10,10,1000,2,2,1,1
5,5,5,125,3,3,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,bin-packing
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,5,0,100
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
10,10,10,1000,2,2,1,1
5,5,5,125,3,3,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION
BIN,0,2,0,0,0,0,10,10,10,
ITEM,0,1,0,0,0,0,10,10,10,XYZ
BIN,0,1,1,0,0,0,10,10,10,
ITEM,1,1,1,0,0,0,5,5,5,XYZ
ITEM,1,1,1,5,0,0,5,5,5,XYZ
ITEM,1,1,1,0,5,0,5,5,5,XYZ
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/bins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,5,0,inf
4 changes: 4 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
6,10,10,600,2,2,0,1
4,10,10,400,2,2,0,1
3,3,3,27,2,2,0,1
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,bin-packing
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/reduced_bins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT
10,10,10,1000,3,0,inf
2 changes: 2 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/reduced_items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ
3,3,3,27,2,2,0,1
7 changes: 7 additions & 0 deletions data/box/tests/bin_packing_perfect_pairs/solution.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION
BIN,0,2,0,0,0,0,10,10,10,
ITEM,0,1,0,0,0,0,6,10,10,XYZ
ITEM,1,1,0,6,0,0,4,10,10,XYZ
BIN,0,1,1,0,0,0,10,10,10,
ITEM,2,1,1,0,0,0,3,3,3,XYZ
ITEM,2,1,1,3,0,0,3,3,3,XYZ
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
10,10,100,1,2
5,5,25,1,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NAME,VALUE
objective,bin-packing
number_of_stages,3
cut_type,non-exact
first_stage_orientation,vertical
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
5,5,25,1,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT
0,2,0,0,0,10,10,0,0,
0,2,1,0,0,10,10,0,1,0
1,1,2,0,0,10,10,0,0,
1,1,3,0,0,5,10,-2,1,2
1,1,4,0,0,5,5,1,2,3
1,1,5,0,5,5,5,1,2,3
1,1,6,5,0,5,10,-2,1,2
1,1,7,5,0,5,5,1,2,6
1,1,8,5,5,5,5,-1,2,6
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
6,10,60,1,2
4,10,40,1,2
3,3,9,1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NAME,VALUE
objective,bin-packing
number_of_stages,3
cut_type,non-exact
first_stage_orientation,vertical
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
3,3,9,1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT
0,2,0,0,0,10,10,0,0,
0,2,1,0,0,6,10,0,1,0
0,2,2,6,0,4,10,1,1,0
1,1,3,0,0,10,10,0,0,
1,1,4,0,0,3,10,-2,1,3
1,1,5,0,0,3,3,2,2,4
1,1,6,0,3,3,3,2,2,4
1,1,7,0,6,3,4,-1,2,4
1,1,8,3,0,7,10,-3,1,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
6,10,60,1,2
3,10,30,1,2
3,3,9,1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NAME,VALUE
objective,bin-packing
number_of_stages,3
cut_type,non-exact
first_stage_orientation,vertical
cut_thickness,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,COPIES
10,10,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES
3,3,9,1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT
0,2,0,0,0,10,10,0,0,
0,2,1,0,0,6,10,0,1,0
0,2,2,7,0,3,10,1,1,0
1,1,3,0,0,10,10,0,0,
1,1,4,0,0,3,10,-2,1,3
1,1,5,0,0,3,3,2,2,4
1,1,6,0,4,3,3,2,2,4
1,1,7,0,8,3,2,-1,2,4
1,1,8,4,0,6,10,-3,1,3
126 changes: 126 additions & 0 deletions include/packingsolver/box/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ struct ReductionParameters: optimizationtools::Parameters
* flag.
*/
bool remove_dominated_bin_types = true;

/**
* Enable/disable reserving a dedicated bin for each copy of an item
* type filling the bin (gates 'Reduction::reduce_full_bin_items').
* Still subject to 'Reduction::full_bin_reduction_applies' regardless
* of this flag.
*/
bool reduce_full_bin_items = true;

/**
* Enable/disable reserving a dedicated bin for pairs of item types
* filling the bin together (gates 'Reduction::reduce_perfect_pairs').
* Still subject to 'Reduction::full_bin_reduction_applies' regardless
* of this flag.
*/
bool reduce_perfect_pairs = true;
};

/**
Expand Down Expand Up @@ -174,6 +190,37 @@ struct ReductionParameters: optimizationtools::Parameters
* the reduced instance back to the original ones. See
* 'remove_dominated_bin_types_applies()'.
*
* - Reserving dedicated bins (see 'reduce_full_bin_items' and
* 'reduce_perfect_pairs'): rectangle's and onedimensional's own
* operations. Compared against the bin shrunk along each axis to the
* largest total length of the items not exceeding it (see
* 'shrunk_bin_length'), using the current (possibly lifted) boxes. An
* item whose box equals the shrunk bin can't share its bin with any
* other item: along each axis, any other item beside it would make a
* total length beyond the shrunk bin. Such an item gets a dedicated bin.
* An allowed rotation of the item giving the shrunk bin is enough: the
* shrunk length along each axis is at least the length of the item along
* it in any rotation fitting the bin, so every such rotation gives the
* same box. Two items spanning the shrunk bin along two axes, whose
* lengths along the third axis sum to the shrunk bin's, also get a
* dedicated bin together: in any solution, the other items of the bin of
* each of them are beside it along the third axis, in two slabs spanning
* the cross-section of the bin, whose total length is at most the length
* of the other item of the pair (shrunk bin); so the items of the two
* bins other than the pair fit in a single bin, next to the bin holding
* the pair. This requires both items to have a single allowed rotation
* (otherwise they could be placed without spanning the two axes). Only
* for 'BinPacking' with a single bin type, without fixed items, and
* without a weight or resource constraint a hidden reservation could
* violate (see 'full_bin_reduction_applies()'). Never reserves more
* dedicated bins than the bin type has copies; if they take every copy
* while items remain, the instance is infeasible (see
* 'proven_infeasible()'). The dedicated items are left out of the
* reduced instance, the bin type has its 'copies' reduced accordingly,
* and 'unreduce_solution' adds the dedicated bins back. Runs in the same
* loop as 'lift_item_dimensions', since lifting can make an item fill
* the shrunk bin, and a reservation can shrink the bin further.
*
* - Merging identical item types (see 'merge_identical_items'): a merged
* item type's copies stay fully visible and independently placed in the
* reduced instance (nothing is hidden from the downstream solve), so this
Expand Down Expand Up @@ -211,6 +258,21 @@ class Reduction
/** Get the reduced instance. */
const Instance& instance() const { return instance_; }

/**
* Number of bins reserved as dedicated bins (see
* 'reduce_full_bin_items'/'reduce_perfect_pairs'), entirely absent from
* 'instance()' - a caller solving 'instance()' needs to add this back
* onto any bin-count bound it finds.
*/
BinPos number_of_dedicated_bins() const;

/**
* 'true' iff the reduction alone proves the original instance
* infeasible: the dedicated bins take every copy of the bin type while
* items remain. 'instance()' is then not meaningful to solve.
*/
bool proven_infeasible() const { return proven_infeasible_; }

/** Unreduce a solution of the reduced instance. */
Solution unreduce_solution(
const Solution& solution) const;
Expand Down Expand Up @@ -258,6 +320,13 @@ class Reduction
*/
static bool remove_dominated_bin_types_applies(const Instance& instance);

/**
* 'true' iff reserving dedicated bins (see 'reduce_full_bin_items' and
* 'reduce_perfect_pairs') is meaningful for 'instance' - see the
* class-level doc comment.
*/
static bool full_bin_reduction_applies(const Instance& instance);

/*
* Private types
*/
Expand Down Expand Up @@ -498,6 +567,63 @@ class Reduction
*/
std::vector<BinTypeId> reduced_to_original_bin_type_id_;

/** A dedicated bin for each copy of an item type filling the bin. */
struct FullBinItem
{
/** Item type id, original instance's id space. */
ItemTypeId item_type_id;

/** Rotation giving the box of the bin. */
Rotation rotation;

/** Number of dedicated bins. */
ItemPos copies;
};

/** Dedicated bins for pairs of item types filling the bin together. */
struct PerfectPair
{
/** Item type ids, original instance's id space. */
ItemTypeId item_type_id_1;
ItemTypeId item_type_id_2;

/** Rotations of the two items. */
Rotation rotation_1;
Rotation rotation_2;

/** Axis along which the two items are side by side. */
int axis;

/** Number of dedicated bins. */
ItemPos copies;
};

/** See 'reduce_full_bin_items'. */
std::vector<FullBinItem> full_bin_items_;

/** See 'reduce_perfect_pairs'. */
std::vector<PerfectPair> perfect_pairs_;

/** See 'proven_infeasible()'. */
bool proven_infeasible_ = false;

/**
* Reserves a dedicated bin for every copy of every item type whose box,
* in one of its allowed rotations, equals the shrunk bin. Returns
* 'true' iff at least one item type was reserved.
*/
bool reduce_full_bin_items(
std::vector<ReductionItemType>& reduction_item_types);

/**
* Reserves a dedicated bin for 'min(copies_1, copies_2)' copies of every
* pair of item types filling the shrunk bin together (including two
* copies of the same item type). Returns 'true' iff at least one pair
* was reserved.
*/
bool reduce_perfect_pairs(
std::vector<ReductionItemType>& reduction_item_types);

/**
* Consumes one copy from the end of 'runs' (a working copy of one
* reduced item type's own entry in 'reduced_item_origin_runs_'),
Expand Down
Loading
Loading