Skip to content

Commit

Permalink
Implement benders decomposition algorithm for rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Jan 25, 2025
1 parent b23c49c commit 3f6673c
Show file tree
Hide file tree
Showing 24 changed files with 720 additions and 11 deletions.
2 changes: 2 additions & 0 deletions data/rectangle/tests/knapsack_benders_all_fit_bins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID,WIDTH,HEIGHT
0,20,10
6 changes: 6 additions & 0 deletions data/rectangle/tests/knapsack_benders_all_fit_items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ID,WIDTH,HEIGHT,ORIENTED,COPIES
0,12,6,1,1
1,8,3,1,1
2,16,4,1,1
3,4,7,1,1
4,4,3,1,1
2 changes: 2 additions & 0 deletions data/rectangle/tests/knapsack_benders_all_fit_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,knapsack
7 changes: 7 additions & 0 deletions data/rectangle/tests/knapsack_benders_all_fit_solution.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPE,ID,COPIES,BIN,X,Y,LX,LY
BIN,0,1,0,0,0,20,10
ITEM,0,1,0,0,0,12,6
ITEM,2,1,0,0,6,16,4
ITEM,1,1,0,12,0,8,3
ITEM,4,1,0,12,3,4,3
ITEM,3,1,0,16,3,4,7
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID,WIDTH,HEIGHT
1,20,10
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID,WIDTH,HEIGHT,ORIENTED,COPIES,PROFIT
0,10,5,1,4,50
1,11,6,1,1,190
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,knapsack
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TYPE,ID,COPIES,BIN,X,Y,LX,LY
BIN,0,1,0,0,0,20,10
ITEM,0,1,0,0,0,10,5
ITEM,0,1,0,0,5,10,5
ITEM,0,1,0,10,0,10,5
ITEM,0,1,0,10,5,10,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID,WIDTH,HEIGHT
1,24,18
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID,WIDTH,HEIGHT,ORIENTED,COPIES,PROFIT
0,8,6,1,9,50
1,9,7,1,1,199
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
objective,knapsack
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TYPE,ID,COPIES,BIN,X,Y,LX,LY
BIN,0,1,0,0,0,24,18
ITEM,0,1,0,0,0,8,6
ITEM,0,1,0,0,6,8,6
ITEM,0,1,0,0,12,8,6
ITEM,0,1,0,8,0,8,6
ITEM,0,1,0,8,6,8,6
ITEM,0,1,0,8,12,8,6
ITEM,0,1,0,16,0,8,6
ITEM,0,1,0,16,6,8,6
ITEM,0,1,0,16,12,8,6
8 changes: 8 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ FetchContent_Declare(
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(mathoptsolverscmake)

# Fetch Highs.
set(BUILD_SHARED_LIBS OFF)
FetchContent_Declare(
highs
URL https://github.com/ERGO-Code/HiGHS/archive/refs/tags/v1.7.2.zip
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(highs)

# Fetch boost.
set(BOOST_INCLUDE_LIBRARIES thread filesystem system program_options dynamic_bitset)
set(BOOST_ENABLE_CMAKE ON)
Expand Down
3 changes: 3 additions & 0 deletions include/packingsolver/rectangle/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct Rectangle

/** Get the legnth of the largest side of the rectangle. */
Length max() const { return std::max(x, y); }

/** Get the legnth of the largest side of the rectangle. */
Length min() const { return std::min(x, y); }
};

bool rect_intersection(Point c1, Rectangle r1, Point c2, Rectangle r2);
Expand Down
12 changes: 12 additions & 0 deletions include/packingsolver/rectangle/optimize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct OptimizeParameters: packingsolver::Parameters<Instance, Solution>
/** Use column generation algorithm. */
bool use_column_generation = false;

/** Use Benders decomposition algorithm. */
bool use_benders_decomposition = false;

/** Guides used in the tree search algorithm. */
std::vector<GuideId> tree_search_guides;

Expand All @@ -63,6 +66,12 @@ struct OptimizeParameters: packingsolver::Parameters<Instance, Solution>
*/
NodeId column_generation_subproblem_queue_size = 128;

/**
* Size of the queue for the pricing knapsack subproblem of the Benders
* decomposition algorithm.
*/
NodeId benders_decomposition_subproblem_queue_size = 128;

/*
* Parameters for non-anytime mode
*/
Expand All @@ -79,6 +88,9 @@ struct OptimizeParameters: packingsolver::Parameters<Instance, Solution>
/** Number of iterations of the sequential value correction algorithm. */
Counter not_anytime_sequential_value_correction_number_of_iterations = 32;

/** Number of iterations of the Benders decomposition algorithm. */
Counter not_anytime_benders_decomposition_number_of_iterations = 32;

/**
* Size of the queue in the bin packing subproblem of the dichotomic search
* algorithm.
Expand Down
4 changes: 3 additions & 1 deletion src/rectangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ target_sources(PackingSolver_rectangle PRIVATE
instance_flipper.cpp
algorithm_formatter.cpp
optimize.cpp
branching_scheme.cpp)
branching_scheme.cpp
benders_decomposition.cpp)
target_include_directories(PackingSolver_rectangle PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_include_directories(PackingSolver_rectangle PRIVATE
${PROJECT_SOURCE_DIR}/src)
target_link_libraries(PackingSolver_rectangle PUBLIC
PackingSolver_algorithms
TreeSearchSolver::treesearchsolver
highs
Threads::Threads)
add_library(PackingSolver::rectangle ALIAS PackingSolver_rectangle)

Expand Down
Loading

0 comments on commit 3f6673c

Please sign in to comment.