Skip to content

Commit 1d7a689

Browse files
committed
Move subset_sum and multiple_choice_subset_sum to another repo
1 parent 2b2bead commit 1d7a689

87 files changed

Lines changed: 250 additions & 4049 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/build.yml‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ jobs:
1515
python-version: ["3.8"]
1616

1717
env:
18-
KNAPSACK_DATA: ${{ github.workspace }}/data/knapsack
19-
SUBSET_SUM_DATA: ${{ github.workspace }}/data/subset_sum
20-
MULITPLE_CHOICE_SUBSET_SUM_DATA: ${{ github.workspace }}/data/multiple_choice_subset_sum
18+
KNAPSACK_DATA: ${{ github.workspace }}/data
2119

2220
steps:
2321
- name: Checkout code
@@ -28,16 +26,15 @@ jobs:
2826
python-version: ${{ matrix.python-version }}
2927
- name: Download data
3028
run: |
31-
python3 -m pip install gdown
29+
python3 -m pip install -r requirements.txt
3230
python3 -u scripts/download_data.py
3331
- name: Build
3432
run: |
3533
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
3634
cmake --build build --config Release --parallel
3735
cmake --install build --config Release --prefix install
3836
- name: Run unit tests
39-
working-directory: build/test
40-
run: ctest --parallel
37+
run: ctest --test-dir build/test --parallel
4138
- name: Run tests
4239
run: python3 -u scripts/run_tests.py test_results
4340
- name: Checkout main branch

‎README.md‎

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
# KnapsackSolver
22

3-
A solver for some knapsack problems:
4-
* 0-1 knapsack problem
5-
* Subset sum problem
6-
* Multiple-choice subset sum problem
3+
A solver for the 0-1 knapsack problem
74

85
![knapsack](knapsack.png?raw=true "knapsack")
96

107
[image source](https://commons.wikimedia.org/wiki/File:Knapsack.svg)
118

12-
These problems often appear as subproblems of more complex problems. For example:
13-
* To generate cuts in branch-and-cut algorithms
14-
* To solve pricing problems in column generation algorithms
15-
* To lift bin and item dimensions in packing problems
16-
17-
And therefore, having efficient algorithms with reliable implementations to solve them is very useful.
18-
19-
The goal of this repository is to provide such efficient and reliable implementations.
20-
21-
Here are some usage examples of this library:
22-
* [Lifting the length of a bin in a 3D packing problem](https://github.com/fontanf/packingsolver/blob/2cddb90686fb4a0e92f4ee1b4335ceaa2048d2f4/src/boxstacks/branching_scheme.cpp#L272)
23-
* [Solving a 0-1 knapsack subproblem inside an algorithm for a geometrical variable-sized bin packing problem](https://github.com/fontanf/packingsolver/blob/2cddb90686fb4a0e92f4ee1b4335ceaa2048d2f4/src/algorithms/dichotomic_search.hpp#L149)
24-
* Solving the pricing problem inside a column generation algorithm for the [cutting stock problem](https://github.com/fontanf/columngenerationsolver/blob/096802d9e20d2826aed5b44e3b68ac9df6b20da2/include/columngenerationsolver/examples/cutting_stock.hpp#L123), the [multiple knapsack problem](https://github.com/fontanf/columngenerationsolver/blob/096802d9e20d2826aed5b44e3b68ac9df6b20da2/include/columngenerationsolver/examples/multiple_knapsack.hpp#L154), or the [genralized assignment problem](https://github.com/fontanf/generalizedassignmentsolver/blob/68be0ab77efd897fd583f1031dd6cbc946b33f5a/src/algorithms/column_generation.cpp#L177)
25-
* [Solving a 0-1 knapsack subproblem inside an algorithm for the packing while travelling problem](https://github.com/fontanf/travellingthiefsolver/blob/ce1b6805e8aee8ee3300fbbc97dbc9153eecff01/src/packing_while_travelling/algorithms/sequential_value_correction.cpp#L19)
9+
<!--Here are some usage examples of this library:-->
10+
<!--* [Solving a 0-1 knapsack subproblem inside an algorithm for a geometrical variable-sized bin packing problem](https://github.com/fontanf/packingsolver/blob/2cddb90686fb4a0e92f4ee1b4335ceaa2048d2f4/src/algorithms/dichotomic_search.hpp#L149)-->
11+
<!--* Solving the pricing problem inside a column generation algorithm for the [cutting stock problem](https://github.com/fontanf/columngenerationsolver/blob/096802d9e20d2826aed5b44e3b68ac9df6b20da2/include/columngenerationsolver/examples/cutting_stock.hpp#L123), the [multiple knapsack problem](https://github.com/fontanf/columngenerationsolver/blob/096802d9e20d2826aed5b44e3b68ac9df6b20da2/include/columngenerationsolver/examples/multiple_knapsack.hpp#L154), or the [genralized assignment problem](https://github.com/fontanf/generalizedassignmentsolver/blob/68be0ab77efd897fd583f1031dd6cbc946b33f5a/src/algorithms/column_generation.cpp#L177)-->
12+
<!--* [Solving a 0-1 knapsack subproblem inside an algorithm for the packing while travelling problem](https://github.com/fontanf/travellingthiefsolver/blob/ce1b6805e8aee8ee3300fbbc97dbc9153eecff01/src/packing_while_travelling/algorithms/sequential_value_correction.cpp#L19)-->
2613

2714
## Implemented algorithms
2815

29-
### Knapsack
30-
3116
* Greedy
3217
* `O(n)` `-a greedy`
3318

@@ -47,25 +32,6 @@ Here are some usage examples of this library:
4732
* Primal-dual (minknap)
4833
* List (partial solution) `-a "dynamic-programming-primal-dual --partial-solution-size 64 --pairing 0"`
4934

50-
### Subset sum
51-
52-
* Dynamic programming
53-
* Bellman
54-
* Array `-a dynamic-programming-bellman-array`
55-
* List (only optimal value) `-a dynamic-programming-bellman-list`
56-
* Word RAM (only optimal value) `-a dynamic-programming-bellman-word-ram`
57-
* Word RAM with recursive scheme `-a dynamic-programming-bellman-word-ram-rec`
58-
* Balancing
59-
* Array (only optimal value) `-a dynamic-programming-balancing-array`
60-
61-
### Multiple-choice subset sum
62-
63-
* Dynamic programming
64-
* Bellman
65-
* Array `-a dynamic-programming-bellman-array`
66-
* Word RAM (only optimal value) `-a dynamic-programming-bellman-word-ram`
67-
* Word RAM with recursive scheme `-a dynamic-programming-bellman-word-ram-rec`
68-
6935
## Usage
7036

7137
### Command line
@@ -85,17 +51,13 @@ python3 scripts/download_data.py
8551
Solve:
8652

8753
```shell
88-
./install/bin/knapsacksolver_knapsack --verbosity-level 1 --algorithm dynamic-programming-primal-dual --input data/knapsack/largecoeff/knapPI_2_10000_10000000/knapPI_2_10000_10000000_50.csv --format pisinger
54+
./install/bin/knapsacksolver --verbosity-level 1 --algorithm dynamic-programming-primal-dual --input data/knapsack/largecoeff/knapPI_2_10000_10000000/knapPI_2_10000_10000000_50.csv --format pisinger
8955
```
9056
```
9157
====================================
9258
KnapsackSolver
9359
====================================
9460
95-
Problem
96-
-------
97-
Knapsack problem
98-
9961
Instance
10062
--------
10163
Number of items: 10000
@@ -205,61 +167,6 @@ Profit: 27018122468
205167
Feasible: 1
206168
```
207169

208-
```shell
209-
./install/bin/knapsacksolver_subset_sum --verbosity-level 1 --input data/subset_sum/pthree/pthree_1000_1 --algorithm dynamic-programming-bellman-word-ram-rec
210-
```
211-
```
212-
====================================
213-
KnapsackSolver
214-
====================================
215-
216-
Problem
217-
-------
218-
Subset sum problem
219-
220-
Instance
221-
--------
222-
Number of items: 1000
223-
Capacity: 250000
224-
225-
Algorithm
226-
---------
227-
Dynamic programming - Bellman - word RAM - recursive scheme
228-
229-
Parameters
230-
----------
231-
Time limit: inf
232-
Messages
233-
Verbosity level: 1
234-
Standard output: 1
235-
File path:
236-
# streams: 0
237-
Logger
238-
Has logger: 0
239-
Standard error: 0
240-
File path:
241-
242-
Time (s) Sol. Value Bound Gap Gap (%) Comment
243-
-------- ---- ----- ----- --- ------- -------
244-
0.000 1 0 250000 250000 100.00
245-
0.033 1 250000 250000 0 0.00 algorithm end (solution)
246-
247-
Final statistics
248-
----------------
249-
Value: 250000
250-
Has solution: 1
251-
Bound: 250000
252-
Absolute optimality gap: 0
253-
Relative optimality gap (%): 0
254-
Time (s): 0.0330949
255-
256-
Solution
257-
--------
258-
Number of items: 484 / 1000 (48.4%)
259-
Weight: 250000 / 250000 (100%)
260-
Feasible: 1
261-
```
262-
263170
Run tests:
264171
```
265172
export KNAPSACK_DATA=$(pwd)/data/knapsack

‎extern/CMakeLists.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ endif()
1414

1515
# Fetch googletest.
1616
if(KNAPSACKSOLVER_BUILD_TEST)
17-
FetchContent_Declare(
18-
googletest
19-
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip)
20-
# For Windows: Prevent overriding the parent project's compiler/linker settings
21-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
22-
set(INSTALL_GTEST OFF)
23-
FetchContent_MakeAvailable(googletest)
17+
FetchContent_Declare(
18+
googletest
19+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip)
20+
# For Windows: Prevent overriding the parent project's compiler/linker settings
21+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
22+
set(INSTALL_GTEST OFF)
23+
FetchContent_MakeAvailable(googletest)
2424
endif()
2525

2626
# Fetch fontanf/optimizationtools.

include/knapsacksolver/knapsack/algorithm_formatter.hpp renamed to include/knapsacksolver/algorithm_formatter.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
3+
#include "knapsacksolver/solution.hpp"
44

55
namespace knapsacksolver
66
{
7-
namespace knapsack
8-
{
97

108
class AlgorithmFormatter
119
{
@@ -63,4 +61,3 @@ class AlgorithmFormatter
6361
};
6462

6563
}
66-
}

include/knapsacksolver/knapsack/algorithms/dynamic_programming_bellman.hpp renamed to include/knapsacksolver/algorithms/dynamic_programming_bellman.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
3+
#include "knapsacksolver/solution.hpp"
44

55
namespace knapsacksolver
66
{
7-
namespace knapsack
8-
{
97

108
Output dynamic_programming_bellman_rec(
119
const Instance& instance,
@@ -157,4 +155,3 @@ Output dynamic_programming_bellman_list(
157155
const DynamicProgrammingBellmanListParameters& parameters = {});
158156

159157
}
160-
}

include/knapsacksolver/knapsack/algorithms/dynamic_programming_primal_dual.hpp renamed to include/knapsacksolver/algorithms/dynamic_programming_primal_dual.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
3+
#include "knapsacksolver/solution.hpp"
44

55
namespace knapsacksolver
66
{
7-
namespace knapsack
8-
{
97

108
struct DynamicProgrammingPrimalDualParameters: Parameters
119
{
@@ -73,4 +71,3 @@ const DynamicProgrammingPrimalDualOutput dynamic_programming_primal_dual(
7371
const DynamicProgrammingPrimalDualParameters& parameters = {});
7472

7573
}
76-
}

include/knapsacksolver/knapsack/algorithms/greedy.hpp renamed to include/knapsacksolver/algorithms/greedy.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
4-
#include "knapsacksolver/knapsack/sort.hpp"
3+
#include "knapsacksolver/solution.hpp"
4+
#include "knapsacksolver/sort.hpp"
55

66
namespace knapsacksolver
77
{
8-
namespace knapsack
9-
{
108

119
Output trivial(
1210
const Instance& instance,
@@ -49,4 +47,3 @@ Output greedy(
4947
const GreedyParameters& parameters = {});
5048

5149
}
52-
}

include/knapsacksolver/knapsack/algorithms/surrogate_relaxation.hpp renamed to include/knapsacksolver/algorithms/surrogate_relaxation.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
3+
#include "knapsacksolver/solution.hpp"
44

55
namespace knapsacksolver
66
{
7-
namespace knapsack
8-
{
97

108
using SolveCallback = std::function<Output(const Instance&)>;
119

@@ -19,4 +17,3 @@ Output surrogate_relaxation(
1917
const SurrogateRelaxationParameters& parameters = {});
2018

2119
}
22-
}

include/knapsacksolver/knapsack/algorithms/upper_bound_dantzig.hpp renamed to include/knapsacksolver/algorithms/upper_bound_dantzig.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/solution.hpp"
4-
#include "knapsacksolver/knapsack/sort.hpp"
3+
#include "knapsacksolver/solution.hpp"
4+
#include "knapsacksolver/sort.hpp"
55

66
namespace knapsacksolver
77
{
8-
namespace knapsack
9-
{
108

119
struct UpperBoundDantzigParameters: Parameters
1210
{
@@ -44,4 +42,3 @@ Output upper_bound_dantzig(
4442
const UpperBoundDantzigParameters& parameters = {});
4543

4644
}
47-
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#pragma once
22

3-
#include "knapsacksolver/knapsack/instance.hpp"
3+
#include "knapsacksolver/instance.hpp"
44

55
#include <random>
66

77
namespace knapsacksolver
88
{
9-
namespace knapsack
10-
{
119

1210
Instance generate_u(
1311
ItemPos number_of_items,
@@ -17,4 +15,3 @@ Instance generate_u(
1715
std::mt19937_64& generator);
1816

1917
}
20-
}

0 commit comments

Comments
 (0)