Build binary
mkdir bin; g++ --std=c++11 src/bb_knap.cpp -o bin/knapsack
Note: tested on python3.6
, the only requirement is click
library.
$ python cli/main.py
Choose a problem instance: 1) ks_60_0 2) ks_4_0 3) ks_45_0 4) ks_30_0 5) ks_lecture_dp_2 6) ks_10000_0 7) ks_300_0 8) ks_200_0 9) ks_100_1 10) ks_100_0 11) ks_200_1 12) ks_500_0 13) ks_400_0 14) ks_lecture_dp_1 15) ks_19_0 16) ks_100_2 17) ks_106_0 18) ks_40_0 19) ks_82_0 20) ks_50_0 21) ks_50_1 22) ks_1000_0
1
./data/ks_60_0
99837 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The first line contains 2 integers: n
the number of lines i.e. the number of items and K
the capacity of the knapsack.
The n
next lines contain 2 integers: the value and the weight of an item.
n K
v_0 w_0
v_1 w_1
...
v_n-1 w_n-1
4 11
84 10
5 15
8 43
The first line contains 2 integers obj
which is the value of the knapsack i.e. the sum of the values of each items in the knapsack. The second integer opt
is either 0 or 1, 1 if obj
is the global optimum (proven), 0 else. The second (and last) line contains n
integers (the number of items) with a value of
1 if the item is in the knapsack or 0 else.
obj opt
x_0 x_1 x_2 ... x_n-1
19 0
0 0 1 1