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
8 changes: 6 additions & 2 deletions include/packingsolver/boxstacks/instance_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ class InstanceBuilder
Length z,
Profit p = -1,
ItemPos copies = 1,
int rotations = 1,
GroupId group = 0);
int rotations = 1);

/** Set the group of an item type. */
void set_item_type_group(
ItemTypeId item_type_id,
GroupId group_id);

/** Set the weight of an item type. */
void set_item_type_weight(
Expand Down
8 changes: 6 additions & 2 deletions include/packingsolver/rectangle/instance_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ class InstanceBuilder
Length y,
Profit p = -1,
ItemPos copies = 1,
bool oriented = false,
GroupId group = 0);
bool oriented = false);

/** Set the group of an item type. */
void set_item_type_group(
ItemTypeId item_type_id,
GroupId group_id);

/** Set the weight of an item type. */
void set_item_type_weight(
Expand Down
57 changes: 34 additions & 23 deletions src/boxstacks/instance_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ ItemTypeId InstanceBuilder::add_item_type(
Length z,
Profit profit,
ItemPos copies,
int rotations,
GroupId group_id)
int rotations)
{
if (x < 0) {
throw std::invalid_argument(
Expand All @@ -274,25 +273,33 @@ ItemTypeId InstanceBuilder::add_item_type(
"item 'copies' must be > 0; "
"copies: " + std::to_string(copies) + ".");
}
if (group_id < 0) {
throw std::invalid_argument(
FUNC_SIGNATURE + ": "
"item 'group_id' must be >= 0; "
"group_id: " + std::to_string(group_id) + ".");
}

ItemType item_type;
item_type.box.x = x;
item_type.box.y = y;
item_type.box.z = z;
item_type.profit = (profit == -1)? x * y * z: profit;
item_type.copies = copies;
item_type.group_id = group_id;
item_type.group_id = 0;
item_type.rotations = rotations;
instance_.item_types_.push_back(item_type);
return instance_.item_types_.size() - 1;
}

void InstanceBuilder::set_item_type_group(
ItemTypeId item_type_id,
GroupId group_id)
{
if (group_id < 0) {
throw std::invalid_argument(
FUNC_SIGNATURE + ": "
"item 'group_id' must be >= 0; "
"group_id: " + std::to_string(group_id) + ".");
}

instance_.item_types_[item_type_id].group_id = group_id;
}

void InstanceBuilder::set_item_type_weight(
ItemTypeId item_type_id,
Weight weight)
Expand Down Expand Up @@ -373,27 +380,29 @@ void InstanceBuilder::add_item_type(
Profit profit,
ItemPos copies)
{
ItemTypeId item_type_id = add_item_type(
ItemTypeId item_type_id = this->add_item_type(
item_type.box.x,
item_type.box.y,
item_type.box.z,
profit,
copies,
item_type.rotations,
item_type.rotations);
this->set_item_type_group(
item_type_id,
item_type.group_id);
set_item_type_weight(
this->set_item_type_weight(
item_type_id,
item_type.weight);
set_item_type_stackability_id(
this->set_item_type_stackability_id(
item_type_id,
item_type.stackability_id);
set_item_type_nesting_height(
this->set_item_type_nesting_height(
item_type_id,
item_type.nesting_height);
set_item_type_maximum_stackability(
this->set_item_type_maximum_stackability(
item_type_id,
item_type.maximum_stackability);
set_item_type_maximum_weight_above(
this->set_item_type_maximum_weight_above(
item_type_id,
item_type.maximum_weight_above);
}
Expand Down Expand Up @@ -762,27 +771,29 @@ void InstanceBuilder::read_item_types(
if (profit == -1)
profit = x * y * z;

ItemTypeId item_type_id = add_item_type(
ItemTypeId item_type_id = this->add_item_type(
x,
y,
z,
profit,
copies,
rotations,
rotations);
this->set_item_type_group(
item_type_id,
group_id);
set_item_type_stackability_id(
this->set_item_type_stackability_id(
item_type_id,
stackability_id);
set_item_type_weight(
this->set_item_type_weight(
item_type_id,
weight);
set_item_type_nesting_height(
this->set_item_type_nesting_height(
item_type_id,
nesting_height);
set_item_type_maximum_stackability(
this->set_item_type_maximum_stackability(
item_type_id,
maximum_stackability);
set_item_type_maximum_weight_above(
this->set_item_type_maximum_weight_above(
item_type_id,
maximum_weight_above);
}
Expand Down
12 changes: 9 additions & 3 deletions src/boxstacks/sequential_onedimensional_rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,9 @@ const SequentialOneDimensionalRectangleOutput boxstacks::sequential_onedimension
y,
stack.profit,
1, // copies
oriented,
oriented);
rectangle_instance_builder.set_item_type_group(
rectangle_item_type_id,
stackability_group.group_id);
rectangle_instance_builder.set_item_type_weight(
rectangle_item_type_id,
Expand Down Expand Up @@ -758,9 +760,13 @@ const SequentialOneDimensionalRectangleOutput boxstacks::sequential_onedimension
solution_stack.y_end - solution_stack.y_start,
profit,
1, // copies
false, // oriented
false); // oriented
rectangle_instance_builder.set_item_type_group(
rectangle_item_type_id,
item_type.group_id);
rectangle_instance_builder.set_item_type_weight(rectangle_item_type_id, weight);
rectangle_instance_builder.set_item_type_weight(
rectangle_item_type_id,
weight);
rectangle_instance_builder.set_group_weight_constraints(
item_type.group_id,
instance.check_weight_constraints(item_type.group_id));
Expand Down
39 changes: 25 additions & 14 deletions src/rectangle/instance_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ ItemTypeId InstanceBuilder::add_item_type(
Length y,
Profit profit,
ItemPos copies,
bool oriented,
GroupId group_id)
bool oriented)
{
if (x < 0) {
throw std::invalid_argument(
Expand All @@ -263,24 +262,32 @@ ItemTypeId InstanceBuilder::add_item_type(
"item 'copies' must be > 0; "
"copies: " + std::to_string(copies) + ".");
}
if (group_id < 0) {
throw std::invalid_argument(
FUNC_SIGNATURE + ": "
"item 'group_id' must be >= 0; "
"group_id: " + std::to_string(group_id) + ".");
}

ItemType item_type;
item_type.rect.x = x;
item_type.rect.y = y;
item_type.profit = (profit == -1)? x * y: profit;
item_type.copies = copies;
item_type.group_id = group_id;
item_type.group_id = 0;
item_type.oriented = oriented;
instance_.item_types_.push_back(item_type);
return instance_.item_types_.size() - 1;
}

void InstanceBuilder::set_item_type_group(
ItemTypeId item_type_id,
GroupId group_id)
{
if (group_id < 0) {
throw std::invalid_argument(
FUNC_SIGNATURE + ": "
"item 'group_id' must be >= 0; "
"group_id: " + std::to_string(group_id) + ".");
}

instance_.item_types_[item_type_id].group_id = group_id;
}

void InstanceBuilder::set_item_type_weight(
ItemTypeId item_type_id,
Weight weight)
Expand Down Expand Up @@ -316,17 +323,19 @@ void InstanceBuilder::add_item_type(
Profit profit,
ItemPos copies)
{
ItemTypeId item_type_id = add_item_type(
ItemTypeId item_type_id = this->add_item_type(
item_type.rect.x,
item_type.rect.y,
profit,
copies,
item_type.oriented,
item_type.oriented);
this->set_item_type_group(
item_type_id,
item_type.group_id);
set_item_type_weight(
this->set_item_type_weight(
item_type_id,
item_type.weight);
set_item_type_eligibility(
this->set_item_type_eligibility(
item_type_id,
item_type.eligibility_id);
}
Expand Down Expand Up @@ -643,7 +652,9 @@ void InstanceBuilder::read_item_types(
y,
profit,
copies,
oriented,
oriented);
this->set_item_type_group(
item_type_id,
group_id);
this->set_item_type_weight(
item_type_id,
Expand Down
Loading